Пример #1
0
 /**
  * Grabs notification and sends it out via available drivers
  *
  * @access  public
  * @params  string  $shouter    The shouting gadget
  * @params  array   $params     [user, group, title, summary, description, priority, send]
  */
 function Execute($shouter, $params)
 {
     if (isset($params['send']) && $params['send'] === false) {
         return;
     }
     $users = array();
     $jUser = new Jaws_User();
     if (isset($params['group']) && !empty($params['group'])) {
         $group_users = $jUser->GetGroupUsers($params['group'], true, false, true);
         if (!Jaws_Error::IsError($group_users) && !empty($group_users)) {
             $users = $group_users;
         }
     }
     if (isset($params['user']) && !empty($params['user'])) {
         $user = $jUser->GetUser($params['user'], true, false, true);
         if (!Jaws_Error::IsError($user) && !empty($user)) {
             $users[] = $user;
         }
     }
     if (empty($users)) {
         return;
     }
     if (!isset($params['summary'])) {
         $params['summary'] = '';
     }
     $drivers = glob(JAWS_PATH . 'include/Jaws/Notification/*.php');
     foreach ($drivers as $driver) {
         $driver = basename($driver, '.php');
         $options = unserialize($this->gadget->registry->fetch($driver . '_options'));
         $driverObj = Jaws_Notification::getInstance($driver, $options);
         $driverObj->notify($users, strip_tags($params['title']), strip_tags($params['summary']), $params['description']);
     }
 }
Пример #2
0
 /**
  * Send notifications in queue
  *
  * @access  public
  * @return  boolean
  */
 function SendNotifications()
 {
     $processing = $this->gadget->registry->fetch('processing');
     $lastUpdate = (int) $this->gadget->registry->fetch('last_update');
     $queueMaxTime = (int) $this->gadget->registry->fetch('queue_max_time');
     if ($processing == 'true' && $lastUpdate + $queueMaxTime < time()) {
         return false;
     }
     $this->gadget->registry->update('last_update', time());
     $this->gadget->registry->update('processing', 'true');
     $model = $this->gadget->model->load('Notification');
     $emailLimit = (int) $this->gadget->registry->fetch('email_pop_count');
     $emailItems = $model->GetNotifications(Notification_Info::NOTIFICATION_TYPE_EMAIL, $emailLimit);
     if (Jaws_Error::IsError($emailItems)) {
         $this->gadget->registry->update('processing', 'false');
         return $emailItems;
     }
     $mobileLimit = (int) $this->gadget->registry->fetch('mobile_pop_count');
     $mobileItems = $model->GetNotifications(Notification_Info::NOTIFICATION_TYPE_MOBILE, $mobileLimit);
     if (Jaws_Error::IsError($mobileItems)) {
         $this->gadget->registry->update('processing', 'false');
         return $mobileItems;
     }
     // send notification to drivers
     $drivers = glob(JAWS_PATH . 'include/Jaws/Notification/*.php');
     foreach ($drivers as $driver) {
         $driver = basename($driver, '.php');
         $options = unserialize($this->gadget->registry->fetch($driver . '_options'));
         $driverObj = Jaws_Notification::getInstance($driver, $options);
         if (!empty($emailItems) && $driver == 'Mail') {
             $emailItemsChunk = $this->GroupSameMessages($emailItems);
             foreach ($emailItemsChunk as $messageId => $emails) {
                 $message = $model->GetNotificationMessage($messageId);
                 $res = $driverObj->notify($emails, $message['title'], $message['summary'], $message['description']);
             }
             // delete notification
             // FIXME : we can increase the performance
             if (!Jaws_Error::IsError($res)) {
                 $itemsId = array();
                 foreach ($emailItems as $item) {
                     $itemsId[] = $item['id'];
                 }
                 $model->DeleteNotificationsById(Notification_Info::NOTIFICATION_TYPE_EMAIL, $itemsId);
             }
         } else {
             if (!empty($mobileItems) && $driver == 'Mobile') {
                 $mobileItemsChunk = $this->GroupSameMessages($mobileItems);
                 foreach ($mobileItemsChunk as $messageId => $mobiles) {
                     $message = $model->GetNotificationMessage($messageId);
                     $res = $driverObj->notify($mobiles, $message['title'], $message['summary'], $message['description']);
                 }
                 // delete notification
                 // FIXME : we can increase the performance
                 if (!Jaws_Error::IsError($res)) {
                     $itemsId = array();
                     foreach ($mobileItems as $item) {
                         $itemsId[] = $item['id'];
                     }
                     $model->DeleteNotificationsById(Notification_Info::NOTIFICATION_TYPE_MOBILE, $itemsId);
                 }
             }
         }
     }
     // finish procession
     $this->gadget->registry->update('processing', 'false');
     return true;
 }