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
namespace tool_policy;
18
 
19
use core\hook\output\before_standard_footer_html_generation;
20
use core\hook\output\before_standard_top_of_body_html_generation;
21
use html_writer;
22
use moodle_url;
23
 
24
/**
25
 * Allows the plugin to add any elements to the footer.
26
 *
27
 * @package    tool_policy
28
 * @copyright  2024 Andrew Lyons <andrew@nicols.co.uk>
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
class hook_callbacks {
32
    /**
33
     * Add the guest consent form to the top of the body.
34
     *
35
     * @param before_standard_top_of_body_html_generation $hook
36
     */
37
    public static function before_standard_top_of_body_html_generation(before_standard_top_of_body_html_generation $hook): void {
38
        global $CFG, $PAGE, $USER;
39
 
40
        if (empty($CFG->sitepolicyhandler)) {
41
            return;
42
        }
43
 
44
        if ($CFG->sitepolicyhandler !== 'tool_policy') {
45
            return;
46
        }
47
 
48
        if (!empty($USER->policyagreed)) {
49
            return;
50
        }
51
 
52
        if (!isguestuser() && isloggedin()) {
53
            return;
54
        }
55
 
56
        $output = $PAGE->get_renderer('tool_policy');
57
        try {
58
            $page = new \tool_policy\output\guestconsent();
59
            $hook->add_html($output->render($page));
60
        } catch (\dml_read_exception $e) {
61
            // During upgrades, the new plugin code with new SQL could be in place but the DB not upgraded yet.
62
            return;
63
        }
64
    }
65
 
66
    /**
67
     * Add the user policy settings link to the footer.
68
     *
69
     * @param before_standard_footer_html_generation $hook
70
     */
71
    public static function before_standard_footer_html_generation(before_standard_footer_html_generation $hook): void {
72
        global $CFG, $PAGE;
73
 
74
        if (empty($CFG->sitepolicyhandler) || $CFG->sitepolicyhandler !== 'tool_policy') {
75
            return;
76
        }
77
 
78
        $policies = api::get_current_versions_ids();
79
        if (!empty($policies)) {
80
            $url = new moodle_url('/admin/tool/policy/viewall.php', ['returnurl' => $PAGE->url]);
81
            $hook->add_html(
82
                html_writer::link($url, get_string('userpolicysettings', 'tool_policy'), ['class' => 'policiesfooter']),
83
            );
84
        }
85
    }
86
}