From c3a1100286c3dea1ab1fb9691533878462bbe033 Mon Sep 17 00:00:00 2001 From: Adrian Czermak Date: Fri, 3 Mar 2023 01:59:44 +0100 Subject: [PATCH 1/3] added open and close date --- lib.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib.php b/lib.php index fdbd465c0..8fdfd8e0d 100644 --- a/lib.php +++ b/lib.php @@ -254,7 +254,7 @@ function questionnaire_get_coursemodule_info($coursemodule) { global $DB; $questionnaire = $DB->get_record('questionnaire', - array('id' => $coursemodule->instance), 'id, name, intro, introformat, + array('id' => $coursemodule->instance), 'id, name, intro, introformat, opendate, closedate, completionsubmit'); if (!$questionnaire) { return null; @@ -266,6 +266,12 @@ function questionnaire_get_coursemodule_info($coursemodule) { if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) { $info->customdata->customcompletionrules['completionsubmit'] = $questionnaire->completionsubmit; } + if ($questionnaire->opendate) { + $info->customdata->opendate = $questionnaire->opendate; + } + if ($questionnaire->closedate) { + $info->customdata->closedate = $questionnaire->closedate; + } return $info; } From 4c2ec554f14951a3ce564aefab95fc6e0789718f Mon Sep 17 00:00:00 2001 From: Adrian Czermak Date: Fri, 3 Mar 2023 02:07:59 +0100 Subject: [PATCH 2/3] missing files --- classes/dates.php | 71 ++++++++++++++++++++++++++++ tests/behat/set_availability.feature | 37 +++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 classes/dates.php create mode 100644 tests/behat/set_availability.feature diff --git a/classes/dates.php b/classes/dates.php new file mode 100644 index 000000000..e266c9d93 --- /dev/null +++ b/classes/dates.php @@ -0,0 +1,71 @@ +. + +/** + * Contains the class for fetching the important dates in mod_questionnaire for a given module instance and a user. + * + * @package mod_questionnaire + * @copyright 2022 University of Vienna + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +declare(strict_types=1); + +namespace mod_questionnaire; + +use core\activity_dates; + +/** + * Class for fetching the important dates in mod_questionnaire for a given module instance and a user. + * + * @copyright 2022 University of Vienna + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class dates extends activity_dates { + + /** + * Returns a list of important dates in mod_questionnaire + * + * @return array + */ + protected function get_dates(): array { + global $DB; + + $timeopen = $this->cm->customdata->opendate ?? null; + $timeclose = $this->cm->customdata->closedate ?? null; + + $now = time(); + $dates = []; + + if ($timeopen) { + $openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened'; + $dates[] = [ + 'label' => get_string($openlabelid, 'core_course'), + 'timestamp' => (int) $timeopen, + ]; + } + + if ($timeclose) { + $closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed'; + $dates[] = [ + 'label' => get_string($closelabelid, 'core_course'), + 'timestamp' => (int) $timeclose, + ]; + } + + return $dates; + } +} diff --git a/tests/behat/set_availability.feature b/tests/behat/set_availability.feature new file mode 100644 index 000000000..660b34c59 --- /dev/null +++ b/tests/behat/set_availability.feature @@ -0,0 +1,37 @@ +@mod @mod_questionnaire +Feature: View questionnaire availability information in the course view + In order to have visibility of the questionnaire availability requirements + As a student + I need to be able to view the availability dates + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | enablecompletion | + | Course 1 | C1 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | student1 | C1 | student | + | teacher1 | C1 | editingteacher | + And the following "activities" exist: + | activity | name | introduction | course | idnumber | + | questionnaire | Test questionnaire | Test questionnaire description | C1 | questionnaire0 | + + @javascript + Scenario: Student can see the open and close dates on the course page + Given I log in as "teacher1" + And I am on the "Test questionnaire" "questionnaire activity" page + And I navigate to "Settings" in current page administration + And I follow "Expand all" + And I set the field "Allow responses from" to "##3 days ago##" + And I set the field "Allow responses until" to "##tomorrow noon##" + And I press "Save and return to course" + And I log out + + When I log in as "student1" + And I am on "Course 1" course homepage + Then I should see "Opened: " + And I should see "Closes: " From b4b24071aa7b7c022e630d8c4d9f8e13cebc2443 Mon Sep 17 00:00:00 2001 From: Adrian Czermak Date: Fri, 3 Mar 2023 04:31:03 +0100 Subject: [PATCH 3/3] behat fix --- tests/behat/set_availability.feature | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/behat/set_availability.feature b/tests/behat/set_availability.feature index 660b34c59..3bb9d0f7e 100644 --- a/tests/behat/set_availability.feature +++ b/tests/behat/set_availability.feature @@ -10,8 +10,8 @@ Feature: View questionnaire availability information in the course view | student1 | Student | 1 | student1@example.com | | teacher1 | Teacher | 1 | teacher1@example.com | And the following "courses" exist: - | fullname | shortname | enablecompletion | - | Course 1 | C1 | 1 | + | fullname | shortname | showactivitydates | + | Course 1 | C1 | 1 | And the following "course enrolments" exist: | user | course | role | | student1 | C1 | student | @@ -34,4 +34,6 @@ Feature: View questionnaire availability information in the course view When I log in as "student1" And I am on "Course 1" course homepage Then I should see "Opened: " + And I should see "##3 days ago##%A, %d %B %Y, %I:%M##" And I should see "Closes: " + And I should see "##tomorrow noon##%A, %d %B %Y, %I:%M##"