Esempio n. 1
0
 public static function updateLastData($threadId)
 {
     $attributes = [];
     $attributes['posts'] = new Expression("[[posts]]+:bp0", [":bp0" => 1]);
     $attributes['last_user_id'] = YiiForum::getIdentity()->id;
     $attributes['last_user_name'] = YiiForum::getIdentity()->username;
     $attributes['last_modify_time'] = TTimeHelper::getCurrentTime();
     Thread::updateAll($attributes, ['id' => intval($threadId)]);
 }
Esempio n. 2
0
 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, 'board_id' => $this->board_id, 'user_id' => $this->user_id, 'create_time' => $this->create_time, 'modify_time' => $this->modify_time, 'views' => $this->views, 'posts' => $this->posts, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'user_name', $this->user_name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'note1', $this->note1])->andFilterWhere(['like', 'note2', $this->note2]);
     return $dataProvider;
 }
Esempio n. 3
0
 public function actionEditPost($id)
 {
     if (!YiiForum::checkAuth('post_edit')) {
         return $this->noPermission();
     }
     YiiForum::checkIsGuest();
     $boardId = YiiForum::getGetValue('boardid');
     $model = Post::findOne(['id' => $id]);
     $data = YiiForum::getPostValue('Post');
     if ($data == null) {
         $thread = Thread::findOne(['id' => $model['thread_id']]);
         $locals = [];
         $locals['thread'] = $thread;
         $locals['currentBoard'] = $this->getBoard($boardId);
         $locals['model'] = $model;
         return $this->render('edit-post', $locals);
     } else {
         $model->load(Yii::$app->request->post());
         $model->modify_time = TTimeHelper::getCurrentTime();
         $model->save();
         return $this->redirect(['view', 'id' => $model->thread_id]);
     }
 }
Esempio n. 4
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.');
     }
 }