/** * handle Ajax call for deleting forum */ public function actionDeleteforum() { $json = array(); if (isset(\Yii::$app->request->post()['id'])) { $model = BbiiForum::find(\Yii::$app->request->post()['id']); if (BbiiForum::find()->exists("cat_id = " . \Yii::$app->request->post()['id'])) { $json['success'] = 'no'; $json['message'] = Yii::t('BbiiModule.bbii', 'There are still forums in this category. Remove these before deleting the category.'); } elseif (BbiiTopic::find()->exists('forum_id = ' . \Yii::$app->request->post()['id'])) { $json['success'] = 'no'; $json['message'] = Yii::t('BbiiModule.bbii', 'There are still topics in this forum. Remove these before deleting the forum.'); } else { BbiiForum::find(\Yii::$app->request->post()['id'])->delete(); $json['success'] = 'yes'; } } echo json_encode($json); \Yii::$app->end(); }
/** * Determine whether a topic has been visited by a user * @param integer forum id * @return boolean */ public function topicIsRead($topic_id) { $model = BbiiTopicRead::find()->where(['user_id' => \Yii::$app->user->identity->id])->one(); if (!empty($model->data)) { $object = new BbiiTopicsRead(); $object->unserialize($model->data); // @todo turn caching back on - DJE : 2015-06-03 //$lastPost = BbiiTopic::find()->cache(300)->findByPk($topic_id)->last_post_id; $lastPost = BbiiTopic::find()->where(['id' => $topic_id])->one()->last_post_id; if ($object->topicLastRead($topic_id) >= $lastPost) { return true; } } return false; }
</ul> </div> <div class="col col-sm-12 col-md-4 statistics"> <h4> <?php echo Yii::t('BbiiModule.bbii', 'Board Statistics'); ?> </h4> <ul class="list-group"> <li class="list-group-item"> <?php echo Yii::t('BbiiModule.bbii', 'Total topics'); ?> <div class="badge pull-right"><?php echo BbiiTopic::find()->count(); ?> </div> </li> <li class="list-group-item"> <?php echo Yii::t('BbiiModule.bbii', 'Total posts'); ?> <div class="badge pull-right"><?php echo BbiiPost::find()->count(); ?> </div> </li> <li class="list-group-item"> <?php echo Yii::t('BbiiModule.bbii', 'Total members');
/** * Ajax call for change, move or merge topic */ public function actionChangeTopic() { $json = array(); if (isset(\Yii::$app->request->post()['BbiiTopic'])) { $model = BbiiTopic::find(\Yii::$app->request->post()['BbiiTopic']['id']); $move = false; $merge = false; $sourceTopicId = \Yii::$app->request->post()['BbiiTopic']['id']; $sourceForumId = $model->forum_id; if ($model->forum_id != \Yii::$app->request->post()['BbiiTopic']['forum_id']) { $move = true; $targetForumId = \Yii::$app->request->post()['BbiiTopic']['forum_id']; } if (!empty(\Yii::$app->request->post()['BbiiTopic']['merge']) && \Yii::$app->request->post()['BbiiTopic']['id'] != \Yii::$app->request->post()['BbiiTopic']['merge']) { $merge = true; $targetTopicId = \Yii::$app->request->post()['BbiiTopic']['merge']; } $model->load(\Yii::$app->request->post()['BbiiTopic']); if ($model->validate()) { $json['success'] = 'yes'; if ($merge || $move) { $numberOfPosts = BbiiPost::find()->where(['topic_id' => $sourceTopicId])->approved()->count(); if ($move) { BbiiPost::find()->updateAll(array('forum_id' => $targetForumId), $criteria); $forum = BbiiForum::find($sourceForumId); $forum->updateCounters(array('num_topics' => -1)); $forum->updateCounters(array('num_posts' => -$numberOfPosts)); $forum = BbiiForum::find($targetForumId); $forum->updateCounters(array('num_topics' => 1)); $forum->updateCounters(array('num_posts' => $numberOfPosts)); $this->resetLastForumPost($sourceForumId); $this->resetLastForumPost($targetForumId); } if ($merge) { BbiiPost::find()->updateAll(array('topic_id' => $targetTopicId), $criteria); if ($move) { $forum = BbiiForum::find($targetForumId); } else { $forum = BbiiForum::find($sourceForumId); } $forum->updateCounters(array('num_topics' => -1)); $topic = BbiiTopic::find($targetTopicId); $topic->updateCounters(array('num_replies' => $numberOfPosts)); $model->delete(); } else { $model->save(); } } else { // no move or merge involved $model->save(); } } else { $json['error'] = json_decode(ActiveForm::validate($model)); } } echo json_encode($json); \Yii::$app->end(); }
/** * [actionView description] * * @version 2.2.0 * @param [type] $id [description] * @return [type] [description] */ public function actionView($id = null) { $object = new BbiiTopicRead(); $read = BbiiTopicRead::find($id); if (isset(\Yii::$app->request->get()['unwatch']) && ($this->isModerator() || $id == \Yii::$app->user->identity->id)) { if ($read !== null) { $object->unserialize($read->data); foreach (\Yii::$app->request->get()['unwatch'] as $topicId => $val) { $object->unsetFollow($topicId); } $read->data = $object->serialize(); $read->save(); } } if (($this->isModerator() || $id == \Yii::$app->user->identity->id) && isset($read->data)) { if ($read === null) { $in = array(0); } else { $object->unserialize($read->data); $in = array_keys($object->getFollow()); } } else { $in = array(0); } // @todo Need to figure out the Yii2 version of `'with' => 'forum',` for ADP - DJE : 2015-05-15 $dataProvider = new ActiveDataProvider(['pagination' => false, 'query' => BbiiPost::find()->where(['approved' => 1, 'user_id' => \Yii::$app->user->identity->id])->orderBy('create_time DESC')->limit(10)]); // @todo Need to figure out the Yii2 version of `'with' => 'forum',` for ADP - DJE : 2015-05-15 $topicProvider = new ActiveDataProvider(['pagination' => false, 'query' => BbiiTopic::find()->where(['id' => $in])->orderBy('id ASC')]); return $this->render('view', array('dataProvider' => $dataProvider, 'topicProvider' => $topicProvider, 'userData' => BbiiMember::find()->where(['id' => is_numeric($id) ? $id : \Yii::$app->request->get('id')])->one())); }
public function getTopic() { return $this->hasOne(BbiiTopic::className(), ['id' => 'topic_id']); }
/** * Retrieves a list of models based on the current search/filter conditions. * * @param [type] $params [description] * @return ActiveDataProvider The data provider that can return the models based on the search/filter conditions. */ public function search($params) { $query = BbiiTopic::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $this->addCondition('approved', $this->approved); $this->addCondition('first_post_id', $this->first_post_id, true); $this->addCondition('forum_id', $this->forum_id, true); $this->addCondition('global', $this->global); $this->addCondition('id', $this->id, true); $this->addCondition('last_post_id', $this->last_post_id, true); $this->addCondition('locked', $this->locked); $this->addCondition('moved', $this->moved, true); $this->addCondition('num_replies', $this->num_replies, true); $this->addCondition('num_views', $this->num_views, true); $this->addCondition('sticky', $this->sticky); $this->addCondition('title', $this->title, true); $this->addCondition('user_id', $this->user_id, true); return $dataProvider; }