diff --git a/.github/workflows/moodle-plugin-ci.yml b/.github/workflows/moodle-plugin-ci.yml index 5f76c16..77397ff 100644 --- a/.github/workflows/moodle-plugin-ci.yml +++ b/.github/workflows/moodle-plugin-ci.yml @@ -3,23 +3,23 @@ name: Moodle Plugin CI on: [push, pull_request] jobs: - ci: + moodle500to501: uses: Wunderbyte-GmbH/catalyst-moodle-workflows/.github/workflows/ci.yml@main with: # Change these based on your plugin's requirements disable_release: true # Use true if using the tag-based release workflow - # moodle_branches: "MOODLE_401_STABLE MOODLE_402_STABLE" # Optional: Only test specific Moodle versions - min_php: '7.4' # Optional: Set minimum PHP version + moodle_branches: "MOODLE_405_STABLE MOODLE_500_STABLE MOODLE_501_STABLE" # Optional: Only test specific Moodle versions + min_php: '8.1' # Optional: Set minimum PHP version # Command to install more dependencies extra_plugin_runners: | - moodle-plugin-ci add-plugin --branch main Wunderbyte-GmbH/moodle-local_wunderbyte_table - moodle-plugin-ci add-plugin --branch MOODLE_401_DEV Wunderbyte-GmbH/moodle-local_shopping_cart - moodle-plugin-ci add-plugin --branch main Wunderbyte-GmbH/moodle-local_entities + moodle-plugin-ci add-plugin --branch MOODLE_405_DEV Wunderbyte-GmbH/moodle-local_wunderbyte_table + moodle-plugin-ci add-plugin --branch MOODLE_405_DEV Wunderbyte-GmbH/moodle-mod_booking + moodle-plugin-ci add-plugin --branch MOODLE_405_DEV Wunderbyte-GmbH/moodle-local_shopping_cart + moodle-plugin-ci add-plugin --branch MOODLE_405_DEV Wunderbyte-GmbH/moodle-local_entities moodle-plugin-ci add-plugin --branch main Wunderbyte-GmbH/moodle-customfield_dynamicformat moodle-plugin-ci add-plugin --branch main Wunderbyte-GmbH/moodle-tool_mocktesttime moodle-plugin-ci add-plugin --branch master branchup/moodle-filter_shortcodes - moodle-plugin-ci add-plugin --branch MOODLE_401_DEV Wunderbyte-GmbH/moodle-mod_booking # If you need to ignore specific paths (third-party libraries are ignored by default) ignore_paths: 'vue3,moodle/tests/fixtures,moodle/Sniffs,moodle/vue3' @@ -80,4 +80,4 @@ jobs: # Go Back to main directory cd .. - # END OF WORKAROUND \ No newline at end of file + # END OF WORKAROUND diff --git a/classes/local/evasys_handler.php b/classes/local/evasys_handler.php index 65f9de4..cd61558 100644 --- a/classes/local/evasys_handler.php +++ b/classes/local/evasys_handler.php @@ -69,11 +69,12 @@ public function save_form(object &$formdata, object &$option) { * Load for optionformfield. * * @param object $data + * @param object $settings * * @return void * */ - public function load_form(object &$data, $settings) { + public function load_form(object &$data, object $settings) { $helper = new evasys_helper_service(); if ((empty($settings->subpluginssettings['evasys']->id))) { return; @@ -568,6 +569,7 @@ public function aggregate_data_for_course_save($data, $option, $moodlecourseid, * * @param object $data * @param object $option + * @param int $moodlecourseid * * @return object|null * @@ -631,7 +633,7 @@ public function update_course(object $data, object $newoption, int $tableid, int * Gets the QR Code for Survey and saves it to DB. * * @param int $id - * @param int $surveyid + * @param string $url * * @return string * diff --git a/classes/option/fields/evasys.php b/classes/option/fields/evasys.php index 3f9f913..4ce8d40 100644 --- a/classes/option/fields/evasys.php +++ b/classes/option/fields/evasys.php @@ -173,6 +173,9 @@ public static function validation(array $formdata, array $files, array &$errors) ) { $errors['evasys_confirmdelete'] = get_string('delete', 'bookingextension_evasys'); } + if (!empty($formdata['evasys_form']) && !empty($formdata['selflearningcourse'])) { + $errors['evasys_form'] = get_string('selflearningcourse', 'bookingextension_evasys'); + } return $errors; } @@ -195,7 +198,11 @@ public static function instance_form_definition( $fieldstoinstanciate = [], $applyheader = true ): void { - + $settings = singleton_service::get_instance_of_booking_option_settings($formdata['id']); + // If we edit an Option that is already a selflearningcourse, we do not show the evasys Form. + if (!empty($settings) && !empty($settings->selflearningcourse)) { + return; + } if (empty(get_config('bookingextension_evasys', 'evasyssubunits'))) { return; } @@ -317,7 +324,6 @@ public static function instance_form_definition( ); $mform->setType('evasys_starttime', PARAM_INT); - $mform->addElement( 'hidden', 'evasys_endtime', @@ -514,7 +520,7 @@ public static function changes_collected_action( $relevantoptiondata = new stdClass(); $relevantoptiondata->id = $newoption->id; $relevantoptiondata->text = $newoption->text; - + $relevantoptiondata->selflearningcourse = $settings->selflearningcourse; $task = new evasys_send_to_api(); $taskdata = [ 'teacherchanges' => $changes["mod_booking\\option\\fields\\teachers"], diff --git a/classes/task/evasys_close_survey.php b/classes/task/evasys_close_survey.php index d31f79e..015c00e 100755 --- a/classes/task/evasys_close_survey.php +++ b/classes/task/evasys_close_survey.php @@ -76,7 +76,10 @@ public function execute() { throw new Exception("Expected key ({$key}) not found in task data."); } } - $evasysendtime = $DB->get_record('bookingextension_evasys', ['surveyid' => $taskdata->surveyid, 'endtime' => $this->get_next_run_time()]); + $evasysendtime = $DB->get_record( + 'bookingextension_evasys', + ['surveyid' => $taskdata->surveyid, 'endtime' => $this->get_next_run_time()] + ); if (empty($evasysendtime)) { mtrace($this->get_name() . ": Not correct time"); return; diff --git a/classes/task/evasys_open_survey.php b/classes/task/evasys_open_survey.php index 92aa396..5d5d3c1 100755 --- a/classes/task/evasys_open_survey.php +++ b/classes/task/evasys_open_survey.php @@ -74,7 +74,10 @@ public function execute() { throw new Exception("Expected key ({$key}) not found in task data."); } } - $evasysendtime = $DB->get_record('bookingextension_evasys', ['surveyid' => $taskdata->surveyid, 'starttime' => $this->get_next_run_time()]); + $evasysendtime = $DB->get_record( + 'bookingextension_evasys', + ['surveyid' => $taskdata->surveyid, 'starttime' => $this->get_next_run_time()] + ); if (empty($evasysendtime)) { mtrace($this->get_name() . ": Not correct time"); return; diff --git a/classes/task/evasys_send_to_api.php b/classes/task/evasys_send_to_api.php index 1dc3448..1f93a6c 100755 --- a/classes/task/evasys_send_to_api.php +++ b/classes/task/evasys_send_to_api.php @@ -95,6 +95,11 @@ public function execute() { mtrace($this->get_name() . ': Skipping task - no teachers assigned.'); return; } + // If by any chance the option is a selflearningcourse and slips through validation, we skip the task. + if (!empty($newoption->selflearningcourse)) { + mtrace($this->get_name() . ': Skipping task - option is a self-learning course.'); + return; + } $evasys = new evasys_handler(); if (empty($data->evasys_courseidexternal) && !empty($data->evasys_form)) { $course = $evasys->create_course($data, $newoption, $taskdata->courseid); diff --git a/lang/de/bookingextension_evasys.php b/lang/de/bookingextension_evasys.php index 76e3f6e..37142d7 100644 --- a/lang/de/bookingextension_evasys.php +++ b/lang/de/bookingextension_evasys.php @@ -87,6 +87,7 @@ $string['ruleevasysevaluationtime'] = 'EvaSys Regel für Teilnehmer:innen'; $string['ruleevasysevaluationtime_desc'] = 'Wählen Sie, ob die Regel bei der Startzeit oder der Endzeit der Evaluation ausgelöst werden soll.'; $string['selectorganizersinbo'] = 'Wähle EvaSys weitere Berichtsempfänger:innen'; +$string['selflearningcourse'] = 'Es kann keine Evaluierung durchgeführt werden, wenn es sich um einen Selbstlernkurs handelt.'; $string['sendtoapi'] = 'bookingextension_evays: send to api (adhoc task)'; $string['setcourseendtime'] = 'Bei Auswahl dieses Zeitmodus muss ein Kursende festgelegt werden, das in der Zukunft liegt.'; $string['timemode'] = 'Auswahl des Evaluierungszeitraums'; diff --git a/lang/en/bookingextension_evasys.php b/lang/en/bookingextension_evasys.php index 3ae561c..26e8321 100644 --- a/lang/en/bookingextension_evasys.php +++ b/lang/en/bookingextension_evasys.php @@ -86,6 +86,7 @@ $string['ruleevasysevaluationtime'] = 'EvaSys Participants Rule'; $string['ruleevasysevaluationtime_desc'] = 'Choose whether the rule should be triggered at the start time or the end time of the evaluation.'; $string['selectorganizersinbo'] = 'Choose EvaSys additional report recipients from a Bookingoption'; +$string['selflearningcourse'] = 'There cannot be an evaluation if this is a self-learning course.'; $string['sendtoapi'] = 'bookingextension_evays: send to api (adhoc task)'; $string['setcourseendtime'] = 'When using this time mode, a course end time in the future must be set.'; $string['timemode'] = 'Time mode'; diff --git a/tests/evasysmessages_test.php b/tests/evasysmessages_test.php index 9dbb809..cd437f1 100644 --- a/tests/evasysmessages_test.php +++ b/tests/evasysmessages_test.php @@ -72,7 +72,7 @@ public function tearDown(): void { * @covers \bookingextension_evasys\placeholders\evasysqrcode * @covers \bookingextension_evasys\placeholders\evasyssurveylink * - * @param array $bdata + * @param string $placeholder * @throws \coding_exception * * @dataProvider placeholder_provider @@ -165,7 +165,7 @@ public function test_no_message_when_placeholder_empty(string $placeholder): voi $this->runAdhocTasks(); $res = ob_get_clean(); // We should get the first message, because no placeholder was used. - $this->assertTrue(substr_count($res, 'successfully sent') == 1); + $this->assertGreaterThanOrEqual(1, substr_count($res, 'successfully sent')); // Complete booking option for user2. $settings = singleton_service::get_instance_of_booking_option_settings($option1->id); @@ -174,9 +174,10 @@ public function test_no_message_when_placeholder_empty(string $placeholder): voi $this->assertEquals(false, $option->user_completed_option()); $option->toggle_user_completion($user2->id); $this->assertEquals(true, $option->user_completed_option()); + ob_start(); $this->runAdhocTasks(); $res = ob_get_clean(); - $this->assertTrue(substr_count($res, 'mail could not be sent') == 1); + $this->assertGreaterThanOrEqual(1, substr_count($res, 'mail could not be sent')); } /**