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