Skip to content

Commit

Permalink
auto-correct PHP code linter errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopfstedt committed Jun 3, 2024
1 parent b61b61f commit 1efafa0
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 188 deletions.
18 changes: 9 additions & 9 deletions classes/form/create_sync_job.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ public function definition() {
return;
}

$role_options = array();
$roleoptions = [];
foreach ($roles as $role) {
$role_options[$role->id] = $role->localname;
$roleoptions[$role->id] = $role->localname;
}

try {
$ilios_client = manager::instantiate_ilios_client();
$access_token = manager::get_config('apikey', '');
$ilios_schools = $ilios_client->get($access_token, 'schools');
if (!empty($ilios_schools)) {
$ilios_schools = array_column($ilios_schools, 'title', 'id');
$iliosclient = manager::instantiate_ilios_client();
$accesstoken = manager::get_config('apikey', '');
$iliosschools = $iliosclient->get($accesstoken, 'schools');
if (!empty($iliosschools)) {
$iliosschools = array_column($iliosschools, 'title', 'id');
}
} catch (\Exception $e) {
$warning = $renderer->notify_error(get_string('ilioserror', 'tool_ilioscategoryassignment'));
Expand All @@ -79,11 +79,11 @@ public function definition() {
$mform->addElement('select', 'categoryid', get_string('selectcategory', 'tool_ilioscategoryassignment'), $categories);
$mform->addRule('categoryid', null, 'required', null, 'client');

$mform->addElement('select', 'roleid', get_string('selectrole', 'tool_ilioscategoryassignment'), $role_options);
$mform->addElement('select', 'roleid', get_string('selectrole', 'tool_ilioscategoryassignment'), $roleoptions);
$mform->addRule('roleid', null, 'required', null, 'client');

$mform->addElement('select', 'iliosschoolid', get_string('selectiliosschool', 'tool_ilioscategoryassignment'),
$ilios_schools);
$iliosschools);
$mform->addRule('iliosschoolid', null, 'required', null, 'client');

$this->add_action_buttons(false, get_string('submit'));
Expand Down
48 changes: 24 additions & 24 deletions classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class manager {
* @throws \moodle_exception
*/
public static function instantiate_ilios_client(): ilios_client {
return new ilios_client(manager::get_config('host_url', ''), new curl());
return new ilios_client(self::get_config('host_url', ''), new curl());
}

/**
Expand All @@ -46,7 +46,7 @@ public static function instantiate_ilios_client(): ilios_client {
* @throws \dml_exception
*/
public static function get_sync_job($id) {
$jobs = self::get_sync_jobs(array('id' => $id));
$jobs = self::get_sync_jobs(['id' => $id]);
return empty($jobs) ? null : $jobs[0];
}

Expand Down Expand Up @@ -103,13 +103,13 @@ public static function set_config($name, $value) {
* @return sync_job[]
* @throws \dml_exception
*/
public static function get_sync_jobs(array $filters = array()) {
public static function get_sync_jobs(array $filters = []) {
global $DB;
$jobs = array();
$job_recs = $DB->get_records('tool_ilioscatassignment', $filters);
foreach ($job_recs as $job_rec) {
$jobs[] = new sync_job($job_rec->id, $job_rec->title, $job_rec->roleid, $job_rec->coursecatid,
(boolean) $job_rec->enabled, $job_rec->schoolid);
$jobs = [];
$jobrecs = $DB->get_records('tool_ilioscatassignment', $filters);
foreach ($jobrecs as $jobrec) {
$jobs[] = new sync_job($jobrec->id, $jobrec->title, $jobrec->roleid, $jobrec->coursecatid,
(boolean) $jobrec->enabled, $jobrec->schoolid);
}

return $jobs;
Expand All @@ -120,13 +120,13 @@ public static function get_sync_jobs(array $filters = array()) {
*
* @throws \dml_exception
*/
public static function disable_job($job_id) {
public static function disable_job($jobid) {
global $DB;
$table_name = 'tool_ilioscatassignment';
$job = $DB->get_record($table_name, array('id' => $job_id));
$tablename = 'tool_ilioscatassignment';
$job = $DB->get_record($tablename, ['id' => $jobid]);
if (!empty($job)) {
$job->enabled = false;
$DB->update_record($table_name, $job);
$DB->update_record($tablename, $job);
}
}

Expand All @@ -135,13 +135,13 @@ public static function disable_job($job_id) {
*
* @throws \dml_exception
*/
public static function enable_job($job_id) {
public static function enable_job($jobid) {
global $DB;
$table_name = 'tool_ilioscatassignment';
$job = $DB->get_record($table_name, array('id' => $job_id));
$tablename = 'tool_ilioscatassignment';
$job = $DB->get_record($tablename, ['id' => $jobid]);
if (!empty($job)) {
$job->enabled = true;
$DB->update_record($table_name, $job);
$DB->update_record($tablename, $job);
}
}

Expand All @@ -160,8 +160,8 @@ public static function create_job(sync_job $job) {
$dto->enabled = $job->is_enabled();
$dto->schoolid = $job->get_school_id();

$job_id = $DB->insert_record('tool_ilioscatassignment', $dto);
return self::get_sync_job($job_id);
$jobid = $DB->insert_record('tool_ilioscatassignment', $dto);
return self::get_sync_job($jobid);
}

/**
Expand All @@ -171,24 +171,24 @@ public static function create_job(sync_job $job) {
* @throws \dml_exception
* @throws \moodle_exception
*/
public static function delete_job($job_id) {
public static function delete_job($jobid) {
global $DB;
$job = self::get_sync_job($job_id);
$job = self::get_sync_job($jobid);
if (empty($job)) {
return;
}

// delete the given job
$DB->delete_records('tool_ilioscatassignment', array('id' => $job_id));
$DB->delete_records('tool_ilioscatassignment', ['id' => $jobid]);

// remove any course category role assignments that were managed by the given job
$category = core_course_category::get($job->get_course_category_id(), IGNORE_MISSING);
if (empty($category)) {
return;
}
$context = $category->get_context();
role_unassign_all(array('component' => 'tool_ilioscategoryassignment', 'roleid' => $job->get_role_id(),
'contextid' => $context->id));
role_unassign_all(['component' => 'tool_ilioscategoryassignment', 'roleid' => $job->get_role_id(),
'contextid' => $context->id]);
}

/**
Expand All @@ -203,7 +203,7 @@ public static function delete_job($job_id) {
*/
public static function course_category_deleted(course_category_deleted $event) {
$category = $event->get_coursecat();
$jobs = self::get_sync_jobs(array('coursecatid' => $category->id));
$jobs = self::get_sync_jobs(['coursecatid' => $category->id]);
foreach ($jobs as $job) {
self::delete_job($job->get_id());
}
Expand Down
56 changes: 28 additions & 28 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,75 +46,75 @@ class renderer extends plugin_renderer_base {
* @throws coding_exception
* @throws moodle_exception
*/
public function sync_jobs_table(array $sync_jobs, array $course_categories, array $roles, array $ilios_schools) {
public function sync_jobs_table(array $syncjobs, array $coursecategories, array $roles, array $iliosschools) {
global $CFG;
$table = new html_table();
$table->head = array(
$table->head = [
get_string('title', 'tool_ilioscategoryassignment'),
get_string('coursecategory'),
get_string('role'),
get_string('iliosschool', 'tool_ilioscategoryassignment'),
get_string('actions')
);
get_string('actions'),
];
$table->attributes['class'] = 'admintable generaltable';
$data = array();
$data = [];

foreach ($sync_jobs as $job) {
foreach ($syncjobs as $job) {
$titlecell = new html_table_cell($job->get_title());
$titlecell->header = true;

$course_category_id = $job->get_course_category_id();
$course_title = get_string('notfound', 'tool_ilioscategoryassignment', $course_category_id);
if (!empty($course_categories[$course_category_id])) {
$course_title = $course_categories[$course_category_id]->get_nested_name();
$coursecategoryid = $job->get_course_category_id();
$coursetitle = get_string('notfound', 'tool_ilioscategoryassignment', $coursecategoryid);
if (!empty($coursecategories[$coursecategoryid])) {
$coursetitle = $coursecategories[$coursecategoryid]->get_nested_name();
}
$coursecatcell = new html_table_cell($course_title);
$coursecatcell = new html_table_cell($coursetitle);

$role_id = $job->get_role_id();
$role_title = get_string('notfound', 'tool_ilioscategoryassignment', $role_id);
if (array_key_exists($role_id, $roles)) {
$role_title = $roles[$role_id]->localname;
$roleid = $job->get_role_id();
$roletitle = get_string('notfound', 'tool_ilioscategoryassignment', $roleid);
if (array_key_exists($roleid, $roles)) {
$roletitle = $roles[$roleid]->localname;
}
$rolecell = new html_table_cell($role_title);
$rolecell = new html_table_cell($roletitle);

$ilios_school_id = $job->get_school_id();
$ilios_school_title = get_string('notfound', 'tool_ilioscategoryassignment', $ilios_school_id);
if (array_key_exists($ilios_school_id, $ilios_schools)) {
$ilios_school_title = $ilios_schools[$ilios_school_id];
$iliosschoolid = $job->get_school_id();
$iliosschooltitle = get_string('notfound', 'tool_ilioscategoryassignment', $iliosschoolid);
if (array_key_exists($iliosschoolid, $iliosschools)) {
$iliosschooltitle = $iliosschools[$iliosschoolid];
}

$iliosschoolcell = new html_table_cell($ilios_school_title);
$iliosschoolcell = new html_table_cell($iliosschooltitle);

$actions = array();
$actions = [];
if ($job->is_enabled()) {
$actions[] = $this->action_icon(
new moodle_url("$CFG->wwwroot/$CFG->admin/tool/ilioscategoryassignment/index.php",
array('job_id' => $job->get_id(), 'action' => 'disable', 'sesskey' => sesskey())),
['job_id' => $job->get_id(), 'action' => 'disable', 'sesskey' => sesskey()]),
new pix_icon('t/hide', new lang_string('disable'))
);
} else {
$actions[] = $this->action_icon(
new moodle_url("$CFG->wwwroot/$CFG->admin/tool/ilioscategoryassignment/index.php",
array('job_id' => $job->get_id(), 'action' => 'enable', 'sesskey' => sesskey())),
['job_id' => $job->get_id(), 'action' => 'enable', 'sesskey' => sesskey()]),
new pix_icon('t/show', new lang_string('enable'))
);
}

$actions[] = $this->action_icon(
new moodle_url("$CFG->wwwroot/$CFG->admin/tool/ilioscategoryassignment/index.php",
array('job_id' => $job->get_id(), 'action' => 'delete', 'sesskey' => sesskey())),
['job_id' => $job->get_id(), 'action' => 'delete', 'sesskey' => sesskey()]),
new pix_icon('t/delete', new lang_string('delete'))
);

$actionscell = new html_table_cell(implode(' ', $actions));

$row = new html_table_row(array(
$row = new html_table_row([
$titlecell,
$coursecatcell,
$rolecell,
$iliosschoolcell,
$actionscell
));
$actionscell,
]);
$data[] = $row;
}
$table->data = $data;
Expand Down
34 changes: 19 additions & 15 deletions classes/sync_job.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,39 @@
class sync_job {
/** @var int $id */
protected $id;

/** @var string $title */
protected $title;

/** @var int $role_id */
protected $role_id;
/** @var int $course_category_id */
protected $course_category_id;
protected $roleid;

/** @var int $coursecategoryid */
protected $coursecategoryid;

/** @var bool $enabled */
protected $enabled;
/** @var int $school_id */
protected $school_id;

/** @var int $school_id */
protected $schoolid;

/**
* sync_job constructor.
* Constructor.
*
* @param $id
* @param $title
* @param $role_id
* @param $roleid
* @param $course_category_id
* @param $enabled
* @param $school_id
* @param $schoolid
*/
public function __construct($id, $title, $role_id, $course_category_id, $enabled, $school_id) {
public function __construct($id, $title, $roleid, $coursecategoryid, $enabled, $schoolid) {
$this->id = $id;
$this->title = $title;
$this->role_id = $role_id;
$this->course_category_id = $course_category_id;
$this->roleid = $roleid;
$this->coursecategoryid = $coursecategoryid;
$this->enabled = $enabled;
$this->school_id = $school_id;
$this->schoolid = $schoolid;
}

/**
Expand All @@ -60,21 +64,21 @@ public function get_title() {
* @return int
*/
public function get_role_id() {
return $this->role_id;
return $this->roleid;
}

/**
* @return int
*/
public function get_school_id() {
return $this->school_id;
return $this->schoolid;
}

/**
* @return int
*/
public function get_course_category_id() {
return $this->course_category_id;
return $this->coursecategoryid;
}

/**
Expand Down
Loading

0 comments on commit 1efafa0

Please sign in to comment.