Esempio n. 1
0
 public function run()
 {
     $form = new CommentForm();
     // Если пользователь не авторизован,
     // запускаем форму со сценарием guest
     if (\Yii::$app->user->isGuest) {
         $form->scenario = 'guest';
     }
     $form->namespace = $this->model->material_model_of_namespace;
     $form->material_id = $this->material->id;
     $form->parent_id = 0;
     echo Html::beginTag('div', ['id' => 'comments']);
     echo Html::beginTag('div', ['class' => 'block-title']);
     echo '<i class="glyphicon glyphicon-comment"></i> ' . $this->title . $this->countComments;
     echo Html::endTag('div');
     // Вывод комментариев
     echo Html::beginTag('div', ['id' => 'commentsList']);
     self::renderTree($this->model->getTree($this->material->commentsallowed));
     echo Html::endTag('div');
     if ($this->model) {
         echo Html::tag('hr');
     }
     echo Html::beginTag('p');
     echo '<a class="comment-link" data-id="0" href="#comment-form"> ' . Module::t('module', 'COMMENT_LEAVE_A_COMMENT') . '</a>';
     echo Html::endTag('p');
     echo Html::beginTag('div', ['class' => 'well comment-well']);
     // Форма добавления комментария
     echo $this->render('_commentForm', ['model' => $form]);
     echo Html::endTag('div');
     echo Html::endTag('div');
 }
Esempio n. 2
0
 /**
  * Обработка формы
  * Добавления комментария
  * @return bool
  */
 public function actionCreate()
 {
     $commentForm = new CommentForm();
     if (Yii::$app->user->isGuest) {
         $commentForm->scenario = CommentForm::SCENARIO_GUEST;
     }
     if (isset($_POST['CommentForm'])) {
         $commentForm->attributes = $_POST['CommentForm'];
         if ($commentForm->validate()) {
             $comment = new $commentForm->namespace();
             $comment->attributes = $commentForm->attributes;
             // Статус модерации по умолчанию
             // если не установлен, ставим требует проверки
             // Комментарии зарегистрированных пользователей публикуем без модерации
             // COMMENT_MODER_PENDING - требуется модерация
             // COMMENT_MODER_ALLOWED - без модерации
             // COMMENT_MODER_DISALLOWED - запрещена публикация
             $userModelNamespace = Yii::$app->getModule(Module::$name)->userModelNamespace;
             if (Yii::$app->user->can($userModelNamespace::ROLE_USER)) {
                 $comment->moder = Comment::COMMENT_MODER_ALLOWED;
             } else {
                 $comment->moder = $comment->moder ? $comment->moder : Comment::COMMENT_MODER_PENDING;
             }
             //$moderStatus = $comment->moder;
             /* @var $comment \app\modules\comment\models\Comment */
             if ($comment->validate()) {
                 if ($comment->save()) {
                     // Формируем сообщение
                     $comment->moderStatusMessage($comment->moder);
                     // Формируем ссылку
                     $url = $comment->id && $comment->moder == Comment::COMMENT_MODER_ALLOWED ? Url::previous() . '#comment_' . $comment->id : Url::previous();
                     // Перенаправляем на предыдущую страницу
                     return $this->redirect($url);
                 } else {
                     // Формируем сообщение
                     Yii::$app->session->setFlash('error', Module::t('module', 'FLASH_SUBMIT_COMMENT_ERROR'));
                     // Перенаправляем на предыдущую страницу
                     return $this->redirect(Url::previous());
                 }
             }
         }
     }
 }
 /**
  * Update comment page.
  *
  * @param integer $id Comment ID
  *
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model->setScenario('admin-update');
     $statusArray = Comment::statusLabels();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if ($model->save(false)) {
                 return $this->refresh();
             } else {
                 Yii::$app->session->setFlash('danger', Module::t('admin', 'BACKEND_FLASH_FAIL_ADMIN_UPDATE'));
                 return $this->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
     }
     return $this->render('update', ['model' => $model, 'statusArray' => $statusArray]);
 }
Esempio n. 4
0
 public function run()
 {
     $modelClass = $this->modelClass;
     $model = new $modelClass(['scenario' => 'create']);
     $statusArray = $modelClass::statusLabels();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if ($model->save(false)) {
                 return $this->controller->redirect(['update', 'id' => $model->id]);
             } else {
                 Yii::$app->session->setFlash('danger', Module::t('admin', 'BACKEND_FLASH_FAIL_ADMIN_CREATE'));
                 return $this->controller->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
     }
     return $this->controller->render('create', ['model' => $model, 'statusArray' => $statusArray]);
 }
Esempio n. 5
0
 public function run()
 {
     $modelClass = $this->modelClass;
     /** @var ActiveRecord $model */
     $model = new $modelClass(['scenario' => 'create']);
     if ($this->checkAccess) {
         call_user_func($this->checkAccess, $model);
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if ($model->save(false)) {
                 return $this->tree($model);
             } else {
                 Yii::$app->response->setStatusCode(500);
                 return Module::t('comment', 'FRONTEND_FLASH_FAIL_CREATE');
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->setStatusCode(400);
             return ActiveForm::validate($model);
         }
     }
 }
