public function load($data, $formName = null) { $result = parent::load($data, $formName); // TODO: Change the autogenerated stub if (isset($data['Generator'])) { foreach ($data['Generator'] as $attr => $value) { if (is_array($value)) { $this->{$attr} = new BaseModelGenerator(ArrayHelper::merge($value, ['additionName' => 'Generator[' . $attr . ']', 'createForm' => false, 'customBehaviors' => ['trans' => ['title' => 'Multilingual behavior', 'alias' => 'trans', 'checked' => true, 'languageField' => $this->languageField ?: 'language', 'langClassSuffix' => '', 'dynamicLangClass' => false, 'requireTranslations' => false, 'abridge' => false, 'langForeignKey' => '', 'attributesLang' => 'title, body, lang', 'langClassName' => '', 'languages' => null, 'class' => 'omgdef\\multilingual\\MultilingualBehavior']], 'addUseQuery' => $attr == 'baseModel' ? 'use omgdef\\multilingual\\MultilingualTrait;' . PHP_EOL : '', 'addTraitsQuery' => $attr == 'baseModel' ? 'use MultilingualTrait;' . PHP_EOL : '', 'translateGenerator' => $attr == 'baseModel' ? true : false])); $this->{$attr}->tableBuilder = new TableGenerator($value['tableBuilder']); $this->{$attr}->behaviorModels = []; foreach ($value['behaviorModels'] as $_next) { $this->{$attr}->behaviorModels[] = new Behaviors($_next); } } else { $this->{$attr} = $value; } } $result = $this->baseModel->validate(); if (!$result) { $this->addError('baseModel', 'Base model error data'); } $result = $this->translateModel->validate(); if (!$result) { $this->addError('translateModel', 'Translate model error data'); } $tblName = $this->baseModel->createTable ? $this->baseModel->tableBuilder->tableName : $this->baseModel->tableName; $table_name = preg_replace('/({{%)(\\w+)(}})?/', "\$2", $tblName); $db = $this->baseModel->db; /** @var Connection $_conn */ $_conn = Yii::$app->{$db}; $this->translateModel->addNewField($_conn->schema->getRawTableName($table_name) . '_' . $this->baseModel->tableBuilder->primaryKeyName, Schema::TYPE_INTEGER, 'Origin content', $tblName, $this->baseModel->tableBuilder->primaryKeyName); } return $result; }
public function load($data, $formName = null) { $result = parent::load($data, $formName); // TODO: Change the autogenerated stub if (isset($data['Generator'])) { foreach ($data['Generator'] as $attr => $value) { if (is_array($value)) { $this->{$attr} = new BaseModelGenerator(ArrayHelper::merge($value, ['additionName' => 'Generator[' . $attr . ']', 'createForm' => false])); $this->{$attr}->tableBuilder = new TableGenerator($value['tableBuilder']); $this->{$attr}->behaviorModels = []; foreach ($value['behaviorModels'] as $_next) { $this->{$attr}->behaviorModels[] = new Behaviors($_next); } } else { $this->{$attr} = $value; } } $result = $this->baseModel->validate(); if (!$result) { $this->addError('baseModel', 'Base model error data'); } $result = $this->translateModel->validate(); if (!$result) { $this->addError('translateModel', 'Translate model error data'); } $tblName = $this->baseModel->createTable ? $this->baseModel->tableBuilder->tableName : $this->baseModel->tableName; $table_name = preg_replace('/({{%)(\\w+)(}})?/', "\$2", $tblName); $db = $this->baseModel->db; /** @var Connection $_conn */ $_conn = Yii::$app->{$db}; $this->translateModel->addNewField($_conn->schema->getRawTableName($table_name) . '_' . $this->baseModel->tableBuilder->primaryKeyName, Schema::TYPE_INTEGER, 'Origin content', $tblName, $this->baseModel->tableBuilder->primaryKeyName); } return $result; }
/** * Loads the generator with the specified ID. * @param string $id the ID of the generator to be loaded. * @return \yii\gii\Generator the loaded generator * @throws NotFoundHttpException */ protected function loadGenerator($id) { if (isset($this->module->generators[$id])) { $this->generator = $this->module->generators[$id]; $this->generator->loadStickyAttributes(); $this->generator->load($_POST); return $this->generator; } else { throw new NotFoundHttpException("Code generator not found: {$id}"); } }
/** * @inheritdoc */ public function load($data, $formName = null) { if (!parent::load($data, $formName)) { return false; } $this->migrationName = preg_replace('/\\s+/', '_', $this->migrationName); $dataFix = ['Table' => [], 'Column' => []]; if (isset($data['Table'])) { foreach ($data['Table'] as $temp) { $dataFix['Table'][] = $temp; } } if (isset($data['Column'])) { foreach ($data['Column'] as $temp) { $columnFix = []; foreach ($temp as $colTemp) { $columnFix[] = $colTemp; } $temp = $columnFix; $dataFix['Column'][] = $temp; } } if (isset($data['Index'])) { foreach ($data['Index'] as $temp) { $dataFix['Index'][] = $temp; } } if (isset($data['ForeignKey'])) { foreach ($data['ForeignKey'] as $temp) { $dataFix['ForeignKey'][] = $temp; } } $data = $dataFix; if (isset($data['Table'])) { $this->tables = static::createMultiple(Table::className(), [], $data); Table::loadMultiple($this->tables, $data); $loadData = []; for ($i = 0; $i < count($this->tables); ++$i) { $loadData['Column'] = $data['Column'][$i]; $this->tables[$i]->columns = static::createMultiple(Column::className(), [], $loadData); $this->tables[$i]->isNewRecord = false; Column::loadMultiple($this->tables[$i]->columns, $loadData); } } else { $this->tables = [new Table()]; } if (isset($data['Index'])) { $this->indices = static::createMultiple(Index::className(), [], $data); Index::loadMultiple($this->indices, $data); foreach ($this->indices as $index) { $index->isNewRecord = false; } } else { $this->indices = [new Index()]; } if (isset($data['ForeignKey'])) { $this->foreignKeys = static::createMultiple(ForeignKey::className(), [], $data); ForeignKey::loadMultiple($this->foreignKeys, $data); foreach ($this->foreignKeys as $fKey) { $fKey->isNewRecord = false; } } else { $this->foreignKeys = [new ForeignKey()]; } return true; }