public function actionCreate($id)
 {
     $forum = Forum::model()->findByPk($id);
     if (null == $forum) {
         throw new CHttpException(404, 'Forum not found.');
     }
     if ($forum->is_locked && (Yii::app()->user->isGuest || !Yii::app()->user->isForumAdmin())) {
         throw new CHttpException(403, 'Forum is locked.');
     }
     $model = new PostForm();
     $model->setScenario('create');
     // This makes subject required
     if (isset($_POST['PostForm'])) {
         if (!isset($_POST['YII_CSRF_TOKEN']) || $_POST['YII_CSRF_TOKEN'] != Yii::app()->getRequest()->getCsrfToken()) {
             throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
         }
         $model->attributes = $_POST['PostForm'];
         if ($model->validate()) {
             $thread = new Thread();
             $thread->forum_id = $forum->id;
             $thread->subject = $model->subject;
             $thread->author_id = Yii::app()->user->id;
             $thread->lastPost_user_id = Yii::app()->user->id;
             $thread->lastPost_time = time();
             $thread->save(false);
             $post = new Post();
             $post->author_id = Yii::app()->user->id;
             $post->thread_id = $thread->id;
             $post->content = $model->content;
             $post->save(false);
             $this->redirect($thread->url);
         }
     }
     $this->render('newThread', array('forum' => $forum, 'model' => $model));
 }
Example #2
0
 /**
  * Отобразить карточку форума
  *
  * @param string $alias - url форума
  * @throws CHttpException
  *
  * @return void
  */
 public function actionShow($alias = null)
 {
     $forum = Forum::model()->open()->findByAttributes(array('alias' => $alias));
     if ($forum === null) {
         throw new CHttpException(404, Yii::t('ForumModule.forum', 'Page was not found!'));
     }
     $this->render('show', array('forum' => $forum));
 }
Example #3
0
 /**
  * Creates a new posts.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     if (isset($_POST['Post'])) {
         $user = User::model()->find('username = :username', array('username' => Yii::app()->user->name));
         $session = Yii::app()->session;
         $topic = Topic::model()->findByPk($session['topic_id']);
         $forum = Forum::model()->findByPk($session['forum_id']);
         /*$transaction = Post::model()->dbConnection->beginTransaction();
         		try {
         		*/
         $now = date('Y-m-d H:i:s');
         $post = new Post();
         $post->user_id = $user->id;
         $post->topic_id = $session['topic_id'];
         $post->forum_id = $session['forum_id'];
         $post->body = $_POST['Post']['body'];
         // TODO: fix me
         $post->body_html = $post->body;
         $post->created_at = $now;
         $post->updated_at = $now;
         if (!$post->save()) {
             var_dump('<pre>', $post->getErrors());
         }
         if (!$user->save()) {
             var_dump('<pre>', $user->getErrors());
         }
         $topic->updated_at = $now;
         /*$topic->replied_at = $now;
         		$topic->replied_by = $user->id;
         		$topic->last_post_id = $post->id;*/
         if (!$topic->save()) {
             var_dump('<pre>', $topic->getErrors());
         }
         /*$transaction->commit();
         
         			} catch(Exception $e) {
         				$transaction->rollBack();
         				throw new CHttpException(500, 'Failed to save post');
         			}*/
         $url = $this->createUrl('topic/view', array('id' => $session['topic_id'], '#' => "post-{$post->id}"));
         $this->redirect($url);
     }
 }
Example #4
0
 public function getFormattedList($parent_id = null, $level = 0)
 {
     $forums = Forum::model()->findAllByAttributes(array('parent_id' => $parent_id));
     $list = array();
     foreach ($forums as $forum) {
         $forum->title = str_repeat('&emsp;', $level) . $forum->title;
         $list[$forum->id] = $forum->title;
         $list = CMap::mergeArray($list, $this->getFormattedList($forum->id, $level + 1));
     }
     return $list;
 }
Example #5
0
echo Yii::t('ForumModule.forum', 'Fields with');
?>
    <span class="required">*</span>
    <?php 
echo Yii::t('ForumModule.forum', 'are required.');
?>
</div>

<?php 
echo $form->errorSummary($model);
?>

<div class="row">
    <div class="col-sm-3">
        <?php 
echo $form->dropDownListGroup($model, 'parent_id', ['widgetOptions' => ['data' => Forum::model()->getFormattedList(), 'htmlOptions' => ['class' => 'popover-help', 'data-original-title' => $model->getAttributeLabel('parent_id'), 'data-content' => $model->getAttributeDescription('parent_id'), 'empty' => Yii::t('ForumModule.forum', '--no--'), 'encode' => false]]]);
?>
    </div>
    <div class="col-sm-4">
        <?php 
