Beispiel #1
0
 /**
  * Creates an instance of NfyMessage model. The passed message body may be modified, @see formatMessage().
  * This method may be overriden in extending classes.
  * @param string $body message body
  * @return NfyMessage
  */
 protected function createMessage($body)
 {
     $now = new DateTime('now', new DateTimezone('UTC'));
     $message = new NfyMessage();
     $message->setAttributes(array('id' => $this->redis->incr($this->id . self::MESSAGE_ID), 'status' => NfyMessage::AVAILABLE, 'created_on' => $now->format('Y-m-d H:i:s'), 'sender_id' => Yii::app()->hasComponent('user') ? Yii::app()->user->getId() : null, 'body' => $body));
     return $this->formatMessage($message);
 }
Beispiel #2
0
 /**
  * Creates an instance of NfyMessage model. The passed message body may be modified, @see formatMessage().
  * This method may be overriden in extending classes.
  * @param string $body message body
  * @return NfyMessage
  */
 protected function createMessage($body)
 {
     $now = new DateTime('now', new DateTimezone('UTC'));
     $message = new NfyMessage();
     $message->setAttributes(array('created_on' => $now->format('Y-m-d H:i:s'), 'sender_id' => Yii::app()->hasComponent('user') ? Yii::app()->user->getId() : null, 'body' => $body));
     return $this->formatMessage($message);
 }
Beispiel #3
0
 public static function createMessages($dbMessages)
 {
     if (!is_array($dbMessages)) {
         $dbMessages = array($dbMessages);
     }
     $result = array();
     foreach ($dbMessages as $dbMessage) {
         $attributes = $dbMessage->getAttributes();
         $attributes['subscriber_id'] = $dbMessage->subscription_id === null ? null : $dbMessage->subscription->subscriber_id;
         unset($attributes['queue_id']);
         unset($attributes['subscription_id']);
         unset($attributes['mimetype']);
         $message = new NfyMessage();
         $message->setAttributes($attributes);
         $result[] = $message;
     }
     return $result;
 }
Beispiel #4
0
    public static function createMessages($dbMessages)
    {
        if (!is_array($dbMessages)) {
            $dbMessages = array($dbMessages);
        }
        $result = array();

        foreach ($dbMessages as $dbMessage) {
            $attributes = $dbMessage->getAttributes();
            $attributes['subscriber_id'] = $dbMessage->subscription_id === null ? null : $dbMessage->subscription->subscriber_id;
            unset($attributes['queue_id']);
            unset($attributes['subscription_id']);
         //   unset($attributes['mimetype']);
            $message = new NfyMessage;
            $message->setAttributes($attributes);

            if(!empty($dbMessage->notification_id)){
                $message->notification = $dbMessage->notification;
                $message->body = $dbMessage->notification->body;
                $message->class_name = $dbMessage->notification->class_name;
                $message->object_pk = $dbMessage->object_pk;
                $message->notification_id = $dbMessage->notification_id;
                $message->subject_pk = $dbMessage->subject_pk;

            } else {
                $message->body = $dbMessage->message_body->body;
                $message->class_name = $dbMessage->message_body->class_name;
                $message->object_pk = $dbMessage->message_body->object_pk;
            }
            
            
            $result[] = $message;
        }
        
        return $result;
    }
Beispiel #5
0
 /**
  * Fetches details of a single message, allows to release or delete it or sends a new message.
  * @param string $id queue name
  * @param string $subscriber_id
  * @param string $message_id
  */
 public function actionMessage($queue_name, $subscriber_id = null, $message_id = null)
 {
     if (($subscriber_id = trim($subscriber_id)) === '') {
         $subscriber_id = null;
     }
     list($queue, $authItems) = $this->loadQueue($queue_name, array('nfy.message.read', 'nfy.message.create'));
     $this->verifySubscriber($queue, $subscriber_id);
     if ($queue instanceof NfyDbQueue) {
         NfyDbMessage::model()->withQueue($queue->id);
         if ($subscriber_id !== null) {
             NfyDbMessage::model()->withSubscriber($subscriber_id);
         }
         $dbMessage = NfyDbMessage::model()->findByPk($message_id);
         if ($dbMessage === null) {
             throw new CHttpException(404, Yii::t("NfyModule.app", 'Message with given ID was not found.'));
         }
         $messages = NfyDbMessage::createMessages($dbMessage);
         $message = reset($messages);
     } else {
         //! @todo should we even bother to locate a single message by id?
         $message = new NfyMessage();
         $message->setAttributes(array('id' => $message_id, 'subscriber_id' => $subscriber_id, 'status' => NfyMessage::AVAILABLE));
     }
     if (isset($_POST['delete'])) {
         $queue->delete($message->id, $message->subscriber_id);
         $this->redirect(array('messages', 'queue_name' => $queue_name, 'subscriber_id' => $message->subscriber_id));
     }
     $this->render('message', array('queue' => $queue, 'queue_name' => $queue_name, 'dbMessage' => $dbMessage, 'message' => $message, 'authItems' => $authItems));
 }
Beispiel #6
0
 public static function createMessages($dbMessages)
 {
     if (!is_array($dbMessages)) {
         $dbMessages = array($dbMessages);
     }
     $result = array();
     $userIds = array();
     foreach ($dbMessages as $dbMessage) {
         $attributes = $dbMessage->getAttributes();
         $attributes['subscriber_id'] = is_null($dbMessage->subscription_id) ? null : $dbMessage->subscription['subscriber_id'];
         unset($attributes['queue_id']);
         unset($attributes['subscription_id']);
         unset($attributes['mimetype']);
         $attributes['body'] = json_decode($attributes['body'], true);
         $message = new NfyMessage();
         $message->setAttributes($attributes);
         $result[] = $message;
         $userIds[] = $message->subscriber_id;
         $userIds[] = $message->sender_id;
     }
     $userIds = array_unique($userIds);
     if (count($userIds) > 0) {
         $sql = "SELECT u.id,fullname,role_name from p_user u\n left outer join \n   p_user_role p on u.id = p.user_id \n   and p.is_default_role = 'Yes' \n left outer join \n   p_role r on r.id = p.role_id \n where u.id IN (" . implode(",", $userIds) . ");";
         $userResult = Yii::app()->db->createCommand($sql)->queryAll();
         $users = array();
         foreach ($userResult as $u) {
             $users[$u['id']] = array('name' => $u['fullname'], 'role' => $u['role_name']);
         }
         foreach ($result as $k => $r) {
             $result[$k]->subscriber_name = $users[$r->subscriber_id]['name'];
             $result[$k]->subscriber_role = $users[$r->subscriber_id]['role'];
             if ($r->sender_id != 0) {
                 $result[$k]->sender_name = $users[$r->sender_id]['name'];
                 $result[$k]->sender_role = $users[$r->sender_id]['role'];
             } else {
                 $result[$k]->sender_name = "Notification";
                 $result[$k]->sender_role = "SYSTEM";
             }
         }
     }
     return $result;
 }