2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Contains the base class for fetching the important dates in an activity module for a given module instance and a user.
21 * @copyright Shamim Rezaie <shamim@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 declare(strict_types
=1);
32 * Class for fetching the important dates of an activity module for a given module instance and a user.
34 * @copyright Shamim Rezaie <shamim@moodle.com>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 abstract class activity_dates
{
40 * @var cm_info The course module information object.
45 * @var int The user id.
50 * activity_dates constructor.
52 * @param cm_info $cm course module
53 * @param int $userid user id
55 public function __construct(cm_info
$cm, int $userid) {
57 $this->userid
= $userid;
61 * Returns a list of important dates in the given module for the user.
63 * @param cm_info $cm The course module information.
64 * @param int $userid The user ID.
65 * @return array|array[]
67 public static function get_dates_for_module(cm_info
$cm, int $userid): array {
68 $cmdatesclassname = static::get_dates_classname($cm->modname
);
69 if (!$cmdatesclassname) {
73 /** @var activity_dates $dates */
74 $dates = new $cmdatesclassname($cm, $userid);
75 return $dates->get_dates();
79 * Fetches the module's dates class implementation if it's available.
81 * @param string $modname The activity module name. Usually from cm_info::modname.
84 private static function get_dates_classname(string $modname): ?
string {
85 $cmdatesclass = "mod_{$modname}\\dates";
86 if (class_exists($cmdatesclass) && is_subclass_of($cmdatesclass, self
::class)) {
94 * Returns a list of important dates for this module.
96 * @return array[] Each element of the array is an array with keys:
97 * label - The label for the date
98 * timestamp - The date
100 protected abstract function get_dates(): array;