echo $form->dropDownListGroup($model, 'status', ['widgetOptions' => ['data' => $model->getStatusList(), 'htmlOptions' => ['class' => 'popover-help', 'data-original-title' => $model->getAttributeLabel('status'), 'data-content' => $model->getAttributeDescription('status')]]]);
?>
    </div>
</div>

<div class="row">
    <div class="col-sm-7">
        <?php 
echo $form->textFieldGroup($model, 'title', ['widgetOptions' => ['htmlOptions' => ['class' => 'popover-help', 'data-original-title' => $model->getAttributeLabel('title'), 'data-content' => $model->getAttributeDescription('title'), 'maxlength' => 250]]]);
?>
    </div>
Example #6
0
    <span class="required">*</span>
    <?php 
echo Yii::t('ForumModule.forum', 'are required.');
?>
</div>

<?php 
echo $form->errorSummary($model);
?>

<div class='control-group <?php 
echo $model->hasErrors("forum_id") ? "error" : "";
?>
'>
    <?php 
echo $form->dropDownListRow($model, 'forum_id', Forum::model()->getFormattedList(), array('empty' => Yii::t('ForumModule.forum', '--no--'), 'class' => 'span7', 'encode' => false));
?>
</div>

<div class='control-group'>
    <?php 
echo $form->dropDownListRow($model, 'status', $model->getStatusList(), array('class' => 'span7'));
?>
</div>

<div class='control-group <?php 
echo $model->hasErrors("title") ? "error" : "";
?>
'>
    <?php 
echo $form->textFieldRow($model, 'title', array('class' => 'span7', 'maxlength' => 250));
 /**
  * deleteForum action
  * Deletes both categories or forums.
  * Will take all subforums, threads and posts inside with it!
  */
 public function actionDelete($id)
 {
     if (!Yii::app()->request->isPostRequest || !Yii::app()->request->isAjaxRequest) {
         throw new CHttpException(400, 'Invalid request');
     }
     // First, we make sure it even exists
     $forum = Forum::model()->findByPk($id);
     if (null == $forum) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $forum->delete();
 }
Example #8
0
">Отменить</a>
            </h2>
            <hr/>
            <?php 
$form = $this->beginWidget('CActiveForm', array('id' => 'post-form', 'enableClientValidation' => true, 'clientOptions' => array('validateOnSubmit' => true), "htmlOptions" => ["class" => "form form-horizontal"]));
?>

            <div class="form-group">
                <div class="col-md-2">
                    <?php 
echo $form->labelEx($model, 'forum_id');
?>
                </div>
                <div class="col-md-9">
                    <?php 
echo CHtml::activeDropDownList($model, 'forum_id', Forum::model()->getArrayForDropDownInThreads(), ["class" => "form-control"]);
?>
                    <?php 
echo $form->error($model, 'forum_id');
?>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-2">
                    <?php 
echo $form->labelEx($model, 'subject');
?>
                </div>
                <div class="col-md-9">
                    <?php 
Example #9
0
    </ul>
    <?php 
/**
 * @var $categories Forum[]
 * @var $sFs Forum[]
 */
$categories = Forum::model()->cache(3600)->findAllByAttributes(["parent_id" => null]);
foreach ($categories as $category) {
    ?>
        <h4><?php 
    echo $category->title;
    ?>
</h4>
        <ul class="nav nav-pills">
            <?php 
    $sFs = Forum::model()->cache(3600)->findAllByAttributes(["parent_id" => $category->id]);
    foreach ($sFs as $item) {
        ?>
                <li <?php 
        if ($menuItem == $item->id) {
            echo ' class="active"';
        }
        ?>
>
                    <a href="<?php 
        echo $item->getUrl();
        ?>
"
                       title="<?php 
        echo $item->description;
        ?>
Example #10
0
<?php

$this->breadcrumbs = array(Yii::t('ForumModule.forum', 'Forums') => array('/forum/forumBackend/index'), Yii::t('ForumModule.forum', 'Manage'));
$this->pageTitle = Yii::t('ForumModule.forum', 'Forums - manage');
$this->menu = Yii::app()->getModule('forum')->getNavigation();
?>
<div class="page-header">
    <h1>
        <?php 
echo Yii::t('ForumModule.forum', 'Forums');
?>
        <small><?php 
echo Yii::t('ForumModule.forum', 'manage');
?>
</small>
    </h1>
</div>

<p><?php 
echo Yii::t('ForumModule.forum', 'This section describes forum management');
?>
</p>

<?php 
$this->widget('yupe\\widgets\\CustomGridView', array('id' => 'forum-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('name' => 'id', 'htmlOptions' => array('style' => 'width:20px'), 'type' => 'raw', 'value' => 'CHtml::link($data->id, array("/forum/forumBackend/update", "id" => $data->id))'), array('class' => 'bootstrap.widgets.TbEditableColumn', 'name' => 'title', 'editable' => array('url' => $this->createUrl('/forum/forumBackend/inline'), 'mode' => 'inline', 'params' => array(Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken))), array('class' => 'bootstrap.widgets.TbEditableColumn', 'name' => 'alias', 'editable' => array('url' => $this->createUrl('/forum/forumBackend/inline'), 'mode' => 'inline', 'params' => array(Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken))), array('name' => 'parent_id', 'value' => '$data->getParentName()', 'filter' => CHtml::activeDropDownList($model, 'parent_id', Forum::model()->getFormattedList(), array('encode' => false, 'empty' => ''))), array('class' => 'bootstrap.widgets.TbEditableColumn', 'editable' => array('url' => $this->createUrl('/forum/forumBackend/inline'), 'mode' => 'popup', 'type' => 'select', 'source' => $model->getStatusList(), 'params' => array(Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken)), 'name' => 'status', 'type' => 'raw', 'value' => '$data->getStatus()', 'filter' => $model->getStatusList()), array('class' => 'bootstrap.widgets.TbButtonColumn'))));
Example #11
0
<?php

$this->breadcrumbs = [Yii::t('ForumModule.forum', 'Forums') => ['/forum/forumBackend/index'], Yii::t('ForumModule.forum', 'Manage')];
$this->pageTitle = Yii::t('ForumModule.forum', 'Forums - manage');
$this->menu = Yii::app()->getModule('forum')->getNavigation();
?>
<div class="page-header">
    <h1>
        <?php 
echo Yii::t('ForumModule.forum', 'Forums');
?>
        <small><?php 
echo Yii::t('ForumModule.forum', 'manage');
?>
</small>
    </h1>
</div>

<p><?php 
echo Yii::t('ForumModule.forum', 'This section describes forum management');
?>
</p>

<?php 
$this->widget('yupe\\widgets\\CustomGridView', ['id' => 'forum-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => [['name' => 'id', 'htmlOptions' => ['style' => 'width:20px'], 'type' => 'raw', 'value' => 'CHtml::link($data->id, ["/forum/forumBackend/update", "id" => $data->id])', 'filter' => CHtml::activeTextField($model, 'id', ['class' => 'form-control', 'style' => 'width:20px'])], ['class' => 'bootstrap.widgets.TbEditableColumn', 'name' => 'title', 'editable' => ['url' => $this->createUrl('/forum/forumBackend/inline'), 'mode' => 'inline', 'params' => [Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken]], 'filter' => CHtml::activeTextField($model, 'title', ['class' => 'form-control'])], ['class' => 'bootstrap.widgets.TbEditableColumn', 'name' => 'alias', 'editable' => ['url' => $this->createUrl('/forum/forumBackend/inline'), 'mode' => 'inline', 'params' => [Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken]], 'filter' => CHtml::activeTextField($model, 'alias', ['class' => 'form-control'])], ['name' => 'parent_id', 'value' => '$data->getParentName()', 'filter' => CHtml::activeDropDownList($model, 'parent_id', Forum::model()->getFormattedList(), ['encode' => false, 'empty' => '', 'class' => 'form-control'])], ['class' => 'yupe\\widgets\\EditableStatusColumn', 'name' => 'status', 'url' => $this->createUrl('/forum/forumBackend/inline'), 'source' => $model->getStatusList(), 'options' => [Forum::STATUS_OPEN => ['class' => 'label-success'], Forum::STATUS_CLOSE => ['class' => 'label-danger']]], ['class' => 'bootstrap.widgets.TbButtonColumn']]]);
Example #12
0
 public function getForums()
 {
     return Forum::model()->open()->findAllByAttributes(array('parent_id' => $this->id));
 }
Example #13
0
 /**
  * Loads the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  */
 protected function loadforum()
 {
     if (isset($_GET['id'])) {
         $forum = Forum::model()->with('topics')->findbyPk($_GET['id']);
     }
     if (isset($forum)) {
         return $forum;
     } else {
         throw new CHttpException(500, 'The requested forum does not exist.');
     }
 }
Example #14
0
 /**
  * Creates a new topic.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     // find forum
     if (isset($_GET['id'])) {
         $forum = Forum::model()->findByPk((int) $_GET['id']);
     }
     if (!isset($forum)) {
         throw new CHttpException(500, 'The requested forum does not exist.');
     }
     $form = new TopicForm();
     if (isset($_POST['TopicForm'])) {
         if ($form->validate()) {
             //die(var_dump(Yii::app()->user->name));
             $user = User::model()->find('username = :username', array('username' => Yii::app()->user->name));
             if ($user === null) {
                 throw new Exception(500, 'You need to login to create a new topic');
             }
             /*$transaction = Topic::model()->dbConnection->beginTransaction();
             		try {
             		*/
             //die(var_dump($_POST['TopicForm']));
             $topic = new Topic();
             $topic->forum_id = $forum->id;
             $topic->user_id = $user->id;
             $topic->title = $_POST['TopicForm']['title'];
             $topic->hits = 1;
             $topic->sticky = 0;
             $topic->locked = 0;
             $topic->created_at = date('Y-m-d H:i:s');
             $topic->updated_at = date('Y-m-d H:i:s');
             if (!$topic->save()) {
                 die(var_dump('<pre>', $topic->getErrors()));
             }
             $post = new Post();
             $post->user_id = $user->id;
             $post->topic_id = $topic->id;
             $post->body = $_POST['TopicForm']['body'];
             // TODO: fix rendering?
             $post->body_html = $post->body;
             $post->created_at = date('Y-m-d H:i:s');
             $post->forum_id = $forum->id;
             if (!$post->save()) {
                 var_dump('<pre>', $post->getErrors());
             }
             /*$user->posts_count++;
             		if(!$user->save()) {
             			var_dump('<pre>', $user->getErrors());
             		}
             		
             		$forum->topics_count++;
             		if(!$forum->save()) {
             			var_dump('<pre>', $forum->getErrors());
             		}*/
             //$transaction->commit();
             /*} catch(Exception $e) {
             			$transaction->rollBack();
             			throw new CHttpException(500, 'Failed to save topic');
             		}*/
             $this->redirect(array('view', 'id' => $topic->id));
         }
         /*if($user->save()) {
         			//var_dump("user saved");
         			
         			//$this->redirect(array('show', 'id' => $users->id ));
         			
         		} else {
         			var_dump($user->getErrors());
         		}*/
     }
     //die(var_dump($_POST['TopicForm']));
     /*$topic = new Topic();
     		if(isset($_POST['Topics']))
     		{
     			$topic->attributes=$_POST['Topics'];
     			if($topic->save())
     				$this->redirect(array('show','id'=>$topic->id));
     		}*/
     $this->render('create', array('form' => $form, 'forum' => $forum));
 }
Example #15
0
 /**
  * Возвращает модель по указанному идентификатору
  * Если модель не будет найдена - возникнет HTTP-исключение.
  *
  * @param integer идентификатор нужной модели
  * @return Forum $model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Forum::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('ForumModule.forum', 'Page was not found!'));
     }
     return $model;
 }
Example #16
0
 /**
  * Returns breadcrumbs array to this forum
  */
 public function getBreadcrumbs($currentlink = false)
 {
     // Get the "path" from our parent to null
     $breadcrumbs = array();
     $forum = $this;
     while (null != $forum->parent_id) {
         $forum = Forum::model()->findByPk($forum->parent_id);
         if ($forum->isCat) {
             $breadcrumbs[] = $forum->title;
         } else {
             $breadcrumbs[$forum->title] = array('/forum/forum/index', 'id' => $forum->id);
         }
     }
     $breadcrumbs = array_merge(array('Форум' => array('/forum')), array_reverse($breadcrumbs));
     if (!$this->isNewRecord) {
         $breadcrumbs = array_merge($breadcrumbs, $currentlink ? array(CHtml::encode($this->title) => array('/forum/forum/index', 'id' => $this->id)) : array(CHtml::encode($this->title)));
     }
     return $breadcrumbs;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Forum::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #18
0
<div class="form" style="margin:20px;">
    <?php 
$form = $this->beginWidget('CActiveForm', ["htmlOptions" => ["class" => "form-horizontal"]]);
?>

    <p class="note">Поля с <span class="required">*</span> обязательны.</p>

    <div class="form-group">
        <div class="col-md-2">
            <?php 
echo $form->labelEx($model, 'parent_id');
?>
        </div>
        <div class="col-md-9">
            <?php 
echo CHtml::activeDropDownList($model, 'parent_id', CHtml::listData(Forum::model()->findAllByAttributes(["parent_id" => null]), 'id', 'title'), ['empty' => 'Никакой (root)', "class" => "form-control"]);
?>
            <?php 
echo $form->error($model, 'parent_id');
?>
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-2">
            <?php 
echo $form->labelEx($model, 'title');
?>
        </div>
        <div class="col-md-9">
            <?php