public function actionTopics() { $me = Yii::$app->getUser()->getIdentity(); $query = Favorite::find()->where(['type' => Favorite::TYPE_TOPIC, 'source_id' => $me->id]); // $countQuery = clone $query; $pages = new Pagination(['totalCount' => $me->userInfo->favorite_topic_count, 'pageSize' => $this->settings['list_pagesize'], 'pageParam' => 'p']); $topics = $query->orderBy(['id' => SORT_DESC])->offset($pages->offset)->innerJoinWith(['topic'])->with(['topic.author', 'topic.lastReply', 'topic.node'])->limit($pages->limit)->asArray()->all(); return $this->render('topics', ['topics' => $topics, 'pages' => $pages]); }
public function actionDoFavorite($imageId) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $favorite = Favorite::find()->where(['imageId' => $imageId])->one(); if ($favorite != null) { if ($favorite->isDelete == 1) { $favorite->isDelete = 0; $favorite->update(); } else { $favorite->isDelete = 1; $favorite->update(); } } else { $favorite = new Favorite(); $favorite->imageId = $imageId; $favorite->isDelete = 0; $now = date('Y-m-d H:i:s'); $favorite->createTime = $now; $favorite->updateTime = $now; $favorite->save(); } return ['code' => 0]; }