Пример #1
0
 public function actionMessageinsert()
 {
     $messageRooms = new MessageRooms();
     $input = \Yii::$app->getRequest()->getBodyParams();
     $user_id_1 = empty($input['sender_id']) ? null : $input['sender_id'];
     $user_id_2 = empty($input['received_id']) ? null : $input['received_id'];
     $message = empty($input['message']) ? null : $input['message'];
     $mr_id = empty($input['mr_id']) ? null : $input['mr_id'];
     if (is_null($mr_id)) {
         $messageRooms->user_id_1 = $user_id_1;
         $messageRooms->user_id_2 = $user_id_2;
         $messageRooms->save();
     } else {
         $messageRooms = MessageRooms::find($mr_id);
     }
     $conversation = new Conversations();
     $conversation->user_id = $user_id_1;
     $conversation->message = $message;
     if ($conversation->save()) {
         $cr_id = $conversation->cr_id;
         $roomConversation = new RoomsConversations();
         $roomConversation->cr_id = $cr_id;
         $roomConversation->mr_id = $messageRooms->mr_id;
         if ($roomConversation->save()) {
             return $conversation;
         } else {
             return false;
         }
     }
 }
Пример #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMr()
 {
     return $this->hasOne(MessageRooms::className(), ['mr_id' => 'mr_id']);
 }