Esempio n. 6
0
<?php

/**
 * Comments widget form view.
 * @var \yii\web\View $this View
 * @var \yii\widgets\ActiveForm $form Form
 * @var \app\modules\comment\models\Comment $model New comment model
 * @var string $route New comment model
 */
use app\modules\comment\Module;
use yii\helpers\Html;
echo Html::beginForm([$route], 'POST', ['class' => 'form-horizontal', 'data-comment' => 'form', 'data-comment-action' => 'create']);
?>
    <div class="form-group" data-comment="form-group">
        <div class="col-sm-12">
            <?php 
echo Html::activeTextarea($model, 'content', ['class' => 'form-control']);
?>
            <?php 
echo Html::error($model, 'content', ['data-comment' => 'form-summary', 'class' => 'help-block hidden']);
?>
        </div>
    </div>
<?php 
echo Html::activeHiddenInput($model, 'parent_id', ['data-comment' => 'parent-id']);
echo Html::activeHiddenInput($model, 'model_class');
echo Html::activeHiddenInput($model, 'model_id');
echo Html::submitButton(Module::t('comment', 'FRONTEND_WIDGET_COMMENTS_FORM_SUBMIT'), ['class' => 'btn btn-danger']);
echo Html::endForm();
Esempio n. 7
0
echo $item->getPostedDate();
?>
</small>
            </h4>
            <p><?php 
echo Module::t('module', 'COMMENT_MODER_DISALLOWED');
?>
</p>
            <div class="row">
                <div class="col-md-2">
                    <div class="pull-left">

                    </div>
                </div>
                <div class="col-md-10">
                    <div class="pull-right">
                        <?php 
if (\Yii::$app->user->can($userModelNamespace::ROLE_MODER)) {
    echo Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['/comment/admin/update', 'id' => $item->id], ['title' => \Yii::t('app', 'Edit')]) . ' ';
    echo Html::a('<span class="glyphicon glyphicon-ok"></span>', ['/comment/admin/delete', 'id' => $item->id], ['title' => Module::t('module', 'BUTTON_ALLOWED')]) . ' ';
    //echo Html::a('<span class="glyphicon glyphicon-random"></span>', ['/comment/admin/manage', 'id' => $item->id]);
}
?>
                    </div>
                </div>
            </div>
        </div>



Esempio n. 8
0
 /**
  * Функция формирования флэш сообщения
  * после добавления комментария
  *
  * @param $moderStatus - 0/1/2
  * @param string $status - success/error
  * @param string $text - сообщение
  * @return bool
  */
 public function moderStatusMessage($moderStatus, $status = '', $text = '')
 {
     if ($moderStatus) {
         // если требуется модерация
         if ($moderStatus == self::COMMENT_MODER_PENDING) {
             $status = 'success';
             $text = Module::t('module', 'FLASH_SUBMIT_COMMENT_SUCCESS');
         }
         // если публиковать без модерации
         if ($moderStatus == self::COMMENT_MODER_ALLOWED) {
             $status = 'success';
             $text = Module::t('module', 'FLASH_SUBMIT_COMMENT_PUBLISH_SUCCESS');
         }
         // если запрещена публикация
         if ($moderStatus == self::COMMENT_MODER_DISALLOWED) {
             $status = 'error';
             $text = Module::t('module', 'FLASH_SUBMIT_COMMENT_ALLOWED');
         }
         Yii::$app->session->setFlash($status, $text);
     }
     return false;
 }
