Fix blocks content

parent 15b534c0
...@@ -4,6 +4,9 @@ namespace common\modules\content\models; ...@@ -4,6 +4,9 @@ namespace common\modules\content\models;
use Yii; use Yii;
use common\modules\languages\models\Languages;
use common\modules\content\models\CoBlocksLang;
/** /**
* This is the model class for table "co_blocks". * This is the model class for table "co_blocks".
* *
...@@ -51,12 +54,9 @@ class CoBlocks extends \common\components\ActiveRecordModel ...@@ -51,12 +54,9 @@ class CoBlocks extends \common\components\ActiveRecordModel
[['title', 'name', 'text'], 'required'], [['title', 'name', 'text'], 'required'],
[['text'], 'string'], [['text'], 'string'],
[['category_id'], 'safe'], [['category_id'], 'safe'],
[['lang'], 'string', 'max' => 2],
[['module'], 'string', 'max' => 100],
[['title'], 'string', 'max' => 250], [['title'], 'string', 'max' => 250],
[['name'], 'string', 'max' => 50], [['name'], 'string', 'max' => 50],
[['lang', 'title'], 'unique', 'targetAttribute' => ['lang', 'title'], 'message' => 'The combination of Язык and Заголовок has already been taken.'], [['name'], 'unique']
[['lang', 'name'], 'unique', 'targetAttribute' => ['lang', 'name'], 'message' => 'The combination of Язык and Название (англ.) has already been taken.']
]; ];
} }
......
...@@ -6,6 +6,7 @@ use Yii; ...@@ -6,6 +6,7 @@ use Yii;
use common\modules\content\models\CoContent; use common\modules\content\models\CoContent;
use common\modules\languages\models\Languages; use common\modules\languages\models\Languages;
use common\modules\content\models\CoBlocks;
/** /**
* This is the model class for table "co_content_lang". * This is the model class for table "co_content_lang".
...@@ -91,28 +92,32 @@ class CoContentLang extends \common\components\ActiveRecordModel ...@@ -91,28 +92,32 @@ class CoContentLang extends \common\components\ActiveRecordModel
{ {
$content = $this->text; $content = $this->text;
$content = \common\components\AppManager::prepareWidget($content); $content = \common\components\AppManager::prepareWidget($content);
$blocks = CoBlocks::find()->all();
$arrWhatReplace = []; $arrWhatReplace = [];
$arrReplace = []; $arrReplace = [];
$arrWhatReplaceNext = []; $arrWhatReplaceNext = [];
$arrReplaceNext = []; $arrReplaceNext = [];
foreach($blocks as $block) {
$blocks = CoBlocks::find()->all();
foreach($blocks as $block)
{
$arrWhatReplace[] = '{' . $block->name . '}'; $arrWhatReplace[] = '{' . $block->name . '}';
$arrReplace[] = $block->text; $arrReplace[] = $block->lang->text;
$arrWhatReplaceNext[] = '[' . $block->name . ']'; $arrWhatReplaceNext[] = '[' . $block->name . ']';
$arrReplaceNext[] = $block->text; $arrReplaceNext[] = $block->lang->text;
} }
$arrWhatReplaceNext[] = '[about-reviews]'; $arrWhatReplaceNext[] = '[about-reviews]';
$arrReplaceNext[] = \common\modules\content\models\CoBlocks::printStaticBlock('about-reviews', true); $arrReplaceNext[] = CoBlocks::printStaticBlock('about-reviews', true);
$arrWhatReplaceNext[] = '[content-phone]'; $arrWhatReplaceNext[] = '[content-phone]';
$arrReplaceNext[] = \common\models\Settings::getValue('content-phone'); $arrReplaceNext[] = \common\models\Settings::getValue('content-phone');
$arrWhatReplaceNext[] = '[cases]'; $arrWhatReplaceNext[] = '[cases]';
$arrReplaceNext[] = \common\modules\content\models\CoBlocks::printStaticBlock('cases', true); $arrReplaceNext[] = CoBlocks::printStaticBlock('cases', true);
$arrWhatReplaceNext[] = '[projects]'; $arrWhatReplaceNext[] = '[projects]';
$arrReplaceNext[] = \common\modules\content\models\CoBlocks::printStaticBlock('projects', true); $arrReplaceNext[] = CoBlocks::printStaticBlock('projects', true);
$arrWhatReplaceNext[] = '[case-subscribe]'; $arrWhatReplaceNext[] = '[case-subscribe]';
$arrReplaceNext[] = \common\modules\content\models\CoBlocks::printStaticBlock('case-subscribe', true); $arrReplaceNext[] = CoBlocks::printStaticBlock('case-subscribe', true);
$arrWhatReplaceNext[] = '[footer]'; $arrWhatReplaceNext[] = '[footer]';
$arrReplaceNext[] = \Yii::$app->getView()->render('@app/views/layouts/footer'); $arrReplaceNext[] = \Yii::$app->getView()->render('@app/views/layouts/footer');
$arrWhatReplaceNext[] = '[footer-index]'; $arrWhatReplaceNext[] = '[footer-index]';
......
...@@ -11,6 +11,9 @@ class m160203_080816_fix_content extends Migration ...@@ -11,6 +11,9 @@ class m160203_080816_fix_content extends Migration
$this->dropColumn('co_blocks_lang', 'name'); $this->dropColumn('co_blocks_lang', 'name');
$this->dropColumn('co_blocks_lang', 'title'); $this->dropColumn('co_blocks_lang', 'title');
$this->dropColumn('co_blocks', 'lang');
$this->dropColumn('co_blocks', 'module');
$this->dropColumn('co_content', 'name'); $this->dropColumn('co_content', 'name');
$this->dropColumn('co_content', 'title'); $this->dropColumn('co_content', 'title');
$this->dropColumn('co_content', 'text'); $this->dropColumn('co_content', 'text');
...@@ -21,6 +24,9 @@ class m160203_080816_fix_content extends Migration ...@@ -21,6 +24,9 @@ class m160203_080816_fix_content extends Migration
$this->addColumn('co_blocks_lang', 'name', Schema::TYPE_STRING.'(50) NOT NULL'); $this->addColumn('co_blocks_lang', 'name', Schema::TYPE_STRING.'(50) NOT NULL');
$this->addColumn('co_blocks_lang', 'title', Schema::TYPE_STRING.'(250) NOT NULL'); $this->addColumn('co_blocks_lang', 'title', Schema::TYPE_STRING.'(250) NOT NULL');
$this->addColumn('co_blocks', 'lang', "char(2) DEFAULT 'ru'");
$this->addColumn('co_blocks', 'module', Schema::TYPE_STRING.'(100) NOT NULL');
$this->addColumn('co_content', 'name', Schema::TYPE_STRING.'(250) NOT NULL'); $this->addColumn('co_content', 'name', Schema::TYPE_STRING.'(250) NOT NULL');
$this->addColumn('co_content', 'title', Schema::TYPE_STRING.'(250) NOT NULL'); $this->addColumn('co_content', 'title', Schema::TYPE_STRING.'(250) NOT NULL');
$this->addColumn('co_content', 'text', 'longtext DEFAULT NULL'); $this->addColumn('co_content', 'text', 'longtext DEFAULT NULL');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment