Ejemplo n.º 1
0
 /**
  * Lists all YBoardForum models.
  * @return mixed
  */
 public function actionIndex()
 {
     $NumberOfTopics = YBoardSetting::find()->where(['key' => 'latest_topic'])->one();
     $NumberOfReplies = YBoardSetting::find()->where(['key' => 'latest_reply'])->one();
     $query = YBoardForum::find()->sortedScope()->andWhere('cat_id IS NULL');
     if (Yii::$app->user->isGuest) {
         $query->categoriesScope()->publicScope()->memberGroupScope();
     } else {
         if (Yii::$app->user->can('admin')) {
             $query->categoriesScope();
         } else {
             $query->memberGroupScope(Yii::$app->user->id);
         }
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]);
     //get forum IDs allowed
     $fids = [];
     foreach ($dataProvider->models as $cat) {
         foreach ($cat->forums as $fmodel) {
             $fids[] = $fmodel->id;
         }
     }
     $recentTopics = YBoardTopic::find()->where(['forum_id' => $fids])->orderBy('id DESC')->limit($NumberOfTopics == null ? 10 : $NumberOfTopics->value)->all();
     $recentReplies = YBoardPost::find()->where(['forum_id' => $fids])->andWhere('original_post=0')->orderBy('create_time DESC')->limit($NumberOfReplies == null ? 10 : $NumberOfReplies->value)->all();
     return $this->render('index', ['dataProvider' => $dataProvider, 'recentTopics' => $recentTopics, 'recentReplies' => $recentReplies]);
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
    <?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>
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
                </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"); }')]]]);
Ejemplo n.º 6
0
 /**
  * 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();
     }
 }
Ejemplo n.º 7
0
 public function actionForum()
 {
     if (!Yii::$app->user->can('app.forum.setting.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.'));
     }
     $model = new YBoardForum();
     $forum = [];
     $category = YBoardForum::find()->sortedScope()->categoryScope()->all();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if ($model->load(\Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['forum']);
     }
     return $this->render('forum', ['model' => $model, 'category' => $category]);
 }