public function actionTopic($username) { $this->title = $username . '发布的主题 - ' . Yii::$app->name; $this->description = ''; $user = $this->findModel($username); $query = Topic::find()->where(['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]); }
/** * @inheritdoc */ public function actions() { return ['error' => ['class' => 'yii\\web\\ErrorAction'], 'auth' => ['class' => 'yii\\authclient\\AuthAction', 'successCallback' => [$this, 'successCallback']], 'rss' => ['class' => SitemapUrlsetAction::className(), 'dataProvider' => new ActiveDataProvider(['query' => Topic::find()->orderBy('updated_at DESC'), 'pagination' => ['pageParam' => 'p', 'pageSize' => 100]]), 'remap' => ['loc' => function ($model) { return Url::to('/topic/' . $model->id, true); }, 'lastmod' => function ($model) { return date(DATE_W3C, $model->updated_at); }, 'changefreq' => function ($model) { return 'daily'; }, 'priority' => function ($model) { return '0.8'; }]]]; }
public function actionList() { $list = Topic::find()->where(['active' => 1])->with('tags'); $countQuery = clone $list; $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => $this->paginate['per_page']]); $cacheKey = 'Topics_' . $this->cacheKeyPaginate($pages); if (false === ($topics = $this->getCache($cacheKey))) { if (null === ($topics = $list->offset($pages->offset)->limit($pages->limit)->all())) { $this->error(404); } $this->setCache($cacheKey, $topics, 'Topic_List', []); } return $this->render('list', ['topics' => $topics, 'pages' => $pages]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Topic::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'node_id' => $this->node_id, 'need_login' => $this->need_login, 'click' => $this->click, 'follow' => $this->follow, 'reply' => $this->reply, 'last_reply_user' => $this->last_reply_user, 'last_reply_time' => $this->last_reply_time, 'updated_at' => $this->updated_at, 'created' => $this->created]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Topic::find()->with('category'); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'owner' => $this->owner, 'created' => $this->created, 'updated' => $this->updated, 'active' => $this->active]); $query->andFilterWhere(['like', 'h1', $this->h1])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'announce', $this->announce])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function actionGetTopics() { $query = Topic::find()->where(['active' => 1])->with('tags'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 3]); $cacheTopics = 'Topics' . $pages->getPage(); if (Yii::$app->request->get('cache')) { Yii::$app->cache->delete($cacheTopics); } if (false === ($topics = Yii::$app->cache->get($cacheTopics))) { if (null === ($topics = $query->offset($pages->offset)->limit($pages->limit)->all())) { throw new NotFoundHttpException(); } Yii::$app->cache->set($cacheTopics, $topics, 86400, new TagDependency(['tags' => []])); } $this->renderJSON($topics); }
/** * Lists all TopicContent models. * @return mixed */ public function actionIndex() { $searchModel = new TopicContentSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $gridColumns[] = ['class' => 'kartik\\grid\\SerialColumn', 'contentOptions' => ['class' => 'kartik-sheet-style'], 'width' => '36px', 'header' => '序号', 'headerOptions' => ['class' => 'kartik-sheet-style']]; $gridColumns[] = ['attribute' => 'topic_id', 'vAlign' => 'middle', 'width' => '180px', 'value' => function ($searchModel, $key, $index, $widget) { return $searchModel->topic->title; }, 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Topic::find()->orderBy('id')->asArray()->all(), 'id', 'title'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => '建议标题'], 'format' => 'raw']; $gridColumns[] = ['attribute' => 'content', 'value' => function ($searchModel, $key, $index, $widget) { return Helper::truncateUtf8String($searchModel->content, 100); }]; $gridColumns[] = ['class' => 'kartik\\grid\\BooleanColumn', 'attribute' => 'is_append', 'vAlign' => 'middle', 'trueLabel' => '是', 'falseLabel' => '否']; $gridColumns[] = ['mergeHeader' => true, 'attribute' => 'created', 'format' => 'datetime']; $gridColumns[] = ['class' => '\\kartik\\grid\\ActionColumn', 'template' => '{view} {update}', 'buttons' => ['view' => function ($url, $model) { return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', Yii::$app->params['domain'] . '/topic/' . $model->topic_id, ['title' => '查看', 'target' => '_blank']); }]]; return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'gridColumns' => $gridColumns]); }
public function actionIndex() { //今天注册用户 $model['userToday'] = User::find()->where(['between', 'created_at', strtotime(date('Y-m-d', time())), strtotime(date('Y-m-d', time())) + 86400])->count(); //今天主题 $model['topicToday'] = Topic::find()->where(['between', 'created', strtotime(date('Y-m-d', time())), strtotime(date('Y-m-d', time())) + 86400])->count(); //今天回复 $model['replyToday'] = Reply::find()->where(['between', 'created', strtotime(date('Y-m-d', time())), strtotime(date('Y-m-d', time())) + 86400])->count(); //7天内注册用户 $model['user7day'] = User::find()->where(['between', 'created_at', strtotime(date('Y-m-d', time())) - 86400 * 7, strtotime(date('Y-m-d', time()))])->count(); //7天内主题 $model['topic7day'] = Topic::find()->where(['between', 'created', strtotime(date('Y-m-d', time())) - 86400 * 7, strtotime(date('Y-m-d', time()))])->count(); //7天内回复 $model['reply7day'] = Reply::find()->where(['between', 'created', strtotime(date('Y-m-d', time())) - 86400 * 7, strtotime(date('Y-m-d', time()))])->count(); //30天内注册用户 $model['user30day'] = User::find()->where(['between', 'created_at', strtotime(date('Y-m-d', time())) - 86400 * 30, strtotime(date('Y-m-d', time()))])->count(); //30天内主题 $model['topic30day'] = Topic::find()->where(['between', 'created', strtotime(date('Y-m-d', time())) - 86400 * 30, strtotime(date('Y-m-d', time()))])->count(); //30天内回复 $model['reply30day'] = Reply::find()->where(['between', 'created', strtotime(date('Y-m-d', time())) - 86400 * 30, strtotime(date('Y-m-d', time()))])->count(); return $this->render('index', ['model' => $model]); }
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 = ''; $SubNode[$node->id] = $node->id; $SubSubNode = ArrayHelper::map(Node::find()->where(['parent_id' => $node->id])->andWhere(['is_hidden' => 0])->all(), 'id', 'id'); $SubNode = array_merge($SubNode, $SubSubNode); array_unique($SubNode); $query = Topic::find()->where(['in', 'node_id', $SubNode]); $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]); }
static function Info($id) { if (!($topicInfo = Yii::$app->cache->get('topic' . $id))) { $topicInfo = Topic::find()->select('topic.id, topic.title, topic.user_id, topic.node_id, topic.created, topic.last_reply_time, topic.last_reply_user, user.username, node.name as nodename, node.enname as nodeenname')->leftJoin('user', 'user.id = topic.user_id')->leftJoin('node', 'node.id = topic.node_id')->where(['topic.id' => $id])->asArray()->one(); Yii::$app->cache->set('topic' . $id, $topicInfo, 0); } return $topicInfo; }
public function actionTopic() { $this->title = '我关注的主题' . ' - ' . Yii::$app->name; $this->description = ''; if (Yii::$app->user->isGuest) { return $this->redirect('/account/login?next=/account/topic'); } $query = Topic::find()->where(['in', 'id', ArrayHelper::map(Follow::findAll(['user_id' => Yii::$app->user->id, 'type' => 3]), 'follow_id', 'follow_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, 'pagination' => $pagination]); }