Merge branch 'MDL-70818-311-4' of git://github.com/rezaies/moodle into MOODLE_311_STABLE

This commit is contained in:
abgreeve
2021-04-23 12:18:31 +08:00
14 changed files with 1029 additions and 1 deletions
+68
View File
@@ -0,0 +1,68 @@
<?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_data for a given module instance and a user.
*
* @package mod_data
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_data;
use core\activity_dates;
/**
* Class for fetching the important dates in mod_data for a given module instance and a user.
*
* @copyright 2021 Shamim Rezaie <[email protected]>
* @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_data
*
* @return array
*/
protected function get_dates(): array {
$timeopen = $this->cm->customdata['timeavailablefrom'] ?? null;
$timeclose = $this->cm->customdata['timeavailableto'] ?? null;
$now = time();
$dates = [];
if ($timeopen) {
$openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened';
$dates[] = [
'label' => get_string($openlabelid, 'course'),
'timestamp' => (int) $timeopen,
];
}
if ($timeclose) {
$closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed';
$dates[] = [
'label' => get_string($closelabelid, 'course'),
'timestamp' => (int) $timeclose,
];
}
return $dates;
}
}
+122
View File
@@ -0,0 +1,122 @@
<?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 unit tests for mod_data\dates.
*
* @package mod_data
* @category test
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_data;
use advanced_testcase;
use cm_info;
use core\activity_dates;
/**
* Class for unit testing mod_data\dates.
*
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dates_test extends advanced_testcase {
/**
* Data provider for get_dates_for_module().
* @return array[]
*/
public function get_dates_for_module_provider(): array {
$now = time();
$before = $now - DAYSECS;
$earlier = $before - DAYSECS;
$after = $now + DAYSECS;
$later = $after + DAYSECS;
return [
'without any dates' => [
null, null, []
],
'only with opening time' => [
$after, null, [
['label' => 'Opens:', 'timestamp' => $after],
]
],
'only with closing time' => [
null, $after, [
['label' => 'Closes:', 'timestamp' => $after],
]
],
'with both times' => [
$after, $later, [
['label' => 'Opens:', 'timestamp' => $after],
['label' => 'Closes:', 'timestamp' => $later],
]
],
'between the dates' => [
$before, $after, [
['label' => 'Opened:', 'timestamp' => $before],
['label' => 'Closes:', 'timestamp' => $after],
]
],
'dates are past' => [
$earlier, $before, [
['label' => 'Opened:', 'timestamp' => $earlier],
['label' => 'Closed:', 'timestamp' => $before],
]
],
];
}
/**
* Test for get_dates_for_module().
*
* @dataProvider get_dates_for_module_provider
* @param int|null $availablefrom The "available from" time in the database activity.
* @param int|null $availableto The "available to" time in the database activity.
* @param array $expected The expected value of calling get_dates_for_module()
*/
public function test_get_dates_for_module(?int $availablefrom, ?int $availableto, array $expected) {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$data = ['course' => $course->id];
if ($availablefrom) {
$data['timeavailablefrom'] = $availablefrom;
}
if ($availableto) {
$data['timeavailableto'] = $availableto;
}
$moddata = $this->getDataGenerator()->create_module('data', $data);
$this->setUser($user);
$cm = get_coursemodule_from_instance('data', $moddata->id);
// Make sure we're using a cm_info object.
$cm = cm_info::create($cm);
$dates = activity_dates::get_dates_for_module($cm, (int) $user->id);
$this->assertEquals($expected, $dates);
}
}
+68
View File
@@ -0,0 +1,68 @@
<?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_feedback for a given module instance and a user.
*
* @package mod_feedback
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_feedback;
use core\activity_dates;
/**
* Class for fetching the important dates in mod_feedback for a given module instance and a user.
*
* @copyright 2021 Shamim Rezaie <[email protected]>
* @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_feedback
*
* @return array
*/
protected function get_dates(): array {
$timeopen = $this->cm->customdata['timeopen'] ?? null;
$timeclose = $this->cm->customdata['timeclose'] ?? null;
$now = time();
$dates = [];
if ($timeopen) {
$openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened';
$dates[] = [
'label' => get_string($openlabelid, 'course'),
'timestamp' => (int) $timeopen,
];
}
if ($timeclose) {
$closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed';
$dates[] = [
'label' => get_string($closelabelid, 'course'),
'timestamp' => (int) $timeclose,
];
}
return $dates;
}
}
+122
View File
@@ -0,0 +1,122 @@
<?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 unit tests for mod_feedback\dates.
*
* @package mod_feedback
* @category test
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_feedback;
use advanced_testcase;
use cm_info;
use core\activity_dates;
/**
* Class for unit testing mod_feedback\dates.
*
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dates_test extends advanced_testcase {
/**
* Data provider for get_dates_for_module().
* @return array[]
*/
public function get_dates_for_module_provider(): array {
$now = time();
$before = $now - DAYSECS;
$earlier = $before - DAYSECS;
$after = $now + DAYSECS;
$later = $after + DAYSECS;
return [
'without any dates' => [
null, null, []
],
'only with opening time' => [
$after, null, [
['label' => 'Opens:', 'timestamp' => $after],
]
],
'only with closing time' => [
null, $after, [
['label' => 'Closes:', 'timestamp' => $after],
]
],
'with both times' => [
$after, $later, [
['label' => 'Opens:', 'timestamp' => $after],
['label' => 'Closes:', 'timestamp' => $later],
]
],
'between the dates' => [
$before, $after, [
['label' => 'Opened:', 'timestamp' => $before],
['label' => 'Closes:', 'timestamp' => $after],
]
],
'dates are past' => [
$earlier, $before, [
['label' => 'Opened:', 'timestamp' => $earlier],
['label' => 'Closed:', 'timestamp' => $before],
]
],
];
}
/**
* Test for get_dates_for_module().
*
* @dataProvider get_dates_for_module_provider
* @param int|null $timeopen The "allow answers from" time in the feedback activity.
* @param int|null $timeclose The "allow answers to" time in the feedback activity.
* @param array $expected The expected value of calling get_dates_for_module()
*/
public function test_get_dates_for_module(?int $timeopen, ?int $timeclose, array $expected) {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$data = ['course' => $course->id];
if ($timeopen) {
$data['timeopen'] = $timeopen;
}
if ($timeclose) {
$data['timeclose'] = $timeclose;
}
$feedback = $this->getDataGenerator()->create_module('feedback', $data);
$this->setUser($user);
$cm = get_coursemodule_from_instance('feedback', $feedback->id);
// Make sure we're using a cm_info object.
$cm = cm_info::create($cm);
$dates = activity_dates::get_dates_for_module($cm, (int) $user->id);
$this->assertEquals($expected, $dates);
}
}
+57
View File
@@ -0,0 +1,57 @@
<?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_forum for a given module instance and a user.
*
* @package mod_forum
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_forum;
use core\activity_dates;
/**
* Class for fetching the important dates in mod_forum for a given module instance and a user.
*
* @copyright 2021 Shamim Rezaie <[email protected]>
* @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_forum
*
* @return array
*/
protected function get_dates(): array {
$duedate = $this->cm->customdata['duedate'] ?? null;
$dates = [];
if ($duedate) {
$dates[] = [
'label' => get_string('activitydate:due', 'mod_forum'),
'timestamp' => (int) $duedate,
];
}
return $dates;
}
}
+1
View File
@@ -23,6 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['activitydate:due'] = 'Due:';
$string['activityoverview'] = 'There are new forum posts';
$string['actionsforgraderinterface'] = 'Actions for the grader interface';
$string['actionsforpost'] = 'Actions for post';
+9 -1
View File
@@ -6617,7 +6617,7 @@ function forum_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, name, intro, introformat, completionposts, completiondiscussions, completionreplies';
$fields = 'id, name, intro, introformat, completionposts, completiondiscussions, completionreplies, duedate, cutoffdate';
if (!$forum = $DB->get_record('forum', $dbparams, $fields)) {
return false;
}
@@ -6637,6 +6637,14 @@ function forum_get_coursemodule_info($coursemodule) {
$result->customdata['customcompletionrules']['completionposts'] = $forum->completionposts;
}
// Populate some other values that can be used in calendar or on dashboard.
if ($forum->duedate) {
$result->customdata['duedate'] = $forum->duedate;
}
if ($forum->cutoffdate) {
$result->customdata['cutoffdate'] = $forum->cutoffdate;
}
return $result;
}
+100
View File
@@ -0,0 +1,100 @@
<?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 unit tests for mod_forum\dates.
*
* @package mod_forum
* @category test
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_forum;
use advanced_testcase;
use cm_info;
use core\activity_dates;
/**
* Class for unit testing mod_forum\dates.
*
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dates_test extends advanced_testcase {
/**
* Data provider for get_dates_for_module().
* @return array[]
*/
public function get_dates_for_module_provider(): array {
$now = time();
$before = $now - DAYSECS;
$after = $now + DAYSECS;
return [
'without any dates' => [
null, []
],
'future due date' => [
$after, [
['label' => 'Due:', 'timestamp' => $after],
]
],
'due date is past' => [
$before, [
['label' => 'Due:', 'timestamp' => $before],
]
],
];
}
/**
* Test for get_dates_for_module().
*
* @dataProvider get_dates_for_module_provider
* @param int|null $duedate Forum's due date.
* @param array $expected The expected value of calling get_dates_for_module()
*/
public function test_get_dates_for_module(?int $duedate, array $expected) {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$data = ['course' => $course->id];
if ($duedate) {
$data['duedate'] = $duedate;
}
$this->setAdminUser();
$forum = $this->getDataGenerator()->create_module('forum', $data);
$this->setUser($user);
$cm = get_coursemodule_from_instance('forum', $forum->id);
// Make sure we're using a cm_info object.
$cm = cm_info::create($cm);
$dates = activity_dates::get_dates_for_module($cm, (int) $user->id);
$this->assertEquals($expected, $dates);
}
}
+68
View File
@@ -0,0 +1,68 @@
<?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_scorm for a given module instance and a user.
*
* @package mod_scorm
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_scorm;
use core\activity_dates;
/**
* Class for fetching the important dates in mod_scorm for a given module instance and a user.
*
* @copyright 2021 Shamim Rezaie <[email protected]>
* @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_scorm
*
* @return array
*/
protected function get_dates(): array {
$timeopen = $this->cm->customdata['timeopen'] ?? null;
$timeclose = $this->cm->customdata['timeclose'] ?? 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;
}
}
+123
View File
@@ -0,0 +1,123 @@
<?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 unit tests for mod_scorm\dates.
*
* @package mod_scorm
* @category test
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_scorm;
use advanced_testcase;
use cm_info;
use core\activity_dates;
/**
* Class for unit testing mod_scorm\dates.
*
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dates_test extends advanced_testcase {
/**
* Data provider for get_dates_for_module().
* @return array[]
*/
public function get_dates_for_module_provider(): array {
$now = time();
$before = $now - DAYSECS;
$earlier = $before - DAYSECS;
$after = $now + DAYSECS;
$later = $after + DAYSECS;
return [
'without any dates' => [
null, null, []
],
'only with opening time' => [
$after, null, [
['label' => 'Opens:', 'timestamp' => $after],
]
],
'only with closing time' => [
null, $after, [
['label' => 'Closes:', 'timestamp' => $after],
]
],
'with both times' => [
$after, $later, [
['label' => 'Opens:', 'timestamp' => $after],
['label' => 'Closes:', 'timestamp' => $later],
]
],
'between the dates' => [
$before, $after, [
['label' => 'Opened:', 'timestamp' => $before],
['label' => 'Closes:', 'timestamp' => $after],
]
],
'dates are past' => [
$earlier, $before, [
['label' => 'Opened:', 'timestamp' => $earlier],
['label' => 'Closed:', 'timestamp' => $before],
]
],
];
}
/**
* Test for get_dates_for_module().
*
* @dataProvider get_dates_for_module_provider
* @param int|null $timeopen The 'available from' value of the scorm.
* @param int|null $timeclose The 'available to' value of the scorm.
* @param array $expected The expected value of calling get_dates_for_module()
*/
public function test_get_dates_for_module(?int $timeopen, ?int $timeclose, array $expected) {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$data = ['course' => $course->id];
if ($timeopen) {
$data['timeopen'] = $timeopen;
}
if ($timeclose) {
$data['timeclose'] = $timeclose;
}
$this->setAdminUser();
$scorm = $this->getDataGenerator()->create_module('scorm', $data);
$this->setUser($user);
$cm = get_coursemodule_from_instance('scorm', $scorm->id);
// Make sure we're using a cm_info object.
$cm = cm_info::create($cm);
$dates = activity_dates::get_dates_for_module($cm, (int) $user->id);
$this->assertEquals($expected, $dates);
}
}
+87
View File
@@ -0,0 +1,87 @@
<?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_workshop for a given module instance and a user.
*
* @package mod_workshop
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_workshop;
use core\activity_dates;
/**
* Class for fetching the important dates in mod_workshop for a given module instance and a user.
*
* @copyright 2021 Shamim Rezaie <[email protected]>
* @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_workshop
*
* @return array
*/
protected function get_dates(): array {
$submissionstart = $this->cm->customdata['submissionstart'] ?? null;
$submissionend = $this->cm->customdata['submissionend'] ?? null;
$assessmentstart = $this->cm->customdata['assessmentstart'] ?? null;
$assessmentend = $this->cm->customdata['assessmentend'] ?? null;
$now = time();
$dates = [];
if ($submissionstart) {
$openlabelid = $submissionstart > $now ? 'activitydate:submissionsopen' : 'activitydate:submissionsopened';
$dates[] = [
'label' => get_string($openlabelid, 'mod_workshop'),
'timestamp' => (int) $submissionstart,
];
}
if ($submissionend) {
$closelabelid = $submissionend > $now ? 'activitydate:submissionsclose' : 'activitydate:submissionsclosed';
$dates[] = [
'label' => get_string($closelabelid, 'mod_workshop'),
'timestamp' => (int) $submissionend,
];
}
if ($assessmentstart) {
$openlabelid = $assessmentstart > $now ? 'activitydate:assessmentsopen' : 'activitydate:assessmentsopened';
$dates[] = [
'label' => get_string($openlabelid, 'mod_workshop'),
'timestamp' => (int) $assessmentstart,
];
}
if ($assessmentend) {
$closelabelid = $assessmentend > $now ? 'activitydate:assessmentsclose' : 'activitydate:assessmentsclosed';
$dates[] = [
'label' => get_string($closelabelid, 'mod_workshop'),
'timestamp' => (int) $assessmentend,
];
}
return $dates;
}
}
+8
View File
@@ -22,6 +22,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['activitydate:assessmentsclose'] = 'Assessments close:';
$string['activitydate:assessmentsclosed'] = 'Assessments closed:';
$string['activitydate:assessmentsopen'] = 'Assessments open:';
$string['activitydate:assessmentsopened'] = 'Assessments opened:';
$string['activitydate:submissionsclose'] = 'Submissions close:';
$string['activitydate:submissionsclosed'] = 'Submissions closed:';
$string['activitydate:submissionsopen'] = 'Submissions open:';
$string['activitydate:submissionsopened'] = 'Submissions opened:';
$string['aggregategrades'] = 'Re-calculate grades';
$string['aggregation'] = 'Grades aggregation';
$string['allocate'] = 'Allocate submissions';
+44
View File
@@ -2209,3 +2209,47 @@ function mod_workshop_get_path_from_pluginfile(string $filearea, array $args) :
'filepath' => $filepath,
];
}
/**
* Add a get_coursemodule_info function in case any feedback type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info|false An object on information that the courses will know about (most noticeably, an icon).
*/
function workshop_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, name, intro, introformat, submissionstart, submissionend, assessmentstart, assessmentend';
if (!$workshop = $DB->get_record('workshop', $dbparams, $fields)) {
return false;
}
$result = new cached_cm_info();
$result->name = $workshop->name;
if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$result->content = format_module_intro('workshop', $workshop, $coursemodule->id, false);
}
// Populate some other values that can be used in calendar or on dashboard.
if ($workshop->submissionstart) {
$result->customdata['submissionstart'] = $workshop->submissionstart;
}
if ($workshop->submissionend) {
$result->customdata['submissionend'] = $workshop->submissionend;
}
if ($workshop->assessmentstart) {
$result->customdata['assessmentstart'] = $workshop->assessmentstart;
}
if ($workshop->assessmentend) {
$result->customdata['assessmentend'] = $workshop->assessmentend;
}
return $result;
}
+152
View File
@@ -0,0 +1,152 @@
<?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 unit tests for mod_workshop\dates.
*
* @package mod_workshop
* @category test
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_workshop;
use advanced_testcase;
use cm_info;
use core\activity_dates;
/**
* Class for unit testing mod_workshop\dates.
*
* @copyright 2021 Shamim Rezaie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dates_test extends advanced_testcase {
/**
* Data provider for get_dates_for_module().
* @return array[]
*/
public function get_dates_for_module_provider(): array {
$now = time();
$before = $now - DAYSECS;
$earlier = $before - DAYSECS;
$earliest = $earlier - DAYSECS;
$after = $now + DAYSECS;
$later = $after + DAYSECS;
$latest = $later + DAYSECS;
return [
'without any dates' => [
null, null, null, null, []
],
'only with start time for submissions' => [
$after, null, null, null, [
['label' => 'Submissions open:', 'timestamp' => $after],
]
],
'only with end time for submissions' => [
null, $after, null, null, [
['label' => 'Submissions close:', 'timestamp' => $after],
]
],
'only with start time for assessments' => [
null, null, $after, null, [
['label' => 'Assessments open:', 'timestamp' => $after],
]
],
'only with end time for assessments' => [
null, null, null, $after, [
['label' => 'Assessments close:', 'timestamp' => $after],
]
],
'all times in future' => [
$after, $later, $latest, $latest + DAYSECS, [
['label' => 'Submissions open:', 'timestamp' => $after],
['label' => 'Submissions close:', 'timestamp' => $later],
['label' => 'Assessments open:', 'timestamp' => $latest],
['label' => 'Assessments close:', 'timestamp' => $latest + DAYSECS],
]
],
'all times in the past' => [
$earliest - DAYSECS, $earliest, $earlier, $before, [
['label' => 'Submissions opened:', 'timestamp' => $earliest - DAYSECS],
['label' => 'Submissions closed:', 'timestamp' => $earliest],
['label' => 'Assessments opened:', 'timestamp' => $earlier],
['label' => 'Assessments closed:', 'timestamp' => $before],
]
],
'between submission and assessment' => [
$earlier, $before, $after, $later, [
['label' => 'Submissions opened:', 'timestamp' => $earlier],
['label' => 'Submissions closed:', 'timestamp' => $before],
['label' => 'Assessments open:', 'timestamp' => $after],
['label' => 'Assessments close:', 'timestamp' => $later],
]
],
];
}
/**
* Test for get_dates_for_module().
*
* @dataProvider get_dates_for_module_provider
* @param int|null $submissionstart The 'Open for submissions from' value of the workshop.
* @param int|null $submissionend The 'Submissions deadline' value of the workshop.
* @param int|null $assessmentstart The 'Open for assessment from' value of the workshop.
* @param int|null $assessmentend The 'Deadline for assessment' value of the workshop.
* @param array $expected The expected value of calling get_dates_for_module()
*/
public function test_get_dates_for_module(?int $submissionstart, ?int $submissionend,
?int $assessmentstart, ?int $assessmentend,
array $expected) {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$data = ['course' => $course->id];
if ($submissionstart) {
$data['submissionstart'] = $submissionstart;
}
if ($submissionend) {
$data['submissionend'] = $submissionend;
}
if ($assessmentstart) {
$data['assessmentstart'] = $assessmentstart;
}
if ($assessmentend) {
$data['assessmentend'] = $assessmentend;
}
$this->setAdminUser();
$workshop = $this->getDataGenerator()->create_module('workshop', $data);
$this->setUser($user);
$cm = get_coursemodule_from_instance('workshop', $workshop->id);
// Make sure we're using a cm_info object.
$cm = cm_info::create($cm);
$dates = activity_dates::get_dates_for_module($cm, (int) $user->id);
$this->assertEquals($expected, $dates);
}
}