<?php ActiveForm::end(); ?> </div><!-- form --> <div class="bbii-box-top"><?php echo Yii::t('BbiiModule.bbii', 'Forum layout'); ?> </div> <div class="sortable"> <?php $items = array(); foreach ($category as $data) { $forum = BbiiForum::find()->where(["cat_id" => $data->getAttribute('id')])->sorted()->forum()->all(); $items['cat_' . $data->id] = $this->render('_category', array('forum' => $forum, 'data' => $data), true); } /* $this->widget('zii.widgets.jui.CJuiSortable', array( 'id' => 'sortcategory', 'items' => $items, 'htmlOptions' => array('style' => 'list-style:none;;margin-top:1px'), 'theme' => $this->module->juiTheme, 'options' => array( 'delay' => '100', 'update' => 'js:function(){Sort(this,"' . $this->createAbsoluteUrl('setting/ajaxSort') . '");}', ), ));*/ echo Sortable::widget(['clientEvents' => ['update' => 'function( event, ui ) {
/** * Create a new topic w/i a forum * @return [type] [description] */ public function actionCreatetopic() { $choiceArr = null; $poll = new BbiiPoll(); $post = new BbiiPost(); if (\Yii::$app->request->post('BbiiForum')) { $post->forum_id = \Yii::$app->request->post('BbiiForum')['id']; $forum = BbiiForum::find($post->forum_id); } if (isset(\Yii::$app->request->post()['choice'])) { $choiceArr = \Yii::$app->request->post()['choice']; while (count($choiceArr) < 3) { $choiceArr[] = ''; } } else { $choiceArr = array('', '', ''); } if (\Yii::$app->request->post('BbiiPost')) { $forum = BbiiForum::findOne(\Yii::$app->request->post('BbiiPost')['forum_id']); $post->load(\Yii::$app->request->post()); $post->approved = $forum->moderated ?: 1; $post->create_time = date('Y-m-d H:m:i'); //$post->forum_id = \Yii::$app->request->post('BbiiForum')['id']; $post->user_id = \Yii::$app->user->identity->id; // if the post is valid, create the topic if ($post->validate() && $post->save()) { // Topic $topic = new BbiiTopic(); $topic->approved = $post->approved; $topic->first_post_id = $post->id; $topic->forum_id = $forum->id; $topic->last_post_id = $post->id; $topic->title = $post->subject; $topic->user_id = \Yii::$app->user->identity->id; if (\Yii::$app->request->post('sticky')) { $topic->sticky = 1; } if (\Yii::$app->request->post('global')) { $topic->global = 1; } if (\Yii::$app->request->post('locked')) { $topic->locked = 1; } // @todo Enable this feature - DJE : 2015-05-26 /* // Poll if (isset(\Yii::$app->request->post()['BbiiPoll']) && isset(\Yii::$app->request->post()['addPoll']) && \Yii::$app->request->post()['addPoll'] == 'yes') { $poll->load(\Yii::$app->request->post()['BbiiPoll']); $poll->post_id = $post->id; $poll->user_id = \Yii::$app->user->identity->id ; if (empty($poll->expire_date)) { unset($poll->expire_date); } $count = 0; $choices = \Yii::$app->request->post()['choice']; foreach($choices as $choice) { if (!empty($choice)) { $count++; } } if ($poll->validate() && $count > 1) { $correct = true; } else { $correct = false; if ($correct < 2) { $poll->addError('question', Yii::t('BbiiModule.bbii','A poll should have at least 2 choices.')); } } } else { $correct = true; } */ //if ($correct && $topic->save()) { if ($topic->validate() && $topic->save()) { // update post with topic $post->topic_id = $topic->id; $post->update(); if (!$forum->moderated) { $forum->updateCounters(array('num_posts' => 1, 'num_topics' => 1)); // method since Yii 2.0 //$post->poster->updateCounters(array('posts' => 1)); // method since Yii 2.0 $forum->last_post_id = $post->id; $forum->update(); $this->assignMembergroup(\Yii::$app->user->identity->id); } else { \Yii::$app->session->addFlash('moderation', Yii::t('BbiiModule.bbii', 'Your post has been saved. It has been placed in a queue and is now waiting for approval by a moderator before it will appear on the forum. Thank you for your contribution to the forum.')); } // @todo Enable this feature - DJE : 2015-05-26 /* if (isset(\Yii::$app->request->post()['BbiiPoll'])) { // @todo Enable this feature - DJE : 2015-05-26 // $poll->save(); $choices = \Yii::$app->request->post()['choice']; $i = 1; foreach($choices as $choice) { if (!empty($choice)) { $ch = new BbiiChoice; $ch->choice = $choice; $ch->poll_id = $poll->id; $ch->sort = $i++; $ch->save(); } } } */ return \Yii::$app->response->redirect(array('forum/forum/topic', 'id' => $topic->id)); } else { \Yii::$app->session->addFlash('warning', Yii::t('BbiiModule.bbii', 'Error, unable to save post.')); $post->delete(); } } } return $this->render('update/forum', array('choices' => $choiceArr, 'forum' => $forum, 'poll' => $poll, 'post' => $post)); }
</div> <div> <?php echo $form->field($model, 'subtitle')->textInput(); ?> </div> <?php if ($model->type != 0) { ?> <div> <div class="form-group field-bbiiforum-cateogry"> <label class="control-label" for="name">Category</label> <?php echo Html::activeDropDownList($model, 'cat_id', ArrayHelper::map(BbiiForum::find()->categories()->all(), 'id', 'name'), ['class' => 'form-control', 'id' => 'cateogry', 'prompt' => 'Choose One']); ?> </div> </div> <?php } ?> <div> <div class="form-group field-bbiiforum-public"> <label class="control-label" for="name">Public</label> <?php echo Html::activeDropDownList($model, 'public', $booleanDDLOptions, ['class' => 'form-control', 'id' => 'public']); ?> </div> </div>
/** * [update description] * * This is the way we should be writing the CRUD methods for V3 * * @version 3.0.5 * @since 2.7.0 * @param [type] $id [description] * @return [type] [description] */ public function actionUpdateforum($id = null) { $model = BbiiForum::find()->where(['id' => (int) ($id ?: \Yii::$app->request->get('id'))])->one(); if (\Yii::$app->request->post('BbiiForum') && $model->load(\Yii::$app->request->post())) { $success = $model->validate() && $model->save() ? true : false; \Yii::$app->getSession()->setFlash($success ? 'success' : 'warning', Yii::t('BbiiModule.bbii', 'Change ' . ($success ? '' : 'NOT') . 'saved.')); } return $this->render('update/forum', ['model' => $model]); }
public static function getAllForumOptions() { $return = array(); // $criteria = new CDbCriteria; // $criteria->condition = 'type = 0'; // $criteria->order = 'sort'; // $category = BbiiForum::find()->findAll($criteria); $category = BbiiForum::find()->where('type = 0')->orderBy('sort')->all(); foreach ($category as $group) { //$criteria->condition = 'type = 1 and cat_id = ' . $group->id; //$forum = BbiiForum::find()->findAll($criteria); $forum = BbiiForum::find()->where('type = 1 and cat_id = ' . $group->id)->all(); foreach ($forum as $option) { $return[] = array('id' => $option->id, 'name' => $option->name, 'group' => $group->name); } } return $return; }
/** * Ajax call for change, move or merge topic */ public function actionChangeTopic() { $json = array(); if (isset(\Yii::$app->request->post()['BbiiTopic'])) { $model = BbiiTopic::find(\Yii::$app->request->post()['BbiiTopic']['id']); $move = false; $merge = false; $sourceTopicId = \Yii::$app->request->post()['BbiiTopic']['id']; $sourceForumId = $model->forum_id; if ($model->forum_id != \Yii::$app->request->post()['BbiiTopic']['forum_id']) { $move = true; $targetForumId = \Yii::$app->request->post()['BbiiTopic']['forum_id']; } if (!empty(\Yii::$app->request->post()['BbiiTopic']['merge']) && \Yii::$app->request->post()['BbiiTopic']['id'] != \Yii::$app->request->post()['BbiiTopic']['merge']) { $merge = true; $targetTopicId = \Yii::$app->request->post()['BbiiTopic']['merge']; } $model->load(\Yii::$app->request->post()['BbiiTopic']); if ($model->validate()) { $json['success'] = 'yes'; if ($merge || $move) { $numberOfPosts = BbiiPost::find()->where(['topic_id' => $sourceTopicId])->approved()->count(); if ($move) { BbiiPost::find()->updateAll(array('forum_id' => $targetForumId), $criteria); $forum = BbiiForum::find($sourceForumId); $forum->updateCounters(array('num_topics' => -1)); $forum->updateCounters(array('num_posts' => -$numberOfPosts)); $forum = BbiiForum::find($targetForumId); $forum->updateCounters(array('num_topics' => 1)); $forum->updateCounters(array('num_posts' => $numberOfPosts)); $this->resetLastForumPost($sourceForumId); $this->resetLastForumPost($targetForumId); } if ($merge) { BbiiPost::find()->updateAll(array('topic_id' => $targetTopicId), $criteria); if ($move) { $forum = BbiiForum::find($targetForumId); } else { $forum = BbiiForum::find($sourceForumId); } $forum->updateCounters(array('num_topics' => -1)); $topic = BbiiTopic::find($targetTopicId); $topic->updateCounters(array('num_replies' => $numberOfPosts)); $model->delete(); } else { $model->save(); } } else { // no move or merge involved $model->save(); } } else { $json['error'] = json_decode(ActiveForm::validate($model)); } } echo json_encode($json); \Yii::$app->end(); }