Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open and close date in course overview #441

Open
wants to merge 4 commits into
base: MOODLE_400_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions classes/dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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;
}
}
8 changes: 7 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
39 changes: 39 additions & 0 deletions tests/behat/set_availability.feature
Original file line number Diff line number Diff line change
@@ -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 | [email protected] |
| teacher1 | Teacher | 1 | [email protected] |
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##"