Skip to content

Commit

Permalink
Merge branch 'MDL-71163-master' of git://github.com/rezaies/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed May 3, 2021
2 parents 3f98128 + 7e50138 commit b04d1c3
Show file tree
Hide file tree
Showing 32 changed files with 237 additions and 219 deletions.
2 changes: 1 addition & 1 deletion admin/tool/behat/tests/behat/datetime_strings.feature
Expand Up @@ -21,5 +21,5 @@ Feature: Transform date time string arguments
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should see "##yesterday##%A, %d %B %Y##"
And I should see "##yesterday##%d %B %Y##"
And I log out
25 changes: 24 additions & 1 deletion course/classes/output/activity_information.php
Expand Up @@ -80,12 +80,35 @@ public function export_for_template(renderer_base $output): stdClass {

$data->cmid = $this->cminfo->id;
$data->activityname = $this->cminfo->name;
$data->activitydates = $this->activitydates;
$this->build_dates_data($data);
$data->hasdates = !empty($this->activitydates);

return $data;
}

/**
* Builds the dates data for export.
*
* @param stdClass $data
*/
protected function build_dates_data(stdClass $data): void {
foreach ($this->activitydates as $date) {
if (empty($date['relativeto'])) {
$date['datestring'] = userdate($date['timestamp'], get_string('strftimedatetime', 'core_langconfig'));
} else {
$diffstr = get_time_interval_string($date['timestamp'], $date['relativeto']);
if ($date['timestamp'] >= $date['relativeto']) {
$date['datestring'] = get_string('relativedatessubmissionduedateafter', 'core_course',
['datediffstr' => $diffstr]);
} else {
$date['datestring'] = get_string('relativedatessubmissionduedatebefore', 'core_course',
['datediffstr' => $diffstr]);
}
}
$data->activitydates[] = $date;
}
}

