public function actionTopic()
 {
     if (!Yii::$app->user->can('app.forum.moderator.topic')) {
         throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
     }
     $json = [];
     if (isset($_POST['id'])) {
         $model = YBoardTopic::findOne($_POST['id']);
         if ($model === null) {
             $json['success'] = 'no';
             $json['message'] = YBoard::t('yboard', 'Topic not found.');
         } else {
             $json['success'] = 'yes';
             $json['forum_id'] = $model->forum_id;
             $json['title'] = $model->title;
             $json['locked'] = $model->locked;
             $json['sticky'] = $model->sticky;
             $json['global'] = $model->global;
             $json['approved'] = $model->approved;
             $json['option'] = '<option value=""></option>';
             foreach (YBoardTopic::find()->where(['forum_id' => $model->forum_id])->all() as $topic) {
                 $json['option'] .= '<option value="' . $topic->id . '">' . $topic->title . '</option>';
             }
         }
     } else {
         $json['success'] = 'no';
         $json['message'] = YBoard::t('yboard', 'Topic not found.');
     }
     echo json_encode($json);
     Yii::$app->end();
 }
Exemplo n.º 2
0
 /**
  * Determine whether a topic is completely read by a user
  * @param integer forum id
  * @return boolean
  */
 public function topicIsRead($topic_id)
 {
     if (Yii::$app->user->isGuest) {
         return false;
     } else {
         $topicLog = YBoardLogTopic::findOne(['member_id' => Yii::$app->user->id, 'topic_id' => $topic_id]);
         if ($topicLog === null) {
             return false;
         } else {
             $topic = Yii::$app->db->cache(function ($db) use($topic_id) {
                 return YBoardTopic::findOne($topic_id);
             }, 300);
             if ($topic->last_post_id > $topicLog->last_post_id) {
                 return false;
             } else {
                 return true;
             }
         }
     }
 }