Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
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.
8
//
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.
13
//
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/>.
16
 
17
/**
18
 * Contains the class for fetching the important dates in mod_assign for a given module instance and a user.
19
 *
20
 * @package   mod_assign
21
 * @copyright 2021 Shamim Rezaie <shamim@moodle.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
declare(strict_types=1);
26
 
27
namespace mod_assign;
28
 
29
use core\activity_dates;
30
 
31
/**
32
 * Class for fetching the important dates in mod_assign for a given module instance and a user.
33
 *
34
 * @copyright 2021 Shamim Rezaie <shamim@moodle.com>
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
37
class dates extends activity_dates {
38
 
1441 ariadna 39
    /** @var int|null $timedue the activity due date */
40
    private ?int $timedue;
41
 
1 efrain 42
    /**
43
     * Returns a list of important dates in mod_assign
44
     *
45
     * @return array
46
     */
47
    protected function get_dates(): array {
48
        global $CFG;
49
 
50
        require_once($CFG->dirroot . '/mod/assign/locallib.php');
51
 
1441 ariadna 52
        $this->timedue = null;
53
 
1 efrain 54
        $course = get_course($this->cm->course);
55
        $context = \context_module::instance($this->cm->id);
56
        $assign = new \assign($context, $this->cm, $course);
57
 
58
        $timeopen = $this->cm->customdata['allowsubmissionsfromdate'] ?? null;
59
        $timedue = $this->cm->customdata['duedate'] ?? null;
60
 
61
        $activitygroup = groups_get_activity_group($this->cm, true);
62
        if ($activitygroup) {
63
            if ($assign->can_view_grades()) {
64
                $groupoverride = \cache::make('mod_assign', 'overrides')->get("{$this->cm->instance}_g_{$activitygroup}");
65
                if (!empty($groupoverride->allowsubmissionsfromdate)) {
66
                    $timeopen = $groupoverride->allowsubmissionsfromdate;
67
                }
68
                if (!empty($groupoverride->duedate)) {
69
                    $timedue = $groupoverride->duedate;
70
                }
71
            }
72
        }
73
 
74
        $now = time();
75
        $dates = [];
76
 
77
        if ($timeopen) {
78
            $openlabelid = $timeopen > $now ? 'activitydate:submissionsopen' : 'activitydate:submissionsopened';
79
            $date = [
80
                'dataid' => 'allowsubmissionsfromdate',
81
                'label' => get_string($openlabelid, 'mod_assign'),
82
                'timestamp' => (int) $timeopen,
83
            ];
84
            if ($course->relativedatesmode && $assign->can_view_grades()) {
85
                $date['relativeto'] = $course->startdate;
86
            }
87
            $dates[] = $date;
88
        }
89
 
90
        if ($timedue) {
1441 ariadna 91
            $this->timedue = (int) $timedue;
1 efrain 92
            $date = [
93
                'dataid' => 'duedate',
94
                'label' => get_string('activitydate:submissionsdue', 'mod_assign'),
1441 ariadna 95
                'timestamp' => $this->timedue,
1 efrain 96
            ];
97
            if ($course->relativedatesmode && $assign->can_view_grades()) {
98
                $date['relativeto'] = $course->startdate;
99
            }
100
            $dates[] = $date;
101
        }
102
 
103
        return $dates;
104
    }
1441 ariadna 105
 
106
    /**
107
     * Returns the dues date data, if any.
108
     * @return int|null the due date timestamp or null if not set.
109
     */
110
    public function get_due_date(): ?int {
111
        if (!isset($this->timedue)) {
112
            $this->get_dates();
113
        }
114
        return $this->timedue;
115
    }
1 efrain 116
}