diff --git a/classes/form/create_sync_job.php b/classes/form/create_sync_job.php
index 4b0e35f..0b614ca 100644
--- a/classes/form/create_sync_job.php
+++ b/classes/form/create_sync_job.php
@@ -1,9 +1,25 @@
.
+
/**
* Form for creating a new sync job.
*
- * @package tool_ilioscategoryassignment
- * @category form
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_ilioscategoryassignment\form;
@@ -11,30 +27,31 @@
defined('MOODLE_INTERNAL') || die();
use core_course_category;
+use Exception;
+use moodle_page;
use moodleform;
use tool_ilioscategoryassignment\manager;
use tool_ilioscategoryassignment\output\renderer;
-/* @global $CFG */
require_once($CFG->libdir . '/accesslib.php');
require_once($CFG->libdir . '/formslib.php');
/**
- * Form for creating a new sync job.
+ * New sync job form class.
*
- * @package tool_ilioscategoryassignment
- * @category form
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class create_sync_job extends moodleform {
-
/**
- * @inheritdoc
+ * Form definition.
*/
- public function definition() {
- /* @var \moodle_page $PAGE */
+ public function definition(): void {
+ /* @var moodle_page $PAGE The current page. */
global $PAGE;
- /* @var renderer $renderer */
+ /* @var renderer $renderer The plugin renderer. */
$renderer = $PAGE->get_renderer('tool_ilioscategoryassignment');
$mform = $this->_form;
@@ -65,13 +82,14 @@ public function definition() {
if (!empty($iliosschools)) {
$iliosschools = array_column($iliosschools, 'title', 'id');
}
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$warning = $renderer->notify_error(get_string('ilioserror', 'tool_ilioscategoryassignment'));
$mform->addElement('html', $warning);
return;
}
- $mform->addElement('text', 'title', get_string('title', 'tool_ilioscategoryassignment')); // Add elements to your form
+ // Add elements to your form.
+ $mform->addElement('text', 'title', get_string('title', 'tool_ilioscategoryassignment'));
$mform->setType('title', PARAM_NOTAGS);
$mform->addRule('title', null, 'required', null, 'client');
$mform->addRule('title', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
diff --git a/classes/manager.php b/classes/manager.php
index d6e7a25..aaa1f4f 100644
--- a/classes/manager.php
+++ b/classes/manager.php
@@ -1,49 +1,70 @@
.
/**
* Handles sync job, configuration and Ilios client management.
*
- * @package tool_ilioscategoryassignment
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_ilioscategoryassignment;
-/* @global $CFG */
+use coding_exception;
use core\event\course_category_deleted;
use core_course_category;
use curl;
+use dml_exception;
use local_iliosapiclient\ilios_client;
+use moodle_exception;
+use stdClass;
+
+defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/accesslib.php');
/**
- * Handles sync job, configuration and Ilios client management.
+ * Handler class for sync job, configuration and Ilios client management.
*
- * In other words, this is kitchen sink.
+ * In other words, this is the kitchen sink.
* This is obviously less than ideal, but still better than polluting the global namespace with functions in locallib.php.
* [ST 2017/07/24]
*
- * @package tool_ilioscategoryassignment
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manager {
-
- const PLUGIN_NAME = 'tool_ilioscategoryassignment';
-
/**
* Instantiates and returns an Ilios API client.
*
* @return ilios_client
- * @throws \moodle_exception
+ * @throws moodle_exception
*/
public static function instantiate_ilios_client(): ilios_client {
return new ilios_client(self::get_config('host_url', ''), new curl());
}
/**
- * @param $id
+ * Retrieves a sync job by its given ID.
*
- * @return sync_job|null
- * @throws \dml_exception
+ * @param int $id The sync job ID.
+ * @return sync_job|null The sync job, or NULL if none were found.
+ * @throws dml_exception
*/
public static function get_sync_job($id) {
$jobs = self::get_sync_jobs(['id' => $id]);
@@ -53,26 +74,25 @@ public static function get_sync_job($id) {
/**
* Loads, caches and returns the configuration for this plugin.
*
- * @return \stdClass
+ * @return stdClass The plugin configuration object.
* @see get_config()
- * @throws \dml_exception
+ * @throws dml_exception
*/
public static function get_plugin_config() {
static $config = null;
if (!isset($config)) {
- $config = get_config(self::PLUGIN_NAME);
+ $config = get_config('tool_ilioscategoryassignment');
}
return $config;
}
/**
- * Returns a configuration value by its given name or a given default value.
- *
- * @param string $name
- * @param string $default value if config does not exist yet
+ * Returns a configuration item by its given name or a given default value.
*
- * @return string value or default
- * @throws \dml_exception
+ * @param string $name The config item name.
+ * @param string $default A default value if the config item does not exist.
+ * @return mixed The config value or the given default value.
+ * @throws dml_exception
*/
public static function get_config($name, $default = null) {
$config = self::get_plugin_config();
@@ -82,28 +102,29 @@ public static function get_config($name, $default = null) {
/**
* Sets and stores a given config value.
*
- * @param string $name name of config
- * @param string $value string config value, null means delete
- *
- * @throws \dml_exception
+ * @param string $name The config item name.
+ * @param string $value string The config item's value, NULL means unset the config item.
+ * @return void
+ * @throws dml_exception
*/
- public static function set_config($name, $value) {
+ public static function set_config($name, $value): void {
$config = self::get_plugin_config();
if ($value === null) {
unset($config->$name);
} else {
$config->$name = $value;
}
- set_config($name, $value, self::PLUGIN_NAME);
+ set_config($name, $value, 'tool_ilioscategoryassignment');
}
/**
- * @param array $filters
+ * Retrieves all sync jobs matching the given filters.
*
- * @return sync_job[]
- * @throws \dml_exception
+ * @param array $filters The filter criteria.
+ * @return array A list of sync jobs.
+ * @throws dml_exception
*/
- public static function get_sync_jobs(array $filters = []) {
+ public static function get_sync_jobs(array $filters = []): array {
global $DB;
$jobs = [];
$jobrecs = $DB->get_records('tool_ilioscatassignment', $filters);
@@ -116,11 +137,13 @@ public static function get_sync_jobs(array $filters = []) {
}
/**
- * @param int $job_id
+ * Disables a given sync job.
*
- * @throws \dml_exception
+ * @param int $jobid The job ID.
+ * @return void
+ * @throws dml_exception
*/
- public static function disable_job($jobid) {
+ public static function disable_job($jobid): void {
global $DB;
$tablename = 'tool_ilioscatassignment';
$job = $DB->get_record($tablename, ['id' => $jobid]);
@@ -131,11 +154,13 @@ public static function disable_job($jobid) {
}
/**
- * @param int $job_id
+ * Enables a given sync job.
*
- * @throws \dml_exception
+ * @param int $jobid The job ID.
+ * @return void
+ * @throws dml_exception
*/
- public static function enable_job($jobid) {
+ public static function enable_job($jobid): void {
global $DB;
$tablename = 'tool_ilioscatassignment';
$job = $DB->get_record($tablename, ['id' => $jobid]);
@@ -146,14 +171,15 @@ public static function enable_job($jobid) {
}
/**
- * @param sync_job $job
- *
- * @return sync_job
- * @throws \dml_exception
+ * Creates and returns a new sync job.
+ * @param sync_job $job The new sync job to create.
+ * @return sync_job The created sync job.
+ * @throws dml_exception
*/
public static function create_job(sync_job $job) {
global $DB;
- $dto = new \stdClass();
+
+ $dto = new stdClass();
$dto->title = $job->get_title();
$dto->roleid = $job->get_role_id();
$dto->coursecatid = $job->get_course_category_id();
@@ -165,23 +191,25 @@ public static function create_job(sync_job $job) {
}
/**
- * @param int $job_id
+ * Deletes a given sync job.
*
- * @throws \coding_exception
- * @throws \dml_exception
- * @throws \moodle_exception
+ * @param int $jobid The sync job ID.
+ * @return void
+ * @throws coding_exception
+ * @throws dml_exception
+ * @throws moodle_exception
*/
- public static function delete_job($jobid) {
+ public static function delete_job($jobid): void {
global $DB;
$job = self::get_sync_job($jobid);
if (empty($job)) {
return;
}
- // delete the given job
+ // Delete the given job.
$DB->delete_records('tool_ilioscatassignment', ['id' => $jobid]);
- // remove any course category role assignments that were managed by the given job
+ // 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;
@@ -195,13 +223,13 @@ public static function delete_job($jobid) {
* Event observer for the "course category deleted" event.
* Removes any sync jobs and role assignments associated with that category.
*
- * @param \core\event\course_category_deleted $event
- *
- * @throws \coding_exception
- * @throws \dml_exception
- * @throws \moodle_exception
+ * @param course_category_deleted $event
+ * @return void
+ * @throws coding_exception
+ * @throws dml_exception
+ * @throws moodle_exception
*/
- public static function course_category_deleted(course_category_deleted $event) {
+ public static function course_category_deleted(course_category_deleted $event): void {
$category = $event->get_coursecat();
$jobs = self::get_sync_jobs(['coursecatid' => $category->id]);
foreach ($jobs as $job) {
diff --git a/classes/output/renderer.php b/classes/output/renderer.php
index 7642e5d..d111050 100644
--- a/classes/output/renderer.php
+++ b/classes/output/renderer.php
@@ -1,4 +1,26 @@
.
+
+/**
+ * Output renderer for the plugin.
+ *
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
namespace tool_ilioscategoryassignment\output;
@@ -19,34 +41,25 @@
use function sesskey;
/**
- * Output renderer for the plugin.
+ * Output renderer class.
*
- * @package tool_ilioscategoryassignment
- * @category output
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-/**
- * Output renderer for the plugin.
- *
- * @package tool_ilioscategoryassignment
- * @category output
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Renders a table displaying all configured sync jobs.
*
- * @param sync_job[] $sync_jobs
- * @param core_course_category[] $course_categories
+ * @param sync_job[] $syncjobs
+ * @param core_course_category[] $coursecategories
* @param stdClass[] $roles
- * @param string[] $ilios_schools
- *
+ * @param string[] $iliosschools
* @return string HTML to output.
* @throws coding_exception
* @throws moodle_exception
*/
- public function sync_jobs_table(array $syncjobs, array $coursecategories, array $roles, array $iliosschools) {
+ public function sync_jobs_table(array $syncjobs, array $coursecategories, array $roles, array $iliosschools): string {
global $CFG;
$table = new html_table();
$table->head = [
@@ -124,7 +137,7 @@ public function sync_jobs_table(array $syncjobs, array $coursecategories, array
/**
* Renders and returns a notification.
*
- * @param string $message the message
+ * @param string $message The message.
* @return string The formatted message.
*/
public function notify_info($message) {
@@ -135,7 +148,7 @@ public function notify_info($message) {
/**
* Renders and returns an error notification.
*
- * @param string $message the message
+ * @param string $message The message.
* @return string The formatted message.
*/
public function notify_error($message) {
@@ -146,7 +159,7 @@ public function notify_error($message) {
/**
* Renders and returns a success notification.
*
- * @param string $message the message
+ * @param string $message The message.
* @return string The formatted message.
*/
public function notify_success($message) {
diff --git a/classes/sync_job.php b/classes/sync_job.php
index f2add34..e91d459 100644
--- a/classes/sync_job.php
+++ b/classes/sync_job.php
@@ -1,41 +1,76 @@
.
+
+/**
+ * Defines the sync job model.
+ *
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
namespace tool_ilioscategoryassignment;
/**
- * Sync job definition model.
+ * Sync job model class.
*
- * @package tool_ilioscategoryassignment
- * @category model
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sync_job {
- /** @var int $id */
+ /**
+ * @var int $id The sync job ID.
+ */
protected $id;
- /** @var string $title */
+ /**
+ * @var string $title The sync job title.
+ */
protected $title;
- /** @var int $role_id */
+ /**
+ * @var int $role_id The Moodle user role ID to assign to users during sync.
+ */
protected $roleid;
- /** @var int $coursecategoryid */
+ /**
+ * @var int $coursecategoryid The Moodle course category ID to sync users into.
+ */
protected $coursecategoryid;
- /** @var bool $enabled */
+ /**
+ * @var bool $enabled TRUE if this job is enabled, otherwise FALSE.
+ */
protected $enabled;
- /** @var int $school_id */
+ /**
+ * @var int $schoolid The Ilios school ID to sync users from.
+ */
protected $schoolid;
/**
* Constructor.
*
- * @param $id
- * @param $title
- * @param $roleid
- * @param $course_category_id
- * @param $enabled
- * @param $schoolid
+ * @param int $id The sync job Id.
+ * @param string $title The sync job title.
+ * @param int $roleid The Moodle user role ID to assign to users during sync.
+ * @param int $coursecategoryid The Moodle course category ID to sync users into.
+ * @param bool $enabled TRUE if this job is enabled, otherwise FALSE.
+ * @param int $schoolid The Ilios school ID to sync users from.
*/
public function __construct($id, $title, $roleid, $coursecategoryid, $enabled, $schoolid) {
$this->id = $id;
@@ -47,58 +82,74 @@ public function __construct($id, $title, $roleid, $coursecategoryid, $enabled, $
}
/**
- * @return int
+ * Returns the sync job ID.
+ *
+ * @return int The sync job ID.
*/
public function get_id() {
return $this->id;
}
/**
- * @return string
+ * Returns the sync job title.
+ *
+ * @return string The sync job title.
*/
public function get_title() {
return $this->title;
}
/**
- * @return int
+ * Returns the Moodle user role ID.
+ *
+ * @return int The user role ID.
*/
public function get_role_id() {
return $this->roleid;
}
/**
- * @return int
+ * Returns the Ilios school ID.
+ *
+ * @return int The school ID.
*/
public function get_school_id() {
return $this->schoolid;
}
/**
- * @return int
+ * Returns the Moodle course category ID.
+ *
+ * @return int The course category ID.
*/
public function get_course_category_id() {
return $this->coursecategoryid;
}
/**
- * @return bool
+ * Returns whether this sync job is enabled or not.
+ *
+ * @return bool TRUE if this job is enabled, otherwise FALSE.
*/
public function is_enabled() {
return $this->enabled;
}
/**
- * @param string $prop
- * @return mixed
+ * Magic getter function.
+ *
+ * @param string $prop The property name.
+ * @return mixed The property value.
*/
public function __get($prop) {
return $this->$prop;
}
/**
- * @param string $prop
- * @return bool
+ * Determine if a variable is declared and is different from NULL.
+ *
+ * @param string $prop The property name.
+ * @return bool TRUE if the property is declared/set, FALSE otherwise.
*/
public function __isset($prop) {
return isset($this->$prop);
diff --git a/classes/task/sync_task.php b/classes/task/sync_task.php
index 18011e3..67cbb00 100644
--- a/classes/task/sync_task.php
+++ b/classes/task/sync_task.php
@@ -1,43 +1,72 @@
.
+
/**
* A scheduled task for syncing users with Ilios.
*
- * @package tool_ilioscategoryassignment
- * @category task
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_ilioscategoryassignment\task;
+use coding_exception;
use core\task\scheduled_task;
use core_course_category;
+use dml_exception;
+use Exception;
use local_iliosapiclient\ilios_client;
+use moodle_exception;
+use stdClass;
use tool_ilioscategoryassignment\manager;
use tool_ilioscategoryassignment\sync_job;
-/* @global $CFG */
+defined('MOODLE_INTERNAL') || die();
+
require_once($CFG->libdir . '/accesslib.php');
/**
- * A scheduled task for syncing users with Ilios.
+ * The scheduled task class.
*
- * @package tool_ilioscategoryassignment
- * @category task
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sync_task extends scheduled_task {
-
/**
- * @inheritdoc
+ * Returns the task name.
+ *
+ * @return string The task name.
+ * @throws coding_exception
*/
public function get_name() {
return get_string('taskname', 'tool_ilioscategoryassignment');
}
/**
- * @inheritdoc
+ * Executes this task.
+ *
+ * @return void
+ * @throws dml_exception
+ * @throws moodle_exception
+ * @throws exception
*/
- public function execute() {
-
- // this may take a while and consume quite a bit of memory...
+ public function execute(): void {
+ // This may take a while and consume quite a bit of memory.
@set_time_limit(0);
raise_memory_limit(MEMORY_HUGE);
@@ -50,14 +79,14 @@ public function execute() {
try {
$iliosclient = manager::instantiate_ilios_client();
- } catch (\Exception $e) {
- // re-throw exception
- throw new \Exception('ERROR: Failed to instantiate Ilios client.' . 0, $e);
+ } catch (Exception $e) {
+ // Re-throw exception.
+ throw new Exception('ERROR: Failed to instantiate Ilios client.' . 0, $e);
}
$accesstoken = manager::get_config('apikey', '');
- // run enabled each sync job
+ // Run enabled each sync job.
foreach ($syncjobs as $syncjob) {
$this->run_sync_job($syncjob, $accesstoken, $iliosclient);
}
@@ -66,30 +95,31 @@ public function execute() {
}
/**
- * @return sync_job[]
- * @throws \dml_exception
+ * Retrieves the list of enabled sync jobs.
+ *
+ * @return array A list of enabled sync jobs.
+ * @throws dml_exception
*/
- protected function get_enabled_sync_jobs() {
+ protected function get_enabled_sync_jobs(): array {
return manager::get_sync_jobs(['enabled' => true]);
}
/**
* Performs a given sync job.
*
- * @param sync_job $sync_job
- * @param string $access_token
- * @param $ilios_client $ilios_client
+ * @param sync_job $syncjob The sync job.
+ * @param string $accesstoken An Ilios API access token.
+ * @param $iliosclient $ilios_client The Ilios API client.
*
- * @throws \moodle_exception
- * @throws \Exception
+ * @throws moodle_exception
+ * @throws Exception
*/
- protected function run_sync_job(sync_job $syncjob, string $accesstoken, ilios_client $iliosclient) {
+ protected function run_sync_job(sync_job $syncjob, string $accesstoken, ilios_client $iliosclient): void {
$jobtitle = $syncjob->get_title();
mtrace("Started sync job '$jobtitle'.");
$coursecategory = core_course_category::get($syncjob->get_course_category_id(), IGNORE_MISSING);
if (empty($coursecategory)) {
mtrace('ERROR: Failed to load course category with ID = ' . $syncjob->get_course_category_id());
-
return;
}
$iliosusers = $this->get_users_from_ilios($syncjob, $accesstoken, $iliosclient);
@@ -100,16 +130,16 @@ protected function run_sync_job(sync_job $syncjob, string $accesstoken, ilios_cl
}
/**
- * Retrieves a list of user campus IDs from Ilios qualifying for the given sync job.
+ * Retrieves a list of campus IDs for users qualifying for the given sync job from Ilios.
*
- * @param sync_job $sync_job
- * @param string $access_token
- * @param ilios_client $ilios_client
+ * @param sync_job $syncjob The sync job.
+ * @param string $accesstoken The Ilios API access token.
+ * @param ilios_client $iliosclient The Ilios API client.
*
- * @return string[] A list of campus IDs.
- * @throws \Exception
+ * @return array A list of campus IDs.
+ * @throws Exception
*/
- protected function get_users_from_ilios(sync_job $syncjob, string $accesstoken, ilios_client $iliosclient) {
+ protected function get_users_from_ilios(sync_job $syncjob, string $accesstoken, ilios_client $iliosclient): array {
$iliosusers = [];
$filters = [
@@ -125,14 +155,13 @@ protected function get_users_from_ilios(sync_job $syncjob, string $accesstoken,
5000
);
- } catch (\Exception $e) {
- // re-throw exception with a better error message
- throw new \Exception('Failed to retrieve users from Ilios with the following parameters: ' .
- print_r($filters, true), 0, $e);
+ } catch (Exception $e) {
+ // Re-throw exception with a better error message.
+ throw new Exception('Failed to retrieve users from Ilios with the following error message.', 0, $e);
}
- // filter out any users that do not fulfill a director or instructor function in ilios.
- $records = array_filter($records, function(\stdClass $rec) {
+ // Filter out any users that do not fulfill a director or instructor function in ilios.
+ $records = array_filter($records, function(stdClass $rec) {
return ! empty($rec->directedCourses) ||
! empty($rec->directedPrograms) ||
! empty($rec->directedSchools) ||
@@ -150,21 +179,18 @@ protected function get_users_from_ilios(sync_job $syncjob, string $accesstoken,
}
}
- $iliosusers = array_unique($iliosusers);
-
- return $iliosusers;
+ return array_unique($iliosusers);
}
/**
* Retrieves the IDs of all users matching a given list of Ilios user campus IDs.
*
- * @param string[] $ilios_users The campus IDs of users retrieved from Ilios.
- *
- * @return int[] A list of Moodle user IDs.
- * @throws \coding_exception
- * @throws \dml_exception
+ * @param array $iliosusers The campus IDs of users retrieved from Ilios.
+ * @return array A list of Moodle user IDs.
+ * @throws coding_exception
+ * @throws dml_exception
*/
- protected function get_moodle_users(array $iliosusers) {
+ protected function get_moodle_users(array $iliosusers): array {
global $DB;
if (empty($iliosusers)) {
return [];
@@ -180,22 +206,20 @@ protected function get_moodle_users(array $iliosusers) {
}
return array_column($users, 'id');
-
}
/**
- * Updates users role assignment in a given category.
+ * Updates users role assignment in a given course category.
*
- * @param sync_job $sync_job
- * @param core_course_category $course_category
- * @param int[] $user_ids
- *
- * @throws \coding_exception
+ * @param sync_job $syncjob The sync job.
+ * @param core_course_category $coursecategory The course category.
+ * @param array $userids A list of IDs of users that were updated during this sync job.
+ * @throws coding_exception
*/
- public function sync_category(sync_job $syncjob, core_course_category $coursecategory, array $userids) {
+ public function sync_category(sync_job $syncjob, core_course_category $coursecategory, array $userids): void {
$formattedcategoryname = $coursecategory->get_formatted_name();
- mtrace("Started syncing course category '{$formattedcategoryname}'.");
- $role = new \stdClass();
+ mtrace("Started syncing course category '$formattedcategoryname'.");
+ $role = new stdClass();
$role->id = $syncjob->get_role_id();
$ctx = $coursecategory->get_context();
$roleassignments = get_users_from_role_on_context($role, $ctx);
@@ -205,10 +229,12 @@ public function sync_category(sync_job $syncjob, core_course_category $coursecat
$allassignedusers = array_column($roleassignments, 'userid');
}
- // filter out any role assignments that weren't made by this plugin
- $roleassignments = array_values(array_filter($roleassignments, function($role) {
- return $role->component === 'tool_ilioscategoryassignment';
- }));
+ // Filter out any role assignments that weren't made by this plugin.
+ $roleassignments = array_values(
+ array_filter($roleassignments, function($role) {
+ return $role->component === 'tool_ilioscategoryassignment';
+ })
+ );
$assignedusers = [];
if (!empty($roleassignments)) {
@@ -231,14 +257,13 @@ public function sync_category(sync_job $syncjob, core_course_category $coursecat
foreach ($addusers as $userid) {
// Prevent double role assignment.
if (in_array($userid, $outofbandassignments)) {
- mtrace("User with id = ${user_id} had this role assigned out-of-band, skipping.");
+ mtrace("User with id = $userid had this role assigned out-of-band, skipping.");
continue;
}
role_assign($syncjob->get_role_id(), $userid, $ctx->id, 'tool_ilioscategoryassignment');
$assignmentcounter++;
}
- mtrace("Assigned ${assignment_counter} user(s) into category.");
-
+ mtrace("Assigned $assignmentcounter user(s) into category.");
}
$unassignmentcounter = 0;
@@ -247,10 +272,9 @@ public function sync_category(sync_job $syncjob, core_course_category $coursecat
role_unassign($syncjob->get_role_id(), $userid, $ctx->id, 'tool_ilioscategoryassignment');
$unassignmentcounter++;
}
- mtrace("Un-assigned {$unassignmentcounter} user(s) from category.");
+ mtrace("Un-assigned $unassignmentcounter user(s) from category.");
}
-
- mtrace("Finished syncing course category '{$formattedcategoryname}'.");
+ mtrace("Finished syncing course category '$formattedcategoryname'.");
}
}
diff --git a/create.php b/create.php
index c5c77f0..fb4cb3b 100644
--- a/create.php
+++ b/create.php
@@ -1,30 +1,42 @@
.
/**
* Create new sync job page.
*
- * @package tool_ilioscategoryassignment
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use tool_ilioscategoryassignment\form\create_sync_job;
use tool_ilioscategoryassignment\manager;
use tool_ilioscategoryassignment\output\renderer;
use tool_ilioscategoryassignment\sync_job;
-use tool_ilioscategoryassignment\sync_source;
require_once(__DIR__ . '/../../../config.php');
require_login();
require_capability('moodle/site:config', context_system::instance());
-/* @var $CFG */
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/tablelib.php');
$action = optional_param('action', 'list', PARAM_ALPHA);
-/* @var moodle_page $PAGE */
-/* @var renderer $renderer */
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/admin/tool/ilioscategoryassignment/create.php');
$PAGE->set_pagelayout('admin');
@@ -53,7 +65,6 @@
$redirecturl = new moodle_url("$CFG->wwwroot/$CFG->admin/tool/ilioscategoryassignment/index.php");
redirect($redirecturl, get_string('newjobcreated', 'tool_ilioscategoryassignment', $syncjob->get_title()), 10);
} else {
- /* @var core_renderer $OUTPUT */
echo $OUTPUT->header();
echo $OUTPUT->heading($strheading);
$mform->display();
diff --git a/db/events.php b/db/events.php
index a5aff91..3aa90ca 100644
--- a/db/events.php
+++ b/db/events.php
@@ -1,11 +1,29 @@
.
/**
* Event observer definitions.
*
- * @package tool_ilioscategoryassignment
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+defined('MOODLE_INTERNAL') || die();
+
// List of observers.
$observers = [
[
diff --git a/db/tasks.php b/db/tasks.php
index 5c45a2b..1326c02 100644
--- a/db/tasks.php
+++ b/db/tasks.php
@@ -1,9 +1,25 @@
.
+
/**
- * Definition of Ilios category assignment tasks
+ * Task definitions.
*
- * @package tool_ilioscategoryassignment
- * @category task
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
diff --git a/db/uninstall.php b/db/uninstall.php
index 2e8d33c..e627804 100644
--- a/db/uninstall.php
+++ b/db/uninstall.php
@@ -1,20 +1,37 @@
.
+
/**
- * Plugin un-installation callback.
+ * Uninstall script.
*
- * @package tool_ilioscategoryassignment
- * @link https://docs.moodle.org/dev/Plugin_files#db.2Funinstall.php
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
-/* @global $CFG */
require_once($CFG->libdir . '/accesslib.php');
/**
- * @return bool
+ * Plugin uninstall callback.
+ * @return bool Always TRUE.
+ * @throws coding_exception
*/
-function xmldb_tool_ilioscategoryassignment_uninstall() {
+function xmldb_tool_ilioscategoryassignment_uninstall(): bool {
role_unassign_all(['component' => 'tool_ilioscategoryassignment']);
return true;
}
diff --git a/db/upgrade.php b/db/upgrade.php
index 60d0395..694debc 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -17,18 +17,24 @@
/**
* Upgrade script.
*
- * @package tool_ilioscategoryassignment
- * @link https://docs.moodle.org/dev/Plugin_files#db.2Funinstall.php
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
/**
- * Upgrade the plugin.
+ * Plugin upgrade callback.
*
- * @param int $oldversion
- * @return bool always true
+ * @param int $oldversion The old plugin version.
+ * @return bool Always TRUE.
+ * @throws ddl_exception
+ * @throws ddl_table_missing_exception
+ * @throws dml_exception
+ * @throws downgrade_exception
+ * @throws moodle_exception
+ * @throws upgrade_exception
*/
-function xmldb_tool_ilioscategoryassignment_upgrade($oldversion) {
+function xmldb_tool_ilioscategoryassignment_upgrade($oldversion): bool {
global $DB;
$dbman = $DB->get_manager();
@@ -39,7 +45,10 @@ function xmldb_tool_ilioscategoryassignment_upgrade($oldversion) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
- $DB->execute('UPDATE {tool_ilioscatassignment} t SET t.schoolid = (SELECT schoolid FROM {tool_ilioscatassignment_src} WHERE jobid = t.id ORDER BY id DESC LIMIT 1)');
+ $DB->execute(
+ 'UPDATE {tool_ilioscatassignment} t SET t.schoolid = ' .
+ ' (SELECT schoolid FROM {tool_ilioscatassignment_src} WHERE jobid = t.id ORDER BY id DESC LIMIT 1)'
+ );
$table = new xmldb_table('tool_ilioscatassignment_src');
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
diff --git a/index.php b/index.php
index 601e95c..08ebd81 100644
--- a/index.php
+++ b/index.php
@@ -1,21 +1,35 @@
.
/**
- * Sync jobs admin pages.
+ * Sync jobs admin page.
*
* @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core\output\notification;
use tool_ilioscategoryassignment\manager;
-use tool_ilioscategoryassignment\output\renderer;
require_once(__DIR__ . '/../../../config.php');
require_login();
require_capability('moodle/site:config', context_system::instance());
-/* @var $CFG */
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/tablelib.php');
@@ -24,10 +38,6 @@
$returnurl = new moodle_url('/admin/tool/ilioscategoryassignment/index.php');
-/* @var moodle_page $PAGE */
-/* @var renderer $renderer */
-/* @var core_renderer $OUTPUT */
-
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/admin/tool/ilioscategoryassignment/index.php');
$PAGE->set_pagelayout('admin');
@@ -50,7 +60,7 @@
manager::disable_job($jobid);
$returnmsg = get_string('jobdisabled', 'tool_ilioscategoryassignment', $job->get_title());
redirect($returnurl, $returnmsg, null, notification::NOTIFY_SUCCESS);
- } else if ('delete' === $action && confirm_sesskey()) {
+ } else if ('delete' === $action && confirm_sesskey()) {
if ($confirm !== md5($action)) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('deletejob', 'tool_ilioscategoryassignment'));
@@ -102,7 +112,7 @@
$iliosschools = [];
if (!empty($jobs)) {
- $coursecategoryids = array_column($jobs, 'course_category_id');
+ $coursecategoryids = array_column($jobs, 'coursecategoryid');
$coursecategories = core_course_category::get_many($coursecategoryids);
$roles = role_get_names();
}
diff --git a/lang/en/tool_ilioscategoryassignment.php b/lang/en/tool_ilioscategoryassignment.php
index 6fcecb2..1118ae5 100644
--- a/lang/en/tool_ilioscategoryassignment.php
+++ b/lang/en/tool_ilioscategoryassignment.php
@@ -1,11 +1,26 @@
.
/**
- * Language strings.
+ * Language strings for the tool_ilioscategoryassignment plugin.
*
- * @package tool_ilioscategoryassignment
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
$string['apikey'] = 'Ilios API key';
$string['apikey_desc'] = 'Enter the API key obtained from your Ilios server.';
$string['clientconfig'] = "Ilios API client configuration";
@@ -14,12 +29,11 @@
$string['deletejobconfirm'] = 'You are about to delete the Ilios category assignment sync job "{$a->jobtitle}". All users currently assigned as course participants in the "{$a->roletitle}" role to courses in the "{$a->coursecattitle}" course category using this method will be removed.
Are you sure you want to continue?';
$string['host_url'] = 'Host URL';
$string['host_url_desc'] = 'Type Ilios server IP address or host URL.';
-$string['ilioserror'] =
- 'An error occurred while accessing Ilios. Please check that Ilios is up and running, and that your connection to Ilios is configured correctly.';
+$string['ilioserror'] = 'An error occurred while accessing Ilios. Please check that Ilios is up and running, and that your connection to Ilios is configured correctly.';
$string['iliosschool'] = 'Ilios school';
-$string['jobenabled'] = 'Enabled sync job "{$a}".';
$string['jobdeleted'] = 'Deleted sync job "{$a}".';
$string['jobdisabled'] = 'Disabled sync job "{$a}".';
+$string['jobenabled'] = 'Enabled sync job "{$a}".';
$string['newjobcreated'] = 'Created new sync job "{$a}".';
$string['newsyncjob'] = "New sync job";
$string['noassignablecategories'] = 'There are currently no course categories that can be used for assignment.';
diff --git a/settings.php b/settings.php
index bcb69f9..6e6616b 100644
--- a/settings.php
+++ b/settings.php
@@ -1,22 +1,35 @@
.
+
/**
- * Adds this plugin to the admin menu.
+ * Admin settings.
*
- * @package tool_ilioscategoryassignment
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
-/* @var admin_root $ADMIN */
-/* @var $CFG */
-
if ($hassiteconfig) {
-
$ADMIN->add('root', new admin_category(
'ilioscategoryassignment',
get_string('pluginname', 'tool_ilioscategoryassignment')));
- // Sync jobs admin page
+ // Sync jobs admin page.
$ADMIN->add('ilioscategoryassignment', new admin_externalpage(
'ilioscategoryassignment_jobs',
get_string('syncjobs', 'tool_ilioscategoryassignment'),
@@ -24,7 +37,7 @@
'moodle/site:config'
));
- // New job page
+ // New job page.
$ADMIN->add('ilioscategoryassignment', new admin_externalpage(
'ilioscategoryassignment_new_jobs',
get_string('newsyncjob', 'tool_ilioscategoryassignment'),
@@ -32,7 +45,7 @@
'moodle/site:config'
));
- // API client settings page
+ // API client settings page.
$settings = new admin_settingpage(
'ilioscategoryassignment_clientconfig',
get_string('clientconfig', 'tool_ilioscategoryassignment'),
diff --git a/version.php b/version.php
index f740378..8ded2e9 100644
--- a/version.php
+++ b/version.php
@@ -1,15 +1,32 @@
.
+
/**
* Ilios category assignment tool - version file.
*
- * @package tool_ilioscategoryassignment
+ * @package tool_ilioscategoryassignment
+ * @copyright The Regents of the University of California
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2024052300; // The current plugin version (Date: YYYYMMDDXX)
-$plugin->requires = 2023100400; // Requires this Moodle version
-$plugin->component = 'tool_ilioscategoryassignment'; // Full name of the plugin (used for diagnostics)
+$plugin->version = 2024052300; // The current plugin version (Date: YYYYMMDDXX).
+$plugin->requires = 2023100400; // Requires this Moodle version.
+$plugin->component = 'tool_ilioscategoryassignment'; // Full name of the plugin (used for diagnostics).
$plugin->release = 'v4.3';
$plugin->supported = [403, 403];
$plugin->maturity = MATURITY_STABLE;