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
use core_completion\manager;
18
 
19
defined('MOODLE_INTERNAL') || die;
20
 
21
require_once($CFG->dirroot.'/course/renderer.php');
22
 
23
/**
24
 * Main renderer for the bulk activity completion stuff.
25
 *
26
 * @package core_course
27
 * @copyright 2017 Adrian Greeve
28
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class core_course_bulk_activity_completion_renderer extends plugin_renderer_base {
31
 
32
    /**
33
     * @deprecated since Moodle 4.0
34
     */
35
    public function navigation() {
36
        throw new coding_exception(__FUNCTION__ . '() has been removed.');
37
    }
38
 
39
    /**
40
     * Render the bulk completion tab.
41
     *
42
     * @param Array|stdClass $data the context data to pass to the template.
43
     * @return bool|string
44
     */
45
    public function bulkcompletion($data) {
46
        return parent::render_from_template('core_course/bulkactivitycompletion', $data);
47
    }
48
 
49
    /**
50
     * Render the default completion tab.
51
     *
52
     * @param array|stdClass $data the context data to pass to the template.
53
     * @param array $modules The modules that have been sent through the form.
54
     * @param moodleform $form The current form that has been sent.
55
     * @return bool|string
56
     */
57
    public function defaultcompletion($data, $modules, $form) {
58
        $course = get_course($data->courseid);
59
        foreach ($data->modules as $module) {
60
            // If the user can manage this module, then the activity completion form needs to be returned too, without the
61
            // cancel button (so only "Save changes" button is displayed).
62
            if ($module->canmanage) {
63
                // Only create the form if it's different from the one that has been sent.
64
                $modform = $form;
65
                if (empty($form) || !in_array($module->id, array_keys($modules))) {
66
                    $modform = new \core_completion_defaultedit_form(
67
                        null,
68
                        [
69
                            'course' => $course,
70
                            'modules' => [
71
                                $module->id => $module,
72
                            ],
73
                            'displaycancel' => false,
74
                            'forceuniqueid' => true,
75
                        ],
76
                    );
77
                    $module->modulecollapsed = true;
78
                }
79
 
80
                $moduleform = manager::get_module_form($module->name, $course);
81
                if ($moduleform) {
82
                    $module->formhtml = $modform->render();
83
                } else {
84
                    // If the module form is not available, then display a message.
85
                    $module->formhtml = $this->output->notification(
86
                        get_string('incompatibleplugin', 'completion'),
87
                        \core\output\notification::NOTIFY_INFO,
88
                        false
89
                    );
90
                }
91
            }
92
        }
93
        $data->issite = $course->id == SITEID;
94
 
95
        return parent::render_from_template('core_course/defaultactivitycompletion', $data);
96
    }
97
 
98
    /**
99
     * Renders the form for bulk editing activities completion
100
     *
101
     * @param moodleform $form
102
     * @param array $activities
103
     * @return string
104
     */
105
    public function edit_bulk_completion($form, $activities) {
106
        ob_start();
107
        $form->display();
108
        $formhtml = ob_get_contents();
109
        ob_end_clean();
110
 
111
        $data = (object)[
112
            'form' => $formhtml,
113
            'activities' => array_values($activities),
114
            'activitiescount' => count($activities),
115
        ];
116
        return parent::render_from_template('core_course/editbulkactivitycompletion', $data);
117
    }
118
 
119
    /**
120
     * Renders the form for editing default completion
121
     *
122
     * @param moodleform $form
123
     * @param array $modules
124
     * @return string
125
     * @deprecated since Moodle 4.3 MDL-78528
126
     * @todo MDL-78711 This will be deleted in Moodle 4.7
127
     */
128
    public function edit_default_completion($form, $modules) {
129
        debugging('edit_default_completion() is deprecated and will be removed.', DEBUG_DEVELOPER);
130
 
131
        ob_start();
132
        $form->display();
133
        $formhtml = ob_get_contents();
134
        ob_end_clean();
135
 
136
        $data = (object)[
137
            'form' => $formhtml,
138
            'modules' => array_values($modules),
139
            'modulescount' => count($modules),
140
        ];
141
        return parent::render_from_template('core_course/editdefaultcompletion', $data);
142
    }
143
 
144
    /**
145
     * Renders the course completion action bar.
146
     *
147
     * @param \core_course\output\completion_action_bar $actionbar
148
     * @return string The HTML output
149
     */
150
    public function render_course_completion_action_bar(\core_course\output\completion_action_bar $actionbar): string {
151
        $data = $actionbar->export_for_template($this->output);
152
        return $this->output->render_from_template('core_course/completion_action_bar', $data);
153
    }
154
}