/**
* Builds the completion data for export.
*
Expand Down
4 changes: 2 additions & 2 deletions course/templates/activity_date.mustache
Expand Up @@ -22,9 +22,9 @@
Example context (json):
{
"label": "Opens:",
"timestamp": 1293876000
"datestring": "6 April 2021, 6:46 PM"
}
}}
<div>
<strong>{{label}}</strong> {{#userdate}} {{timestamp}}, {{#str}} strftimedatetime, core_langconfig {{/str}} {{/userdate}}
<strong>{{label}}</strong> {{datestring}}
</div>
2 changes: 2 additions & 0 deletions lang/en/course.php
Expand Up @@ -97,6 +97,8 @@
$string['privacy:metadata:favouritessummary'] = 'The course contains information relating to the course being starred by the user.';
$string['recommend'] = 'Recommend';
$string['recommendcheckbox'] = 'Recommend activity: {$a}';
$string['relativedatessubmissionduedateafter'] = '{$a->datediffstr} after course start';
$string['relativedatessubmissionduedatebefore'] = '{$a->datediffstr} before course start';
$string['searchactivitiesbyname'] = 'Search for activities by name';
$string['searchresults'] = 'Search results: {$a}';
$string['submitsearch'] = 'Submit search';
Expand Down
19 changes: 10 additions & 9 deletions lib/tests/behat/datetime_any.feature
Expand Up @@ -19,15 +19,16 @@ Feature: Any day / month / year combination in date form elements works ok.
And I set the field "Due date" to "<initial_date>"
And I set the field "Due date" to "<final_date>"
When I press "Save and display"
Then I should see "<date_result>" in the "Due date" "table_row"
Then the activity date in "Assignment 01" should contain "Due:"
And the activity date in "Assignment 01" should contain "<date_result>"

Examples:
| initial_date | final_date | date_result | case_explanation (times Australia/Perth) |
| ##today## | ##tomorrow noon## | ##tomorrow noon##%A, %d %B %Y, %I:%M## | change of day, any day, back and forth |
| ##tomorrow## | ##today noon## | ##today noon##%A, %d %B %Y, %I:%M## | |
| 1617256800 | 1617170400 | Wednesday, 31 March 2021, 2:00 | change of month, back and forth |
| 1617170400 | 1617256800 | Thursday, 1 April 2021, 2:00 | |
| 1740808800 | 1709186400 | Thursday, 29 February 2024, 2:00 | change of month, leap year, back and forth |
| 1709186400 | 1740808800 | Saturday, 1 March 2025, 2:00 | |
| 1577858400 | 1577772000 | Tuesday, 31 December 2019, 2:00 | change of year, back and forth |
| 1577772000 | 1577858400 | Wednesday, 1 January 2020, 2:00 | |
| ##today## | ##tomorrow noon## | ##tomorrow noon##%d %B %Y, %I:%M %p## | change of day, any day, back and forth |
| ##tomorrow## | ##today noon## | ##today noon##%d %B %Y, %I:%M %p## | |
| 1617256800 | 1617170400 | 31 March 2021, 2:00 PM | change of month, back and forth |
| 1617170400 | 1617256800 | 1 April 2021, 2:00 PM | |
| 1740808800 | 1709186400 | 29 February 2024, 2:00 PM | change of month, leap year, back and forth |
| 1709186400 | 1740808800 | 1 March 2025, 2:00 PM | |
| 1577858400 | 1577772000 | 31 December 2019, 2:00 PM | change of year, back and forth |
| 1577772000 | 1577858400 | 1 January 2020, 2:00 PM | |
34 changes: 32 additions & 2 deletions mod/assign/classes/dates.php
Expand Up @@ -42,24 +42,54 @@ class dates extends activity_dates {
* @return array
*/
protected function get_dates(): array {
global $CFG;

require_once($CFG->dirroot . '/mod/assign/locallib.php');

$course = get_course($this->cm->course);
$context = \context_module::instance($this->cm->id);
$assign = new \assign($context, $this->cm, $course);

$timeopen = $this->cm->customdata['allowsubmissionsfromdate'] ?? null;
$timedue = $this->cm->customdata['duedate'] ?? null;

$activitygroup = groups_get_activity_group($this->cm, true);
if ($activitygroup) {
if ($assign->can_view_grades()) {
$groupoverride = \cache::make('mod_assign', 'overrides')->get("{$this->cm->instance}_g_{$activitygroup}");
if (!empty($groupoverride->allowsubmissionsfromdate)) {
$timeopen = $groupoverride->allowsubmissionsfromdate;
}
if (!empty($groupoverride->duedate)) {
$timedue = $groupoverride->duedate;
}
}
}

$now = time();
$dates = [];

if ($timeopen) {
$openlabelid = $timeopen > $now ? 'activitydate:submissionsopen' : 'activitydate:submissionsopened';
$dates[] = [
$date = [
'label' => get_string($openlabelid, 'mod_assign'),
'timestamp' => (int) $timeopen,
];
if ($course->relativedatesmode && $assign->can_view_grades()) {
$date['relativeto'] = $course->startdate;
}
$dates[] = $date;
}

if ($timedue) {
$dates[] = [
$date = [
'label' => get_string('activitydate:submissionsdue', 'mod_assign'),
'timestamp' => (int) $timedue,
];
if ($course->relativedatesmode && $assign->can_view_grades()) {
$date['relativeto'] = $course->startdate;
}
$dates[] = $date;
}

return $dates;
Expand Down
16 changes: 9 additions & 7 deletions mod/assign/lang/en/assign.php
Expand Up @@ -22,9 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['activitydate:submissionsdue'] = 'Submissions due:';
$string['activitydate:submissionsopen'] = 'Submissions open:';
$string['activitydate:submissionsopened'] = 'Submissions opened:';
$string['activitydate:submissionsdue'] = 'Due:';
$string['activitydate:submissionsopen'] = 'Opens:';
$string['activitydate:submissionsopened'] = 'Opened:';
$string['activityoverview'] = 'You have assignments that need attention';
$string['addsubmission'] = 'Add submission';
$string['addsubmission_help'] = 'You have not made a submission yet.';
Expand All @@ -41,8 +41,6 @@
$string['allowsubmissionsshort'] = 'Allow submission changes';
$string['allowsubmissionsfromdate'] = 'Allow submissions from';
$string['allowsubmissionsfromdate_help'] = 'If enabled, students will not be able to submit before this date. If disabled, students will be able to start submitting right away.';
$string['allowsubmissionsfromdatesummary'] = 'This assignment will accept submissions from <strong>{$a}</strong>';
$string['allowsubmissionsanddescriptionfromdatesummary'] = 'The assignment details and submission form will be available from <strong>{$a}</strong>';
$string['alwaysshowdescription'] = 'Always show description';
$string['alwaysshowdescription_help'] = 'If disabled, the assignment description above will only become visible to students on the "Allow submissions from" date.';
$string['applytoteam'] = 'Apply grades and feedback to entire group';
Expand Down Expand Up @@ -451,8 +449,6 @@
$string['quickgradingchangessaved'] = 'The grade changes were saved';
$string['quickgrading_help'] = 'Quick grading allows you to assign grades (and outcomes) directly in the submissions table. Quick grading is not compatible with advanced grading and is not recommended when there are multiple markers.';
$string['relativedatessubmissiontimeleft'] = 'Calculated for each student';
$string['relativedatessubmissionduedateafter'] = '{$a->datediffstr} after course start';
$string['relativedatessubmissionduedatebefore'] = '{$a->datediffstr} before course start';
$string['removeallgroupoverrides'] = 'Delete all group overrides';
$string['removealluseroverrides'] = 'Delete all user overrides';
$string['reopenuntilpassincompatiblewithblindmarking'] = 'Reopen until pass option is incompatible with anonymous submissions, because the grades are not released to the gradebook until the student identities are revealed.';
Expand Down Expand Up @@ -641,3 +637,9 @@
$string['nosubmissionsacceptedafter'] = 'No submissions accepted after ';
$string['notsubmittedyet'] = 'Not submitted yet';
$string['submissionsnotgraded'] = 'Submissions not graded: {$a}';

// Deprecated since Moodle 3.11.
$string['allowsubmissionsfromdatesummary'] = 'This assignment will accept submissions from <strong>{$a}</strong>';
$string['allowsubmissionsanddescriptionfromdatesummary'] = 'The assignment details and submission form will be available from <strong>{$a}</strong>';
$string['relativedatessubmissionduedateafter'] = '{$a->datediffstr} after course start';
$string['relativedatessubmissionduedatebefore'] = '{$a->datediffstr} before course start';
4 changes: 4 additions & 0 deletions mod/assign/lang/en/deprecated.txt
@@ -1,6 +1,10 @@
allowsubmissionsfromdatesummary,mod_assign
allowsubmissionsanddescriptionfromdatesummary,mod_assign
duedateno,mod_assign
mysubmission,mod_assign
nolatesubmissions,mod_assign
nosubmissionsacceptedafter,mod_assign
notsubmittedyet,mod_assign
relativedatessubmissionduedateafter,mod_assign
relativedatessubmissionduedatebefore,mod_assign
submissionsnotgraded,mod_assign
10 changes: 10 additions & 0 deletions mod/assign/lib.php
Expand Up @@ -572,6 +572,16 @@ function mod_assign_cm_info_dynamic(cm_info $cm) {
}
}

// Calculate relative dates. The assignment module calculates relative date only for duedate.
// A user or group override always has higher priority over any relative date calculation.
if (empty($override->duedate) && !empty($cm->customdata['duedate'])) {
$course = get_course($cm->course);
$usercoursedates = course_get_course_dates_for_user_id($course, $USER->id);
if ($usercoursedates['start']) {
$override->duedate = $cm->customdata['duedate'] + $usercoursedates['startoffset'];
}
}

// Populate some other values that can be used in calendar or on dashboard.
if (!is_null($override->allowsubmissionsfromdate)) {
$cm->override_customdata('allowsubmissionsfromdate', $override->allowsubmissionsfromdate);
Expand Down
37 changes: 1 addition & 36 deletions mod/assign/renderer.php
Expand Up @@ -335,26 +335,8 @@ public function render_assign_grading_summary(assign_grading_summary $summary) {

$time = time();
if ($summary->duedate) {
// Due date.
$cell1content = get_string('duedate', 'assign');
$duedate = $summary->duedate;
if ($summary->courserelativedatesmode) {
// Returns a formatted string, in the format '10d 10h 45m'.
$diffstr = get_time_interval_string($duedate, $summary->coursestartdate);
if ($duedate >= $summary->coursestartdate) {
$cell2content = get_string('relativedatessubmissionduedateafter', 'mod_assign',
['datediffstr' => $diffstr]);
} else {
$cell2content = get_string('relativedatessubmissionduedatebefore', 'mod_assign',
['datediffstr' => $diffstr]);
}
} else {
$cell2content = userdate($duedate);
}

$this->add_table_row_tuple($t, $cell1content, $cell2content);

// Time remaining.
$duedate = $summary->duedate;
$cell1content = get_string('timeremaining', 'assign');
if ($summary->courserelativedatesmode) {
$cell2content = get_string('relativedatessubmissiontimeleft', 'mod_assign');
Expand Down Expand Up @@ -667,18 +649,6 @@ public function render_assign_submission_status(assign_submission_status $status
$o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
$time = time();

if ($status->allowsubmissionsfromdate &&
$time <= $status->allowsubmissionsfromdate) {
$o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
if ($status->alwaysshowdescription) {
$date = userdate($status->allowsubmissionsfromdate);
$o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date);
} else {
$date = userdate($status->allowsubmissionsfromdate);
$o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date);
}
$o .= $this->output->box_end();
}
$o .= $this->output->box_start('boxaligncenter submissionsummarytable');

$t = new html_table();
Expand Down Expand Up @@ -810,11 +780,6 @@ public function render_assign_submission_status(assign_submission_status $status
$submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
$duedate = $status->duedate;
if ($duedate > 0) {
// Due date.
$cell1content = get_string('duedate', 'assign');
$cell2content = userdate($duedate);
$this->add_table_row_tuple($t, $cell1content, $cell2content);

if ($status->view == assign_submission_status::GRADER_VIEW) {
if ($status->cutoffdate) {
// Cut off date.
Expand Down
14 changes: 7 additions & 7 deletions mod/assign/tests/behat/assign_group_override.feature
Expand Up @@ -93,12 +93,12 @@ Feature: Assign group override
And I log in as "student2"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
Then I should see "Saturday, 1 January 2000, 8:00"
Then the activity date in "Test assignment name" should contain "Due: 1 January 2000, 8:00 AM"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should see "Wednesday, 1 January 2020, 8:00"
And the activity date in "Test assignment name" should contain "Due: 1 January 2020, 8:00 AM"

Scenario: Allow a group to have a different cut off date
Given I log in as "teacher1"
Expand Down Expand Up @@ -149,13 +149,13 @@ Feature: Assign group override
And I log in as "student2"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
Then I should see "This assignment will accept submissions from Tuesday, 1 January 2030, 8:00"
Then the activity date in "Test assignment name" should contain "Opens: 1 January 2030, 8:00 AM"
And I should not see "Add submission"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should not see "This assignment will accept submissions from Tuesday, 1 January 2030, 8:00"
And I should not see "1 January 2030, 8:00 AM"

@javascript
Scenario: Add both a user and group override and verify that both are applied correctly
Expand Down Expand Up @@ -187,17 +187,17 @@ Feature: Assign group override
Then I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should see "This assignment will accept submissions from Wednesday, 1 January 2031, 8:00"
And the activity date in "Test assignment name" should contain "Opens: 1 January 2031, 8:00 AM"
And I log out
And I log in as "student2"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should see "This assignment will accept submissions from Sunday, 1 January 2040, 8:00"
And the activity date in "Test assignment name" should contain "Opens: 1 January 2040, 8:00 AM"
And I log out
And I log in as "student3"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should see "This assignment will accept submissions from Tuesday, 1 January 2030, 8:00"
And the activity date in "Test assignment name" should contain "Opens: 1 January 2030, 8:00 AM"

Scenario: Override a group when teacher is in no group, and does not have accessallgroups permission, and the activity's group mode is "separate groups"
Given the following "permission overrides" exist:
Expand Down
8 changes: 4 additions & 4 deletions mod/assign/tests/behat/assign_user_override.feature
Expand Up @@ -85,12 +85,12 @@ Feature: Assign user override
And I log in as "student2"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
Then I should see "Saturday, 1 January 2000, 8:00"
Then the activity date in "Test assignment name" should contain "Due: 1 January 2000, 8:00 AM"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should see "Wednesday, 1 January 2020, 8:00"
And the activity date in "Test assignment name" should contain "Due: 1 January 2020, 8:00 AM"

@javascript
Scenario: Allow a user to have a different cut off date
Expand Down Expand Up @@ -143,12 +143,12 @@ Feature: Assign user override
And I log in as "student2"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
Then I should see "This assignment will accept submissions from Tuesday, 1 January 2030, 8:00"
Then the activity date in "Test assignment name" should contain "Opens: 1 January 2030, 8:00 AM"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should not see "This assignment will accept submissions from Tuesday, 1 January 2030, 8:00"
And I should not see "1 January 2030, 8:00 AM"

Scenario: Override a user when teacher is in no group, and does not have accessallgroups permission, and the activity's group mode is "separate groups"
Given the following "permission overrides" exist:
Expand Down

0 comments on commit b04d1c3

Please sign in to comment.