Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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          $formaction = new \moodle_url('/auth/lti/login.php');
  37          $notification = new notification(get_string('firstlaunchnotice', 'auth_lti'), \core\notification::INFO, false);
  38          $noauthnotice = new notification(get_string('firstlaunchnoauthnotice', 'auth_lti', get_docs_url('Publish_as_LTI_tool')),
  39              \core\notification::WARNING, false);
  40          $cancreateaccounts = !get_config('moodle', 'authpreventaccountcreation');
  41          if ($provisioningmode == \auth_plugin_lti::PROVISIONING_MODE_PROMPT_EXISTING_ONLY) {
  42              $cancreateaccounts = false;
  43          }
  44  
  45          $accountinfo = ['isloggedin' => isloggedin()];
  46          if (isloggedin()) {
  47              global $USER;
  48              $accountinfo = array_merge($accountinfo, [
  49                  'firstname' => $USER->firstname,
  50                  'lastname' => $USER->lastname,
  51                  'email' => $USER->email,
  52                  'picturehtml' => $this->output->user_picture($USER,  ['size' => 35, 'class' => 'round']),
  53              ]);
  54          }
  55  
  56          $context = [
  57              'info' => $notification->export_for_template($this),
  58              'formaction' => $formaction->out(),
  59              'sesskey' => sesskey(),
  60              'accountinfo' => $accountinfo,
  61              'cancreateaccounts' => $cancreateaccounts,
  62              'noauthnotice' => $noauthnotice->export_for_template($this)
  63          ];
  64          return parent::render_from_template('auth_lti/local/ltiadvantage/login', $context);
  65      }
  66  
  67      /**
  68       * Render the page displayed when the account binding is complete, letting the user continue to the launch.
  69       *
  70       * Callers can provide different messages depending on which type of binding took place. For example, a newly
  71       * provisioned account may require a slightly different message to an existing account being linked.
  72       *
  73       * The return URL is the page the user will be taken back to when they click 'Continue'. This is likely the launch
  74       * or deeplink launch endpoint but could be any calling code in LTI which wants to use the account binding workflow.
  75       *
  76       * @param notification $notification the notification containing the message describing the binding success.
  77       * @param \moodle_url $returnurl the URL to return to when the user clicks continue on the rendered page.
  78       * @return string the rendered HTML
  79       */
  80      public function render_account_binding_complete(notification $notification, \moodle_url $returnurl): string {
  81          $context = (object) [
  82              'notification' => $notification->export_for_template($this),
  83              'returnurl' => $returnurl->out()
  84          ];
  85          return parent::render_from_template('auth_lti/local/ltiadvantage/account_binding_complete', $context);
  86      }
  87  }