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 auth_lti\output;
18
 
19
use core\output\notification;
20
 
21
/**
22
 * Renderer class for auth_lti.
23
 *
24
 * @package    auth_lti
25
 * @copyright  2021 Jake Dallimore <jrhdallimore@gmail.com>
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
class renderer extends \plugin_renderer_base {
29
    /**
30
     * Render the account options view, displayed to instructors on first launch if no account binding exists.
31
     *
32
     * @param int $provisioningmode the desired account provisioning mode, see auth_plugin_lti constants for details.
33
     * @return string the html.
34
     */
35
    public function render_account_binding_options_page(int $provisioningmode): string {
36
 
37
        $formaction = new \moodle_url('/auth/lti/login.php');
38
        $notification = new notification(get_string('firstlaunchnotice', 'auth_lti'), \core\notification::INFO, false);
39
        $cancreateaccounts = !get_config('moodle', 'authpreventaccountcreation');
40
        if ($provisioningmode == \auth_plugin_lti::PROVISIONING_MODE_PROMPT_EXISTING_ONLY) {
41
            $cancreateaccounts = false;
42
        }
43
 
44
        $accountinfo = [];
45
        if (isloggedin()) {
46
            global $USER;
47
            $accountinfo = [
48
                'firstname' => $USER->firstname,
49
                'lastname' => $USER->lastname,
50
                'email' => $USER->email,
51
                'picturehtml' => $this->output->user_picture($USER,  ['size' => 35, 'class' => 'round']),
52
            ];
53
        }
54
 
55
        $context = [
56
            'isloggedin' => isloggedin(),
57
            'info' => $notification->export_for_template($this),
58
            'formaction' => $formaction->out(),
59
            'sesskey' => sesskey(),
60
            'accountinfo' => $accountinfo,
61
            'cancreateaccounts' => $cancreateaccounts,
62
        ];
63
        return parent::render_from_template('auth_lti/local/ltiadvantage/login', $context);
64
    }
65
 
66
    /**
67
     * Render the page displayed when the account binding is complete, letting the user continue to the launch.
68
     *
69
     * Callers can provide different messages depending on which type of binding took place. For example, a newly
70
     * provisioned account may require a slightly different message to an existing account being linked.
71
     *
72
     * The return URL is the page the user will be taken back to when they click 'Continue'. This is likely the launch
73
     * or deeplink launch endpoint but could be any calling code in LTI which wants to use the account binding workflow.
74
     *
75
     * @param notification $notification the notification containing the message describing the binding success.
76
     * @param \moodle_url $returnurl the URL to return to when the user clicks continue on the rendered page.
77
     * @return string the rendered HTML
78
     */
79
    public function render_account_binding_complete(notification $notification, \moodle_url $returnurl): string {
80
        $context = (object) [
81
            'notification' => $notification->export_for_template($this),
82
            'returnurl' => $returnurl->out()
83
        ];
84
        return parent::render_from_template('auth_lti/local/ltiadvantage/account_binding_complete', $context);
85
    }
86
}