コード例 #1
0
 /**
  * Takes notification data and sends a message or email.
  * Expected data:
  * - sender => stdClass (User object)
  * - subject => string
  * - content => string
  * - contentformat => int (e.g. FORMAT_HTML). Optional; default FORMAT_PLAIN
  * - notification => bool|int
  * - recipients => array (Array of user objects)
  * - recipientemails => array (Array of email addresses)
  *
  * @param array $data Notification data
  * @return array
  */
 public static function notify(\core\event\base $event)
 {
     $dataformid = $event->other['dataid'];
     $man = \mod_dataform_notification_manager::instance($dataformid);
     $result = false;
     if ($rules = $man->get_type_rules_enabled()) {
         $params = array();
         $params['event'] = $event->eventname;
         $params['dataformid'] = $dataformid;
         $params['viewid'] = !empty($event->other['viewid']) ? $event->other['viewid'] : null;
         $params['entryid'] = !empty($event->other['entryid']) ? $event->other['entryid'] : null;
         foreach ($rules as $rule) {
             if ($rule->is_applicable($params)) {
                 $notification = new notification();
                 $message = $notification->prepare_data($event, $rule);
                 $result = ($result or $notification->send_message($message));
             }
         }
     }
     return $result;
 }