<?php /** * Comment model form view. * * @var \yii\base\View $this View * @var \yii\widgets\ActiveForm $form Form * @var \vova07\comments\models\backend\Model $model Model * @var \vova07\themes\admin\widgets\Box $box Box widget instance * @var array $statusArray Statuses array */ use vova07\comments\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, 'name')->textInput(['placeholder' => Module::t('comments-models', 'BACKEND_CREATE_PLACEHOLDER_NAME')]); ?> </div> </div> <?php $box->endBody(); $box->beginFooter(); echo Html::submitButton($model->isNewRecord ? Module::t('comments-models', 'BACKEND_CREATE_SUBMIT') : Module::t('comments-models', 'BACKEND_UPDATE_SUBMIT'), ['class' => $model->isNewRecord ? 'btn btn-primary btn-large' : 'btn btn-success btn-large']); $box->endFooter(); ActiveForm::end();
<?php /** * Comment model update view. * * @var \yii\base\View $this View * @var \vova07\comments\models\backend\Model $model Model * @var \vova07\themes\admin\widgets\Box $box Box widget instance * @var array $statusArray Statuses array */ use vova07\comments\Module; use vova07\themes\admin\widgets\Box; $this->title = Module::t('comments-models', 'BACKEND_UPDATE_TITLE'); $this->params['subtitle'] = Module::t('comments-models', 'BACKEND_UPDATE_SUBTITLE'); $this->params['breadcrumbs'] = [['label' => $this->title, 'url' => ['index']], $this->params['subtitle']]; $boxButtons = ['{cancel}']; if (Yii::$app->user->can('BCreateCommentsModels')) { $boxButtons[] = '{create}'; } if (Yii::$app->user->can('BDeleteCommentsModels')) { $boxButtons[] = '{delete}'; } $boxButtons = !empty($boxButtons) ? implode(' ', $boxButtons) : null; ?> <div class="row"> <div class="col-sm-12"> <?php $box = Box::begin(['title' => $this->params['subtitle'], 'renderBody' => false, 'options' => ['class' => 'box-success'], 'bodyOptions' => ['class' => 'table-responsive'], 'buttonsTemplate' => $boxButtons]); echo $this->render('_form', ['model' => $model, 'statusArray' => $statusArray, 'box' => $box]); Box::end(); ?>
Box::begin(['title' => Module::t('comments-models', 'BACKEND_INDEX_TITLE_ENABLING'), 'options' => ['class' => 'box-primary']]); ?> <?php if (Yii::$app->base->hasExtension('blogs')) { ?> <?php if (Model::isExtensionEnabled('blogs')) { ?> <?php echo Html::a(Html::tag('span', Html::tag('i', '', ['class' => 'fa fa-check']), ['class' => 'badge bg-green']) . Html::tag('i', '', ['class' => 'fa fa-book']) . Module::t('comments-models', 'BACKEND_INDEX_MODULE_BLOGS'), ['/comments/models/disable', 'name' => 'blogs'], ['class' => 'btn btn-app', 'data-method' => 'post', 'data-confirm' => Module::t('comments-models', 'BACKEND_INDEX_MODULES_DISABLE_CONFIRMATION')]); ?> <?php } else { ?> <?php echo Html::a(Html::tag('span', Html::tag('i', '', ['class' => 'fa fa-times']), ['class' => 'badge bg-red']) . Html::tag('i', '', ['class' => 'fa fa-book']) . Module::t('comments-models', 'BACKEND_INDEX_MODULE_BLOGS'), ['/comments/models/enable', 'name' => 'blogs'], ['class' => 'btn btn-app', 'data-method' => 'post']); ?> <?php } ?> <?php } ?> <?php Box::end(); ?> </div> </div> <?php } ?>
/** * 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('comments', 'FRONTEND_FLASH_RECORD_NOT_FOUND')); } }
/** * @inheritdoc */ public function attributeLabels() { return ['id' => Module::t('comments-models', 'ATTR_ID'), 'name' => Module::t('comments-models', 'ATTR_NAME'), 'status_id' => Module::t('comments-models', 'ATTR_STATUS'), 'created_at' => Module::t('comments-models', 'ATTR_CREATED'), 'updated_at' => Module::t('comments-models', 'ATTR_UPDATED')]; }
<?php /** * Comments widget form view. * @var \yii\web\View $this View * @var \yii\widgets\ActiveForm $form Form * @var \vova07\comments\models\frontend\Comment $model New comment model */ use vova07\comments\Module; use yii\helpers\Html; echo Html::beginForm(['/comments/default/create'], '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('comments', 'FRONTEND_WIDGET_COMMENTS_FORM_SUBMIT'), ['class' => 'btn btn-danger btn-lg']); echo Html::endForm();
echo Module::t('comments', 'FRONTEND_WIDGET_COMMENTS_DELETE'); ?> </a> <?php } ?> </div> <?php } ?> </div> <?php if ($comment->isDeleted) { ?> <?php echo Module::t('comments', 'FRONTEND_WIDGET_COMMENTS_DELETED_COMMENT_TEXT'); ?> <?php } else { ?> <div class="content" data-comment="content"><?php echo $comment->content; ?> </div> <?php } ?> </div> <?php if ($comment->children) { ?>
use vova07\themes\admin\widgets\GridView; use vova07\comments\Module; use yii\grid\ActionColumn; use yii\grid\CheckboxColumn; use yii\helpers\Html; use yii\jui\DatePicker; $this->title = Module::t('comments', 'BACKEND_INDEX_TITLE'); $this->params['subtitle'] = Module::t('comments', '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('comments', '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('comments', '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('BUpdateComments')) { $actions[] = '{update}'; $showActions = $showActions || true; } if (Yii::$app->user->can('BDeleteComments')) { $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;
/** * @inheritdoc */ public function attributeLabels() { return ['id' => Module::t('comments', 'ATTR_ID'), 'parent_id' => Module::t('comments', 'ATTR_PARENT'), 'model_class' => Module::t('comments', 'ATTR_MODEL_CLASS'), 'model_id' => Module::t('comments', 'ATTR_MODEL'), 'author_id' => Module::t('comments', 'ATTR_AUTHOR'), 'content' => Module::t('comments', 'ATTR_CONTENT'), 'status_id' => Module::t('comments', 'ATTR_STATUS'), 'created_at' => Module::t('comments', 'ATTR_CREATED'), 'updated_at' => Module::t('comments', 'ATTR_UPDATED')]; }
/** * Disable comments for indicated extension * * @param string $name Extension name * * @return mixed */ public function actionDisable($name) { if (!Model::disableExtension($name)) { Yii::$app->session->setFlash('danger', Module::t('comments-models', 'BACKEND_FLASH_FAIL_ADMIN_DISABLE')); } return $this->redirect(['index']); }
* Comments list view. * * @var \yii\web\View $this View * @var \vova07\comments\models\frontend\Comment[] $models Comments models * @var \vova07\comments\models\frontend\Comment $model New comment model */ use vova07\comments\Module; ?> <div id="comments"> <div id="comments-list" data-comment="list"> <?php echo $this->render('_index_item', ['models' => $models]); ?> </div> <!--/ #comments-list --> <?php if (Yii::$app->user->can('createComments')) { ?> <h3><?php echo Module::t('comments', 'FRONTEND_WIDGET_COMMENTS_FORM_TITLE'); ?> </h3> <?php echo $this->render('_form', ['model' => $model]); ?> <?php } ?> </div>