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 default activity list from a section.
19
 *
20
 * @package   core_courseformat
21
 * @copyright 2020 Ferran Recio <ferran@moodle.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace core_courseformat\output\local\content\section;
26
 
27
use core\output\named_templatable;
28
use core_courseformat\base as course_format;
29
use core_courseformat\output\local\courseformat_named_templatable;
30
use moodle_url;
31
use renderable;
32
use section_info;
33
use stdClass;
34
 
35
/**
36
 * Base class to render a section activity list.
37
 *
38
 * @package   core_courseformat
39
 * @copyright 2020 Ferran Recio <ferran@moodle.com>
40
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
 */
42
class cmlist implements named_templatable, renderable {
43
 
44
    use courseformat_named_templatable;
45
 
46
    /** @var course_format the course format class */
47
    protected $format;
48
 
49
    /** @var section_info the course section class */
50
    protected $section;
51
 
52
    /** @var array optional display options */
53
    protected $displayoptions;
54
 
55
    /** @var string the item output class name */
56
    protected $itemclass;
57
 
1441 ariadna 58
    // TODO remove movehereclass as part of MDL-83530.
1 efrain 59
    /** @var optional move here output class */
60
    protected $movehereclass;
61
 
62
    /**
63
     * Constructor.
64
     *
65
     * @param course_format $format the course format
66
     * @param section_info $section the section info
67
     * @param array $displayoptions optional extra display options
68
     */
69
    public function __construct(course_format $format, section_info $section, array $displayoptions = []) {
70
        $this->format = $format;
71
        $this->section = $section;
72
        $this->displayoptions = $displayoptions;
73
 
74
        // Get the necessary classes.
75
        $this->itemclass = $format->get_output_classname('content\\section\\cmitem');
76
    }
77
 
78
    /**
79
     * Export this data so it can be used as the context for a mustache template.
80
     *
81
     * @param renderer_base $output typically, the renderer that's calling this function
82
     * @return array data context for a mustache template
83
     */
84
    public function export_for_template(\renderer_base $output): stdClass {
85
        global $USER;
86
 
87
        $format = $this->format;
88
        $section = $this->section;
89
        $course = $format->get_course();
90
        $modinfo = $format->get_modinfo();
91
        $user = $USER;
92
 
93
        $data = new stdClass();
94
        $data->cms = [];
95
 
1441 ariadna 96
        // TODO remove showmovehere and the if clause as part of MDL-83530.
1 efrain 97
        $showmovehere = ismoving($course->id);
98
        if ($showmovehere) {
1441 ariadna 99
            // By default, non-ajax controls are disabled but in some places like the frontpage
100
            // it is necessary to display them. This is a temporal solution while JS is still
101
            // optional for course editing.
1 efrain 102
            $data->hascms = true;
103
            $data->showmovehere = true;
104
            $data->strmovefull = strip_tags(get_string("movefull", "", "'$user->activitycopyname'"));
105
            $data->movetosectionurl = new moodle_url('/course/mod.php', ['movetosection' => $section->id, 'sesskey' => sesskey()]);
106
            $data->movingstr = strip_tags(get_string('activityclipboard', '', $user->activitycopyname));
107
            $data->cancelcopyurl = new moodle_url('/course/mod.php', ['cancelcopy' => 'true', 'sesskey' => sesskey()]);
108
        }
109
 
110
        if (empty($modinfo->sections[$section->section])) {
111
            return $data;
112
        }
113
 
114
        foreach ($modinfo->sections[$section->section] as $modnumber) {
115
            $mod = $modinfo->cms[$modnumber];
1441 ariadna 116
            // TODO remove this if as part of MDL-83530.
1 efrain 117
            if ($showmovehere && $USER->activitycopy == $mod->id) {
1441 ariadna 118
                // If the old non-ajax move is necessary, we do not print the selected cm.
1 efrain 119
                continue;
120
            }
1441 ariadna 121
            if ($mod->is_visible_on_course_page() && $mod->is_of_type_that_can_display()) {
1 efrain 122
                $item = new $this->itemclass($format, $section, $mod, $this->displayoptions);
123
                $data->cms[] = (object)[
124
                    'cmitem' => $item->export_for_template($output),
125
                    'moveurl' => new moodle_url('/course/mod.php', array('moveto' => $modnumber, 'sesskey' => sesskey())),
126
                ];
127
            }
128
        }
129
 
130
        if (!empty($data->cms)) {
131
            $data->hascms = true;
132
        }
133
 
134
        return $data;
135
    }
136
}