Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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 a base class for extension by message processors
  19   *
  20   * @package   core_message
  21   * @copyright Luis Rodrigues
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  /**
  26   * Base message processor class for extension by message processors
  27   *
  28   * @package   core_message
  29   * @copyright 2008 Luis Rodrigues
  30   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  abstract class message_output {
  33      /**
  34       * Process a message received by a user
  35       *
  36       * @see message_send()
  37       * @param stdClass $message The event data submitted by the message provider to message_send() plus $eventdata->savedmessageid
  38       */
  39      public abstract function send_message($message);
  40  
  41      /**
  42       * Load the config data from database to put on the config form on the messaging preferences page
  43       *
  44       * @param array $preferences Array of user preferences
  45       * @param int $userid The user ID
  46       */
  47      public abstract function load_data(&$preferences, $userid);
  48  
  49      /**
  50       * Create necessary fields in the config form on the messaging preferences page
  51       *
  52       * @param array $preferences An array of user preferences
  53       */
  54      public abstract function config_form($preferences);
  55  
  56      /**
  57       * Parse the submitted form and save data into an array of user preferences
  58       *
  59       * @param stdClass $form preferences form class
  60       * @param array $preferences preferences array
  61       */
  62      public abstract function process_form($form, &$preferences);
  63  
  64      /**
  65       * Are the message processor's system settings configured?
  66       *
  67       * @return bool True if all necessary config settings been entered
  68       */
  69      public function is_system_configured() {
  70          return true;
  71      }
  72  
  73      /**
  74       * Are the message processor's user specific settings configured?
  75       *
  76       * @param  stdClass $user the user object, defaults to $USER.
  77       * @return bool True if the user has all necessary settings in their messaging preferences
  78       */
  79      public function is_user_configured($user = null) {
  80          return true;
  81      }
  82  
  83      /**
  84       * Returns the message processors default settings
  85       * Should the processor be enabled for logged in users by default?
  86       * Should the processor be enabled for logged off users by default?
  87       * Is enabling it disallowed, permitted or forced?
  88       *
  89       * @return int The Default message output settings expressed as a bit mask
  90       *         MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF + MESSAGE_DISALLOWED|MESSAGE_PERMITTED|MESSAGE_FORCED
  91       */
  92      public function get_default_messaging_settings() {
  93          return MESSAGE_PERMITTED;
  94      }
  95  
  96      /**
  97       * Returns true if message can be sent to fake/internal user as well.
  98       * If message_output support message to be sent to fake user, then it should return true, like email.
  99       *
 100       * @return bool
 101       */
 102      public function can_send_to_any_users() {
 103          return false;
 104      }
 105  
 106      /**
 107       * Returns true if this processor has configurable message preferences. This is
 108       * distinct from notification preferences.
 109       *
 110       * @return bool
 111       */
 112      public function has_message_preferences() {
 113          return true;
 114      }
 115  
 116      /**
 117       * Determines if this processor should process a message regardless of user preferences or site settings.
 118       *
 119       * @return bool
 120       */
 121      public function force_process_messages() {
 122          return false;
 123      }
 124  
 125      /**
 126       * Allow processors to perform cleanup tasks for all notifications by overriding this method
 127       *
 128       * @since Moodle 3.9
 129       * @param int $notificationdeletetime
 130       * @return void
 131       */
 132      public function cleanup_all_notifications(int $notificationdeletetime): void {
 133          return;
 134      }
 135  
 136      /**
 137       * Allow processors to perform cleanup tasks for read notifications by overriding this method
 138       *
 139       * @since Moodle 3.9
 140       * @param int $notificationdeletetime
 141       * @return void
 142       */
 143      public function cleanup_read_notifications(int $notificationdeletetime): void {
 144          return;
 145      }
 146  }