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  /**
  18   * Contains processor class for displaying on message preferences page.
  19   *
  20   * @package   core_message
  21   * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_message\output\preferences;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use renderable;
  30  use templatable;
  31  
  32  /**
  33   * Class to create context for one of the message processors settings on the message preferences page.
  34   *
  35   * @package   core_message
  36   * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class processor implements templatable, renderable {
  40  
  41      /**
  42       * @var \stdClass The message processor.
  43       */
  44      protected $processor;
  45  
  46      /**
  47       * @var \stdClass list of message preferences.
  48       */
  49      protected $preferences;
  50  
  51      /**
  52       * @var \stdClass A user.
  53       */
  54      protected $user;
  55  
  56      /**
  57       * @var string The processor type.
  58       */
  59      protected $type;
  60  
  61      /**
  62       * Constructor.
  63       *
  64       * @param \stdClass $processor
  65       * @param \stdClass $preferences
  66       * @param \stdClass $user
  67       * @param string $type
  68       */
  69      public function __construct($processor, $preferences, $user, $type) {
  70          $this->processor = $processor;
  71          $this->preferences = $preferences;
  72          $this->user = $user;
  73          $this->type = $type;
  74      }
  75  
  76      public function export_for_template(\renderer_base $output) {
  77          return [
  78              'userid' => $this->user->id,
  79              'displayname' => get_string('pluginname', 'message_'.$this->type),
  80              'name' => $this->type,
  81              'formhtml' => $this->processor->config_form($this->preferences),
  82          ];
  83      }
  84  }