public function forumInit()
 {
     Console::output('创建默认版块 ....');
     $forum = new Forum();
     $forum->setAttributes(['name' => '默认版块', 'description' => '默认版块描述']);
     if ($forum->save()) {
         $message = '成功';
         $this->forumId = $forum->primaryKey;
     } else {
         $message = '失败';
     }
     Console::output('创建默认版块' . $message);
 }
 public function forumInit()
 {
     echo PHP_EOL . '创建默认版块 ....' . PHP_EOL;
     $forum = new Forum();
     $forum->setAttributes(['name' => '默认版块', 'description' => '默认版块描述']);
     if ($forum->save()) {
         $message = '成功';
         $this->forumId = $forum->primaryKey;
     } else {
         $message = '失败';
     }
     echo PHP_EOL . '创建默认版块' . $message . PHP_EOL;
 }
Beispiel #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Forum::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent' => $this->parent, 'topic_count' => $this->topic_count])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'icon', $this->icon])->orderBy($order);
     return $dataProvider;
 }
Beispiel #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Forum::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'forum_name', $this->forum_name])->andFilterWhere(['like', 'forum_desc', $this->forum_desc])->andFilterWhere(['like', 'forum_url', $this->forum_url])->andFilterWhere(['like', 'forum_icon', $this->forum_icon]);
     return $dataProvider;
 }
Beispiel #5
0
 public function getForumModel()
 {
     return $this->hasOne(Forum::className(), ['id' => 'forum_id']);
 }
Beispiel #6
0
 /**
  * Finds the Forum model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Forum the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Forum::findOne(['forum_url' => $id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #7
0
 /**
  * Finds the Forum model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Forum the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     $cache = Yii::$app->cache;
     $cachePrefix = Yii::$app->getModule('forum')->cachePrefix;
     $cacheKey = $cachePrefix . $id;
     $model = $cache->get($cacheKey);
     if ($model === false) {
         if (($model = Forum::findOne(['forum_url' => $id])) !== null) {
             $cache->set($cacheKey, $model);
             return $model;
         } else {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     } else {
         return $model;
     }
 }
Beispiel #8
0
 /**
  * 创建新评论
  * @param $topic
  * @return Comment
  */
 protected function newTopic(Forum $forum)
 {
     $model = new Topic();
     $request = Yii::$app->request;
     if ($model->load($request->post())) {
         $model->author_id = Yii::$app->user->id;
         if ($forum->addTopic($model, true)) {
             if ($tags = $request->post('tags')) {
                 $tags = Tag::find()->where(['name' => explode(',', $tags)])->active()->all();
                 $model->addTags($tags);
             }
             $this->flash('发表话题成功!', 'success');
             return Yii::$app->end(0, $this->redirect(['topic/view', 'id' => $model->id]));
         }
     }
     return $model;
 }