Skip to content

Commit

Permalink
Tidy up presenation of form data
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpchi committed Sep 23, 2024
1 parent 75b6f13 commit d16f375
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 19 deletions.
6 changes: 3 additions & 3 deletions classes/local/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class user {
/**
* Is this user working in the jobshop
*
* @var boolean
* @var bool
*/
private $isjobshopuser;

Expand Down Expand Up @@ -250,15 +250,15 @@ public function course_search($coursesearch) {
[$andsql, $andparams] = $this->get_course_filter();

$params += $andparams;
$sql = "SELECT c.id, c.idnumber, c.shortname, c.fullname, c.startdate as startunix
$sql = "SELECT c.id, c.idnumber, c.shortname, c.fullname, c.startdate as startunix, c.enddate as endunix
FROM {course} c
JOIN {course_categories} cc on c.category = cc.id
WHERE ({$coursesearch1like} OR {$coursesearch2like})
$andsql
AND c.id {$inorequalsql}
AND ({$moduleslike} OR {$courseslike})
AND c.visible = 1
ORDER BY c.shortname DESC";
ORDER BY c.startdate DESC, c.shortname ASC";
$courses = $DB->get_records_sql($sql, $params);

return $courses;
Expand Down
18 changes: 13 additions & 5 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,33 @@ public function definition() {

// Then loop through that array and check for roles.
$radioarray = [];
$ccount = 0;
foreach ($courses as $course) {
$odd = $ccount & 1;
$style = $odd ? 'background-color: var(--gray-200)' : 'background-color: var(--gray-100)';
$fullname = explode('(Start', $course->fullname);
$courselabel = get_string('courselabel', 'local_enrolstaff', [
'idnumber' => $course->idnumber,
'fullname' => $fullname[0],
'startunix' => date('d/m/Y', $course->startunix)]);
'startunix' => date('d/m/Y', $course->startunix),
'endunix' => date('d/m/Y', $course->endunix),
]);
if (array_key_exists($course->id, $coursearray)) {
$style = 'background-color: var(--teal)';
$radioarray[] =& $mform->createElement('radio', 'course', '',
$courselabel .
get_string('existingroles', 'local_enrolstaff', rtrim($coursearray[$course->id], ", ")),
'<div class="w-100 p-1" style="' . $style . '">' . $courselabel .
'<br>' . get_string('existingroles', 'local_enrolstaff', rtrim($coursearray[$course->id], ", ")) .
'</div>',
$course->id, 'disabled');
} else {
$radioarray[] =& $mform->createElement('radio', 'course', '',
$courselabel, $course->id, 'required');
'<div class="w-100 p-1" style="' . $style . '">' . $courselabel . '</div>', $course->id, 'required');
}
$ccount++;
}

$mform->addGroup($radioarray, 'radioar', get_string('selectamodule', 'local_enrolstaff'),
['<br /><br />', '<br /><br />'], false);
'<br />', false);
$mform->addGroupRule('radioar', get_string('required'), 'required');
$mform->addElement('hidden', 'action', 'role_select');
$mform->setType('action', PARAM_ALPHANUMEXT);
Expand Down
2 changes: 1 addition & 1 deletion lang/en/local_enrolstaff.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
$string['codesbcas'] = "Comma separated list of BCAS module code prefixes";
$string['codesqahe'] = "Comma separated list of QAHE module code prefixes";
$string['commaseparatedlist'] = 'Comma separated list';
$string['courselabel'] = '{$a->idnumber} - {$a->fullname} - Start date: {$a->startunix}';
$string['courselabel'] = '{$a->idnumber}<br />{$a->fullname}</br />Start/End: {$a->startunix} - {$a->endunix}';
$string['coursesearch'] = "Module code";
$string['currentcourses'] = 'Current enrolments';

Expand Down
82 changes: 72 additions & 10 deletions tests/helper_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,83 @@

namespace local_enrolstaff;

use core_course_category;
use stdClass;

/**
* Some reusable components for unit tests
*/
trait helper_trait {

public $moduleleader;
public $qamoduleleader;
public $coursescat;
public $modulescat;
public $levelscat;
public $otherscat;
public $courses;
public $teachingroles;
public $qateachingroles;
public $users;
/**
* Module leader role
*
* @var int
*/
public int $moduleleader;

/**
* QA module leader role
*
* @var int
*/
public int $qamoduleleader;

/**
* Courses category
*
* @var core_course_category
*/
public core_course_category $coursescat;

/**
* Modules category
*
* @var core_course_category
*/
public core_course_category $modulescat;

/**
* Levels category
*
* @var core_course_category
*/
public core_course_category $levelscat;

/**
* Others category
*
* @var core_course_category
*/
public core_course_category $otherscat;

/**
* Courses/Modules
*
* @var array
*/
public array $courses;

/**
* Teaching role
*
* @var array
*/
public array $teachingroles;

/**
* Qa teaching roles
*
* @var array
*/
public array $qateachingroles;

/**
* Users
*
* @var array
*/
public array $users;

/**
* Sets up roles and role settings for plugins
Expand Down

0 comments on commit d16f375

Please sign in to comment.