Commit adc7e08f9e3c48400becb2a86a09777dcde931bd

Authored by Anastasia
1 parent a391ca66

add slug

- main menu
backend/actions/Create.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace backend\actions;
  4 +
  5 + use artbox\core\admin\actions\Save;
  6 + use artbox\core\models\Language;
  7 + use function call_user_func;
  8 + use yii\base\Model;
  9 +
  10 + /**
  11 + * Create action for Artbox CRUD
  12 + *
  13 + * @package artbox\core\admin\actions
  14 + */
  15 + class Create extends Save
  16 + {
  17 + /**
  18 + * @var string
  19 + */
  20 + public $viewPath = '@backend/actions/views/create';
  21 +
  22 + /**
  23 + * If this parameter is setted - when creating aliases for model, write this parameter to aliase's entity
  24 + * Created to keep back reference with FilterHelper
  25 + *
  26 + * @var null
  27 + */
  28 + public $overwriteEntity = null;
  29 +
  30 + /**
  31 + * Creates new model, loading aliases, languages and gallery
  32 + *
  33 + * @return string|\yii\web\Response
  34 + */
  35 + public function run()
  36 + {
  37 + $model = call_user_func(
  38 + [
  39 + $this->controller,
  40 + 'newModel',
  41 + ]
  42 + );
  43 + $languages = Language::getActive();
  44 + if ($this->hasAlias) {
  45 + /**
  46 + * @var \artbox\core\models\Alias[] $aliases
  47 + */
  48 + $aliases = $model->loadAliases();
  49 + }
  50 +
  51 + $post = \Yii::$app->request->post();
  52 +
  53 + if (!empty($this->languageFields)) {
  54 + Model::loadMultiple($model->getVariationModels(), $post);
  55 + }
  56 +
  57 + if ($model->load($post) && $model->save()) {
  58 + if ($this->hasAlias) {
  59 + /**
  60 + * @var \artbox\core\models\Alias[] $aliases
  61 + */
  62 + Model::loadMultiple($aliases, $post);
  63 + foreach ($aliases as $alias) {
  64 + $alias->route = $model->getRoute();
  65 + if ($this->overwriteEntity === null) {
  66 + $alias->entity = $model::className();
  67 + } else {
  68 + $alias->entity = $this->overwriteEntity;
  69 + }
  70 + $alias->save();
  71 +
  72 + /**
  73 + * @var \yii\db\ActiveRecord $modelLang
  74 + */
  75 + $modelLang = $model->getVariationModel($alias->language_id);
  76 + $modelLang->alias_id = $alias->id;
  77 + $modelLang->save();
  78 + }
  79 + }
  80 +
  81 + if ($this->hasGallery) {
  82 + $model->saveImages($post);
  83 + }
  84 +
  85 + return $this->controller->redirect([ 'index' ]);
  86 + }
  87 +
  88 + return $this->controller->render(
  89 + $this->viewPath,
  90 + [
  91 + 'action' => $this,
  92 + 'model' => $model,
  93 + 'languages' => $languages,
  94 + ]
  95 + );
  96 + }
  97 + }
0 98 \ No newline at end of file
... ...
backend/actions/Update.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace backend\actions;
  4 +
  5 + use artbox\core\admin\actions\Save;
  6 + use artbox\core\models\Language;
  7 + use function call_user_func_array;
  8 + use yii\base\Model;
  9 +
  10 + class Update extends Save
  11 + {
  12 + /**
  13 + * @var string
  14 + */
  15 + public $viewPath = '@abackend/actions/views/update';
  16 +
  17 + /**
  18 + * Updates existing model with langs, aliases and gallery
  19 + *
  20 + * @param $id
  21 + *
  22 + * @return string|\yii\web\Response
  23 + */
  24 + public function run($id)
  25 + {
  26 + $model = call_user_func_array(
  27 + [
  28 + $this->controller,
  29 + 'findModel',
  30 + ],
  31 + [ $id ]
  32 + );
  33 + $languages = Language::getActive();
  34 + $post = \Yii::$app->request->post();
  35 +
  36 + if (!empty($this->languageFields)) {
  37 + Model::loadMultiple($model->getVariationModels(), $post);
  38 + }
  39 +
  40 + if ($model->load($post) && $model->save()) {
  41 + if ($this->hasAlias) {
  42 + /**
  43 + * @var \artbox\core\models\Alias[] $aliases
  44 + */
  45 + $aliases = $model->loadAliases();
  46 + Model::loadMultiple($aliases, $post);
  47 + foreach ($aliases as $alias) {
  48 + $alias->save();
  49 + }
  50 + }
  51 +
  52 + if ($this->hasGallery) {
  53 + $model->saveImages($post);
  54 + }
  55 +
  56 + return $this->controller->redirect([ 'index' ]);
  57 + }
  58 +
  59 + return $this->controller->render(
  60 + $this->viewPath,
  61 + [
  62 + 'action' => $this,
  63 + 'model' => $model,
  64 + 'languages' => $languages,
  65 + ]
  66 + );
  67 + }
  68 + }