Esempio n. 9
0
<?php

/**
 * Comment model create view.
 *
 * @var \yii\base\View $this View
 * @var array $statusArray Statuses array
 */
use app\modules\comment\Module;
use app\themes\admin\widgets\Box;
$this->title = Module::t('admin', 'BACKEND_CREATE_TITLE');
$this->params['subtitle'] = Module::t('admin', 'BACKEND_CREATE_SUBTITLE');
$this->params['breadcrumbs'] = [['label' => $this->title, 'url' => ['index']], $this->params['subtitle']];
?>
<div class="row">
    <div class="col-sm-12">
        <?php 
$box = Box::begin(['title' => $this->params['subtitle'], 'renderBody' => false, 'options' => ['class' => 'box-primary'], 'bodyOptions' => ['class' => 'table-responsive'], 'buttonsTemplate' => '{cancel}']);
echo $this->render('_form', ['model' => $model, 'statusArray' => $statusArray, 'box' => $box]);
Box::end();
?>
    </div>
</div>
Esempio n. 10
0
 /**
  * Disable comments for indicated extension
  *
  * @param string $name Extension name
  *
  * @return mixed
  */
 public function actionDisable($name)
 {
     if (!CommentModel::disableExtension($name)) {
         Yii::$app->session->setFlash('danger', Module::t('admin', 'BACKEND_FLASH_FAIL_ADMIN_DISABLE'));
     }
     return $this->redirect(['index']);
 }
Esempio n. 11
0
    ?>
            <?php 
    echo $this->render('_index_item', ['models' => $models]);
    ?>
        <?php 
}
?>
    </div>

    <div class="well comments__form">
        <?php 
if ($user->can('commentCreate')) {
    ?>
            <h3><?php 
    echo Module::t('comment', 'Post comment');
    ?>
</h3>
            <?php 
    echo $this->render('_form', ['model' => $model, 'route' => $route]);
    ?>
        <?php 
} else {
    ?>
            <?php 
    echo Module::t('comment', '<a href="{login}">Login</a> or <a href="{register}">register</a> to post comments', ['login' => Url::to($user->loginUrl), 'register' => Url::to(['/user/guest/signup'])]);
    ?>
        <?php 
}
?>
    </div>
</div>
 /**
  * Find model by ID.
  *
  * @param integer|array $id Comment ID
  *
  * @return Comment Model
  *
  * @throws HttpException 404 error if comment not found
  */
 protected function findModel($id)
 {
     /** @var Comment $model */
     $model = Comment::findOne($id);
     if ($model !== null) {
         return $model;
     } else {
         throw new HttpException(404, Module::t('comment', 'FRONTEND_FLASH_RECORD_NOT_FOUND'));
     }
 }
Esempio n. 13
0
use app\themes\admin\widgets\GridView;
use app\modules\comment\Module;
use yii\grid\ActionColumn;
use yii\grid\CheckboxColumn;
use yii\helpers\Html;
use yii\jui\DatePicker;
$this->title = Module::t('admin', 'BACKEND_INDEX_TITLE');
$this->params['subtitle'] = Module::t('admin', 'BACKEND_INDEX_SUBTITLE');
$this->params['breadcrumbs'] = [$this->title];
$gridId = 'comments-grid';
$gridConfig = ['id' => $gridId, 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => CheckboxColumn::classname()], 'id', 'parent_id', 'model_id', ['attribute' => 'model_class', 'value' => function ($model) {
    return $model->class->name;
}, 'filter' => Html::activeDropDownList($searchModel, 'model_class', $modelArray, ['class' => 'form-control', 'prompt' => Module::t('admin', 'BACKEND_PROMPT_MODEL_CLASS')])], 'content', ['attribute' => 'status_id', 'format' => 'html', 'value' => function ($model) {
    $class = $model->status_id === $model::STATUS_ACTIVE ? 'label-success' : 'label-danger';
    return '<span class="label ' . $class . '">' . $model->status . '</span>';
}, 'filter' => Html::activeDropDownList($searchModel, 'status_id', $statusArray, ['class' => 'form-control', 'prompt' => Module::t('admin', 'BACKEND_PROMPT_STATUS')])], ['attribute' => 'created_at', 'format' => 'date', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'created_at', 'options' => ['class' => 'form-control'], 'clientOptions' => ['dateFormat' => 'dd.mm.yy']])], ['attribute' => 'updated_at', 'format' => 'date', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'updated_at', 'options' => ['class' => 'form-control'], 'clientOptions' => ['dateFormat' => 'dd.mm.yy']])]]];
$boxButtons = $actions = [];
$showActions = false;
if (Yii::$app->user->can('commentUpdate')) {
    $actions[] = '{update}';
    $showActions = $showActions || true;
}
if (Yii::$app->user->can('commentDelete')) {
    $boxButtons[] = '{batch-delete}';
    $actions[] = '{delete}';
    $showActions = $showActions || true;
}
if ($showActions === true) {
    $gridConfig['columns'][] = ['class' => ActionColumn::className(), 'template' => implode(' ', $actions)];
}
$boxButtons = !empty($boxButtons) ? implode(' ', $boxButtons) : null;
Esempio n. 14
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     return ['id' => Module::t('model', 'ATTR_ID'), 'name' => Module::t('model', 'ATTR_NAME'), 'status_id' => Module::t('model', 'ATTR_STATUS'), 'created_at' => Module::t('model', 'ATTR_CREATED'), 'updated_at' => Module::t('model', 'ATTR_UPDATED')];
 }
Esempio n. 15
0
        <?php 
echo Html::activeHiddenInput($model, 'namespace');
?>
        <?php 
echo Html::activeHiddenInput($model, 'material_id');
?>
        <?php 
echo Html::activeHiddenInput($model, 'parent_id');
?>

        <?php 
// Выводим капчу только гостям
if (Yii::$app->user->isGuest) {
    ?>
            <?php 
    echo $form->field($model, 'verifyCode')->widget(Captcha::className(), ['captchaAction' => '/comment/default/captcha', 'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>']);
    ?>
        <?php 
}
?>

    </div>
    <?php 
echo Html::submitButton(Module::t('module', 'BUTTON_SUBMIT'), ['class' => 'btn btn-primary']);
?>

<?php 
ActiveForm::end();
?>
</div>
Esempio n. 16
0
 * @var \yii\base\View $this View
 * @var \yii\widgets\ActiveForm $form Form
 * @var \app\themes\admin\widgets\Box $box Box widget instance
 * @var array $statusArray Statuses array
 */
use app\modules\comment\Module;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$form = ActiveForm::begin();
$box->beginBody();
?>
    <div class="row">
        <div class="col-sm-12">
            <?php 
echo $form->field($model, 'status_id')->dropDownList($statusArray, ['prompt' => Module::t('admin', 'BACKEND_PROMPT_STATUS')]);
?>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <?php 
echo $form->field($model, 'content')->textarea();
?>
        </div>
    </div>
<?php 
$box->endBody();
$box->beginFooter();
echo Html::submitButton($model->isNewRecord ? Module::t('admin', 'BACKEND_CREATE_SUBMIT') : Module::t('admin', 'BACKEND_UPDATE_SUBMIT'), ['class' => $model->isNewRecord ? 'btn btn-primary btn-large' : 'btn btn-success btn-large']);
$box->endFooter();
ActiveForm::end();
Esempio n. 17
0
                ?>
                                            &nbsp;
                                            <span class="btn btn-default" data-comment="delete"
                                                  data-comment-id="<?php 
                echo $comment->id;
                ?>
" data-comment-url="<?php 
                echo Url::to(['/comment/default/delete', 'id' => $comment->id]);
                ?>
"
                                                  data-comment-confirm="<?php 
                echo Module::t('comment', 'FRONTEND_WIDGET_COMMENTS_DELETE_CONFIRMATION');
                ?>
">
                                                <i class="icon-trash"></i> <?php 
                echo Module::t('comment', 'FRONTEND_WIDGET_COMMENTS_DELETE');
                ?>
                                            </span>
                                        <?php 
            }
            ?>
                                    </span>
                                </div>
                            </div>
                        <?php 
        }
        ?>

                    </div>
                </div>
                <?php 
Esempio n. 18
0
 /**
  * @return array
  */
 public function attributeLabels()
 {
     return ['author' => Module::t('module', 'COMMENT_NAME'), 'email' => Module::t('module', 'COMMENT_EMAIL'), 'site' => Module::t('module', 'COMMENT_SITE'), 'text' => Module::t('module', 'COMMENT_COMMENT'), 'verifyCode' => Module::t('module', 'COMMENT_VERIFY_CODE')];
 }
Esempio n. 19
0
<?php

use app\models\ModuleDefinition;
use app\modules\comment\Module;
return ['id' => 'comment', 'class' => Module::className(), 'config' => [], 'name' => 'Comments', 'package' => ModuleDefinition::PACKAGE_CORE, 'category' => Module::TRANSLATE_CATEGORY, 'required' => false, 'menu' => ['comment.index' => ['title' => 'Comments', 'icon' => 'fa-comments'], 'comment.content' => ['title' => 'Content', 'route' => ['/comment/content/index'], 'parent' => 'comment.index'], 'comment.moderate' => ['title' => 'Moderate', 'route' => ['/comment/content/moderate'], 'parent' => 'comment.index'], 'comment.reports' => ['title' => 'Reports', 'route' => ['/comment/content/reports'], 'parent' => 'comment.index']]];
Esempio n. 20
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     return ['id' => Module::t('model', 'ATTR_ID'), 'parent_id' => Module::t('model', 'ATTR_PARENT'), 'model_class' => Module::t('model', 'ATTR_MODEL_CLASS'), 'model_id' => Module::t('model', 'ATTR_MODEL'), 'author_id' => Module::t('model', 'ATTR_AUTHOR'), 'content' => Module::t('model', 'ATTR_CONTENT'), 'status_id' => Module::t('model', 'ATTR_STATUS'), 'created_at' => Module::t('model', 'ATTR_CREATED'), 'updated_at' => Module::t('model', 'ATTR_UPDATED')];
 }
Esempio n. 21
0
 <small><i><?php 
    echo $item->getPostedDate();
    ?>
</i></small>
            </h4>
            <?php 
    echo $item->text;
    ?>
            <div class="row">
                <div class="col-md-2">
                    <div class="pull-left">
                        <?php 
    echo Html::a(Module::t('module', 'BUTTON_REPLY'), '#comment-form', ['class' => 'reply-link', 'data-id' => $item->id, 'onclick' => 'return false;']);
    ?>
                    </div>
                </div>
                <div class="col-md-10">
                    <div class="pull-right">
                        <?php 
    if (\Yii::$app->user->can($userModelNamespace::ROLE_MODER)) {
        echo Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['/comment/admin/update', 'id' => $item->id], ['title' => \Yii::t('app', 'Edit')]) . ' ';
        echo Html::a('<span class="glyphicon glyphicon-ban-circle"></span>', ['/comment/admin/disallowed', 'id' => $item->id], ['title' => Module::t('module', 'BUTTON_DISALLOWED')]) . ' ';
        //echo Html::a('<span class="glyphicon glyphicon-random"></span>', ['/comment/admin/manage', 'id' => $item->id]);
    }
    ?>
                    </div>
                </div>
            </div>
        </div>
<?php 
}