/** * Searching through the forum. * @return string */ public function actionSearch() { $dataProvider = null; $searchModel = new Vocabulary(); if ($searchModel->load(Yii::$app->request->get(), '')) { $dataProvider = $searchModel->search(); } else { $model = new SearchForm(); $model->match = 'all'; $model->type = 'posts'; $model->display = 'topics'; $categories = Category::find()->orderBy(['name' => SORT_ASC])->all(); $forums = Forum::find()->orderBy(['name' => SORT_ASC])->all(); $list = []; foreach ($categories as $cat) { $catlist = []; foreach ($forums as $for) { if ($for->category_id == $cat->id) { $catlist[$for->id] = '|-- ' . Html::encode($for->name); } } $list[Html::encode($cat->name)] = $catlist; } if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (empty($model->query) && empty($model->author)) { $this->error(Yii::t('podium/flash', "You have to enter words or author's name first.")); } else { $stop = false; if (!empty($model->query)) { $words = explode(' ', preg_replace('/\\s+/', ' ', $model->query)); $checkedWords = []; foreach ($words as $word) { if (mb_strlen($word, 'UTF-8') > 2) { $checkedWords[] = $word; } } $model->query = implode(' ', $checkedWords); if (mb_strlen($model->query, 'UTF-8') < 3) { $this->error(Yii::t('podium/flash', 'You have to enter word at least 3 characters long.')); $stop = true; } } if (!$stop) { $dataProvider = $model->searchAdvanced(); } } } return $this->render('search', ['model' => $model, 'list' => $list, 'dataProvider' => $dataProvider, 'query' => $model->query, 'author' => $model->author]); } return $this->render('search', ['dataProvider' => $dataProvider, 'query' => $searchModel->query]); }
/** * Adding new forum. * @param integer $cid parent category ID * @return string|\yii\web\Response */ public function actionNewForum($cid = null) { $category = Category::findOne((int) $cid); if (empty($category)) { $this->error('Sorry! We can not find Category with this ID.'); return $this->redirect(['admin/categories']); } $model = new Forum(); $model->category_id = $category->id; $model->visible = 1; $model->sort = 0; if ($model->load(Yii::$app->request->post()) && $model->save()) { Log::info('Forum added', !empty($model->id) ? $model->id : '', __METHOD__); $this->success('New forum has been created.'); return $this->redirect(['admin/forums', 'cid' => $category->id]); } else { return $this->render('forum', ['model' => $model, 'forums' => Forum::find()->where(['category_id' => $category->id])->orderBy(['sort' => SORT_ASC, 'id' => SORT_ASC])->all(), 'categories' => Category::find()->orderBy(['sort' => SORT_ASC, 'id' => SORT_ASC])->all()]); } }
/** * Adding new forum. * @param integer $cid parent category ID * @return string|\yii\web\Response */ public function actionNewForum($cid = null) { $category = Category::findOne((int) $cid); if (empty($category)) { $this->error(Yii::t('podium/flash', 'Sorry! We can not find Category with this ID.')); return $this->redirect(['admin/categories']); } if (User::can(Rbac::PERM_CREATE_FORUM)) { $model = new Forum(); $model->category_id = $category->id; $model->visible = 1; $model->sort = 0; if ($model->load(Yii::$app->request->post()) && $model->save()) { Log::info('Forum added', $model->id, __METHOD__); $this->success(Yii::t('podium/flash', 'New forum has been created.')); return $this->redirect(['admin/forums', 'cid' => $category->id]); } else { return $this->render('forum', ['model' => $model, 'forums' => Forum::find()->where(['category_id' => $category->id])->orderBy(['sort' => SORT_ASC, 'id' => SORT_ASC])->all(), 'categories' => Category::find()->orderBy(['sort' => SORT_ASC, 'id' => SORT_ASC])->all()]); } } else { $this->error(Yii::t('podium/flash', 'You are not allowed to perform this action.')); return $this->redirect(['admin/forums', 'cid' => $category->id]); } }
/** * Updating the forums order. * @return string|\yii\web\Response */ public function actionSortForum() { if (!Yii::$app->request->isAjax) { return $this->redirect(['admin/forums']); } if (!User::can(Rbac::PERM_UPDATE_FORUM)) { return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'You are not allowed to perform this action.'), ['class' => 'text-danger']); } $modelId = Yii::$app->request->post('id'); $modelCategory = Yii::$app->request->post('category'); $new = Yii::$app->request->post('new'); if (!is_numeric($modelId) || !is_numeric($modelCategory) || !is_numeric($new)) { return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Sorry! Sorting parameters are wrong.'), ['class' => 'text-danger']); } $moved = Forum::find()->where(['id' => $modelId])->limit(1)->one(); $movedCategory = Category::find()->where(['id' => $modelCategory])->limit(1)->one(); if (empty($moved) || empty($modelCategory) || $moved->category_id != $movedCategory->id) { return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Sorry! We can not find Forum with this ID.'), ['class' => 'text-danger']); } if ($moved->newOrder((int) $new)) { return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-ok-circle']) . ' ' . Yii::t('podium/view', "New forums' order has been saved."), ['class' => 'text-success']); } return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', "Sorry! We can not save new forums' order."), ['class' => 'text-danger']); }