/** * Creating the thread of given category ID and forum ID. * @param integer $cid category's ID * @param integer $fid forum's ID * @return string|\yii\web\Response */ public function actionNewThread($cid = null, $fid = null) { if (Yii::$app->user->isGuest) { $this->warning(Yii::t('podium/flash', 'Please sign in to create a new thread.')); return $this->redirect(['account/login']); } if (!User::can(Rbac::PERM_CREATE_THREAD)) { $this->error(Yii::t('podium/flash', 'Sorry! You do not have the required permission to perform this action.')); return $this->redirect(['default/index']); } $forum = Forum::find()->where(['id' => $fid, 'category_id' => $cid])->limit(1)->one(); if (empty($forum)) { $this->error(Yii::t('podium/flash', 'Sorry! We can not find the forum you are looking for.')); return $this->redirect(['default/index']); } $model = new Thread(); $model->scenario = 'new'; $model->subscribe = 1; $preview = ''; $postData = Yii::$app->request->post(); if ($model->load($postData)) { $model->posts = 0; $model->views = 0; $model->category_id = $forum->category->id; $model->forum_id = $forum->id; $model->author_id = User::loggedId(); if ($model->validate()) { if (isset($postData['preview-button'])) { $preview = $model->post; } else { if ($model->podiumNew()) { $this->success(Yii::t('podium/flash', 'New thread has been created.')); return $this->redirect(['thread', 'cid' => $forum->category->id, 'fid' => $forum->id, 'id' => $model->id, 'slug' => $model->slug]); } else { $this->error(Yii::t('podium/flash', 'Sorry! There was an error while creating the thread. Contact administrator about this problem.')); } } } } return $this->render('new-thread', ['preview' => $preview, 'model' => $model, 'forum' => $forum]); }