diff --git a/classes/cohortmembersync.php b/classes/cohortmembersync.php index 0d006fc..7e82647 100644 --- a/classes/cohortmembersync.php +++ b/classes/cohortmembersync.php @@ -43,19 +43,19 @@ class cohortmembersync { /** @var array errors when prcessing file or updating cohorts */ - protected $errors = array(); + protected $errors = []; /** @var string the file name of the file */ protected $filename = ''; /** @var array updating cohorts options */ - protected $params = array(); + protected $params = []; /** @var array warnings if cohort or user are not found */ - protected $warnings = array(); + protected $warnings = []; /** @var array informations about members added or deleted */ - protected $infos = array('usersadded' => array(), 'usersdeleted' => array()); + protected $infos = ['usersadded' => [], 'usersdeleted' => []]; /** @var progress_trace trace */ protected $trace = null; @@ -67,7 +67,7 @@ class cohortmembersync { * @param string $filepath the file path of the cohorts members file * @param array $params Options for processing file */ - public function __construct($trace, $filepath, $params = array()) { + public function __construct($trace, $filepath, $params = []) { $this->trace = $trace; if (!empty($filepath)) { @@ -90,12 +90,12 @@ public function __construct($trace, $filepath, $params = array()) { $this->errors[] = "Unknown delimiter : " . $this->params['flatfiledelimiter']; } // Validate useridentifier. - if (!in_array($this->params['useridentifier'], array('id', 'idnumber', 'username'))) { + if (!in_array($this->params['useridentifier'], ['id', 'idnumber', 'username'])) { $this->errors[] = "Unknown user identifier : " . $this->params['useridentifier']; } // Validate cohortidentifier. - if (!in_array($this->params['cohortidentifier'], array('name', 'idnumber', 'id'))) { + if (!in_array($this->params['cohortidentifier'], ['name', 'idnumber', 'id'])) { $this->errors[] = "Unknown cohort identifier : " . $this->params['cohortidentifier']; } } @@ -137,12 +137,12 @@ public function update_cohortsmembers() { * @return array params list */ protected function get_defaults_params() { - return array( + return [ 'useridentifier' => get_config('tool_cohortsync', 'useridentifier'), 'cohortidentifier' => get_config('tool_cohortsync', 'cohortidentifier'), 'flatfiledelimiter' => get_config('tool_cohortsync', 'flatfiledelimiter'), - 'flatfileencoding' => get_config('tool_cohortsync', 'flatfileencoding') - ); + 'flatfileencoding' => get_config('tool_cohortsync', 'flatfileencoding'), + ]; } /** @@ -174,15 +174,15 @@ protected function process_file() { return; } - $cachedusers = array(); - $cachedcohorts = array(); + $cachedusers = []; + $cachedcohorts = []; // We may need more memory here. \core_php_time_limit::raise(); \raise_memory_limit(MEMORY_HUGE); $this->trace->output("Processing flat file cohort members"); - $data = array(); + $data = []; $content = file_get_contents($this->filename); $delimiters = \csv_import_reader::get_delimiter_list(); @@ -238,10 +238,10 @@ protected function process_file() { $select = $DB->sql_equal($this->params['useridentifier'], ':useridentifier', false) . ' AND deleted = :deleted'; - $params = array( + $params = [ 'useridentifier' => $fields[2], - 'deleted' => 0 - ); + 'deleted' => 0, + ]; $user = $DB->get_record_select('user', $select, $params); if ($user) { @@ -265,9 +265,9 @@ protected function process_file() { $cachedcohorts[$fields[1]] = 0; $select = $DB->sql_equal($this->params['cohortidentifier'], ':cohortidentifier', false); - $params = array( - 'cohortidentifier' => $fields[1] - ); + $params = [ + 'cohortidentifier' => $fields[1], + ]; $cohort = $DB->get_record_select('cohort', $select, $params); if ($cohort) { diff --git a/classes/cohortsync.php b/classes/cohortsync.php index 60e64e6..d048785 100644 --- a/classes/cohortsync.php +++ b/classes/cohortsync.php @@ -44,13 +44,13 @@ class cohortsync { /** @var array errors when prcessing csv file or updating cohorts */ - protected $errors = array(); + protected $errors = []; /** @var string the file name of the csv file */ protected $filename = ''; /** @var array updating cohorts options */ - protected $params = array(); + protected $params = []; /** @var array cached list of available contexts */ protected $contextlist = null; @@ -59,10 +59,10 @@ class cohortsync { protected $defaultcontext = null; /** @var array warnings if cohort or user are not found */ - protected $warnings = array(); + protected $warnings = []; /** @var array list of cohort data */ - protected $cohorts = array(); + protected $cohorts = []; /** @var progress_trace trace */ protected $trace = null; @@ -74,7 +74,7 @@ class cohortsync { * @param string $filepath the file path of the csv cohorts file * @param array $params Options for processing csv file */ - public function __construct($trace, $filepath, $params = array()) { + public function __construct($trace, $filepath, $params = []) { $this->trace = $trace; if (!empty($filepath)) { @@ -133,11 +133,11 @@ public function update_cohorts() { * @return array params list */ protected function get_defaults_params() { - return array( + return [ 'defaultcontext' => get_config('tool_cohortsync', 'defaultcontext'), 'csvdelimiter' => get_config('tool_cohortsync', 'csvdelimiter'), - 'csvencoding' => get_config('tool_cohortsync', 'encoding') - ); + 'csvencoding' => get_config('tool_cohortsync', 'encoding'), + ]; } /** @@ -166,7 +166,7 @@ public function get_warnings() { protected function get_context_options() { if ($this->contextlist === null) { - $this->contextlist = array(); + $this->contextlist = []; $displaylist = \core_course_category::make_categories_list('moodle/cohort:manage'); // We need to index the options array by context id instead of category id and add option for system context. $syscontext = \context_system::instance(); @@ -195,7 +195,7 @@ protected function process_file() { return; } - $cohorts = array(); + $cohorts = []; $uploadid = \csv_import_reader::get_new_iid('cohortsync'); $cir = new \csv_import_reader($uploadid, 'cohortsync'); @@ -208,11 +208,11 @@ protected function process_file() { $columns = $cir->get_columns(); // Check that columns include 'name' and warn about extra columns. - $allowedcolumns = array('contextid', 'name', 'idnumber', 'description', 'descriptionformat', 'visible'); - $additionalcolumns = array('context', 'category', 'category_id', 'category_idnumber', 'category_path'); - $displaycolumns = array(); - $extracolumns = array(); - $columnsmapping = array(); + $allowedcolumns = ['contextid', 'name', 'idnumber', 'description', 'descriptionformat', 'visible']; + $additionalcolumns = ['context', 'category', 'category_id', 'category_idnumber', 'category_path']; + $displaycolumns = []; + $extracolumns = []; + $columnsmapping = []; foreach ($columns as $i => $columnname) { $columnnamelower = preg_replace('/ /', '', \core_text::strtolower($columnname)); $columnsmapping[$i] = null; @@ -241,11 +241,11 @@ protected function process_file() { // Parse data rows. $cir->init(); $rownum = 0; - $idnumbers = array(); + $idnumbers = []; while ($row = $cir->next()) { $rownum++; - $cohorts[$rownum] = array(); - $hash = array(); + $cohorts[$rownum] = []; + $hash = []; foreach ($row as $i => $value) { if ($columnsmapping[$i]) { $hash[$columnsmapping[$i]] = $value; @@ -257,7 +257,7 @@ protected function process_file() { $this->warnings = array_merge($this->warnings, $warnings); if (!empty($hash['idnumber'])) { - if (isset($idnumbers[$hash['idnumber']]) || $DB->record_exists('cohort', array('idnumber' => $hash['idnumber']))) { + if (isset($idnumbers[$hash['idnumber']]) || $DB->record_exists('cohort', ['idnumber' => $hash['idnumber']])) { $this->errors[] = new \lang_string('duplicateidnumber', 'cohort'); } $idnumbers[$hash['idnumber']] = true; @@ -321,7 +321,7 @@ protected function clean_cohort_data(&$hash) { protected function resolve_context(&$hash) { global $DB; - $warnings = array(); + $warnings = []; if (!empty($hash['contextid'])) { // Contextid was specified, verify we can post there. @@ -388,7 +388,7 @@ protected function resolve_context(&$hash) { if (empty($this->categoriescache[$field][$value])) { $record = $DB->get_record_sql("SELECT c.id, ctx.id contextid FROM {context} ctx JOIN {course_categories} c ON ctx.contextlevel = ? AND ctx.instanceid = c.id - WHERE c.$field = ?", array(CONTEXT_COURSECAT, $value)); + WHERE c.$field = ?", [CONTEXT_COURSECAT, $value]); if ($record && ($contextoptions = $this->get_context_options()) && isset($contextoptions[$record->contextid])) { $contextid = $record->contextid; } else { diff --git a/cli/cohortmembersync.php b/cli/cohortmembersync.php index fefff9b..d31c3c9 100644 --- a/cli/cohortmembersync.php +++ b/cli/cohortmembersync.php @@ -34,22 +34,22 @@ // Now get cli options. list($options, $unrecognized) = cli_get_params( - array( + [ 'help' => false, 'filepath' => false, 'flatfiledelimiter' => false, 'flatfileencoding' => false, 'cohortidentifier' => false, 'useridentifier' => false, - 'verbose' => false), - array( + 'verbose' => false], + [ 'h' => 'help', 'f' => 'filepath', 'd' => 'flatfiledelimiter', 'e' => 'flatfileencoding', 'c' => 'cohortidentifier', 'u' => 'useridentifier', - 'v' => 'verbose') + 'v' => 'verbose'] ); if ($options['help']) { @@ -83,15 +83,15 @@ die; } -$params = array( +$params = [ 'help', 'verbose', 'filepath', 'flatfiledelimiter', 'flatfileencoding', 'cohortidentifier', - 'useridentifier' -); + 'useridentifier', +]; foreach ($params as $param) { if ($options[$param] === false) { diff --git a/cli/cohortsync.php b/cli/cohortsync.php index 31295a4..4c6ab8a 100644 --- a/cli/cohortsync.php +++ b/cli/cohortsync.php @@ -34,20 +34,20 @@ // Now get cli options. list($options, $unrecognized) = cli_get_params( - array( + [ 'help' => false, 'filepath' => false, 'csvdelimiter' => false, 'csvencoding' => false, 'context' => false, - 'verbose' => false), - array( + 'verbose' => false], + [ 'h' => 'help', 'f' => 'filepath', 'd' => 'csvdelimiter', 'e' => 'csvencoding', 'ctx' => 'context', - 'v' => 'verbose') + 'v' => 'verbose'] ); if ($options['help']) { @@ -76,21 +76,21 @@ die; } -$params = array( +$params = [ 'help', 'verbose', 'filepath', 'csvdelimiter', 'csvencoding', - 'context' -); + 'context', +]; foreach ($params as $param) { if ($options[$param] === false) { unset($options[$param]); } } // Emulate normal session. -cron_setup_user(); +\core\cron::setup_user(); if (empty($options['verbose'])) { $trace = new \null_progress_trace(); diff --git a/settings.php b/settings.php index 36033a8..b0f51cf 100644 --- a/settings.php +++ b/settings.php @@ -45,7 +45,7 @@ get_string('encoding', 'tool_cohortsync'), '', 'UTF-8', $choices)); // GEt context for cohorts. - $contextoptions = array(); + $contextoptions = []; $displaylist = core_course_category::make_categories_list('moodle/cohort:manage'); // We need to index the options array by context id instead of category id and add option for system context. $syscontext = context_system::instance(); @@ -67,11 +67,11 @@ $settings->add(new admin_setting_heading('cohortmembersyncheader', get_string('cohortmembersyncheader', 'tool_cohortsync'), '')); - $useridentifieroptions = array( + $useridentifieroptions = [ 'id' => 'id', 'username' => 'username', - 'idnumber' => 'idnumber' - ); + 'idnumber' => 'idnumber', + ]; $settings->add(new admin_setting_configselect('tool_cohortsync/useridentifier', get_string('useridentifier', 'tool_cohortsync'), @@ -79,11 +79,11 @@ 'username', $useridentifieroptions)); - $cohortidentifieroptions = array( + $cohortidentifieroptions = [ 'id' => 'id', 'name' => 'name', - 'idnumber' => 'idnumber' - ); + 'idnumber' => 'idnumber', + ]; $settings->add(new admin_setting_configselect('tool_cohortsync/cohortidentifier', new lang_string('cohortidentifier', 'tool_cohortsync'), diff --git a/tests/cohortmembersync_test.php b/tests/cohortmembersync_test.php index 55f58c8..13b5d3f 100644 --- a/tests/cohortmembersync_test.php +++ b/tests/cohortmembersync_test.php @@ -88,42 +88,42 @@ public function setUp(): void { $this->trace = new \null_progress_trace(); - $this->cat1 = $this->getDataGenerator()->create_category(array('name' => 'CAT1')); - $this->cat2 = $this->getDataGenerator()->create_category(array('name' => 'CAT2')); + $this->cat1 = $this->getDataGenerator()->create_category(['name' => 'CAT1']); + $this->cat2 = $this->getDataGenerator()->create_category(['name' => 'CAT2']); $this->contextcat1 = \context_coursecat::instance($this->cat1->id); $this->contextcat2 = \context_coursecat::instance($this->cat2->id); - $this->cohort1 = $this->getDataGenerator()->create_cohort(array( + $this->cohort1 = $this->getDataGenerator()->create_cohort([ 'name' => 'Cohort1', 'idnumber' => 'ID-Coh1', - 'contextid' => $this->contextcat1->id)); + 'contextid' => $this->contextcat1->id]); - $this->cohort2 = $this->getDataGenerator()->create_cohort(array( + $this->cohort2 = $this->getDataGenerator()->create_cohort([ 'name' => 'Cohort2', 'idnumber' => 'ID-Coh2', - 'contextid' => $this->contextcat2->id)); + 'contextid' => $this->contextcat2->id]); - $this->user1 = $this->getDataGenerator()->create_user(array( + $this->user1 = $this->getDataGenerator()->create_user([ 'firstname' => 'User1', 'lastname' => 'User1', 'username' => 'user1', 'idnumber' => 'ID-number1', - 'email' => 'nomail+user1@test.com')); + 'email' => 'nomail+user1@test.com']); - $this->user2 = $this->getDataGenerator()->create_user(array( + $this->user2 = $this->getDataGenerator()->create_user([ 'firstname' => 'User2', 'lastname' => 'User2', 'username' => 'user2', 'idnumber' => 'ID-number2', - 'email' => 'nomail+user2@test.com')); + 'email' => 'nomail+user2@test.com']); - $this->user3 = $this->getDataGenerator()->create_user(array( + $this->user3 = $this->getDataGenerator()->create_user([ 'firstname' => 'User3', 'lastname' => 'User3', 'username' => 'user3', 'idnumber' => 'ID-number3', - 'email' => 'nomail+user3@test.com')); + 'email' => 'nomail+user3@test.com']); } @@ -132,11 +132,11 @@ public function setUp(): void { */ public function test_cohortmembersync_with_userid_cohortid() { - $lines = array(); - $lines[] = array('add', $this->cohort1->id, $this->user1->id); - $lines[] = array('add', $this->cohort1->id, $this->user2->id); - $lines[] = array('add', $this->cohort1->id, $this->user3->id); - $lines[] = array('add', $this->cohort2->id, $this->user1->id); + $lines = []; + $lines[] = ['add', $this->cohort1->id, $this->user1->id]; + $lines[] = ['add', $this->cohort1->id, $this->user2->id]; + $lines[] = ['add', $this->cohort1->id, $this->user3->id]; + $lines[] = ['add', $this->cohort2->id, $this->user1->id]; $filename = $this->set_csv_file($lines); @@ -160,11 +160,11 @@ public function test_cohortmembersync_with_useridnumber_cohortid() { set_config('useridentifier', 'idnumber', 'tool_cohortsync'); - $lines = array(); - $lines[] = array('add', $this->cohort1->id, $this->user1->idnumber); - $lines[] = array('add', $this->cohort1->id, $this->user2->idnumber); - $lines[] = array('add', $this->cohort1->id, $this->user3->idnumber); - $lines[] = array('add', $this->cohort2->id, $this->user1->idnumber); + $lines = []; + $lines[] = ['add', $this->cohort1->id, $this->user1->idnumber]; + $lines[] = ['add', $this->cohort1->id, $this->user2->idnumber]; + $lines[] = ['add', $this->cohort1->id, $this->user3->idnumber]; + $lines[] = ['add', $this->cohort2->id, $this->user1->idnumber]; $filename = $this->set_csv_file($lines); @@ -187,11 +187,11 @@ public function test_cohortmembersync_with_username_cohortid() { set_config('useridentifier', 'username', 'tool_cohortsync'); - $lines = array(); - $lines[] = array('add', $this->cohort1->id, $this->user1->username); - $lines[] = array('add', $this->cohort1->id, $this->user2->username); - $lines[] = array('add', $this->cohort1->id, $this->user3->username); - $lines[] = array('add', $this->cohort2->id, $this->user1->username); + $lines = []; + $lines[] = ['add', $this->cohort1->id, $this->user1->username]; + $lines[] = ['add', $this->cohort1->id, $this->user2->username]; + $lines[] = ['add', $this->cohort1->id, $this->user3->username]; + $lines[] = ['add', $this->cohort2->id, $this->user1->username]; $filename = $this->set_csv_file($lines); @@ -214,11 +214,11 @@ public function test_cohortmembersync_with_userid_cohortname() { set_config('cohortidentifier', 'name', 'tool_cohortsync'); - $lines = array(); - $lines[] = array('add', $this->cohort1->name, $this->user1->id); - $lines[] = array('add', $this->cohort1->name, $this->user2->id); - $lines[] = array('add', $this->cohort1->name, $this->user3->id); - $lines[] = array('add', $this->cohort2->name, $this->user1->id); + $lines = []; + $lines[] = ['add', $this->cohort1->name, $this->user1->id]; + $lines[] = ['add', $this->cohort1->name, $this->user2->id]; + $lines[] = ['add', $this->cohort1->name, $this->user3->id]; + $lines[] = ['add', $this->cohort2->name, $this->user1->id]; $filename = $this->set_csv_file($lines); @@ -241,11 +241,11 @@ public function test_cohortmembersync_with_userid_cohortidnumner() { set_config('cohortidentifier', 'idnumber', 'tool_cohortsync'); - $lines = array(); - $lines[] = array('add', $this->cohort1->idnumber, $this->user1->id); - $lines[] = array('add', $this->cohort1->idnumber, $this->user2->id); - $lines[] = array('add', $this->cohort1->idnumber, $this->user3->id); - $lines[] = array('add', $this->cohort2->idnumber, $this->user1->id); + $lines = []; + $lines[] = ['add', $this->cohort1->idnumber, $this->user1->id]; + $lines[] = ['add', $this->cohort1->idnumber, $this->user2->id]; + $lines[] = ['add', $this->cohort1->idnumber, $this->user3->id]; + $lines[] = ['add', $this->cohort2->idnumber, $this->user1->id]; $filename = $this->set_csv_file($lines); @@ -277,8 +277,8 @@ public function test_cohortmembersync_delete() { // Check cohort members are not created. $this->assertEquals(1, $DB->count_records('cohort_members')); - $lines = array(); - $lines[] = array('del', $this->cohort1->id, $this->user1->id); + $lines = []; + $lines[] = ['del', $this->cohort1->id, $this->user1->id]; $filename = $this->set_csv_file($lines); @@ -300,17 +300,17 @@ public function test_cohortmembersync_delete() { public function test_cohortmembersync_with_wrong_parameters() { global $DB; - $lines = array(); - $lines[] = array('add', $this->cohort1->id, $this->user1->id); - $lines[] = array('add', $this->cohort1->id, $this->user2->id); - $lines[] = array('add', $this->cohort1->id, $this->user3->id); - $lines[] = array('add', $this->cohort2->id, $this->user1->id); + $lines = []; + $lines[] = ['add', $this->cohort1->id, $this->user1->id]; + $lines[] = ['add', $this->cohort1->id, $this->user2->id]; + $lines[] = ['add', $this->cohort1->id, $this->user3->id]; + $lines[] = ['add', $this->cohort2->id, $this->user1->id]; $filename = $this->set_csv_file($lines); - $params = array ('cohortidentifier' => 'badvalue', + $params = ['cohortidentifier' => 'badvalue', 'useridentifier' => 'badvalue', - 'flatfiledelimiter' => 'badvalue'); + 'flatfiledelimiter' => 'badvalue']; $cohortmembersync = new cohortmembersync($this->trace, $filename, $params); $cohortmembersync->update_cohortsmembers(); @@ -332,11 +332,11 @@ public function test_cohortmembersync_with_wrong_parameters() { */ public function test_cohortmembersync_with_good_parameters() { - $lines = array(); - $lines[] = array('add', $this->cohort1->idnumber, $this->user1->idnumber); - $lines[] = array('add', $this->cohort1->idnumber, $this->user2->idnumber); - $lines[] = array('add', $this->cohort1->idnumber, $this->user3->idnumber); - $lines[] = array('add', $this->cohort2->idnumber, $this->user1->idnumber); + $lines = []; + $lines[] = ['add', $this->cohort1->idnumber, $this->user1->idnumber]; + $lines[] = ['add', $this->cohort1->idnumber, $this->user2->idnumber]; + $lines[] = ['add', $this->cohort1->idnumber, $this->user3->idnumber]; + $lines[] = ['add', $this->cohort2->idnumber, $this->user1->idnumber]; $filename = $this->set_csv_file($lines); @@ -345,9 +345,9 @@ public function test_cohortmembersync_with_good_parameters() { $filename = $this->set_csv_file($lines, ';'); - $params = array ('cohortidentifier' => 'idnumber', + $params = ['cohortidentifier' => 'idnumber', 'useridentifier' => 'idnumber', - 'flatfiledelimiter' => 'semicolon'); + 'flatfiledelimiter' => 'semicolon']; $cohortmembersync = new cohortmembersync($this->trace, $filename, $params); $cohortmembersync->update_cohortsmembers(); @@ -368,12 +368,12 @@ public function test_cohortmembersync_with_good_parameters() { public function test_cohortmembersync_warning() { global $DB; - $lines = array(); - $lines[] = array('badvalue', $this->cohort1->id, $this->user1->id); - $lines[] = array('add', 'badcohortid', $this->user2->id); - $lines[] = array('add', $this->cohort1->id, 'badcohortid'); - $lines[] = array('add', '', $this->user1->id); - $lines[] = array('add', $this->cohort1->id, ''); + $lines = []; + $lines[] = ['badvalue', $this->cohort1->id, $this->user1->id]; + $lines[] = ['add', 'badcohortid', $this->user2->id]; + $lines[] = ['add', $this->cohort1->id, 'badcohortid']; + $lines[] = ['add', '', $this->user1->id]; + $lines[] = ['add', $this->cohort1->id, '']; $filename = $this->set_csv_file($lines); diff --git a/tests/cohortsync_test.php b/tests/cohortsync_test.php index edd1b71..713850c 100644 --- a/tests/cohortsync_test.php +++ b/tests/cohortsync_test.php @@ -68,7 +68,7 @@ public static function setUpBeforeClass(): void { public function setUp(): void { $this->resetAfterTest(); $this->setAdminUser(); - $this->commonheader = array('name', 'idnumber', 'description', 'visible'); + $this->commonheader = ['name', 'idnumber', 'description', 'visible']; $this->trace = new \null_progress_trace(); } @@ -79,24 +79,24 @@ public function setUp(): void { public function test_cohortsync_with_column_category_as_name() { global $DB; - $cat1 = $this->getDataGenerator()->create_category(array('name' => 'CAT1')); - $cat2 = $this->getDataGenerator()->create_category(array('name' => 'CAT2')); + $cat1 = $this->getDataGenerator()->create_category(['name' => 'CAT1']); + $cat2 = $this->getDataGenerator()->create_category(['name' => 'CAT2']); - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1, 'CAT1'); - $cohorts[] = array('cohort name 2', 'cohortid2', 'first description', 1, 'CAT2'); - $cohorts[] = array('cohort name 3', 'cohortid3', 'first description', 1, 'CAT2'); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1, 'CAT1']; + $cohorts[] = ['cohort name 2', 'cohortid2', 'first description', 1, 'CAT2']; + $cohorts[] = ['cohort name 3', 'cohortid3', 'first description', 1, 'CAT2']; - $extraheader = array('category'); + $extraheader = ['category']; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); $cohortsync = new cohortsync($this->trace, $csvfilename); $cohortsync->update_cohorts(); $this->assertEmpty($cohortsync->get_errors()); - $cohort1 = $DB->get_record('cohort', array('idnumber' => 'cohortid1')); - $cohort2 = $DB->get_record('cohort', array('idnumber' => 'cohortid2')); - $cohort3 = $DB->get_record('cohort', array('idnumber' => 'cohortid3')); + $cohort1 = $DB->get_record('cohort', ['idnumber' => 'cohortid1']); + $cohort2 = $DB->get_record('cohort', ['idnumber' => 'cohortid2']); + $cohort3 = $DB->get_record('cohort', ['idnumber' => 'cohortid3']); $this->assertEquals('cohortid1', $cohort1->idnumber); $this->assertEquals('cohortid2', $cohort2->idnumber); @@ -117,15 +117,15 @@ public function test_cohortsync_with_column_category_as_name() { public function test_cohortsync_with_column_category_as_id() { global $DB; - $cat1 = $this->getDataGenerator()->create_category(array('name' => 'CAT1')); - $cat2 = $this->getDataGenerator()->create_category(array('name' => 'CAT2')); + $cat1 = $this->getDataGenerator()->create_category(['name' => 'CAT1']); + $cat2 = $this->getDataGenerator()->create_category(['name' => 'CAT2']); - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1, $cat1->id); - $cohorts[] = array('cohort name 2', 'cohortid2', 'first description', 1, $cat2->id); - $cohorts[] = array('cohort name 3', 'cohortid3', 'first description', 1, $cat2->id); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1, $cat1->id]; + $cohorts[] = ['cohort name 2', 'cohortid2', 'first description', 1, $cat2->id]; + $cohorts[] = ['cohort name 3', 'cohortid3', 'first description', 1, $cat2->id]; - $extraheader = array('category'); + $extraheader = ['category']; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); $cohortsync = new cohortsync($this->trace, $csvfilename); @@ -133,9 +133,9 @@ public function test_cohortsync_with_column_category_as_id() { $this->assertEmpty($cohortsync->get_errors()); - $cohort1 = $DB->get_record('cohort', array('idnumber' => 'cohortid1')); - $cohort2 = $DB->get_record('cohort', array('idnumber' => 'cohortid2')); - $cohort3 = $DB->get_record('cohort', array('idnumber' => 'cohortid3')); + $cohort1 = $DB->get_record('cohort', ['idnumber' => 'cohortid1']); + $cohort2 = $DB->get_record('cohort', ['idnumber' => 'cohortid2']); + $cohort3 = $DB->get_record('cohort', ['idnumber' => 'cohortid3']); $this->assertEquals('cohortid1', $cohort1->idnumber); $this->assertEquals('cohortid2', $cohort2->idnumber); @@ -155,15 +155,15 @@ public function test_cohortsync_with_column_category_as_id() { public function test_cohortsync_with_column_category_as_idnumber() { global $DB; - $cat1 = $this->getDataGenerator()->create_category(array('name' => 'CAT1', 'idnumber' => 'IDNBCAT1')); - $cat2 = $this->getDataGenerator()->create_category(array('name' => 'CAT2', 'idnumber' => 'IDNBCAT2')); + $cat1 = $this->getDataGenerator()->create_category(['name' => 'CAT1', 'idnumber' => 'IDNBCAT1']); + $cat2 = $this->getDataGenerator()->create_category(['name' => 'CAT2', 'idnumber' => 'IDNBCAT2']); - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1, $cat1->idnumber); - $cohorts[] = array('cohort name 2', 'cohortid2', 'first description', 1, $cat2->idnumber); - $cohorts[] = array('cohort name 3', 'cohortid3', 'first description', 1, $cat2->idnumber); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1, $cat1->idnumber]; + $cohorts[] = ['cohort name 2', 'cohortid2', 'first description', 1, $cat2->idnumber]; + $cohorts[] = ['cohort name 3', 'cohortid3', 'first description', 1, $cat2->idnumber]; - $extraheader = array('category'); + $extraheader = ['category']; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); $cohortsync = new cohortsync($this->trace, $csvfilename); @@ -171,9 +171,9 @@ public function test_cohortsync_with_column_category_as_idnumber() { $this->assertEmpty($cohortsync->get_errors()); - $cohort1 = $DB->get_record('cohort', array('idnumber' => 'cohortid1')); - $cohort2 = $DB->get_record('cohort', array('idnumber' => 'cohortid2')); - $cohort3 = $DB->get_record('cohort', array('idnumber' => 'cohortid3')); + $cohort1 = $DB->get_record('cohort', ['idnumber' => 'cohortid1']); + $cohort2 = $DB->get_record('cohort', ['idnumber' => 'cohortid2']); + $cohort3 = $DB->get_record('cohort', ['idnumber' => 'cohortid3']); $this->assertEquals('cohortid1', $cohort1->idnumber); $this->assertEquals('cohortid2', $cohort2->idnumber); @@ -193,18 +193,18 @@ public function test_cohortsync_with_column_category_as_idnumber() { public function test_cohortsync_with_column_contextid() { global $DB; - $cat1 = $this->getDataGenerator()->create_category(array('name' => 'CAT1')); - $cat2 = $this->getDataGenerator()->create_category(array('name' => 'CAT2')); + $cat1 = $this->getDataGenerator()->create_category(['name' => 'CAT1']); + $cat2 = $this->getDataGenerator()->create_category(['name' => 'CAT2']); $contextcat1 = \context_coursecat::instance($cat1->id); $contextcat2 = \context_coursecat::instance($cat2->id); - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1, $contextcat1->id); - $cohorts[] = array('cohort name 2', 'cohortid2', 'first description', 1, $contextcat2->id); - $cohorts[] = array('cohort name 3', 'cohortid3', 'first description', 1, $contextcat2->id); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1, $contextcat1->id]; + $cohorts[] = ['cohort name 2', 'cohortid2', 'first description', 1, $contextcat2->id]; + $cohorts[] = ['cohort name 3', 'cohortid3', 'first description', 1, $contextcat2->id]; - $extraheader = array('contextid'); + $extraheader = ['contextid']; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); $cohortsync = new cohortsync($this->trace, $csvfilename); @@ -212,9 +212,9 @@ public function test_cohortsync_with_column_contextid() { $this->assertEmpty($cohortsync->get_errors()); - $cohort1 = $DB->get_record('cohort', array('idnumber' => 'cohortid1')); - $cohort2 = $DB->get_record('cohort', array('idnumber' => 'cohortid2')); - $cohort3 = $DB->get_record('cohort', array('idnumber' => 'cohortid3')); + $cohort1 = $DB->get_record('cohort', ['idnumber' => 'cohortid1']); + $cohort2 = $DB->get_record('cohort', ['idnumber' => 'cohortid2']); + $cohort3 = $DB->get_record('cohort', ['idnumber' => 'cohortid3']); $this->assertEquals('cohortid1', $cohort1->idnumber); $this->assertEquals('cohortid2', $cohort2->idnumber); @@ -231,15 +231,15 @@ public function test_cohortsync_with_column_contextid() { public function test_cohortsync_with_column_category_id() { global $DB; - $cat1 = $this->getDataGenerator()->create_category(array('name' => 'CAT1')); - $cat2 = $this->getDataGenerator()->create_category(array('name' => 'CAT2')); + $cat1 = $this->getDataGenerator()->create_category(['name' => 'CAT1']); + $cat2 = $this->getDataGenerator()->create_category(['name' => 'CAT2']); - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1, $cat1->id); - $cohorts[] = array('cohort name 2', 'cohortid2', 'first description', 1, $cat2->id); - $cohorts[] = array('cohort name 3', 'cohortid3', 'first description', 1, $cat2->id); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1, $cat1->id]; + $cohorts[] = ['cohort name 2', 'cohortid2', 'first description', 1, $cat2->id]; + $cohorts[] = ['cohort name 3', 'cohortid3', 'first description', 1, $cat2->id]; - $extraheader = array('category_id'); + $extraheader = ['category_id']; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); $cohortsync = new cohortsync($this->trace, $csvfilename); @@ -247,9 +247,9 @@ public function test_cohortsync_with_column_category_id() { $this->assertEmpty($cohortsync->get_errors()); - $cohort1 = $DB->get_record('cohort', array('idnumber' => 'cohortid1')); - $cohort2 = $DB->get_record('cohort', array('idnumber' => 'cohortid2')); - $cohort3 = $DB->get_record('cohort', array('idnumber' => 'cohortid3')); + $cohort1 = $DB->get_record('cohort', ['idnumber' => 'cohortid1']); + $cohort2 = $DB->get_record('cohort', ['idnumber' => 'cohortid2']); + $cohort3 = $DB->get_record('cohort', ['idnumber' => 'cohortid3']); $this->assertEquals('cohortid1', $cohort1->idnumber); $this->assertEquals('cohortid2', $cohort2->idnumber); @@ -269,15 +269,15 @@ public function test_cohortsync_with_column_category_id() { public function test_cohortsync_with_column_category_idnumber() { global $DB; - $cat1 = $this->getDataGenerator()->create_category(array('name' => 'CAT1', 'idnumber' => 'IDNBCAT1')); - $cat2 = $this->getDataGenerator()->create_category(array('name' => 'CAT2', 'idnumber' => 'IDNBCAT2')); + $cat1 = $this->getDataGenerator()->create_category(['name' => 'CAT1', 'idnumber' => 'IDNBCAT1']); + $cat2 = $this->getDataGenerator()->create_category(['name' => 'CAT2', 'idnumber' => 'IDNBCAT2']); - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1, $cat1->idnumber); - $cohorts[] = array('cohort name 2', 'cohortid2', 'first description', 1, $cat2->idnumber); - $cohorts[] = array('cohort name 3', 'cohortid3', 'first description', 1, $cat2->idnumber); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1, $cat1->idnumber]; + $cohorts[] = ['cohort name 2', 'cohortid2', 'first description', 1, $cat2->idnumber]; + $cohorts[] = ['cohort name 3', 'cohortid3', 'first description', 1, $cat2->idnumber]; - $extraheader = array('category_idnumber'); + $extraheader = ['category_idnumber']; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); $cohortsync = new cohortsync($this->trace, $csvfilename); @@ -285,9 +285,9 @@ public function test_cohortsync_with_column_category_idnumber() { $this->assertEmpty($cohortsync->get_errors()); - $cohort1 = $DB->get_record('cohort', array('idnumber' => 'cohortid1')); - $cohort2 = $DB->get_record('cohort', array('idnumber' => 'cohortid2')); - $cohort3 = $DB->get_record('cohort', array('idnumber' => 'cohortid3')); + $cohort1 = $DB->get_record('cohort', ['idnumber' => 'cohortid1']); + $cohort2 = $DB->get_record('cohort', ['idnumber' => 'cohortid2']); + $cohort3 = $DB->get_record('cohort', ['idnumber' => 'cohortid3']); $this->assertEquals('cohortid1', $cohort1->idnumber); $this->assertEquals('cohortid2', $cohort2->idnumber); @@ -307,15 +307,15 @@ public function test_cohortsync_with_column_category_idnumber() { public function test_cohortsync_with_column_category_path() { global $DB; - $cat1 = $this->getDataGenerator()->create_category(array('name' => 'CAT1')); - $cat2 = $this->getDataGenerator()->create_category(array('parent' => $cat1->id, 'name' => 'CAT2')); + $cat1 = $this->getDataGenerator()->create_category(['name' => 'CAT1']); + $cat2 = $this->getDataGenerator()->create_category(['parent' => $cat1->id, 'name' => 'CAT2']); - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1, 'CAT1'); - $cohorts[] = array('cohort name 2', 'cohortid2', 'first description', 1, 'CAT1 / CAT2'); - $cohorts[] = array('cohort name 3', 'cohortid3', 'first description', 1, 'CAT1 / CAT2'); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1, 'CAT1']; + $cohorts[] = ['cohort name 2', 'cohortid2', 'first description', 1, 'CAT1 / CAT2']; + $cohorts[] = ['cohort name 3', 'cohortid3', 'first description', 1, 'CAT1 / CAT2']; - $extraheader = array('category_path'); + $extraheader = ['category_path']; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); $cohortsync = new cohortsync($this->trace, $csvfilename); @@ -323,9 +323,9 @@ public function test_cohortsync_with_column_category_path() { $this->assertEmpty($cohortsync->get_errors()); - $cohort1 = $DB->get_record('cohort', array('idnumber' => 'cohortid1')); - $cohort2 = $DB->get_record('cohort', array('idnumber' => 'cohortid2')); - $cohort3 = $DB->get_record('cohort', array('idnumber' => 'cohortid3')); + $cohort1 = $DB->get_record('cohort', ['idnumber' => 'cohortid1']); + $cohort2 = $DB->get_record('cohort', ['idnumber' => 'cohortid2']); + $cohort3 = $DB->get_record('cohort', ['idnumber' => 'cohortid3']); $this->assertEquals('cohortid1', $cohort1->idnumber); $this->assertEquals('cohortid2', $cohort2->idnumber); @@ -345,21 +345,21 @@ public function test_cohortsync_with_column_category_path() { public function test_cohortsync_with_defaultcontext() { global $DB; - $defaultcat = $this->getDataGenerator()->create_category(array('name' => 'DEFAULTCAT')); + $defaultcat = $this->getDataGenerator()->create_category(['name' => 'DEFAULTCAT']); $contextdefault = \context_coursecat::instance($defaultcat->id); - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1]; - $extraheader = array(); + $extraheader = []; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); - $cohortsync = new cohortsync($this->trace, $csvfilename, array('context' => $defaultcat->id)); + $cohortsync = new cohortsync($this->trace, $csvfilename, ['context' => $defaultcat->id]); $cohortsync->update_cohorts(); $this->assertEmpty($cohortsync->get_errors()); - $cohort1 = $DB->get_record('cohort', array('idnumber' => 'cohortid1')); + $cohort1 = $DB->get_record('cohort', ['idnumber' => 'cohortid1']); $this->assertEquals('cohortid1', $cohort1->idnumber); @@ -373,10 +373,10 @@ public function test_cohortsync_with_defaultcontext() { public function test_cohortsync_no_defaultcontext() { global $DB; - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1]; - $extraheader = array(); + $extraheader = []; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); $cohortsync = new cohortsync($this->trace, $csvfilename); @@ -384,7 +384,7 @@ public function test_cohortsync_no_defaultcontext() { $this->assertEmpty($cohortsync->get_errors()); - $cohort1 = $DB->get_record('cohort', array('idnumber' => 'cohortid1')); + $cohort1 = $DB->get_record('cohort', ['idnumber' => 'cohortid1']); $this->assertEquals('cohortid1', $cohort1->idnumber); @@ -398,13 +398,13 @@ public function test_cohortsync_no_defaultcontext() { public function test_cohortsync_wrong_defaultcontext() { global $DB; - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1]; - $extraheader = array(); + $extraheader = []; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); - $cohortsync = new cohortsync($this->trace, $csvfilename, array('context' => 100)); + $cohortsync = new cohortsync($this->trace, $csvfilename, ['context' => 100]); $this->assertEquals(1, count($cohortsync->get_errors())); $errormsg = $cohortsync->get_errors()[0]; @@ -445,16 +445,16 @@ public function test_cohortsync_with_notfoundfile() { */ public function test_cohortsync_with_no_columnnames() { - $cat1 = $this->getDataGenerator()->create_category(array('name' => 'CAT1')); + $cat1 = $this->getDataGenerator()->create_category(['name' => 'CAT1']); - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1, $cat1->id); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1, $cat1->id]; - $extracolums = array('category_path'); + $extracolums = ['category_path']; $columnname = false; - $header = array(); - $extraheader = array(); + $header = []; + $extraheader = []; $csvfilename = $this->set_csv_file($header, $extraheader, $cohorts); $cohortsync = new cohortsync($this->trace, $csvfilename); @@ -471,10 +471,10 @@ public function test_cohortsync_with_no_columnnames() { public function test_cohortsync_warnings_when_notfoundcategory() { global $DB; - $cohorts = array(); - $cohorts[] = array('cohort name 1', 'cohortid1', 'first description', 1, 100); + $cohorts = []; + $cohorts[] = ['cohort name 1', 'cohortid1', 'first description', 1, 100]; - $extraheader = array('category_id'); + $extraheader = ['category_id']; $csvfilename = $this->set_csv_file($this->commonheader, $extraheader, $cohorts); $cohortsync = new cohortsync($this->trace, $csvfilename); @@ -488,7 +488,7 @@ public function test_cohortsync_warnings_when_notfoundcategory() { // Test no errors found when creating cohorts. $this->assertEmpty($cohortsync->get_errors()); - $cohort1 = $DB->get_record('cohort', array('idnumber' => 'cohortid1')); + $cohort1 = $DB->get_record('cohort', ['idnumber' => 'cohortid1']); $this->assertEquals('cohortid1', $cohort1->idnumber); $contextsystem = \context_system::instance(); diff --git a/version.php b/version.php index 7930523..81902df 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2021112500; -$plugin->requires = 2021051704; +$plugin->version = 2024012500; +$plugin->requires = 2023100400; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '1.1.1 (Build 2021112500)'; +$plugin->release = '1.4.0 (Build 2024012500)'; $plugin->component = 'tool_cohortsync';