Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = $this->_query !== null ? $this->_query : Threads::find()->with(['forum', 'forum.section', 'lastPost']);
     if (Yii::$app->user->isGuest || !Yii::$app->user->can(Yii::$app->controller->module->moderRole)) {
         $query->where(['forum_threads.state' => Threads::STATE_ACTIVE]);
     }
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query->orderBy('flag DESC, updated_at DESC')]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'forum_id' => $this->forum_id, 'flag' => $this->flag, 'state' => $this->state, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function actionNewThread()
 {
     $model = new Threads();
     $model->forum_id = Yii::$app->request->get('forum_id');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect($model->url);
     }
     return $this->render('edit', ['model' => $model, 'lang' => $this->lang]);
 }
Exemplo n.º 3
0
 public function getThread()
 {
     return $this->hasOne(Threads::className(), ['id' => 'thread_id'])->inverseOf('posts');
 }
Exemplo n.º 4
0
 public function getLastThreads()
 {
     return $this->hasMany(Threads::className(), ['forum_id' => 'id'])->where(['forum_threads.state' => Threads::STATE_ACTIVE])->orderBy('flag DESC, updated_at DESC')->limit(3)->inverseOf('forum');
 }