Ejemplo n.º 1
0
 /**
  * handle Ajax call for saving forum
  */
 public function actionSaveForum()
 {
     if (!Yii::$app->user->can('app.forum.setting.save-forum')) {
         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['YBoardForum'])) {
         $model = YBoardForum::findOne($_POST['YBoardForum']['id']);
         $model->load(Yii::$app->request->post());
         if ($model->save()) {
             $json['success'] = 'yes';
         } else {
             $json['error'] = array_values($model->errors);
         }
     }
     echo json_encode($json);
     Yii::$app->end();
 }
 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();
 }
Ejemplo n.º 3
0
 /**
  * Finds the YBoardForum model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return YBoardForum the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = YBoardForum::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }