diff --git a/classes/local/api.php b/classes/local/api.php index 6528d7f..ef3208e 100644 --- a/classes/local/api.php +++ b/classes/local/api.php @@ -147,8 +147,8 @@ public static function get_courses_series_title($courseid) { * @throws \moodle_exception */ public static function get_instance($instanceid = null, - $settings = array(), - $customconfigs = array(), + $settings = [], + $customconfigs = [], $enableingest = false) { if (self::use_test_api() === true) { @@ -203,8 +203,8 @@ private static function use_test_api() : bool { * @throws \moodle_exception */ public function __construct($instanceid = null, - $settings = array(), - $customconfigs = array(), + $settings = [], + $customconfigs = [], $enableingest = false) { // Allow access to local ips. $settings['ignoresecurity'] = true; @@ -268,9 +268,9 @@ public function __construct($instanceid = null, throw new empty_configuration_exception('apiurlempty', 'tool_opencast'); } - $this->setopt(array( + $this->setopt([ 'CURLOPT_TIMEOUT_MS' => $this->timeout, - 'CURLOPT_CONNECTTIMEOUT_MS' => $this->connecttimeout)); + 'CURLOPT_CONNECTTIMEOUT_MS' => $this->connecttimeout, ]); $config = [ 'url' => $this->baseurl, @@ -289,7 +289,7 @@ public function __construct($instanceid = null, */ public function set_timeout($timeout) { $this->timeout = $timeout; - $this->setopt(array('CURLOPT_TIMEOUT_MS' => $this->timeout)); + $this->setopt(['CURLOPT_TIMEOUT_MS' => $this->timeout]); } /** @@ -298,7 +298,7 @@ public function set_timeout($timeout) { */ public function set_connecttimeout($connecttimeout) { $this->connecttimeout = $connecttimeout; - $this->setopt(array('CURLOPT_CONNECTTIMEOUT_MS' => $this->connecttimeout)); + $this->setopt(['CURLOPT_CONNECTTIMEOUT_MS' => $this->connecttimeout]); } /** @@ -331,9 +331,9 @@ public function get_http_code() { * @return array of authentification headers * @throws \moodle_exception */ - private function get_authentication_header($runwithroles = array()) { + private function get_authentication_header($runwithroles = []) { - $options = array('CURLOPT_HEADER' => true); + $options = ['CURLOPT_HEADER' => true]; $this->setopt($options); // Restrict to Roles. @@ -344,7 +344,7 @@ private function get_authentication_header($runwithroles = array()) { $basicauth = base64_encode($this->username . ":" . $this->password); - $header = array(); + $header = []; $header[] = sprintf( 'Authorization: Basic %s', $basicauth @@ -362,14 +362,14 @@ private function get_authentication_header($runwithroles = array()) { * @return string JSON String of result. * @throws \moodle_exception */ - public function oc_get($resource, $runwithroles = array()) { + public function oc_get($resource, $runwithroles = []) { $url = $this->baseurl . $resource; $this->resetHeader(); $header = $this->get_authentication_header($runwithroles); $header[] = 'Content-Type: application/json'; $this->setHeader($header); - $this->setopt(array('CURLOPT_HEADER' => false)); + $this->setopt(['CURLOPT_HEADER' => false]); return $this->get($url); } @@ -460,7 +460,7 @@ private function add_postname_chunkupload($file, $key) { * @return string JSON String of result. * @throws \moodle_exception */ - public function oc_post($resource, $params = array(), $runwithroles = array()) { + public function oc_post($resource, $params = [], $runwithroles = []) { $url = $this->baseurl . $resource; @@ -468,12 +468,12 @@ public function oc_post($resource, $params = array(), $runwithroles = array()) { $header = $this->get_authentication_header($runwithroles); $header[] = "Content-Type: multipart/form-data"; $this->setHeader($header); - $this->setopt(array('CURLOPT_HEADER' => false)); + $this->setopt(['CURLOPT_HEADER' => false]); $options['CURLOPT_POST'] = 1; if (is_array($params)) { - $this->_tmp_file_post_params = array(); + $this->_tmp_file_post_params = []; foreach ($params as $key => $value) { if ($value instanceof \stored_file) { $value->add_to_curl_request($this, $key); @@ -505,18 +505,18 @@ public function oc_post($resource, $params = array(), $runwithroles = array()) { * @return string JSON String of result. * @throws \moodle_exception */ - public function oc_put($resource, $params = array(), $runwithroles = array()) { + public function oc_put($resource, $params = [], $runwithroles = []) { $url = $this->baseurl . $resource; $this->resetHeader(); $header = $this->get_authentication_header($runwithroles); $this->setHeader($header); - $this->setopt(array('CURLOPT_HEADER' => false)); + $this->setopt(['CURLOPT_HEADER' => false]); $options['CURLOPT_CUSTOMREQUEST'] = "PUT"; if (is_array($params)) { - $this->_tmp_file_post_params = array(); + $this->_tmp_file_post_params = []; foreach ($params as $key => $value) { $this->_tmp_file_post_params[$key] = $value; } @@ -540,18 +540,18 @@ public function oc_put($resource, $params = array(), $runwithroles = array()) { * @return string JSON String of result. * @throws \moodle_exception */ - public function oc_delete($resource, $params = array(), $runwithroles = array()) { + public function oc_delete($resource, $params = [], $runwithroles = []) { $url = $this->baseurl . $resource; $this->resetHeader(); $header = $this->get_authentication_header($runwithroles); $this->setHeader($header); - $this->setopt(array('CURLOPT_HEADER' => false)); + $this->setopt(['CURLOPT_HEADER' => false]); $options['CURLOPT_CUSTOMREQUEST'] = "DELETE"; if (is_array($params)) { - $this->_tmp_file_post_params = array(); + $this->_tmp_file_post_params = []; foreach ($params as $key => $value) { $this->_tmp_file_post_params[$key] = $value; } diff --git a/classes/local/api_testable.php b/classes/local/api_testable.php index 11aef87..56829e2 100644 --- a/classes/local/api_testable.php +++ b/classes/local/api_testable.php @@ -92,7 +92,7 @@ public function __construct($instanceid = null, $enableingest = false) { 'password' => $this->password, 'timeout' => (intval($this->timeout) / 1000), 'connect_timeout' => (intval($this->connecttimeout) / 1000), - 'version' => $this->version + 'version' => $this->version, ]; $handler = \OpencastApi\Mock\OcMockHanlder::getHandlerStackWithPath($this->jsonresponses); @@ -139,10 +139,10 @@ public static function add_json_response($resource, $method, $status = 200, $bod $jsonresponses = []; } if (!array_key_exists($resource, $jsonresponses)) { - $jsonresponses[$resource] = array(); + $jsonresponses[$resource] = []; } if (!isset($jsonresponses[$resource][strtoupper($method)])) { - $jsonresponses[$resource][strtoupper($method)] = array(); + $jsonresponses[$resource][strtoupper($method)] = []; } $responseobject = compact('status', 'body', 'version', 'reason', 'params', 'headers'); $jsonresponses[$resource][strtoupper($method)][] = $responseobject; diff --git a/classes/local/settings_api.php b/classes/local/settings_api.php index 434cfe4..5b0ba39 100644 --- a/classes/local/settings_api.php +++ b/classes/local/settings_api.php @@ -221,12 +221,12 @@ public static function get_ocinstances() : array { try { $ocinstancesconfig = get_config('tool_opencast', 'ocinstances'); } catch (\dml_exception $exception) { - return array(); + return []; } $dynamicocinstances = json_decode($ocinstancesconfig); - $ocinstances = array(); + $ocinstances = []; foreach ($dynamicocinstances as $dynamicocinstance) { $ocinstances[] = new opencast_instance($dynamicocinstance); } @@ -243,7 +243,7 @@ public static function get_ocinstances() : array { * The Opencast instance, to that all configured Opencast instances are set to. */ public static function set_ocinstances_to_ocinstance($dynamicocinstance) : void { - set_config('ocinstances', json_encode(array($dynamicocinstance)), 'tool_opencast'); + set_config('ocinstances', json_encode([$dynamicocinstance]), 'tool_opencast'); } /** diff --git a/classes/seriesmapping.php b/classes/seriesmapping.php index dbf9a46..ab349dc 100644 --- a/classes/seriesmapping.php +++ b/classes/seriesmapping.php @@ -45,26 +45,26 @@ class seriesmapping extends \core\persistent { */ protected static function define_properties() { - return array( - 'id' => array( + return [ + 'id' => [ 'type' => PARAM_INT, - ), - 'courseid' => array( + ], + 'courseid' => [ 'type' => PARAM_INT, - ), - 'series' => array( + ], + 'series' => [ 'type' => PARAM_ALPHANUMEXT, - ), - 'ocinstanceid' => array( + ], + 'ocinstanceid' => [ 'type' => PARAM_INT, 'default' => function () { return settings_api::get_default_ocinstance()->id; - } - ), - 'isdefault' => array( + }, + ], + 'isdefault' => [ 'type' => PARAM_BOOL, - ), - ); + ], + ]; } /** @@ -73,7 +73,7 @@ protected static function define_properties() { * @param false $skipdefault * @return false|seriesmapping */ - public static function get_record($filters = array(), $skipdefault = false) { + public static function get_record($filters = [], $skipdefault = false) { // TODO later deprecate skipdefault and remove this compatibility stuff. // Keep it compatible with old versions. if (!$skipdefault && !array_key_exists('isdefault', $filters)) { diff --git a/classes/settings/admin_settings_builder.php b/classes/settings/admin_settings_builder.php index 93d0380..a35f56e 100644 --- a/classes/settings/admin_settings_builder.php +++ b/classes/settings/admin_settings_builder.php @@ -436,7 +436,7 @@ private static function add_connection_test_tool(\admin_settingpage $settings, 'class' => 'btn btn-warning disabled testtool-modal', 'disabled' => 'disabled', 'title' => get_string('testtooldisabledbuttontitle', self::PLUGINNAME), - 'data-instanceid' => strval($instanceid) + 'data-instanceid' => strval($instanceid), ]; $connectiontoolbutton = \html_writer::tag( diff --git a/db/access.php b/db/access.php index 196d32d..34a75ba 100644 --- a/db/access.php +++ b/db/access.php @@ -24,30 +24,30 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ - 'tool/opencast:instructor' => array( + 'tool/opencast:instructor' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'editingteacher' => CAP_ALLOW - ) - ), + 'archetypes' => [ + 'editingteacher' => CAP_ALLOW, + ], + ], - 'tool/opencast:learner' => array( + 'tool/opencast:learner' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ) - ), + ], + ], - 'tool/opencast:externalapi' => array( + 'tool/opencast:externalapi' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( - ) - ), -); + 'archetypes' => [ + ], + ], +]; diff --git a/db/services.php b/db/services.php index 3acea16..42d8c0a 100644 --- a/db/services.php +++ b/db/services.php @@ -22,32 +22,32 @@ */ defined('MOODLE_INTERNAL') || die(); -$functions = array( - 'tool_opencast_get_courses_for_learner' => array( +$functions = [ + 'tool_opencast_get_courses_for_learner' => [ 'classname' => 'tool_opencast_external', 'methodname' => 'get_courses_for_learner', 'classpath' => 'admin/tool/opencast/external.php', 'description' => 'Service to query the courses in which a user has the capability of a learner', 'type' => 'read', 'capabilities' => 'tool/opencast:externalapi', - ), - 'tool_opencast_get_courses_for_instructor' => array( + ], + 'tool_opencast_get_courses_for_instructor' => [ 'classname' => 'tool_opencast_external', 'methodname' => 'get_courses_for_instructor', 'classpath' => 'admin/tool/opencast/external.php', 'description' => 'Service to query the courses in which a user has the capability of a instructor', 'type' => 'read', 'capabilities' => 'tool/opencast:externalapi', - ), - 'tool_opencast_get_groups_for_learner' => array( + ], + 'tool_opencast_get_groups_for_learner' => [ 'classname' => 'tool_opencast_external', 'methodname' => 'get_groups_for_learner', 'classpath' => 'admin/tool/opencast/external.php', 'description' => 'Service to query the groups in which a user has a membership in', 'type' => 'read', 'capabilities' => 'tool/opencast:externalapi, moodle/site:accessallgroups', - ), - 'tool_opencast_connection_test_tool' => array( + ], + 'tool_opencast_connection_test_tool' => [ 'classname' => 'tool_opencast_external', 'methodname' => 'connection_test_tool', 'classpath' => 'admin/tool/opencast/external.php', @@ -56,19 +56,19 @@ 'capabilities' => 'tool/opencast:externalapi', 'ajax' => true, 'loginrequired' => true, - ), -); + ], +]; -$services = array( - 'Opencast web service' => array( - 'functions' => array ( +$services = [ + 'Opencast web service' => [ + 'functions' => [ 'tool_opencast_get_courses_for_learner', 'tool_opencast_get_courses_for_instructor', 'tool_opencast_get_groups_for_learner', 'core_user_get_users_by_field', - ), + ], 'restrictedusers' => 1, // If 1, the administrator must manually select which user can use this service. // (Administration > Plugins > Web services > Manage services > Authorised users). 'enabled' => 1, // If 0, then token linked to this service won't work. - ) -); + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index 3d77797..6ce2c01 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -44,8 +44,8 @@ function xmldb_tool_opencast_upgrade($oldversion) { $table->add_field('series', XMLDB_TYPE_CHAR, '36', null, XMLDB_NOTNULL, null, null); // Adding keys to table tool_opencast_series. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('fk_course', XMLDB_KEY_FOREIGN_UNIQUE, array('courseid'), 'course', array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_key('fk_course', XMLDB_KEY_FOREIGN_UNIQUE, ['courseid'], 'course', ['id']); // Conditionally launch create table for tool_opencast_series. if (!$dbman->table_exists($table)) { @@ -67,7 +67,7 @@ function xmldb_tool_opencast_upgrade($oldversion) { } // Remove unique key. - $dbman->drop_key($table, new xmldb_key('fk_course', XMLDB_KEY_FOREIGN_UNIQUE, array('courseid'), 'course', array('id'))); + $dbman->drop_key($table, new xmldb_key('fk_course', XMLDB_KEY_FOREIGN_UNIQUE, ['courseid'], 'course', ['id'])); // Check that each course has only exactly one series. $sql = "SELECT courseid, COUNT(id) FROM {tool_opencast_series} GROUP BY courseid "; @@ -110,8 +110,8 @@ function xmldb_tool_opencast_upgrade($oldversion) { $dbman->change_field_notnull($table, $field); // Add new foreign key and unique constraint. - $table->add_key('fk_course', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); - $table->add_key('unq_course_series_ocinstance', XMLDB_KEY_UNIQUE, array('courseid', 'ocinstanceid', 'series')); + $table->add_key('fk_course', XMLDB_KEY_FOREIGN, ['courseid'], 'course', ['id']); + $table->add_key('unq_course_series_ocinstance', XMLDB_KEY_UNIQUE, ['courseid', 'ocinstanceid', 'series']); // Opencast savepoint reached. upgrade_plugin_savepoint(true, 2021091200, 'tool', 'opencast'); diff --git a/external.php b/external.php index e15214a..1a9e64b 100644 --- a/external.php +++ b/external.php @@ -47,9 +47,9 @@ class tool_opencast_external extends external_api { */ public static function get_courses_for_instructor_parameters() { return new external_function_parameters( - array( + [ 'username' => new external_value(core_user::get_property_type('username'), 'User Name'), - ) + ] ); } @@ -61,9 +61,9 @@ public static function get_courses_for_instructor_parameters() { */ public static function get_courses_for_learner_parameters() { return new external_function_parameters( - array( + [ 'username' => new external_value(core_user::get_property_type('username'), 'User Name'), - ) + ] ); } @@ -75,9 +75,9 @@ public static function get_courses_for_learner_parameters() { */ public static function get_groups_for_learner_parameters() { return new external_function_parameters( - array( + [ 'username' => new external_value(core_user::get_property_type('username'), 'User Name'), - ) + ] ); } @@ -92,7 +92,7 @@ public static function get_groups_for_learner_parameters() { * @throws required_capability_exception */ public static function get_courses_for_instructor($username) { - self::validate_parameters(self::get_courses_for_instructor_parameters(), array('username' => $username)); + self::validate_parameters(self::get_courses_for_instructor_parameters(), ['username' => $username]); return self::get_courses_with_capability($username, 'tool/opencast:instructor'); } @@ -108,7 +108,7 @@ public static function get_courses_for_instructor($username) { * @throws required_capability_exception */ public static function get_courses_for_learner($username) { - self::validate_parameters(self::get_courses_for_learner_parameters(), array('username' => $username)); + self::validate_parameters(self::get_courses_for_learner_parameters(), ['username' => $username]); return self::get_courses_with_capability($username, 'tool/opencast:learner'); } @@ -124,7 +124,7 @@ public static function get_courses_for_learner($username) { * @throws required_capability_exception */ public static function get_groups_for_learner($username) { - self::validate_parameters(self::get_groups_for_learner_parameters(), array('username' => $username)); + self::validate_parameters(self::get_groups_for_learner_parameters(), ['username' => $username]); $context = context_system::instance(); if (!has_capability('tool/opencast:externalapi', $context)) { @@ -136,7 +136,7 @@ public static function get_groups_for_learner($username) { global $DB; $user = core_user::get_user_by_username($username); - return $DB->get_records('groups_members', array('userid' => $user->id), '', 'groupid as id'); + return $DB->get_records('groups_members', ['userid' => $user->id], '', 'groupid as id'); } /** @@ -149,7 +149,7 @@ public static function get_groups_for_learner($username) { * @throws required_capability_exception */ private static function get_courses_with_capability($username, $capability) { - $result = array(); + $result = []; $context = context_system::instance(); if (!has_capability('tool/opencast:externalapi', $context)) { @@ -161,7 +161,7 @@ private static function get_courses_with_capability($username, $capability) { foreach ($courses as $course) { $context = context_course::instance($course->id); if (has_capability($capability, $context, $user)) { - $result[] = array('id' => $course->id); + $result[] = ['id' => $course->id]; } } return $result; @@ -175,9 +175,9 @@ private static function get_courses_with_capability($username, $capability) { public static function get_courses_for_instructor_returns() { return new external_multiple_structure( new external_single_structure( - array( + [ 'id' => new external_value(PARAM_INT, 'id of course'), - ) + ] ) ); } @@ -190,9 +190,9 @@ public static function get_courses_for_instructor_returns() { public static function get_courses_for_learner_returns() { return new external_multiple_structure( new external_single_structure( - array( + [ 'id' => new external_value(PARAM_INT, 'id of course'), - ) + ] ) ); } @@ -205,9 +205,9 @@ public static function get_courses_for_learner_returns() { public static function get_groups_for_learner_returns() { return new external_multiple_structure( new external_single_structure( - array( + [ 'id' => new external_value(PARAM_INT, 'id of group'), - ) + ] ) ); } @@ -219,9 +219,9 @@ public static function get_groups_for_learner_returns() { */ public static function connection_test_tool_returns() { return new external_single_structure( - array( + [ 'testresult' => new external_value(PARAM_RAW, 'Opencast API URL Test result'), - ) + ] ); } @@ -233,13 +233,13 @@ public static function connection_test_tool_returns() { */ public static function connection_test_tool_parameters() { return new external_function_parameters( - array( + [ 'apiurl' => new external_value(PARAM_TEXT, 'Opencast API URL'), 'apiusername' => new external_value(PARAM_TEXT, 'Opencast API User'), 'apipassword' => new external_value(PARAM_RAW, 'Opencast API Password'), 'apitimeout' => new external_value(PARAM_INT, 'API timeout', VALUE_DEFAULT, 2000), 'apiconnecttimeout' => new external_value(PARAM_INT, 'API connect timeout', VALUE_DEFAULT, 1000), - ) + ] ); } @@ -259,14 +259,14 @@ private static function connection_test_tool_build_html_alert_tag($connectiontes return html_writer::tag( 'p', get_string($testsuccessfulstringidentifier, 'tool_opencast'), - array('class' => 'alert alert-success') + ['class' => 'alert alert-success'] ); } return html_writer::tag( 'p', get_string($testfailedstringidentifier, 'tool_opencast', $connectiontestresult), - array('class' => 'alert alert-danger') + ['class' => 'alert alert-danger'] ); } @@ -288,23 +288,23 @@ public static function connection_test_tool($apiurl, $apiusername, $apipassword, // Validate the parameters. $params = self::validate_parameters(self::connection_test_tool_parameters(), - array( + [ 'apiurl' => $apiurl, 'apiusername' => $apiusername, 'apipassword' => $apipassword, 'apitimeout' => $apitimeout, - 'apiconnecttimeout' => $apiconnecttimeout - ) + 'apiconnecttimeout' => $apiconnecttimeout, + ] ); // Get a customized api instance to use. - $customizedapi = \tool_opencast\local\api::get_instance(null, array(), array( + $customizedapi = \tool_opencast\local\api::get_instance(null, [], [ 'apiurl' => $params['apiurl'], 'apiusername' => $params['apiusername'], 'apipassword' => $params['apipassword'], 'apitimeout' => $params['apitimeout'], - 'apiconnecttimeout' => $params['apiconnecttimeout'] - )); + 'apiconnecttimeout' => $params['apiconnecttimeout'], + ]); // Test the URL. $connectiontesturlresult = $customizedapi->connection_test_url(); @@ -321,7 +321,7 @@ public static function connection_test_tool($apiurl, $apiusername, $apipassword, 'apicreadentialstestfailedshort'); return [ - 'testresult' => $resulthtml + 'testresult' => $resulthtml, ]; } } diff --git a/tests/generator/behat_tool_opencast_generator.php b/tests/generator/behat_tool_opencast_generator.php index fa53a07..5e20270 100644 --- a/tests/generator/behat_tool_opencast_generator.php +++ b/tests/generator/behat_tool_opencast_generator.php @@ -43,7 +43,7 @@ protected function get_creatable_entities(): array { 'series' => [ 'singular' => 'series', 'datagenerator' => 'series', - 'required' => ['course', 'series', 'isdefault', 'ocinstanceid'] + 'required' => ['course', 'series', 'isdefault', 'ocinstanceid'], ], ]; } diff --git a/tests/generator/lib.php b/tests/generator/lib.php index eaf0eae..cb79adc 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -39,13 +39,13 @@ class tool_opencast_generator extends testing_module_generator { */ public function create_series($data) { global $DB; - $courses = $DB->get_records('course', array('shortname' => $data['course'])); + $courses = $DB->get_records('course', ['shortname' => $data['course']]); $series = (object)[ 'courseid' => reset($courses)->id, 'series' => $data['series'], 'isdefault' => $data['isdefault'], - 'ocinstanceid' => $data['ocinstanceid'] + 'ocinstanceid' => $data['ocinstanceid'], ]; $DB->insert_record('tool_opencast_series', $series); } diff --git a/version.php b/version.php index f1c63a0..aa909d7 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'tool_opencast'; -$plugin->release = 'development-version'; -$plugin->version = 2023051200; -$plugin->requires = 2020061500; // Requires Moodle 3.9+. -$plugin->maturity = MATURITY_ALPHA; +$plugin->release = 'v4.3-r1'; +$plugin->version = 2023112200; +$plugin->requires = 2020061524; // Requires Moodle 3.9+. +$plugin->maturity = MATURITY_STABLE;