/** * Action method for creating a new forum topic. * @return string|Response action method execution result. */ public function actionCreate() { $topic = new Topic(); if ($topic->load(Yii::$app->request->post()) && $topic->save()) { return $this->redirect($topic->url); } return $this->render('create', ['topic' => $topic, 'categories' => Category::find()->all(), 'sections' => empty($topic->category_id) ? [] : Section::findAll(['category_id' => $topic->category_id])]); }
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]); }
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]); }
/** * 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; }
/** * 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; }
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]); }
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); }
public function actionUndo($type, $follow) { $model = Follow::findOne(['user_id' => Yii::$app->user->id, 'type' => $type, 'follow_id' => $follow]); if ($model !== null) { if ($model->delete() && $type == 3) { $topic = Topic::findOne($follow); $topic->follow = $topic->follow - 1; $topic->save(); } } $next = Yii::$app->request->get('next'); if (isset($next)) { return $this->redirect($next); } else { $this->goHome(); } }
/** * 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 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]); }
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]); }
<section> <div class="block-header"><small>统计</small> </div> <div class="block-content"> 会员 <b><?php echo \common\models\User::UserCount(); ?> </b> <div class="mt5"></div> 建议 <b><?php echo \common\models\Topic::TopicCount(); ?> </b> <div class="mt5"></div> 回复 <b><?php echo \common\models\Reply::ReplyCount(); ?> </b> </div> </section>
public function afterDelete() { if ($this->type == 1) { Yii::$app->cache->delete('UserCount' . $this->user_id); Yii::$app->cache->delete('FollowUserId' . Yii::$app->user->id); Yii::$app->cache->delete('FollowUser' . Yii::$app->user->id); } if ($this->type == 2) { Yii::$app->cache->delete('NodeCount' . $this->user_id); Yii::$app->cache->delete('FollowNodeId' . Yii::$app->user->id); Yii::$app->cache->delete('FollowNode' . Yii::$app->user->id); } if ($this->type == 3) { Yii::$app->cache->delete('TopicCount' . $this->user_id); Yii::$app->cache->delete('NoticeCount' . $this->follow_id); Yii::$app->cache->delete('FollowTopic' . Yii::$app->user->id); $topic = Topic::findOne($this->follow_id); $topic->follow = $topic->follow - 1; $topic->save(); } return parent::afterDelete(); }
/** * @return \yii\db\ActiveQuery */ public function getTopic() { return $this->hasOne(Topic::className(), ['id' => 'topic_id']); }
/** * @return \yii\db\ActiveQuery */ public function getTopicList() { return $this->hasMany(Topic::className(), ['user_id' => 'id'])->orderBy(['id' => SORT_DESC])->limit(10); }
/** * Finds the Topic model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Topic the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Topic::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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; }
/** * @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(); }
<section> <div class="block-header">统计 </div> <div class="block-content"> 会员 <b><?php echo \common\models\User::Count(); ?> </b> <div class="mt5"></div> 主题 <b><?php echo \common\models\Topic::TopicStat(); ?> </b> <div class="mt5"></div> 回复 <b><?php echo \common\models\Reply::Count(); ?> </b> </div> </section>
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]); }
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]); }
$this->title = '通知'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="row"> <div class="col-md-9"> <section> <?php echo yii\widgets\Breadcrumbs::widget(['options' => ['class' => 'breadcrumb mb0'], 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]); ?> <?php foreach ($model as $n) { ?> <?php $topicInfo = \common\models\Topic::Info($n->topic_id); ?> <?php $fromUserInfo = \common\models\User::Info($n->from_user_id); ?> <?php $toUserInfo = \common\models\User::Info($n->to_user_id); ?> <?php if ($n->type == 1) { ?> <article class="notice"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr>
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]); }
$this->params['breadcrumbs'][] = '搜索'; $this->params['breadcrumbs'][] = $keyword; $agent = \common\components\Helper::agent(); ?> <div class="row"> <div class="col-md-9"> <section> <?php echo yii\widgets\Breadcrumbs::widget(['options' => ['class' => 'breadcrumb mb0'], 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]); ?> <?php foreach ($topic as $t) { ?> <?php $topicInfo = \common\models\Topic::Info($t['topic_id']); ?> <?php $userInfo = \common\models\User::Info($topicInfo['user_id']); ?> <?php $lastReplyUser = \common\models\User::Info($topicInfo['last_reply_user']); ?> <article class="item"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody><tr> <?php if ($agent == 'is_iphone' || $agent == 'is_android') { ?> <td width="24" valign="middle" align="center"><a href="/member/<?php echo $userInfo['username'];
<?php $ranking = \common\models\Topic::Ranking(); if (!empty($ranking)) { ?> <section> <div class="block-header"><small>提建议排行榜</small></div> <?php foreach ($ranking as $r) { ?> <article class="sidebar block-hot-topic"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="24" valign="middle" align="center"> <a href="/member/<?php echo $r['username']; ?> "><img src="<?php echo Yii::$app->params['avatarUrl'] . '/24/' . $r['avatar']; ?> " class="img-rounded"></a> </td> <td width="10"></td> <td width="auto" valign="middle"><span class="hot_topic"><a href="/member/<?php echo $r['username']; ?> "><?php echo $r['username']; ?>
/** * @return ActiveQuery */ public function getTopics() { return $this->hasMany(Topic::className(), ['category_id' => 'id']); }
/** * 热门节点 * @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; }
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; }
<?php $HotTopic = \common\models\Topic::HotTopic(); if (!empty($HotTopic)) { ?> <section> <div class="block-header">今日热门主题</div> <div class="mt5"></div> <?php foreach ($HotTopic as $topic) { ?> <article class="sidebar block-hot-topic"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody><tr> <td width="24" valign="middle" align="center"> <a href="/member/<?php echo $topic['username']; ?> "><img src="<?php echo Yii::$app->params['avatarUrl'] . '/24/' . $topic['avatar']; ?> " class="img-rounded"></a> </td> <td width="10"></td> <td width="auto" valign="middle"> <span class="hot_topic"> <a href="/topic/<?php echo $topic['id']; ?> "><?php echo $topic['title'];