public function doRestCreate($data)
 {
     $data['initiator_id'] = Yii::app()->user->id;
     $participants = $data['participants'];
     unset($data['participants']);
     $models = $this->saveModel($this->getModel(), $data);
     $conversation = $models[0];
     foreach ($participants as $participantAttrs) {
         $participant = new ConversationParticipant();
         $participant->user_id = $participantAttrs['user_id'];
         $participant->conversation_id = $conversation->id;
         $participant->save();
     }
     $conversation->participants = $conversation->participants(array('with' => array('user' => array('select' => 'user_id, first_name, last_name, photo, photo_thmbnl_64'))));
     $conversation->messages = $conversation->messages(array('order' => 'created_ts DESC', 'limit' => 1));
     $models[0] = $conversation;
     $this->outputHelper('Record(s) Created', $models, 1);
 }
示例#2
0
 public function doRestList()
 {
     $userId = Yii::app()->user->id;
     $conversationId = $this->plainFilter['conversation_id'];
     $participant = ConversationParticipant::model()->findByAttributes(array('conversation_id' => $conversationId, 'user_id' => $userId));
     if (!$participant) {
         throw new CHttpException(403, 'Specified user is not participant of specified conversation.');
     }
     $criteria = $this->getModel()->with($this->nestedRelations)->filter($this->restFilter)->orderBy('created_ts', 'DESC');
     $this->outputHelper('Records Retrieved Successfully', $criteria->limit($this->restLimit)->offset($this->restOffset)->findAll(), $this->getModel()->with($this->nestedRelations)->filter($this->restFilter)->count());
 }