Пример #1
0
 /**
  * Deletes an existing Board model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $forum_url = $model->forum['forum_url'];
     Thread::deleteAll(['board_id' => $model->id]);
     $model->delete();
     Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Deleted successfully.'));
     return $this->redirect(['/forum/forum/update', 'id' => $forum_url, 'action' => 'board']);
 }
Пример #2
0
 /**
  * Deletes an existing Post model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $thread_id = $model->thread_id;
     $model->delete();
     $thread = Thread::findOne($thread_id);
     $thread->post_count = $thread->post_count - 1;
     $thread->update();
     Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Deleted successfully.'));
     return $this->redirect(['/forum/post/index']);
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Thread::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'user_id' => $this->user_id, 'board_id' => $this->board_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Пример #4
0
 /**
  * Deletes an existing Board model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $forum_url = $model->forum['forum_url'];
     if ($model->user_id === Yii::$app->user->id) {
         Thread::deleteAll(['board_id' => $model->id]);
         $model->delete();
         Yii::$app->getSession()->setFlash('success', 'Delete successfully.');
     } else {
         throw new ForbiddenHttpException('You are not allowed to perform this action.');
     }
     return $this->redirect(['/forum/forum/update', 'id' => $forum_url, 'action' => 'board']);
 }
Пример #5
0
 protected function newThread($id)
 {
     $newThread = new Thread();
     if ($newThread->load(Yii::$app->request->post())) {
         $newThread->board_id = $id;
         $newThread->save();
         Yii::$app->db->createCommand()->update('{{%forum_board}}', ['updated_at' => time(), 'updated_by' => Yii::$app->user->id], 'id=:id', [':id' => $id])->execute();
         $this->refresh();
     }
     return $newThread;
 }
Пример #6
0
 /**
  * Finds the Thread model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Thread the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Thread::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }