public function search($params) { $query = YBoardForum::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'cat_id' => $this->cat_id, 'type' => $this->type, 'public' => $this->public, 'locked' => $this->locked, 'moderated' => $this->moderated, 'sort' => $this->sort, 'num_posts' => $this->num_posts, 'num_topics' => $this->num_topics, 'last_post_id' => $this->last_post_id, 'poll' => $this->poll, 'membergroup_id' => $this->membergroup_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'subtitle', $this->subtitle]); return $dataProvider; }
<?php echo $form->field($model, 'name')->textInput(['id' => 'YBoardForum_name']); ?> <?php echo $form->field($model, 'subtitle')->textArea(['id' => 'YBoardForum_subtitle']); ?> <?php echo $form->field($model, 'sort')->textInput(['id' => 'YBoardForum_sort']); ?> <span class="YBoardForum_category"> <?php echo $form->field($model, 'cat_id')->dropDownList(ArrayHelper::map(YBoardForum::find()->categoriesScope()->all(), 'id', 'name'), ['prompt' => YBoard::t('yboard', '-- Select Category --'), 'id' => 'YBoardForum_category']); ?> </span> <span class="YBoardForum_public"> <?php echo $form->field($model, 'public')->dropDownList(['0' => YBoard::t('yboard', 'No'), '1' => YBoard::t('yboard', 'Yes')], ['id' => 'YBoardForum_public']); ?> </span> <span class="YBoardForum_locked"> <?php echo $form->field($model, 'locked')->dropDownList(['0' => YBoard::t('yboard', 'No'), '1' => YBoard::t('yboard', 'Yes')], ['id' => 'YBoardForum_locked']); ?> </span>
/** * @return \yii\db\ActiveQuery */ public function getForum() { return $this->hasOne(YBoardForum::className(), ['id' => 'forum_id']); }
</div> <?php \yii\widgets\ActiveForm::end(); ?> </div><!-- form --> <div class="spacer"></div> <div class="row"> <div class="sortable"> <?php $items = []; foreach ($category as $data) { $forum = YBoardForum::find()->sortedScope()->forumScope()->andWhere(['cat_id' => $data->id])->all(); if ($data !== null) { $items['cat_' . $data->id] = $this->render('_category', ['data' => $data, 'forum' => $forum], true); } } echo Sortable::widget(['id' => 'sortcategory', 'items' => $items, 'options' => ['style' => 'list-style:none; margin-top:1px'], 'clientOptions' => ['delay' => '100', 'update' => new JsExpression('function(){Sort(this,"' . \Yii::$app->urlManager->createAbsoluteUrl('setting/ajax-sort') . '");}')]]); ?> </div> </div> <div class="spacer"></div> </div> <?php \yii\jui\Dialog::begin(['id' => 'dlgEditForum', 'clientOptions' => ['title' => 'Edit', 'autoOpen' => false, 'modal' => true, 'width' => 400, 'height' => 400, 'show' => 'fade', 'buttons' => [YBoard::t('yboard', 'Delete') => new JsExpression('function(){ deleteForum("' . Yii::$app->urlManager->createAbsoluteUrl(Yii::$app->controller->module->id . '/setting/delete-forum') . '"); }'), YBoard::t('yboard', 'Save') => new JsExpression('function(){ saveForum("' . Yii::$app->urlManager->createAbsoluteUrl(Yii::$app->controller->module->id . '/setting/save-forum') . '"); }'), YBoard::t('yboard', 'Cancel') => new JsExpression('function(){ $(this).dialog("close"); }')]]]);
public static function getForumOptions($isGuest, $uid) { $return = []; $category = YBoardForum::find()->where(['type' => 0])->orderBy('sort')->all(); foreach ($category as $group) { $forum = YBoardForum::find()->where(['type' => 1])->andWhere(['cat_id' => $group->id])->orderBy('sort')->all(); foreach ($forum as $option) { if ($option->public || !$isGuest) { if ($option->membergroup_id == 0) { $return[] = ['id' => $option->id, 'name' => $option->name, 'group' => $group->name]; } else { if (!$isGuest) { $groupId = YBoardMember::findOne($uid)->group_id; if ($option->membergroup_id == $groupId) { $return[] = ['id' => $option->id, 'name' => $option->name, 'group' => $group->name]; } } } } } } return $return; }
private function resetLastForumPost($id) { $model = YBoardForum::findOne($id); $criteria = "forum_id = {$id} and approved = 1"; $post = YBoardPost::find()->where($criteria)->orderBy('id DESC')->one(); if ($post !== null) { $model->last_post_id = $post->id; } else { $model->last_post_id = null; } $model->save(); }
/** * Reset the last post of a topic and a forum when post is deleted */ private function resetLastPost() { $forum = YBoardForum::find()->where(['last_post_id' => $this->id])->one(); $topic = YBoardTopic::find()->where(['last_post_id' => $this->id])->one(); if ($forum !== null) { $post = YBoardPost::find()->where(['forum_id' => $forum->id, 'approved' => 1])->orderBy('id DESC')->limit(1)->one(); if ($post === null) { $forum->last_post_id = null; } else { $forum->last_post_id = $post->id; } $forum->update(); } if ($topic !== null) { $post = YBoardPost::find()->where(['topic_id' => $topic->id, 'approved' => 1])->orderBy('id DESC')->limit(1)->one(); if ($post === null) { $topic->last_post_id = null; } else { $topic->last_post_id = $post->id; } $topic->update(); } }
use app\modules\yboard\YBoard; ?> <div class="container"> <div class="row"> <div class="col-md-1" style="padding:5px 0 0 5px;"> <?php if (!\Yii::$app->user->isGuest) { echo Html::a(YBoard::t('yboard', 'Mark all read'), ['forum/mark-all-read'], ['class' => 'btn btn-warning btn-xs']); } ?> </div> <div class="col-md-7 hidden-xs"> </div> <div class="col-md-4 hidden-xs" style="padding:5px 0 5px 5px;"> <?php echo Html::dropDownList('yboard-jumpto', '', ArrayHelper::map(YBoardForum::getForumOptions(Yii::$app->user->isGuest, Yii::$app->user->id), 'id', 'name', 'group'), ['empty' => YBoard::t('yboard', 'Select forum'), 'onchange' => "\n group = \$(this.options[this.selectedIndex]).closest('optgroup').prop('label');\n window.location.href='" . BaseUrl::toRoute(['forum']) . "?id='+\$(this).val()", 'class' => 'form-control', 'id' => 'forum-categories-list']); ?> <?php if (isset($_GET['id'])) { $this->registerJs("\$('#forum-categories-list option[value=" . $_GET['id'] . "]').prop('selected', true);"); } ?> </div> </div> </div>
/** * handle Ajax call for saving forum */ public function actionSaveForum() { if (!Yii::$app->user->can('app.forum.setting.save-forum')) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.')); } $json = []; if (isset($_POST['YBoardForum'])) { $model = YBoardForum::findOne($_POST['YBoardForum']['id']); $model->load(Yii::$app->request->post()); if ($model->save()) { $json['success'] = 'yes'; } else { $json['error'] = array_values($model->errors); } } echo json_encode($json); Yii::$app->end(); }
/** * Finds the YBoardForum model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return YBoardForum the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = YBoardForum::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }