Proyectos de Subversion Moodle

Rev

| 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
namespace core_course\output;
18
 
19
use renderable;
20
use renderer_base;
21
use stdClass;
22
use templatable;
23
 
24
/**
25
 * The activity dates renderable class.
26
 *
27
 * @package    core_course
28
 * @copyright  2023 Mikel Martín <mikel@moodle.com>
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
class activity_dates implements renderable, templatable {
32
 
33
    /**
34
     * Constructor.
35
     *
36
     * @param array $activitydates The activity dates.
37
     */
38
    public function __construct(
39
        protected array $activitydates
40
    ) {
41
    }
42
 
43
    /**
44
     * Export this data so it can be used as the context for a mustache template.
45
     *
46
     * @param renderer_base $output Renderer base.
47
     * @return stdClass
48
     */
49
    public function export_for_template(renderer_base $output): stdClass {
50
        $activitydates = [];
51
        foreach ($this->activitydates as $date) {
52
            if (empty($date['relativeto'])) {
53
                $date['datestring'] = userdate($date['timestamp'], get_string('strftimedaydatetime', 'core_langconfig'));
54
            } else {
55
                $diffstr = get_time_interval_string($date['timestamp'], $date['relativeto']);
56
                if ($date['timestamp'] >= $date['relativeto']) {
57
                    $date['datestring'] = get_string('relativedatessubmissionduedateafter', 'core_course',
58
                        ['datediffstr' => $diffstr]);
59
                } else {
60
                    $date['datestring'] = get_string('relativedatessubmissionduedatebefore', 'core_course',
61
                        ['datediffstr' => $diffstr]);
62
                }
63
            }
64
            $activitydates[] = $date;
65
        }
66
 
67
        return (object) [
68
            'hasdates' => !empty($this->activitydates),
69
            'activitydates' => $activitydates,
70
        ];
71
    }
72
}