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 core_courseformat\output\local\overview;
18
 
19
use core\output\action_link;
20
use core\output\named_templatable;
21
use core\output\renderable;
22
use core\output\notification;
23
use core\plugin_manager;
24
use core\url;
25
use stdClass;
26
 
27
/**
28
 * Class missingoverviewnotice
29
 *
30
 * @package    core_courseformat
31
 * @copyright  2025 Ferran Recio <ferran@moodle.com>
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class missingoverviewnotice implements renderable, named_templatable {
35
    /**
36
     * Constructor.
37
     *
38
     * @param stdClass $course The course object.
39
     * @param string $modname The module name.
40
     */
41
    public function __construct(
42
        /** @var stdClass $course the course object  */
43
        private stdClass $course,
44
        /** @var string $modname the activity module name  */
45
        private string $modname,
46
    ) {
47
    }
48
 
49
    #[\Override]
50
    public function export_for_template(\renderer_base $output): stdClass {
51
        if (!$this->activity_has_overview_integration($this->modname)) {
52
            return $this->export_legacy_overview($output);
53
        }
54
        // The notice is not needed for plugins with overview class.
55
        return (object) [];
56
    }
57
 
58
    /**
59
     * Checks if a given activity module has an overview integration.
60
     *
61
     * The method search for an integration class named `\mod_{modname}\course\overview`.
62
     *
63
     * @param string $modname The name of the activity module.
64
     * @return bool True if the activity module has an overview integration, false otherwise.
65
     */
66
    private function activity_has_overview_integration(string $modname): bool {
67
        $classname = 'mod_' . $modname . '\courseformat\overview';
68
        if ($modname === 'resource') {
69
            $classname = 'core_courseformat\local\overview\resourceoverview';
70
        }
71
        return class_exists($classname);
72
    }
73
 
74
    /**
75
     * Exports the legacy overview for a given module.
76
     *
77
     * This export only applies to modules that do not have an overview integration.
78
     *
79
     * @param \renderer_base $output
80
     * @return stdClass
81
     */
82
    private function export_legacy_overview(
83
        \renderer_base $output,
84
    ): stdClass {
85
        $legacyoverview = '/mod/' . $this->modname . '/index.php';
86
        $name = plugin_manager::instance()->plugin_name($this->modname);
87
 
88
        $link = new action_link(
89
            url: new url($legacyoverview, ['id' => $this->course->id]),
90
            text: get_string('overview_modname', 'core_course', $name),
91
        );
92
 
93
        $notification = new notification(
94
            message: get_string('overview_missing_notice', 'core_course', $output->render($link)),
95
            messagetype: notification::NOTIFY_INFO,
96
            closebutton: false,
97
            title: get_string('overview_missing_title', 'core_course', $name),
98
            titleicon: 'i/circleinfo',
99
        );
100
 
101
        return (object) [
102
            'name' => $name,
103
            'shortname' => $this->modname,
104
            'notification' => $notification->export_for_template($output),
105
            'missingoverview' => true,
106
        ];
107
    }
108
 
109
    #[\Override]
110
    public function get_template_name(\renderer_base $renderer): string {
111
        return 'core_courseformat/local/overview/missingoverviewnotice';
112
    }
113
}