Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 39 and 402]

   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  /**
  18   * Output rendering for the plugin.
  19   *
  20   * @package     auth_oauth2
  21   * @copyright   2017 Damyon Wiese
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace auth_oauth2\output;
  25  
  26  use plugin_renderer_base;
  27  use html_table;
  28  use html_table_cell;
  29  use html_table_row;
  30  use html_writer;
  31  use auth_oauth2\linked_login;
  32  use moodle_url;
  33  
  34  defined('MOODLE_INTERNAL') || die();
  35  
  36  /**
  37   * Implements the plugin renderer
  38   *
  39   * @copyright 2017 Damyon Wiese
  40   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class renderer extends plugin_renderer_base {
  43      /**
  44       * This function will render one beautiful table with all the linked_logins.
  45       *
  46       * @param linked_login[] $linkedlogins - list of all linked logins.
  47       * @return string HTML to output.
  48       */
  49      public function linked_logins_table($linkedlogins) {
  50          global $CFG;
  51  
  52          $table = new html_table();
  53          $table->head  = [
  54              get_string('issuer', 'auth_oauth2'),
  55              get_string('info', 'auth_oauth2'),
  56              get_string('edit'),
  57          ];
  58          $table->attributes['class'] = 'admintable generaltable';
  59          $data = [];
  60  
  61          $index = 0;
  62  
  63          foreach ($linkedlogins as $linkedlogin) {
  64              // Issuer.
  65              $issuerid = $linkedlogin->get('issuerid');
  66              $issuer = \core\oauth2\api::get_issuer($issuerid);
  67              $issuercell = new html_table_cell(s($issuer->get('name')));
  68  
  69              // Issuer.
  70              $username = $linkedlogin->get('username');
  71              $email = $linkedlogin->get('email');
  72              $usernamecell = new html_table_cell(s($email) . ', (' . s($username) . ')');
  73  
  74              $links = '';
  75  
  76              // Delete.
  77              $deleteparams = ['linkedloginid' => $linkedlogin->get('id'), 'action' => 'delete', 'sesskey' => sesskey()];
  78              $deleteurl = new moodle_url('/auth/oauth2/linkedlogins.php', $deleteparams);
  79              $deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
  80              $links .= ' ' . $deletelink;
  81  
  82              $editcell = new html_table_cell($links);
  83  
  84              $row = new html_table_row([
  85                  $issuercell,
  86                  $usernamecell,
  87                  $editcell,
  88              ]);
  89  
  90              $data[] = $row;
  91              $index++;
  92          }
  93          $table->data = $data;
  94          return html_writer::table($table);
  95      }
  96  }