0 69 \ No newline at end of file
... ...
backend/actions/views/create.php 0 → 100755
  1 +<?php
  2 +
  3 + /**
  4 + * @var View $this
  5 + * @var \artbox\core\admin\actions\Create $action
  6 + * @var \yii\db\ActiveRecord $model
  7 + * @var array $languages
  8 + */
  9 +
  10 + use yii\helpers\Inflector;
  11 + use yii\web\View;
  12 + use yiister\gentelella\widgets\Panel;
  13 +
  14 + $modelName = ( new ReflectionClass($model::className()) )->getShortName();
  15 +
  16 + $this->params[ 'breadcrumbs' ][] = [
  17 + 'label' => \Yii::t('core', Inflector::pluralize($modelName)),
  18 + 'url' => [ $action->controller->id . '/index' ],
  19 + ];
  20 +
  21 + $this->title = \Yii::t('core', 'Create ' . lcfirst($modelName));
  22 +
  23 + $this->params[ 'breadcrumbs' ][] = $this->title;
  24 +
  25 +?>
  26 +
  27 +<div class="adm-create">
  28 + <div class="x_panel">
  29 + <div class="x_title"><h2><?php echo $this->title; ?></h2><div class="clearfix"></div></div>
  30 +
  31 + <div class="style lang-page-block-wr">
  32 + <?php if (!empty($action->languageFields)) {?>
  33 + <div class="lang-page-block">
  34 + <?php foreach ($languages as $language){?>
  35 + <span class="<?=$language['default'] ? 'active' : ''?>"><?=$language['url']?></span>
  36 + <?php } ?>
  37 + <!-- первому(выбранному языку...) давать active -->
  38 + <!-- <span class="active">ru</span>-->
  39 + <!-- <span>укр</span>-->
  40 + <!-- <span>eng</span>-->
  41 + </div>
  42 + <?php } ?>
  43 + <div class="lang-page-block-text">
  44 + <!-- первому давать active -->
  45 + <?php if (!empty($action->languageFields)) {?>
  46 + <span class="active">Языковой блок</span>
  47 + <?php }?>
  48 + <span>Основной блок</span>
  49 + <?php if ($action->hasAlias){?>
  50 + <span>Seo</span>
  51 + <?PHP }?>
  52 + <?php if ($action->hasGallery){?>
  53 + <span>Галерея</span>
  54 + <?php }?>
  55 + </div>
  56 + </div>
  57 + </div>
  58 + <div class="fix-absolute-panel"></div>
  59 + <?php
  60 +
  61 +
  62 + echo backend\widgets\Form::widget(
  63 + [
  64 + 'action' => $action,
  65 + 'model' => $model,
  66 + ]
  67 + );
  68 +
  69 +
  70 + ?>
  71 +</div>
  72 +
... ...
backend/actions/views/update.php 0 → 100755
  1 +<?php
  2 +
  3 + /**
  4 + * @var View $this
  5 + * @var \artbox\core\admin\actions\Create $action
  6 + * @var \yii\db\ActiveRecord $model
  7 + * @var array $languages
  8 + */
  9 +
  10 + use yii\helpers\Inflector;
  11 + use yii\web\View;
  12 + use yiister\gentelella\widgets\Panel;
  13 +
  14 +
  15 + $modelName = ( new ReflectionClass($model::className()) )->getShortName();
  16 +
  17 + $this->params[ 'breadcrumbs' ][] = [
  18 + 'label' => \Yii::t('core', Inflector::pluralize($modelName)),
  19 + 'url' => [ $action->controller->id . '/index' ],
  20 + ];
  21 +
  22 + $this->title = \Yii::t('core', 'Update ' . lcfirst($modelName));
  23 +
  24 + $this->params[ 'breadcrumbs' ][] = $this->title;
  25 +?>
  26 +
  27 +<div class="adm-update error-has">
  28 +
  29 + <div class="x_panel">
  30 + <div class="x_title"><h2><?php echo $this->title; ?></h2><div class="clearfix"></div></div>
  31 +
  32 + <div class="style lang-page-block-wr">
  33 + <?php if (!empty($action->languageFields)) {?>
  34 + <div class="lang-page-block">
  35 + <?php foreach ($languages as $language){?>
  36 + <span class="<?=$language['default'] ? 'active' : ''?>"><?=$language['url']?></span>
  37 + <?php } ?>
  38 + <!-- первому(выбранному языку...) давать active -->
  39 +<!-- <span class="active">ru</span>-->
  40 +<!-- <span>укр</span>-->
  41 +<!-- <span>eng</span>-->
  42 + </div>
  43 + <?php }?>
  44 + <div class="lang-page-block-text">
  45 + <?php if (!empty($action->languageFields)) {?>
  46 + <span class="active">Языковой блок</span>
  47 + <?php }?>
  48 + <span>Основной блок</span>
  49 + <?php if ($action->hasAlias){?>
  50 + <span>Seo</span>
  51 + <?PHP }?>
  52 + <?php if ($action->hasGallery){?>
  53 + <span>Галерея</span>
  54 + <?php }?>
  55 + </div>
  56 + </div>
  57 + </div>
  58 + <div class="fix-absolute-panel"></div>
  59 + <?php
  60 +
  61 +
  62 + echo backend\widgets\Form::widget(
  63 + [
  64 + 'action' => $action,
  65 + 'model' => $model,
  66 + ]
  67 + );
  68 +
  69 +
  70 + ?>
  71 +</div>
  72 +
