public function actionTopic($username)
 {
     $this->title = $username . '提的建议 - ' . Yii::$app->name;
     $this->description = '';
     $this->canonical = Yii::$app->params['domain'] . 'member/' . $username . '/topic';
     $user = $this->findModel($username);
     $query = (new Query())->select('topic.*, node.enname, node.name, user.username, user.avatar')->from(Topic::tableName())->leftJoin(Node::tableName(), 'node.id = topic.node_id')->leftJoin(User::tableName(), 'user.id = topic.user_id')->where(['node.is_hidden' => 0])->andWhere(['topic.user_id' => $user->id]);
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $model = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('topic', ['model' => $model, 'user' => $user, 'pagination' => $pagination]);
 }
 public function actionView($nodeName)
 {
     $node = $this->findModel($nodeName);
     if ($node->need_login == 1 && Yii::$app->user->isGuest) {
         Yii::$app->getSession()->setFlash('danger', '你访问的节点需要登陆之后才能查看');
         return $this->redirect('/account/login?next=/node/' . $nodeName);
     }
     if (!empty($node->bg) && $node->use_bg == 1) {
         $this->bg = $node->bg;
     }
     if (!empty($node->bg_color)) {
         $this->bg_color = $node->bg_color;
     }
     $this->title = $node->name . ' - ' . Yii::$app->name;
     $this->description = '';
     $this->canonical = Yii::$app->params['domain'] . 'node/' . $nodeName;
     $query = (new Query())->select('topic.*, node.enname, node.name, user.username, user.avatar')->from(Topic::tableName())->leftJoin(Node::tableName(), 'node.id = topic.node_id')->leftJoin(User::tableName(), 'user.id = topic.user_id')->where(['node.id' => $node->id]);
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $model = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('view', ['model' => $model, 'node' => $node, 'pagination' => $pagination]);
 }
Beispiel #3
0
 static function Ranking()
 {
     if (!($Ranking = Yii::$app->cache->get('Ranking'))) {
         $Ranking = (new Query())->select('count(topic.id) topic_count, user.username, user.avatar')->from(Topic::tableName() . ' topic')->leftJoin(Node::tableName(), 'node.id = topic.node_id')->leftJoin(User::tableName() . ' user', 'user.id = topic.user_id')->where(['node.is_hidden' => 0])->groupBy(['topic.user_id'])->orderBy(['topic_count' => SORT_DESC])->limit(10)->all();
         Yii::$app->cache->set('Ranking', $Ranking, 86400);
     }
     return $Ranking;
 }
Beispiel #4
0
 /**
  * 热门主题
  * @param int $num 获取几条热门主题
  * @return array|\yii\db\ActiveRecord[]
  */
 static function HotTopic($num = 8)
 {
     return $topic = (new Query())->select('topic.*, user.username, user.avatar')->from(Topic::tableName() . ' topic')->leftJoin(Node::tableName() . ' node', 'node.id = topic.node_id')->leftJoin(User::tableName() . ' user', 'user.id = topic.user_id')->where('node.is_hidden = 0')->andWhere(['between', 'topic.created', strtotime(date('Y-m-d H:i', time())) - 86400, strtotime(date('Y-m-d H:i', time()))])->orderBy(['topic.reply' => SORT_DESC])->limit($num)->all();
 }
Beispiel #5
0
 public function actionRecent()
 {
     $this->title = '最近的主题 - ' . Yii::$app->name;
     $this->description = '';
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => (new Query())->from(Topic::tableName() . ' topic')->leftJoin(Node::tableName() . ' node', 'node.id = topic.node_id')->where('node.is_hidden = 0')->count()]);
     $topic = (new Query())->select('topic.*, node.enname, node.name, user.username, user.avatar')->from(Topic::tableName() . ' topic')->leftJoin(Node::tableName() . ' node', 'node.id = topic.node_id')->leftJoin(User::tableName() . ' user', 'user.id = topic.user_id')->where('node.is_hidden = 0')->orderBy(['topic.id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('recent', ['topic' => $topic, 'pagination' => $pagination]);
 }
Beispiel #6
0
 /**
  * 热门节点
  * @param int $num 获取热门节点
  * @return array|\yii\db\ActiveRecord[]
  */
 static function HotNode($num = 15)
 {
     if (!($hotNode = Yii::$app->cache->get('hotNode' . $num))) {
         $hotNode = (new Query())->select('node.enname, node.name')->from(Topic::tableName() . ' topic')->leftJoin(Node::tableName() . ' node', 'node.id = topic.node_id')->where('node.is_hidden = 0')->groupBy('topic.node_id')->orderBy('topic.node_id')->limit($num)->all();
         Yii::$app->cache->set('hotNode' . $num, $hotNode, 86400);
     }
     return $hotNode;
 }
 public function actionTopic()
 {
     $this->title = '关注的建议' . ' - ' . Yii::$app->name;
     $this->description = '';
     if (Yii::$app->user->isGuest) {
         return $this->redirect('/account/login?next=/account/topic');
     }
     $query = (new Query())->select('topic.*, node.enname, node.name, user.username, user.avatar')->from(Topic::tableName())->leftJoin(Node::tableName(), 'node.id = topic.node_id')->leftJoin(User::tableName(), 'user.id = topic.user_id')->where(['in', 'topic.id', Follow::Topic()]);
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $model = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('topic', ['model' => $model, 'pagination' => $pagination]);
 }
Beispiel #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getReplyList()
 {
     return (new Query())->select('reply.*, topic.title, node.enname, node.name, user.username, user.avatar')->from(Reply::tableName())->leftJoin(Topic::tableName(), 'topic.id = reply.topic_id')->leftJoin(Node::tableName(), 'node.id = topic.node_id')->leftJoin(User::tableName() . ' user', 'user.id = reply.user_id')->where(['node.is_hidden' => 0])->andWhere(['reply.user_id' => $this->id])->orderBy(['id' => SORT_DESC])->limit(10)->all();
 }