예제 #1
0
 function postProcessing(&$data)
 {
     if (\Yii::app()->request->requestType == 'GET') {
         include_once \Yii::getPathOfAlias('site.frontend.vendor.simplehtmldom_1_5') . DIRECTORY_SEPARATOR . 'simple_html_dom.php';
         for ($i = 0; $i < count($data); $i++) {
             $data[$i]['isReadByInterlocutor'] = \MessagingMessage::model()->findByPk($data[$i]['id'])->getIsReadByInterlocutor();
             $data[$i]['text'] = HtmlParser::handleHtml($data[$i]['text'])->outertext;
         }
     }
 }
예제 #2
0
 private function handleContacts(&$contacts)
 {
     for ($i = 0; $i < count($contacts); $i++) {
         /**
          * @var \User $user
          */
         $user = \User::model()->findByPk($contacts[$i]['id']);
         if (!$user) {
             throw new NotFoundApiException('InvalidContact:UserNotFound');
         }
         Formatter::formatUser($user);
         $contacts[$i]['avatar'] = $user->getAttributes()['avatarInfo'];
         $message = \MessagingMessage::model()->between($this->controller->identity->getId(), $user->id)->find(array('order' => \MessagingMessage::model()->getTableAlias() . ".created desc"));
         Formatter::formatCommon($message);
         $contacts[$i]['message'] = $message->getAttributes();
     }
 }
예제 #3
0
 public function deleteMessage()
 {
     $required = array('messageId' => true);
     $messageId = $this->controller->getParams($required)['messageId'];
     /**
      * @var \MessagingMessage $message
      */
     $message = \MessagingMessage::model()->withMyStatsOnTop($this->controller->identity->getId())->findByPk($messageId);
     $this->checkMessage($message);
     if (!$message->delete()) {
         throw new ApiException($message->errors, 500);
     }
     $this->controller->data = $message;
     $comet = new \CometModel();
     $messageData = array('id' => $message->id, 'to_id' => $message->messageUsers[1]->user_id, 'from_id' => $message->messageUsers[0]->user_id);
     $comet->send($message->messageUsers[0]->user_id, array('dialog' => array('id' => $message->messageUsers[1]->user_id), 'message' => $messageData), \CometModel::MESSAGING_MESSAGE_CANCELLED);
     $comet->send($message->messageUsers[1]->user_id, array('dialog' => array('id' => $message->messageUsers[0]->user_id), 'message' => $messageData), \CometModel::MESSAGING_MESSAGE_CANCELLED);
 }