diff --git a/classes/dates.php b/classes/dates.php new file mode 100644 index 00000000..e266c9d9 --- /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/lib.php b/lib.php index 46ac3232..83fc00f2 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; } diff --git a/tests/behat/set_availability.feature b/tests/behat/set_availability.feature new file mode 100644 index 00000000..3bb9d0f7 --- /dev/null +++ b/tests/behat/set_availability.feature @@ -0,0 +1,39 @@ +@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 | showactivitydates | + | 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 "##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##"