コード例 #1
0
ファイル: PoprigunChatDialog.php プロジェクト: poprigun/chat
 /**
  * Delete dialog/delete dialog messages (change status)
  *
  * @param integer $dialogId
  * @param integer|null $userId
  * @return int
  */
 public static function deleteDialog($dialogId, $userId = null)
 {
     $userId = $userId ? $userId : Yii::$app->user->id;
     $messageIds = PoprigunChatMessage::find()->select([PoprigunChatMessage::tableName() . '.id', PoprigunChatUser::tableName() . '.id as chat_user_id'])->innerJoinWith('chatUserRel')->innerJoinWith('chatUserRel.chatUser')->andWhere([PoprigunChatMessage::tableName() . '.dialog_id' => $dialogId])->andWhere([PoprigunChatUser::tableName() . '.user_id' => $userId])->asArray()->all();
     if (empty($messageIds)) {
         return false;
     }
     return PoprigunChatUserRel::updateAll(['status' => PoprigunChatUserRel::STATUS_DELETED], ['message_id' => ArrayHelper::map($messageIds, 'id', 'id'), 'chat_user_id' => ArrayHelper::map($messageIds, 'chat_user_id', 'chat_user_id')]);
 }