public function beforeAction($action) { if (parent::beforeAction($action)) { //update users online information $this->updateOnlineStatus($action); // register visit by webspider if (isset($_SERVER['HTTP_USER_AGENT'])) { $spider = YBoardSpider::find()->where(['user_agent' => $_SERVER['HTTP_USER_AGENT']])->one(); } else { $spider = null; } if ($spider != null) { $spider->setScenario('visit'); $spider->hits++; $spider->last_visit = null; $spider->save(); } //menu fixed for Views $approvals1 = YBoardPost::find()->unapprovedScope()->count(); $approvals2 = YBoardTopic::find()->andWhere(['approved' => 0])->count(); $reports = YBoardMessage::find()->reportScope()->unreadScope()->count(); $this->params['foroMenu'] = [['label' => Yii::t('app', 'Members'), 'url' => ['member/index']], ['label' => Yii::t('app', 'Pending') . ' (' . ($approvals1 + $approvals2) . ')', 'url' => ['moderator/approve'], 'visible' => Yii::$app->user->can('moderator')], ['label' => Yii::t('app', 'Reported') . ' (' . $reports . ')', 'url' => ['moderator/reported'], 'visible' => Yii::$app->user->can('moderator')]]; return true; } else { return false; } }
/** * Returns the css class when a member has posted in a topic */ public function hasPostedClass() { if (!\Yii::$app->user->isGuest && YBoardPost::find()->where("topic_id = {$this->id} and user_id = " . \Yii::$app->user->id)->exists()) { return 'posted'; } return ''; }
<?php /* @var $this ForumController */ /* @var $forum YBoardForum */ /* @var $dataProvider DataProvider */ use app\modules\yboard\YBoard; use app\modules\yboard\models\YBoardPost; use app\modules\yboard\models\YBoardTopic; use app\modules\yboard\models\YBoardMessage; use yii\widgets\ListView; use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\jui\Dialog; use yii\web\JsExpression; $this->params['breadcrumbs'] = [['label' => YBoard::t('yboard', 'Forums'), 'url' => ['forum/index']], $forum->name]; $approvals = YBoardPost::find()->unapprovedScope()->count(); $reports = YBoardMessage::find()->reportScope()->count(); $this->title = $forum->name; ?> <?php if (\Yii::$app->session->hasFlash('moderation')) { ?> <div class="flash-notice"> <?php echo \Yii::$app->session->getFlash('moderation'); ?> </div> <?php } ?>
?> </div> <div class="col-md-1"><?php echo YBoardTopic::find()->count(); ?> </div> <div class="col-md-9"></div> </div> <div class="row"> <div class="col-md-2"><?php echo YBoard::t('yboard', 'Total posts'); ?> </div> <div class="col-md-1"><?php echo YBoardPost::find()->count(); ?> </div> <div class="col-md-9"></div> </div> <div class="row"> <div class="col-md-2"><?php echo YBoard::t('yboard', 'Total members'); ?> </div> <div class="col-md-1"><?php echo YBoardMember::find()->count(); ?> </div> <div class="col-md-9"></div>
private function resetLastForumPost($id) { $model = YBoardForum::findOne($id); $criteria = "forum_id = {$id} and approved = 1"; $post = YBoardPost::find()->where($criteria)->orderBy('id DESC')->one(); if ($post !== null) { $model->last_post_id = $post->id; } else { $model->last_post_id = null; } $model->save(); }
/** * Reset the first post id of a topic when a first post is deleted */ private function resetFirstTopicPost() { $model = YBoardTopic::find()->where(['first_post_id' => $this->id])->one(); if ($model !== null) { $post = YBoardPost::find()->where(['topic_id' => $model->id])->orderBy('id DESC')->one(); if ($post !== null) { $model->user_id = $post->user_id; $model->first_post_id = $post->id; $model->save(); } } }
public function actionTopic($id, $nav = null, $postId = null) { $topic = YBoardTopic::findOne($id); if ($topic === null) { throw new NotFoundHttpException(YBoard::t('yboard', 'The requested topic does not exist.')); } $replyModel = new YBoardPost(); $replyModel->topic_id = $topic->id; $replyModel->subject = YBoard::t('yboard', 're:') . $topic->title; $forum = YBoardForum::findOne($topic->forum_id); if (Yii::$app->user->isGuest && $forum->public == 0) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to read requested topic.')); } if ($topic->approved == 0 && !Yii::$app->user->can('moderator')) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to read requested topic.')); } if ($forum->membergroup_id != 0) { if (Yii::$app->user->isGuest) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to read requested topic.')); } elseif (!Yii::$app->user->can('moderator')) { $groupId = YBoardMember::findOne(Yii::$app->user->id)->group_id; if ($forum->membergroup_id != $groupId) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to read requested topic.')); } } } $dataProvider = new ActiveDataProvider(['query' => YBoardPost::find()->where(['approved' => 1])->andWhere(['topic_id' => $topic->id])->orderBy('id')->with('poster'), 'pagination' => array('pageSize' => $this->module->postsPerPage)]); // Determine poll $this->poll = YBoardPoll::find()->where(['post_id' => $topic->first_post_id])->one(); if ($this->poll !== null) { $this->choiceProvider = new ActiveDataProvider(['query' => YBoardChoice::find()->where(['poll_id' => $this->poll->id])->orderBy('sort'), 'pagination' => false]); // Determine whether user has voted if (Yii::$app->user->isGuest) { $this->voted = true; // A guest may not vote and sees the result immediately } else { $this->voted = YBoardVote::find()->where(['poll_id' => $this->poll->id])->andWhere(['user_id' => Yii::$app->user->id])->exists(); } // Determine wheter the poll has expired if (!$this->voted && isset($this->poll->expire_date) && $this->poll->expire_date < date('Y-m-d')) { $this->voted = true; } } // Navigate to a post in a topic if (isset($nav)) { $cPage = $dataProvider->getPagination(); if (is_numeric($nav)) { $count = YBoardPost::find()->where('topic_id = ' . $topic->id . ' and id <= ' . $nav . ' and approved = 1')->count(); $page = ceil($count / $cPage->pageSize); $post = $nav; } else { $page = ceil($dataProvider->totalCount / $cPage->pageSize); $post = $topic->last_post_id; } if (Yii::$app->session->hasFlash('moderation')) { Yii::$app->session->setFlash('moderation', Yii::$app->session->getFlash('moderation')); } //set current page to calculated if we are having last page if (!isset($_GET['per-page'])) { $dataProvider->pagination->page = $page - 1; } //pages are 0 indexed } // Increase topic views $topic->updateCounters(['num_views' => 1]); // Register the last visit of a topic if (!Yii::$app->user->isGuest) { $topicLog = YBoardLogTopic::findOne(['member_id' => Yii::$app->user->id, 'topic_id' => $topic->id]); if ($topicLog === null) { $topicLog = new YBoardLogTopic(); $topicLog->member_id = Yii::$app->user->id; $topicLog->topic_id = $topic->id; $topicLog->forum_id = $topic->forum_id; } $topicLog->last_post_id = $topic->last_post_id; $topicLog->save(); } return $this->render('topic', array('forum' => $forum, 'reply' => $replyModel, 'topic' => $topic, 'dataProvider' => $dataProvider, 'choiceProvider' => $this->choiceProvider, 'postId' => $postId)); }