Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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 report_outline\output;
18
 
19
use core_report\output\coursestructure;
20
use course_modinfo;
21
 
22
/**
23
 * Activities list page in a hierarchical format.
24
 *
25
 * @package    report_outline
26
 * @copyright  2024 Amaia Anabitarte <amaia@moodle.com>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class hierarchicalactivities extends coursestructure {
30
 
31
    /**
32
     * Exports the data for a single activity.
33
     *
34
     * @param \renderer_base $output
35
     * @param \cm_info $cm
36
     * @param bool $indelegated Whether the activity is part of a delegated section or not.
37
     * @return array
38
     */
39
    public function export_activity_data(\renderer_base $output, \cm_info $cm, bool $indelegated = false): array {
40
        if (!$cm->has_view()) {
41
            return [];
42
        }
43
        if (!$cm->uservisible) {
44
            return [];
45
        }
46
 
47
        return [
48
            'isactivity' => true,
49
            'isdelegated' => false,
50
            'indelegated' => $indelegated,
51
            'visible' => $cm->visible,
52
            'id' => $cm->id,
53
        ];
54
    }
55
 
56
 
57
    /**
58
     * Print activity data.
59
     *
60
     * @param \renderer_base $output
61
     * @param string $mode
62
     * @param \cm_info $mod
63
     * @param \stdClass $user
64
     * @param \stdClass $course
65
     */
66
    public function print_activity(
67
            \renderer_base $output,
68
            string $mode,
69
            \cm_info $mod,
70
            \stdClass $user,
71
            \stdClass $course,
72
    ): void {
73
        global $CFG, $DB;
74
 
75
        $instance = $DB->get_record($mod->modname, ['id' => $mod->instance]);
76
        $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
77
 
78
        if (!file_exists($libfile)) {
79
            return;
80
        }
81
 
82
        require_once($libfile);
83
 
84
        switch ($mode) {
85
            case "outline":
86
                $useroutline = $mod->modname . "_user_outline";
87
                if (function_exists($useroutline)) {
88
                    $toprint = $useroutline($course, $user, $mod, $instance);
89
                } else {
90
                    $toprint = report_outline_user_outline($user->id, $mod->id, $mod->modname, $mod->instance);
91
                }
92
                if (!$toprint) {
93
                    $toprint = (object) ['info' => '-'];
94
                }
95
                report_outline_print_row($mod, $instance, $toprint);
96
                break;
97
            case "complete":
98
                $usercomplete = $mod->modname . "_user_complete";
99
                $image = $output->pix_icon('monologo', $mod->modfullname, 'mod_' . $mod->modname, ['class' => 'icon']);
100
                echo "<h4 class=\"h6\">$image $mod->modfullname: " .
101
                        "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">" .
102
                        format_string($instance->name, true) . "</a></h4>";
103
 
104
                ob_start();
105
 
106
                echo "<ul>";
107
                if (function_exists($usercomplete)) {
108
                    $usercomplete($course, $user, $mod, $instance);
109
                } else {
110
                    echo report_outline_user_complete($user->id, $mod->id, $mod->modname, $mod->instance);
111
                }
112
                echo "</ul>";
113
 
114
                $toprint = ob_get_contents();
115
                ob_end_clean();
116
 
117
                if (str_replace(' ', '', $toprint) != '<ul></ul>') {
118
                    echo $toprint;
119
                }
120
                break;
121
        }
122
    }
123
}