diff --git a/.github/workflows/moodle-plugin-ci.yml b/.github/workflows/moodle-plugin-ci.yml index 04e3a5d..5998def 100644 --- a/.github/workflows/moodle-plugin-ci.yml +++ b/.github/workflows/moodle-plugin-ci.yml @@ -41,43 +41,48 @@ jobs: moodle-branch: master database: mariadb - - php: 8.2 - moodle-branch: MOODLE_403_STABLE + - php: 8.1 + moodle-branch: master database: pgsql - - php: 8.2 - moodle-branch: MOODLE_403_STABLE + - php: 8.1 + moodle-branch: master + database: mariadb + - php: 8.1 + moodle-branch: master + database: pgsql + - php: 8.1 + moodle-branch: master database: mariadb + - php: 8.2 - moodle-branch: MOODLE_402_STABLE + moodle-branch: MOODLE_403_STABLE database: pgsql - php: 8.2 - moodle-branch: MOODLE_402_STABLE + moodle-branch: MOODLE_403_STABLE database: mariadb - - php: 8.1 moodle-branch: MOODLE_403_STABLE database: pgsql - php: 8.1 moodle-branch: MOODLE_403_STABLE database: mariadb - - php: 8.1 + - php: 8.0 + moodle-branch: MOODLE_403_STABLE + database: pgsql + - php: 8.0 + moodle-branch: MOODLE_403_STABLE + database: mariadb + - php: 8.2 moodle-branch: MOODLE_402_STABLE database: pgsql - - php: 8.1 + - php: 8.2 moodle-branch: MOODLE_402_STABLE database: mariadb - php: 8.1 - moodle-branch: MOODLE_401_STABLE + moodle-branch: MOODLE_402_STABLE database: pgsql - php: 8.1 - moodle-branch: MOODLE_401_STABLE - database: mariadb - - - php: 8.0 - moodle-branch: MOODLE_403_STABLE - database: pgsql - - php: 8.0 - moodle-branch: MOODLE_403_STABLE + moodle-branch: MOODLE_402_STABLE database: mariadb - php: 8.0 moodle-branch: MOODLE_402_STABLE @@ -85,42 +90,41 @@ jobs: - php: 8.0 moodle-branch: MOODLE_402_STABLE database: mariadb - - php: 8.0 + - php: 8.1 moodle-branch: MOODLE_401_STABLE database: pgsql - - php: 8.0 + - php: 8.1 moodle-branch: MOODLE_401_STABLE database: mariadb - php: 8.0 - moodle-branch: MOODLE_400_STABLE + moodle-branch: MOODLE_401_STABLE database: pgsql - php: 8.0 - moodle-branch: MOODLE_400_STABLE + moodle-branch: MOODLE_401_STABLE database: mariadb - - php: 7.4 moodle-branch: MOODLE_401_STABLE database: pgsql - php: 7.4 moodle-branch: MOODLE_401_STABLE database: mariadb - - php: 7.4 + - php: 8.0 moodle-branch: MOODLE_400_STABLE database: pgsql - - php: 7.4 + - php: 8.0 moodle-branch: MOODLE_400_STABLE database: mariadb - php: 7.4 - moodle-branch: MOODLE_311_STABLE + moodle-branch: MOODLE_400_STABLE database: pgsql - php: 7.4 - moodle-branch: MOODLE_311_STABLE + moodle-branch: MOODLE_400_STABLE database: mariadb - php: 7.4 - moodle-branch: MOODLE_310_STABLE + moodle-branch: MOODLE_311_STABLE database: pgsql - php: 7.4 - moodle-branch: MOODLE_310_STABLE + moodle-branch: MOODLE_311_STABLE database: mariadb - php: 7.4 moodle-branch: MOODLE_39_STABLE @@ -128,109 +132,26 @@ jobs: - php: 7.4 moodle-branch: MOODLE_39_STABLE database: mariadb - - php: 7.4 - moodle-branch: MOODLE_38_STABLE - database: pgsql - - php: 7.4 - moodle-branch: MOODLE_38_STABLE - database: mariadb - - php: 7.3 - moodle-branch: MOODLE_400_STABLE - database: pgsql - - php: 7.3 - moodle-branch: MOODLE_400_STABLE - database: mariadb - php: 7.3 moodle-branch: MOODLE_311_STABLE database: pgsql - php: 7.3 moodle-branch: MOODLE_311_STABLE database: mariadb - - php: 7.3 - moodle-branch: MOODLE_310_STABLE - database: pgsql - - php: 7.3 - moodle-branch: MOODLE_310_STABLE - database: mariadb - php: 7.3 moodle-branch: MOODLE_39_STABLE database: pgsql - php: 7.3 moodle-branch: MOODLE_39_STABLE database: mariadb - - php: 7.3 - moodle-branch: MOODLE_38_STABLE - database: pgsql - - php: 7.3 - moodle-branch: MOODLE_38_STABLE - database: mariadb - - php: 7.3 - moodle-branch: MOODLE_37_STABLE - database: pgsql - - php: 7.3 - moodle-branch: MOODLE_37_STABLE - database: mariadb - - php: 7.3 - moodle-branch: MOODLE_36_STABLE - database: pgsql - - php: 7.3 - moodle-branch: MOODLE_36_STABLE - database: mariadb - - php: 7.2 - moodle-branch: MOODLE_310_STABLE - database: pgsql - - php: 7.2 - moodle-branch: MOODLE_310_STABLE - database: mariadb - php: 7.2 moodle-branch: MOODLE_39_STABLE database: pgsql - php: 7.2 moodle-branch: MOODLE_39_STABLE database: mariadb - - php: 7.2 - moodle-branch: MOODLE_38_STABLE - database: pgsql - - php: 7.2 - moodle-branch: MOODLE_38_STABLE - database: mariadb - - php: 7.2 - moodle-branch: MOODLE_37_STABLE - database: pgsql - - php: 7.2 - moodle-branch: MOODLE_37_STABLE - database: mariadb - - php: 7.2 - moodle-branch: MOODLE_36_STABLE - database: pgsql - - php: 7.2 - moodle-branch: MOODLE_36_STABLE - database: mariadb - - - php: 7.1 - moodle-branch: MOODLE_38_STABLE - database: pgsql - - php: 7.1 - moodle-branch: MOODLE_38_STABLE - database: mariadb - - php: 7.1 - moodle-branch: MOODLE_37_STABLE - database: pgsql - - php: 7.1 - moodle-branch: MOODLE_37_STABLE - database: mariadb - - php: 7.1 - moodle-branch: MOODLE_36_STABLE - database: pgsql - - php: 7.1 - moodle-branch: MOODLE_36_STABLE - database: mariadb - - - php: 7.0 - moodle-branch: MOODLE_36_STABLE - database: mariadb steps: - name: Check out repository code diff --git a/classes/external/exporter/bool_dto.php b/classes/external/exporter/bool_dto.php index 5d3dca7..c87f909 100644 --- a/classes/external/exporter/bool_dto.php +++ b/classes/external/exporter/bool_dto.php @@ -65,7 +65,7 @@ protected static function define_other_properties() { return [ 'result' => [ 'type' => PARAM_BOOL, - 'description' => 'a boolean value.' + 'description' => 'a boolean value.', ], ]; } diff --git a/classes/external/exporter/tab.php b/classes/external/exporter/tab.php index 690fc89..8df1b86 100644 --- a/classes/external/exporter/tab.php +++ b/classes/external/exporter/tab.php @@ -90,12 +90,12 @@ protected static function define_related() { * @return array */ protected function get_other_values(\renderer_base $output) { - $values = array( + $values = [ 'id' => $this->tab->id, 'tabtitle' => $this->tab->tabtitle, 'tabcolor' => $this->tab->tabcolor, 'targetinput' => $this->tab->targetinput, - ); + ]; return $values; } diff --git a/classes/external/handlers.php b/classes/external/handlers.php index faebf40..b19b6ab 100644 --- a/classes/external/handlers.php +++ b/classes/external/handlers.php @@ -51,10 +51,10 @@ class handlers extends \external_api { */ public static function get_handlers_parameters() { return new external_function_parameters( - array ( + [ 'userid' => new external_value(PARAM_INT, 'userid'), 'learninggoalid' => new external_value(PARAM_INT, 'learninggoalid'), - ) + ] ); } @@ -67,37 +67,37 @@ public static function get_handlers_parameters() { public static function get_handlers_returns() { return new external_multiple_structure( new external_single_structure( - array( + [ 'tabs' => new external_multiple_structure( new external_single_structure( - array( + [ 'id' => new external_value(PARAM_INT, 'Tabulator id', VALUE_OPTIONAL), 'tabtitle' => new external_value(PARAM_TEXT, 'Tabulator title', VALUE_OPTIONAL), 'tabcolor' => new external_value(PARAM_TEXT, 'Tabulator color', VALUE_OPTIONAL), 'targetinput' => new external_value(PARAM_TEXT, 'Target input field', VALUE_OPTIONAL), 'categories' => new external_multiple_structure( new external_single_structure( - array( + [ 'parenttabid' => new external_value(PARAM_TEXT, 'Parent tabulator id', VALUE_OPTIONAL), 'cattitle' => new external_value(PARAM_TEXT, 'Category title', VALUE_OPTIONAL), 'cattext' => new external_value(PARAM_TEXT, 'Category text', VALUE_OPTIONAL), 'words' => new external_multiple_structure( new external_single_structure( - array( + [ 'title' => new external_value(PARAM_TEXT, 'Word title', VALUE_OPTIONAL), 'text' => new external_value(PARAM_TEXT, 'Word text', VALUE_OPTIONAL), 'targetinput' => new external_value(PARAM_TEXT, 'Learning goal text field to be filled'), - ) + ] ), 'Category words', VALUE_OPTIONAL ), - ) + ] ), 'Tabulator categories', VALUE_OPTIONAL ), - ) + ] ), 'Tabulators', VALUE_OPTIONAL ), - ) + ] ), 'Handler tabs', VALUE_OPTIONAL ); } @@ -112,10 +112,10 @@ public static function get_handlers_returns() { */ public static function get_handlers($userid, $learninggoalid) { self::validate_parameters(self::get_handlers_parameters(), - array( + [ 'userid' => $userid, - 'learninggoalid' => $learninggoalid - ) + 'learninggoalid' => $learninggoalid, + ] ); self::validate_context(\context_system::instance()); @@ -125,7 +125,7 @@ public static function get_handlers($userid, $learninggoalid) { // Do additional setup stuff. $settings = external_settings::get_instance(); - $displaylang = $settings->get_lang() ? $settings->get_lang() : ($SESSION->lang ? $SESSION->lang : $USER->lang); + $displaylang = $settings->get_lang() ? $settings->get_lang() : (isset($SESSION->lang) ? $SESSION->lang : $USER->lang); $ctx = \context_system::instance(); diff --git a/classes/external/learninggoal.php b/classes/external/learninggoal.php index b6bcebe..f26664b 100644 --- a/classes/external/learninggoal.php +++ b/classes/external/learninggoal.php @@ -159,10 +159,10 @@ public static function duplicate_learninggoal_returns() { public static function get_learninggoal($userid, $learninggoalid) { global $USER; $params = self::validate_parameters(self::get_learninggoal_parameters(), - array( + [ 'userid' => $userid, - 'learninggoalid' => $learninggoalid - ) + 'learninggoalid' => $learninggoalid, + ] ); // TODO check if the learning goal really belongs to the user. @@ -173,10 +173,7 @@ public static function get_learninggoal($userid, $learninggoalid) { // Do additional setup stuff. $settings = external_settings::get_instance(); - $sessionlang = $settings->get_lang(); - if (!empty($sessionlang)) { - $SESSION->lang = $sessionlang; - } + $displaylang = $settings->get_lang() ? $settings->get_lang() : (isset($SESSION->lang) ? $SESSION->lang : $USER->lang); $ctx = \context_system::instance(); if ($learninggoalid > 0) { @@ -210,19 +207,19 @@ public static function get_learninggoal($userid, $learninggoalid) { get_string('clicktoedit', 'local_differentiator') . "' AS \"name\", " . "'' AS \"description\", '" . get_string('prethinkingskill', 'local_differentiator') . "' AS \"pre_thinking_skill\", " . - "(SELECT tswetext from {local_differentiator_tswe} WHERE tswid = 1 AND lang = '" . $SESSION->lang . "') AS " . + "(SELECT tswetext from {local_differentiator_tswe} WHERE tswid = 1 AND lang = '" . $displaylang . "') AS " . "\"thinking_skill\", " . - "(SELECT cwetext from {local_differentiator_cwe} WHERE cwid = 1 AND lang = '" . $SESSION->lang . "') AS " . + "(SELECT cwetext from {local_differentiator_cwe} WHERE cwid = 1 AND lang = '" . $displaylang . "') AS " . "\"content\", '" . get_string('clicktoedit', 'local_differentiator') . "' AS \"subject\", '" . get_string('preresource', 'local_differentiator') . "' AS \"pre_resource\", " . - "(SELECT rwetext from {local_differentiator_rwe} WHERE rwid = 1 AND lang = '" . $SESSION->lang . "') AS " . + "(SELECT rwetext from {local_differentiator_rwe} WHERE rwid = 1 AND lang = '" . $displaylang . "') AS " . "\"resource\", '" . get_string('preproduct', 'local_differentiator') . "' AS \"pre_product\", " . - "(SELECT pwetext from {local_differentiator_pwe} WHERE pwid = 37 AND lang = '" . $SESSION->lang . "') AS " . + "(SELECT pwetext from {local_differentiator_pwe} WHERE pwid = 37 AND lang = '" . $displaylang . "') AS " . "\"product\", '" . get_string('pregroup', 'local_differentiator') . "' AS \"pre_group\", " . - "(SELECT gwetext from {local_differentiator_gwe} WHERE gwid = 1 AND lang = '" . $SESSION->lang . "') AS \"group\""; + "(SELECT gwetext from {local_differentiator_gwe} WHERE gwid = 1 AND lang = '" . $displaylang . "') AS \"group\""; $learninggoal = $DB->get_record_sql($sql); } $exporter = new exporter\learninggoal($learninggoal, $ctx); @@ -272,7 +269,7 @@ public static function save_learninggoal($userid, $learninggoalid, $name, $preth 'pre_product' => $preproduct, 'product' => $product, 'pre_group' => $pregroup, - 'group' => $group + 'group' => $group, ]; self::validate_parameters(self::save_learninggoal_parameters(), $params); @@ -325,10 +322,10 @@ public static function delete_learninggoal($userid, $learninggoalid) { global $USER; $params = self::validate_parameters(self::get_learninggoal_parameters(), - array( + [ 'userid' => $userid, - 'learninggoalid' => $learninggoalid - ) + 'learninggoalid' => $learninggoalid, + ] ); // TODO check if the learning goal really belongs to the user. @@ -343,7 +340,7 @@ public static function delete_learninggoal($userid, $learninggoalid) { $ctx = \context_system::instance(); if (isset($learninggoalid) && ($learninggoalid > 0)) { - $DB->delete_records('local_differentiator_lg', array('id' => $learninggoalid, 'userid' => $USER->id)); + $DB->delete_records('local_differentiator_lg', ['id' => $learninggoalid, 'userid' => $USER->id]); } // Return success status. @@ -363,10 +360,10 @@ public static function duplicate_learninggoal($userid, $learninggoalid) { global $USER; $params = self::validate_parameters(self::get_learninggoal_parameters(), - array( + [ 'userid' => $userid, - 'learninggoalid' => $learninggoalid - ) + 'learninggoalid' => $learninggoalid, + ] ); // TODO check if the learning goal really belongs to the user. diff --git a/classes/external/learninggoals.php b/classes/external/learninggoals.php index 844d8fc..9a27679 100644 --- a/classes/external/learninggoals.php +++ b/classes/external/learninggoals.php @@ -29,6 +29,20 @@ use external_value; use external_single_structure; +// This work-around is required until Moodle 4.2 is the lowest version we support. +if (class_exists('core_external\external_api') && class_exists('core_external\external_function_parameters') + && class_exists('core_external\external_value') && class_exists('core_external\external_multiple_structure')) { + class_alias('core_external\external_api', '\local_differentiator_external_api_class_alias'); + class_alias('core_external\external_function_parameters', '\local_differentiator_external_function_parameters_class_alias'); + class_alias('core_external\external_value', '\local_differentiator_external_value_class_alias'); + class_alias('core_external\external_multiple_structure', '\local_differentiator_external_multiple_structure_class_alias'); +} else { + class_alias('external_api', '\local_differentiator_external_api_class_alias'); + class_alias('external_function_parameters', '\local_differentiator_external_function_parameters_class_alias'); + class_alias('external_value', '\local_differentiator_external_value_class_alias'); + class_alias('external_multiple_structure', '\local_differentiator_external_multiple_structure_class_alias'); +} + /** * Class learninggoals * @@ -36,7 +50,7 @@ * @copyright 2019 Luca Bösch * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class learninggoals extends \external_api { +class learninggoals extends \local_differentiator_external_api_class_alias { /** * Definition of parameters for {@see get_learninggoals()}. * Returns description of method parameters. @@ -44,9 +58,9 @@ class learninggoals extends \external_api { * @return external_function_parameters */ public static function get_learninggoals_parameters() { - return new external_function_parameters([ - 'userid' => new external_value(PARAM_INT, 'userid'), - 'learninggoalid' => new external_value(PARAM_INT, 'learninggoalid'), + return new \local_differentiator_external_function_parameters_class_alias([ + 'userid' => new \local_differentiator_external_value_class_alias(PARAM_INT, 'userid'), + 'learninggoalid' => new \local_differentiator_external_value_class_alias(PARAM_INT, 'learninggoalid'), ]); } @@ -57,7 +71,7 @@ public static function get_learninggoals_parameters() { * @return external_multiple_structure */ public static function get_learninggoals_returns() { - return new external_multiple_structure( + return new \local_differentiator_external_multiple_structure_class_alias( exporter\learninggoal::get_read_structure() ); } @@ -73,10 +87,10 @@ public static function get_learninggoals_returns() { public static function get_learninggoals($userid, $learninggoalid) { global $USER; $params = self::validate_parameters(self::get_learninggoals_parameters(), - array( + [ 'userid' => $userid, - 'learninggoalid' => $learninggoalid - ) + 'learninggoalid' => $learninggoalid, + ] ); $userid = $USER->id; diff --git a/classes/form/form_controller.php b/classes/form/form_controller.php index aaaf375..167199c 100644 --- a/classes/form/form_controller.php +++ b/classes/form/form_controller.php @@ -24,7 +24,7 @@ namespace local_differentiator\form; -use \local_differentiator\differentiator; +use local_differentiator\differentiator; /** * Class form_controller diff --git a/db/access.php b/db/access.php index eb8c0ca..ba7de8e 100644 --- a/db/access.php +++ b/db/access.php @@ -31,15 +31,15 @@ 'captype' => 'view', 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => [ - 'user' => CAP_ALLOW - ] + 'user' => CAP_ALLOW, + ], ], 'local/differentiator:edit' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => [ - 'user' => CAP_ALLOW - ] + 'user' => CAP_ALLOW, + ], ], ]; diff --git a/db/services.php b/db/services.php index 3b88c96..6564618 100644 --- a/db/services.php +++ b/db/services.php @@ -24,50 +24,50 @@ defined('MOODLE_INTERNAL') || die(); -$functions = array( - 'local_differentiator_get_learninggoals' => array( +$functions = [ + 'local_differentiator_get_learninggoals' => [ 'classname' => 'local_differentiator\external\learninggoals', 'methodname' => 'get_learninggoals', 'description' => 'Get all learning goals.', 'type' => 'read', 'ajax' => true, 'capabilities' => 'local/differentiator:edit', - ), - 'local_differentiator_get_learninggoal' => array( + ], + 'local_differentiator_get_learninggoal' => [ 'classname' => 'local_differentiator\external\learninggoal', 'methodname' => 'get_learninggoal', 'description' => 'Get a specific learning goal.', 'type' => 'read', 'ajax' => true, 'capabilities' => 'local/differentiator:edit', - ), - 'local_differentiator_get_handlers' => array( + ], + 'local_differentiator_get_handlers' => [ 'classname' => 'local_differentiator\external\handlers', 'methodname' => 'get_handlers', 'description' => 'Get the differentiator handlers.', 'type' => 'read', 'ajax' => true, 'capabilities' => 'local/differentiator:edit', - ), - 'local_differentiator_save_learninggoal' => array( + ], + 'local_differentiator_save_learninggoal' => [ 'classname' => 'local_differentiator\external\learninggoal', 'methodname' => 'save_learninggoal', 'description' => 'Save a specific learning goal.', 'type' => 'write', 'ajax' => true, - ), - 'local_differentiator_delete_learninggoal' => array( + ], + 'local_differentiator_delete_learninggoal' => [ 'classname' => 'local_differentiator\external\learninggoal', 'methodname' => 'delete_learninggoal', 'description' => 'Delete a specific learning goal.', 'type' => 'write', 'ajax' => true, - ), - 'local_differentiator_duplicate_learninggoal' => array( + ], + 'local_differentiator_duplicate_learninggoal' => [ 'classname' => 'local_differentiator\external\learninggoal', 'methodname' => 'duplicate_learninggoal', 'description' => 'Duplicate a specific learning goal.', 'type' => 'write', 'ajax' => true, - ), -); + ], +]; diff --git a/tests/behat/add.feature b/tests/behat/add.feature new file mode 100644 index 0000000..6b57bef --- /dev/null +++ b/tests/behat/add.feature @@ -0,0 +1,8 @@ +@javascript @local @local_differentiator +Feature: Access differentiator and add a learning goal. + + @javascript + Scenario: Access a differentiator and add a learning goal + Given I log in as "admin" + And I am on the "Differentiator" "local_differentiator > Differentiator" page + And I press "Add a new goal" diff --git a/tests/behat/behat_local_differentiator.php b/tests/behat/behat_local_differentiator.php new file mode 100644 index 0000000..2d6b957 --- /dev/null +++ b/tests/behat/behat_local_differentiator.php @@ -0,0 +1,51 @@ +. + +/** + * Behat local/differentiator related steps definitions. + * + * @package local_differentiator + * @category test + * @copyright 2024 Luca Bösch + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. + +require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); + +/** + * Step definitions related to local_differentiator. + */ +class behat_local_differentiator extends behat_base { + /** + * Convert page names to URLs for the step 'When I am on the "Differentiator" page'. + * + * @param string $type identifies which type of page this is, e.g. 'Differentiator'. + * @param string $identifier identifies the particular page, e.g. 'Test questionnaire > preview > Attempt 1'. + * @return moodle_url the corresponding URL. + * @throws Exception with a meaningful error message if the specified page cannot be found. + */ + protected function resolve_page_instance_url(string $type, string $identifier): moodle_url { + switch (strtolower($type)) { + case 'differentiator': + return new moodle_url('/local/differentiator/index.php'); + default: + return new moodle_url('/local/differentiator/index.php'); + } + } +} + diff --git a/version.php b/version.php index abe85dc..b51e596 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'local_differentiator'; -$plugin->release = 'v4.3-r1'; -$plugin->version = 2023010700; -$plugin->requires = 2018051700; +$plugin->release = 'v4.3-r2'; +$plugin->version = 2024030200; +$plugin->requires = 2020061500; $plugin->maturity = MATURITY_STABLE; -$plugin->supported = [36, 403]; +$plugin->supported = [39, 403];