コード例 #1
0
 public function actionFollowing()
 {
     $query = Topic::find()->innerJoinWith('authorFollowedBy')->where([Favorite::tableName() . '.source_id' => Yii::$app->getUser()->id, Favorite::tableName() . '.type' => Favorite::TYPE_USER]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(1), 'pageSize' => $this->settings['list_pagesize'], 'pageParam' => 'p']);
     $topics = $query->select([Topic::tableName() . '.id'])->orderBy([Topic::tableName() . '.id' => SORT_DESC])->offset($pages->offset)->with(['topic.author', 'topic.node', 'topic.lastReply'])->limit($pages->limit)->all();
     return $this->render('following', ['topics' => Util::convertModelToArray($topics), 'pages' => $pages]);
 }
コード例 #2
0
ファイル: Topic.php プロジェクト: 0ps/simpleforum
 public static function getTopicsFromIndex($pages)
 {
     $key = 'topics-index-p-' . $pages->getPage();
     $cache = Yii::$app->getCache();
     $settings = Yii::$app->params['settings'];
     if (intval($settings['cache_enabled']) === 0 || ($models = $cache->get($key)) === false) {
         $models = static::find()->select('id')->orderBy(['replied_at' => SORT_DESC])->offset($pages->offset)->with(['topic.node', 'topic.author', 'topic.lastReply'])->limit($pages->limit)->asArray()->all();
         if (intval($settings['cache_enabled']) !== 0) {
             $dep = new DbDependency(['sql' => 'SELECT MAX(updated_at) FROM ' . Topic::tableName()]);
             $cache->set($key, $models, intval($settings['cache_time']) * 60, $dep);
         }
     }
     return $models;
 }