... ...
backend/controllers/PageController.php
... ... @@ -3,10 +3,10 @@
3 3 namespace backend\controllers;
4 4  
5 5 use function array_merge;
6   - use artbox\core\admin\actions\Create;
  6 + use backend\actions\Create;
7 7 use artbox\core\admin\actions\Delete;
8 8 use backend\actions\Index;
9   - use artbox\core\admin\actions\Update;
  9 + use backend\actions\Update;
10 10 use artbox\core\admin\actions\View;
11 11 use artbox\core\admin\interfaces\ControllerInterface;
12 12 use artbox\core\admin\widgets\Form;
... ... @@ -159,6 +159,7 @@
159 159 [
160 160 'name' => 'title',
161 161 'type' => Form::STRING,
  162 + 'decorate' => true
162 163 ],
163 164 [
164 165 'name' => 'body',
... ...
backend/widgets/Form.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace backend\widgets;
  4 +
  5 + use artbox\core\admin\assets\DateRangePicker;
  6 + use artbox\core\admin\assets\Switchery;
  7 + use artbox\core\admin\widgets\ImageInput;
  8 + use artbox\core\helpers\SlugifyDecorator;
  9 + use artbox\core\models\Language;
  10 + use artbox\core\services\Languages;
  11 + use artbox\core\widgets\GalleryWidget;
  12 + use function call_user_func;
  13 + use dosamigos\tinymce\TinyMce;
  14 + use kartik\select2\Select2;
  15 + use mihaildev\ckeditor\CKEditor;
  16 + use yii\base\InvalidConfigException;
  17 + use yii\base\Widget;
  18 + use yii\db\ActiveRecord;
  19 + use yii\helpers\ArrayHelper;
  20 + use yii\helpers\Html;
  21 + use yii\widgets\ActiveForm;
  22 +
  23 + /**
  24 + * Render inputs to create or save ActiveRecord model with all relational models
  25 + *
  26 + * @package artbox\core\admin\widgets
  27 + */
  28 + class Form extends Widget
  29 + {
  30 + /**
  31 + * Generates WYSIWYG redactor
  32 + *
  33 + * @see TinyMce, https://www.tinymce.com/
  34 + */
  35 + const WYSIWYG = 'wysiwyg';
  36 +
  37 + /**
  38 + * Generates text input
  39 + */
  40 + const STRING = 'string';
  41 +
  42 + /**
  43 + * Generates textarea
  44 + */
  45 + const TEXTAREA = 'textarea';
  46 +
  47 + /**
  48 + * Generates checkbox
  49 + */
  50 + const BOOL = 'boolean';
  51 +
  52 + /**
  53 + * Generates simple number input type
  54 + */
  55 + const NUMBER = 'number';
  56 +
  57 + /**
  58 + * Generates select2 widget
  59 + */
  60 + const RELATION = 'relation';
  61 +
  62 + /**
  63 + * Generates one image input
  64 + */
  65 + const IMAGE = 'image';
  66 +
  67 + /**
  68 + * Generates Gallery widget
  69 + *
  70 + * @see GalleryWidget, \artbox\core\behaviors\GalleryBehavior
  71 + */
  72 + const GALLERY = 'gallery';
  73 +
  74 + /**
  75 + *
  76 + */
  77 + const DATE = 'date';
  78 +
  79 + /**
  80 + * generate select
  81 + */
  82 + const SELECT = 'select';
  83 + /**
  84 + * @var \artbox\core\admin\actions\Save
  85 + */
  86 + public $action;
  87 +
  88 + /**
  89 + * @var Languages
  90 + */
  91 + protected $languages;
  92 +
  93 + /**
  94 + * @var \yii\db\ActiveRecord
  95 + */
  96 + public $model;
  97 +
  98 + /**
  99 + * Template for 1 language tab
  100 + *
  101 + * @var string
  102 + */
  103 + public $langTabTemplate = '<div class="style tabs-lang" style="display: {display};"><div class="style title-edit-page">{title}</div>{tab}</div>';
  104 +
  105 + /**
  106 + * Template for block of all languages tabs
  107 + *
  108 + * @var string
  109 + */
  110 + public $langBlockTemplate = '<div class="x_panel x_panel-scroll tabs-lang-wr">{tabs}</div>';
  111 + /**
  112 + * @var array fields for seo value
  113 + */
  114 + public $decorateField = [];
  115 + /**
  116 + * @inheritdoc
  117 + * @todo Remove H1 stabs
  118 + * @return string|void
  119 + * @throws \Exception
  120 + * @throws \yii\base\InvalidConfigException
  121 + */
  122 + public function run()
  123 + {
  124 + Switchery::register($this->view);
  125 +
  126 + $js = <<< JS
  127 +$('.switchery').each(function(idx, elem) {
  128 + new Switchery(elem, {
  129 + color:'#46b749',
  130 + secondaryColor:'#e2e2e2'
  131 + });
  132 +});
  133 +JS;
  134 +
  135 +
  136 + $this->languages = new Languages();
  137 +
  138 + $this->view->registerJs($js, \yii\web\View::POS_READY);
  139 + $notify = <<<JS
  140 + $('form').on('afterValidate', function(form, attribute, messages){
  141 + if (messages.length > 0){
  142 + new PNotify({
  143 + title: 'Info',
  144 + text: 'Проверьте заполнение полей',
  145 + type: 'info',
  146 + styling: "bootstrap3"
  147 + });
  148 + }
  149 + });
  150 +JS;
  151 +
  152 + $this->view->registerJs($notify, \yii\web\View::POS_READY);
  153 +
  154 + $form = ActiveForm::begin();
  155 + if (!empty($this->action->languageFields)) {
  156 + echo str_replace(
  157 + [
  158 + '{tabs}',
  159 + '{title}',
  160 + ],
  161 + [
  162 + $this->generateLangBlock($form),
  163 + 'Языковой блок',
  164 + ],
  165 + $this->langBlockTemplate
  166 + );
  167 + }
  168 +
  169 + echo '<div class="x_panel x_panel-scroll">';
  170 +
  171 + echo '<div class="wrapp-blocks-edit-page columns-2">';
  172 + echo '<div class="style title-edit-page">Основной блок</div>';
  173 + $this->generateCommonBlock($form);
  174 + echo '</div>';
  175 +
  176 + echo '</div>';
  177 +
  178 + if ($this->action->hasAlias) {
  179 + echo str_replace(
  180 + [
  181 + '{tabs}',
  182 + '{title}',
  183 + ],
  184 + [
  185 + $this->generateAliasBlock($form),
  186 + 'Seo блок',
  187 + ],
  188 + $this->langBlockTemplate
  189 + );
  190 + }
  191 +
  192 + if ($this->action->hasGallery) {
  193 + echo '<div class="x_panel x_panel-scroll">';
  194 + echo '<div class="wrapp-blocks-edit-page">';
  195 + echo '<div class="style title-edit-page">Галерея</div>';
  196 + echo GalleryWidget::widget(
  197 + [
  198 + 'model' => $this->model,
  199 + ]
  200 + );
  201 + echo '</div>';
  202 + echo '</div>';
  203 + }
  204 +
  205 + echo '<div class="style buttons-page-wr">';
  206 + echo Html::submitButton(
  207 + \Yii::t('core', 'Save'),
  208 + [
  209 + 'class' => 'btn btn-success',
  210 + ]
  211 + );
  212 + echo '</div>';
  213 +
  214 + $form::end();
  215 +
  216 + $this->registerClientScripts();
  217 + }
  218 +
  219 + protected function registerClientScripts()
  220 + {
  221 + $js = <<<JS
  222 + $(document)
  223 + .on('click', '.pos-minus-adm', function(e) {
  224 + e.preventDefault();
  225 + var input = $(this)
  226 + .parent()
  227 + .find('input');
  228 + var newVal = parseInt(input.val()) - 1;
  229 + if (newVal > 0) {
  230 + input.val(newVal);
  231 + }
  232 + });
  233 + $(document)
  234 + .on('click', '.pos-pluse-adm', function(e) {
  235 + e.preventDefault();
  236 + var input = $(this)
  237 + .parent()
  238 + .find('input');
  239 + var newVal = parseInt((input.val() === '' ? 0 : input.val())) + 1;
  240 + input.val(newVal);
  241 + });
  242 +
  243 + $('#page-sort').keypress(function(e) {
  244 + var symbol = (e.which) ? e.which : e.keyCode;
  245 + if (symbol < 48 || symbol > 57) {
  246 + return false;
  247 + }
  248 + })
  249 +JS;
  250 +
  251 + $this->view->registerJs($js, \yii\web\View::POS_READY);
  252 + }
  253 +
  254 + /**
  255 + * If model has languages
  256 + *
  257 + * @param \yii\widgets\ActiveForm $form
  258 + *
  259 + * @return string
  260 + * @throws \yii\base\InvalidConfigException
  261 + */
  262 + protected function generateLangBlock(ActiveForm $form): string
  263 + {
  264 + $tabs = '';
  265 + $i = 1;
  266 + foreach ($this->getVariationModels() as $index => $variationModel) {
  267 + $tab = '';
  268 + foreach ($this->action->languageFields as $languageField) {
  269 + switch ($languageField[ 'type' ]) {
  270 + case self::STRING:
  271 + if (isset($languageField[ 'decorate' ]) and $languageField[ 'decorate' ]) {
  272 + $this->decorateField[ $index ] = $form->field(
  273 + $variationModel,
  274 + '[' . $index . ']' . $languageField[ 'name' ]
  275 + )
  276 + ->label(
  277 + self::getLanguageLabel(
  278 + $variationModel,
  279 + $languageField[ 'name' ],
  280 + $variationModel->language_id
  281 + )
  282 + );
  283 + $tab .= $this->decorateField[ $index ];
  284 + } else {
  285 + $tab .= $form->field($variationModel, '[' . $index . ']' . $languageField[ 'name' ])
  286 + ->label(
  287 + self::getLanguageLabel(
  288 + $variationModel,
  289 + $languageField[ 'name' ],
  290 + $variationModel->language_id
  291 + )
  292 + );
  293 + }
  294 + break;
  295 + case self::TEXTAREA:
  296 + $tab .= $form->field($variationModel, '[' . $index . ']' . $languageField[ 'name' ])
  297 + ->textarea(
  298 + [
  299 + 'rows' => 6,
  300 + ]
  301 + )
  302 + ->label(
  303 + self::getLanguageLabel(
  304 + $variationModel,
  305 + $languageField[ 'name' ],
  306 + $variationModel->language_id
  307 + )
  308 + );
  309 + break;
  310 + case self::IMAGE:
  311 + $tab .= $form->field(
  312 + $variationModel,
  313 + '[' . $index . ']' . $languageField[ 'name' ],
  314 + [ 'options' => [ 'class' => 'form-group filed-upload-imgs' ] ]
  315 + )
  316 + ->widget(
  317 + ImageInput::className(),
  318 + [
  319 + 'showPreview' => true,
  320 + ]
  321 + )
  322 + ->label(
  323 + self::getLanguageLabel(
  324 + $variationModel,
  325 + $languageField[ 'name' ],
  326 + $variationModel->language_id
  327 + )
  328 + );
  329 + break;
  330 + case self::WYSIWYG:
  331 + $tab .= $form->field($variationModel, '[' . $index . ']' . $languageField[ 'name' ])
  332 + ->widget(
  333 + TinyMce::className(),
  334 + $this->action->getTinyMceConfig()
  335 + )
  336 + ->label(
  337 + self::getLanguageLabel(
  338 + $variationModel,
  339 + $languageField[ 'name' ],
  340 + $variationModel->language_id
  341 + )
  342 + );
  343 + break;
  344 + default:
  345 + throw new InvalidConfigException(
  346 + \Yii::t(
  347 + 'core',
  348 + 'Unavailable or unknown type: {type}',
  349 + [
  350 + 'type' => $languageField[ 'type' ],
  351 + ]
  352 + )
  353 + );
  354 + }
  355 + }
  356 +
  357 + if ($variationModel->language_id === $this->languages->getDefault()->id) {
  358 + $tabs .= str_replace(
  359 + [
  360 + '{tab}',
  361 + '{display}',
  362 + ],
  363 + [
  364 + $tab,
  365 + 'block',
  366 + ],
  367 + $this->langTabTemplate
  368 + );
  369 + } else {
  370 + $tabs .= str_replace(
  371 + [
  372 + '{tab}',
  373 + '{display}',
  374 + ],
  375 + [
  376 + $tab,
  377 + 'none',
  378 + ],
  379 + $this->langTabTemplate
  380 + );
  381 + }
  382 +
  383 + $i++;
  384 + }
  385 +
  386 + return $tabs;
  387 + }
  388 +
  389 + /**
  390 + * Common block
  391 + *
  392 + * @param \yii\widgets\ActiveForm $form
  393 + *
  394 + * @throws \yii\base\InvalidConfigException
  395 + */
  396 + protected function generateCommonBlock(ActiveForm $form)
  397 + {
  398 + foreach ($this->action->fields as $field) {
  399 + switch ($field[ 'type' ]) {
  400 + case self::STRING:
  401 + echo $form->field($this->model, $field[ 'name' ]);
  402 + break;
  403 + case self::TEXTAREA:
  404 + echo $form->field($this->model, $field[ 'name' ])
  405 + ->textarea(
  406 + [
  407 + 'rows' => 6,
  408 + ]
  409 + );
  410 + break;
  411 + case self::WYSIWYG:
  412 + echo $form->field($this->model, $field[ 'name' ])
  413 + ->widget(
  414 + TinyMce::className(),
  415 + $this->action->getTinyMceConfig()
  416 + );
  417 + break;
  418 + case self::BOOL:
  419 + echo $form->field(
  420 + $this->model,
  421 + $field[ 'name' ],
  422 + [
  423 + 'template' => "<div class='div_ style' style='margin-bottom: 10px;'>{label}</div>\n{input}\n{error}",
  424 + ]
  425 + )
  426 + ->checkbox(
  427 + [
  428 + 'class' => 'switchery',
  429 + ],
  430 + false
  431 + );
  432 + break;
  433 + case self::NUMBER:
  434 + echo $form->field(
  435 + $this->model,
  436 + $field[ 'name' ],
  437 + [
  438 + 'template' => '{label}<span class="pos-minus-adm"></span>{input}<span class="pos-pluse-adm"></span>
  439 + {error}{hint}',
  440 + 'options' => [ 'class' => 'form-group filed-sort' ],
  441 + ]
  442 + );
  443 + break;
  444 + case self::RELATION:
  445 + $isMultiple = $field[ 'multiple' ] ?? false;
  446 + echo $form->field($this->model, $field[ 'name' ])
  447 + ->widget(
  448 + Select2::classname(),
  449 + [
  450 + 'data' => $this->action->relationalData[ $field[ 'name' ] ],
  451 + 'options' => [
  452 + 'placeholder' => \Yii::t('core', 'Select ...'),
  453 + 'multiple' => $isMultiple,
  454 + ],
  455 + 'pluginOptions' => [
  456 + 'allowClear' => true,
  457 + ],
  458 + ]
  459 + );
  460 + break;
  461 + case self::SELECT:
  462 + $isMultiple = $field[ 'multiple' ] ?? false;
  463 + echo $form->field($this->model, $field[ 'name' ])
  464 + ->widget(
  465 + Select2::classname(),
  466 + [
  467 + 'data' => $field['data'],
  468 + 'options' => [
  469 + 'placeholder' => \Yii::t('core', 'Select ...'),
  470 + 'multiple' => $isMultiple,
  471 + ],
  472 + 'pluginOptions' => [
  473 + 'allowClear' => true,
  474 + ],
  475 + ]
  476 + );
  477 +
  478 + break;
  479 + case self::IMAGE:
  480 + echo $form->field(
  481 + $this->model,
  482 + $field[ 'name' ],
  483 + [ 'options' => [ 'class' => 'form-group filed-upload-imgs' ] ]
  484 + )
  485 + ->widget(
  486 + ImageInput::className(),
  487 + [
  488 + 'showPreview' => true,
  489 + ]
  490 + );
  491 + break;
  492 + case self::DATE:
  493 + DateRangePicker::register($this->view);
  494 + $mindate = date("d-m-Y H:i");
  495 + $value = $this->model->{$field['name']};
  496 + $js = <<< JS
  497 +var dateRangeInputFrom = $('#date_field');
  498 +var dateFormat = '{$this->model->clientDateFormat}';
  499 +dateRangeInputFrom.daterangepicker({
  500 + singleDatePicker: true,
  501 + autoUpdateInput: true,
  502 + showDropdowns: true,
  503 + minDate: '{$mindate}',
  504 + timePicker: true,
  505 + timePicker24Hour: true,
  506 + locale: {
  507 + cancelLabel: 'Clear',
  508 + format: dateFormat
  509 + }
  510 +}, function(){
  511 +
  512 + });
  513 +dateRangeInputFrom.on('cancel.daterangepicker', function(ev, picker) {
  514 + //do something, like clearing an input
  515 + dateRangeInputFrom.val('');
  516 +});
  517 +if ("{$value}" == ""){
  518 + dateRangeInputFrom.val('');
  519 +}
  520 +JS;
  521 + $this->view->registerJs($js, \yii\web\View::POS_READY);
  522 + echo $form->field(
  523 + $this->model,
  524 + $field[ 'name' ],
  525 + [ 'options' => [ 'class' => 'form-group date-search' ] ]
  526 + )->textInput(['id' => "date_field"]);
  527 + break;
  528 +
  529 + default:
  530 + throw new InvalidConfigException(
  531 + \Yii::t(
  532 + 'core',
  533 + 'Unavailable or unknown type: {type}',
  534 + [
  535 + 'type' => $field[ 'type' ],
  536 + ]
  537 + )
  538 + );
  539 + }
  540 + }
  541 + }
  542 +
  543 + /**
  544 + * Generate seo block
  545 + *
  546 + * @param \yii\widgets\ActiveForm $form
  547 + *
  548 + * @return string
  549 + */
  550 + protected function generateAliasBlock(ActiveForm $form)
  551 + {
  552 + $tabs = '';
  553 + $i = 1;
  554 + foreach ($this->getAliases() as $index => $alias) {
  555 + $tab = '';
  556 + if (isset($this->decorateField[ $index ])) {
  557 + $tab .= '<div class="seo-btns-wr">' . SlugifyDecorator::decorate(
  558 + $form->field($alias, "[$index]value"),
  559 + [ '/seo/alias/slugify' ],
  560 + $this->decorateField[ $index ],
  561 + false,
  562 + $alias->language_id
  563 + )
  564 + ->textInput(
  565 + [ 'maxlength' => true ]
  566 + ) . "</div>";
  567 + } else {
  568 + $tab .= $form->field($alias, '[' . $index . ']value')
  569 + ->label(
  570 + self::getLanguageLabel($alias, 'value', $alias->language_id)
  571 + );
  572 + }
  573 +
  574 + $tab .= $form->field($alias, '[' . $index . ']title')
  575 + ->label(
  576 + self::getLanguageLabel($alias, 'title', $alias->language_id)
  577 + );
  578 +
  579 + $tab .= $form->field($alias, '[' . $index . ']description')
  580 + ->textarea(
  581 + [
  582 + 'rows' => 6,
  583 + ]
  584 + )
  585 + ->label(
  586 + self::getLanguageLabel($alias, 'description', $alias->language_id)
  587 + );
  588 +
  589 + $tab .= $form->field($alias, '[' . $index . ']h1')
  590 + ->label(
  591 + self::getLanguageLabel($alias, 'h1', $alias->language_id)
  592 + );
  593 +
  594 + $tab .= $form->field($alias, '[' . $index . ']seo_text')
  595 + ->widget(
  596 + TinyMce::className(),
  597 + $this->action->getTinyMceConfig()
  598 + )
  599 + ->label(
  600 + self::getLanguageLabel($alias, 'seo_text', $alias->language_id)
  601 + );
  602 +
  603 + $tab .= $form->field($alias, '[' . $index . ']robots')
  604 + ->widget(
  605 + Select2::class,
  606 + [
  607 + 'data' => [
  608 + 'index, follow' => 'index, follow',
  609 + 'index, nofollow' => 'index, nofollow',
  610 + 'noindex, follow' => 'noindex, follow',
  611 + 'noindex, nofollow' => 'noindex, nofollow',
  612 + ],
  613 + ]
  614 + )
  615 + ->label(
  616 + self::getLanguageLabel($alias, 'robots', $alias->language_id)
  617 + );
  618 +
  619 + if ($alias->language_id === $this->languages->getDefault()->id) {
  620 + $tabs .= str_replace(
  621 + [
  622 + '{tab}',
  623 + '{display}',
  624 + ],
  625 + [
  626 + $tab,
  627 + 'block',
  628 + ],
  629 + $this->langTabTemplate
  630 + );
  631 + } else {
  632 + $tabs .= str_replace(
  633 + [
  634 + '{tab}',
  635 + '{display}',
  636 + ],
  637 + [
  638 + $tab,
  639 + 'none',
  640 + ],
  641 + $this->langTabTemplate
  642 + );
  643 + }
  644 +
  645 + $i++;
  646 + }
  647 +
  648 + return $tabs;
  649 + }
  650 +
  651 + /**
  652 + * Appends language short name to label
  653 + *
  654 + * @param \yii\db\ActiveRecord $model
  655 + * @param string $field
  656 + * @param $language_id
  657 + *
  658 + * @return string
  659 + */
  660 + protected static function getLanguageLabel(ActiveRecord $model, string $field, $language_id): string
  661 + {
  662 + $languages = Language::getActive();
  663 + return $model->getAttributeLabel(
  664 + $field
  665 + ) . ' (' . $languages[ $language_id ]->url . ')';
  666 +
  667 + }
  668 +
  669 + /**
  670 + * @return ActiveRecord[]
  671 + */
  672 + protected function getVariationModels(): array
  673 + {
  674 + return call_user_func(
  675 + [
  676 + $this->model,
  677 + 'getVariationModels',
  678 + ]
  679 + );
  680 + }
  681 +
  682 + /**
  683 + * @return \artbox\core\models\Alias[]
  684 + */
  685 + protected function getAliases(): array
  686 + {
  687 + return call_user_func(
  688 + [
  689 + $this->model,
  690 + 'loadAliases',
  691 + ]
  692 + );
  693 + }
  694 + }
  695 +
  696 +?>
  697 +
  698 +
  699 +
... ...
console/migrations/m180831_083021_alter_page_columns.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +/**
  6 + * Class m180831_083021_alter_page_columns
  7 + */
  8 +class m180831_083021_alter_page_columns extends Migration
  9 +{
  10 + /**
  11 + * {@inheritdoc}
  12 + */
  13 + public function safeUp()
  14 + {
  15 + $this->dropColumn('page', 'created_at');
  16 + $this->dropColumn('page', 'updated_at');
  17 +
  18 + $this->addColumn('page', 'created_at', $this->integer());
  19 + $this->addColumn('page', 'updated_at', $this->integer());
  20 + }
  21 +
  22 + /**
  23 + * {@inheritdoc}
  24 + */
  25 + public function safeDown()
  26 + {
  27 + $this->dropColumn('page', 'created_at');
  28 + $this->dropColumn('page', 'updated_at');
  29 +
  30 + $this->addColumn('page', 'created_at', $this->timestamp());
  31 + $this->addColumn('page', 'updated_at', $this->timestamp());
  32 + }
  33 +
  34 + /*
  35 + // Use up()/down() to run migration code without a transaction.
  36 + public function up()
  37 + {
  38 +
  39 + }
  40 +
  41 + public function down()
  42 + {
  43 + echo "m180831_083021_alter_page_columns cannot be reverted.\n";
  44 +
  45 + return false;
  46 + }
  47 + */
  48 +}
... ...
frontend/views/layouts/main.php
... ... @@ -139,17 +139,16 @@ JS;
139 139 <div class="col-xs-12 col-sm-9">
140 140 <nav>
141 141 <ul>
  142 + <?php foreach ($pageCategories as $category){?>
142 143 <li>
143   - <a href="#">ПРО ЗАХІД</a>
  144 + <a href="#"><?=$category->language->title?></a>
144 145 <ul>
145   - <li><a href="#">Результати минулих форумів</a></li>
146   - <li><a href="#">Концептуальна записка</a></li>
147   - <li><a href="#">Офіційні документи</a></li>
  146 + <?php foreach ($category->pages as $page){?>
  147 + <li><a href="<?=Url::to(['alias' => $page->alias])?>"><?=$page->language->title?></a></li>
  148 + <?php }?>
148 149 </ul>
149 150 </li>
150   - <li><a href="#">ОРГАНІЗАТОРИ</a></li>
151   - <li><a href="#">ПРОГРАМА ЗАХОДУ</a></li>
152   - <li><a href="#">ПЛАНУВАННЯ</a></li>
  151 + <?php }?>
153 152 <li><a href="<?=Url::to(['site/register'])?>"><?=Yii::t('app', 'РЕЄСТРАЦІЯ')?></a></li>
154 153 <li><a href="<?=Url::to(['site/contacts'])?>"><?=Yii::t('app', 'КОНТАКТИ')?></a></li>
155 154 </ul>
... ... @@ -178,19 +177,18 @@ JS;
178 177 <div class="mobi-menu-primary">
179 178 <ul class="mobi-menu-primary-ul">
180 179 <li><a href="#">Главная</a></li>
  180 + <?php foreach ($pageCategories as $category){ ?>
181 181 <li>
182   - <a href="#">ПРО ЗАХІД</a>
  182 + <a href="#"><?=$category->language->title?></a>
183 183 <div class="sub-menu-hidden-mob">
184 184 <ul>
185   - <li><a href="#">Результати минулих форумів</a></li>
186   - <li><a href="#">Концептуальна записка</a></li>
187   - <li><a href="#">Офіційні документи</a></li>
  185 + <?php foreach ($category->pages as $page){?>
  186 + <li><a href="<?=Url::to(['alias' => $page->alias])?>"><?=$page->language->title?></a></li>
  187 + <?php }?>
188 188 </ul>
189 189 </div>
190 190 </li>
191   - <li><a href="#">ОРГАНІЗАТОРИ</a></li>
192   - <li><a href="#">ПРОГРАМА ЗАХОДУ</a></li>
193   - <li><a href="#">ПЛАНУВАННЯ</a></li>
  191 + <?php }?>
194 192 <li><a href="<?=Url::to(['site/register'])?>"><?=Yii::t('app', 'РЕЄСТРАЦІЯ')?></a></li>
195 193 <li><a href="<?=Url::to(['site/contacts'])?>"><?=Yii::t('app', 'КОНТАКТИ')?></a></li>
196 194 </ul>
... ...
frontend/views/page/view.php
... ... @@ -18,54 +18,15 @@
18 18 $this->params[ 'breadcrumbs' ][] = $seo->title;
19 19 ?>
20 20  
21   -<div id="content">
  21 +<section class="section-text">
22 22 <div class="container">
23   -
24 23 <div class="row">
25   -
26   - <!-- *** LEFT COLUMN ***
27   -_________________________________________________________ -->
28   - <div class="col-md-9 clearfix">
29   - <section>
30   - <div id="text-page">
31   -
32   - <?= $model->body ?>
33   -
34   - </div>
35   - </section>
36   -
37   - <?php if (!empty($images)) { ?>
38   - <section>
39   - <div class="project owl-carousel">
40   -
41   - <?php foreach ($images as $image) { ?>
42   - <div class="item">
43   - <img class="img-responsive" src="<?= $image->getUrl() ?>" alt="">
44   - </div>
45   - <?php } ?>
46   -
47   - </div>
48   - <!-- /.project owl-slider -->
49   - </section>
50   -
51   - <?php } ?>
52   -
  24 + <div class="col-xs-12">
  25 + <h1 class="text-page-title"><?=$model->language->title?></h1>
  26 + </div>
  27 + <div class="col-xs-12 editor-home">
  28 + <?=$model->language->body?>
53 29 </div>
54   - <!-- /.col-md-9 -->
55   -
56   - <!-- *** LEFT COLUMN END *** -->
57   -
58   - <!-- *** RIGHT COLUMN ***
59   -
60   - <!-- /.col-md-3 -->
61   -
62   - <!-- *** RIGHT COLUMN END *** -->
63   -
64   -
65 30 </div>
66   - <!-- /.row -->
67   -
68 31 </div>
69   - <!-- /.container -->
70   -</div>
71   -<!-- /#content -->
  32 +</section>
... ...