Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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  /**
  18   * Output rendering for the plugin.
  19   *
  20   * @package     tool_messageinbound
  21   * @copyright   2014 Andrew Nicols
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Implements the plugin renderer
  29   *
  30   * @copyright 2014 Andrew Nicols
  31   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class tool_messageinbound_renderer extends plugin_renderer_base {
  34  
  35      /**
  36       * Render a table listing all of the Inbound Message handlers.
  37       *
  38       * @param array $handlers - list of all messageinbound handlers.
  39       * @return string HTML to output.
  40       */
  41      public function messageinbound_handlers_table(array $handlers) {
  42          global $CFG;
  43  
  44          $table = new html_table();
  45          $handlername = new html_table_cell(get_string('name', 'tool_messageinbound') . "\n" .
  46                  html_writer::tag('span', get_string('classname', 'tool_messageinbound'), array('class' => 'handler-function')));
  47  
  48          // Prepare some of the rows with additional styling.
  49          $enabled = new html_table_cell(get_string('enabled', 'tool_messageinbound'));
  50          $enabled->attributes['class'] = 'state';
  51          $edit = new html_table_cell(get_string('edit', 'tool_messageinbound'));
  52          $edit->attributes['class'] = 'edit';
  53          $table->head  = array(
  54                  $handlername,
  55                  get_string('description', 'tool_messageinbound'),
  56                  $enabled,
  57                  $edit,
  58              );
  59          $table->attributes['class'] = 'admintable generaltable messageinboundhandlers';
  60  
  61          $yes = get_string('yes');
  62          $no = get_string('no');
  63  
  64          $data = array();
  65  
  66          // Options for description formatting.
  67          $descriptionoptions = new stdClass();
  68          $descriptionoptions->trusted = false;
  69          $descriptionoptions->noclean = false;
  70          $descriptionoptions->smiley = false;
  71          $descriptionoptions->filter = false;
  72          $descriptionoptions->para = true;
  73          $descriptionoptions->newlines = false;
  74          $descriptionoptions->overflowdiv = true;
  75  
  76          $editurlbase = new moodle_url('/admin/tool/messageinbound/index.php');
  77          foreach ($handlers as $handler) {
  78              $handlername = new html_table_cell($handler->name . "\n" .
  79                      html_writer::tag('span', $handler->classname, array('class' => 'handler-function')));
  80              $handlername->header = true;
  81  
  82              $editurl = new moodle_url($editurlbase, array('classname' => $handler->classname));
  83              $editlink = $this->action_icon($editurl, new pix_icon('t/edit',
  84                      get_string('edithandler', 'tool_messageinbound', $handler->classname)));
  85  
  86              // Prepare some of the rows with additional styling.
  87              $enabled = new html_table_cell($handler->enabled ? $yes : $no);
  88              $enabled->attributes['class'] = 'state';
  89              $edit = new html_table_cell($editlink);
  90              $edit->attributes['class'] = 'edit';
  91  
  92              // Add the row.
  93              $row = new html_table_row(array(
  94                          $handlername,
  95                          format_text($handler->description, FORMAT_MARKDOWN, $descriptionoptions),
  96                          $enabled,
  97                          $edit,
  98                      ));
  99  
 100              if (!$handler->enabled) {
 101                  $row->attributes['class'] = 'disabled';
 102              }
 103              $data[] = $row;
 104          }
 105          $table->data = $data;
 106          return html_writer::table($table);
 107      }
 108  
 109  }