Exemplo n.º 1
0
 public function actionIndex()
 {
     $conversationId = $this->getQuery('conversationId');
     if (empty($conversationId)) {
         throw new BadRequestHttpException("Missing conversationId");
     }
     $query = ChatMessage::find();
     if ($orderBy = $this->getQuery('orderBy', 'createdAt')) {
         if (StringUtil::isJson($orderBy)) {
             $orderBy = Json::decode($orderBy, true);
             foreach ($orderBy as $key => $value) {
                 if ($value === 'asc' || $value === 'ASC') {
                     $orderBy[$key] = SORT_ASC;
                 } else {
                     $orderBy[$key] = SORT_DESC;
                 }
             }
         } else {
             $orderBy = [$orderBy => SORT_DESC];
         }
         $query->orderBy($orderBy);
     }
     $query->where(['isDeleted' => false, 'conversationId' => new \MongoId($this->getQuery('conversationId'))]);
     return new ActiveDataProvider(['query' => $query]);
 }