public static function primaryKey() { return ', Helper::implode($primaryKey->key, 2), '; } '; } // title key $titleKey = $tableSchema->tk; if ($titleKey) { echo ' /** * @inheritdoc */ public static function titleKey() { return ', Helper::implode($titleKey->key, 2), '; } /** * @inheritdoc */ // public function getTitleText() // { // return $this->', implode(' . static::TITLE_SEPARATOR . $this->', $titleKey->key), '; // } '; } // methods "new" foreach ($allRelations as $relationName => $relation) { if (!$relation['direct'] && !$relation['viaTable']) { if ($relation['hasMany']) {
if ($relation['direct']) { $depends[] = $relationFixtureClass; } else { $backDepends[] = $relationFixtureClass; } } } } if (count($depends)) { echo ' public $depends = ', Helper::implode($depends, 1), '; '; } if (count($backDepends)) { echo ' public $backDepends = ', Helper::implode($backDepends, 1), '; '; } echo ' /*[ '; /* @var $columns yii\gii\plus\db\ColumnSchema[] */ $columns = array_values($tableSchema->columns); foreach ($columns as $i => $column) { $comma = $i < count($columns) - 1 ? ',' : ''; echo ' \'', $column->name, '\' => \'\'', $comma, ' '; } echo ' ]*/ public $dataFile = \'', $dataFile, '\';
/** * @inheritdoc * @param \yii\gii\plus\db\TableSchema $table */ public function generateRules($table) { $booleanAttributes = []; $integerAttributes = []; $uIntegerAttributes = []; $numberAttributes = []; $uNumberAttributes = []; $dateFormats = []; $matchPatterns = []; $defaultExpressions = []; $defaultValues = []; $defaultNullAttributes = []; foreach ($table->columns as $column) { if ($column->autoIncrement) { continue; } if ($column->getIsBoolean()) { $booleanAttributes[] = $column->name; } elseif ($column->getIsInteger()) { if ($column->unsigned) { $uIntegerAttributes[] = $column->name; } else { $integerAttributes[] = $column->name; } } elseif ($column->getIsNumber()) { if ($column->unsigned) { $uNumberAttributes[] = $column->name; } else { $numberAttributes[] = $column->name; } } if ($column->getHasDateFormat()) { $dateFormats[$column->getDateFormat()][] = $column->name; } if ($column->getHasPattern()) { $matchPatterns[$column->getPattern()][] = $column->name; } if (!is_null($column->defaultValue)) { if ($column->defaultValue instanceof Expression) { $this->relationUses[$table->fullName][] = 'yii\\db\\Expression'; $defaultExpressions[$column->defaultValue->expression][] = $column->name; } else { $defaultValues[$column->defaultValue][] = $column->name; } } elseif ($column->allowNull) { $defaultNullAttributes[] = $column->name; } } $rules = []; if (count($booleanAttributes)) { $rules[] = '[' . Helper::implode($booleanAttributes, 3) . ', \'filter\', \'filter\' => function ($value) {' . "\n" . ' return $value ? 1 : 0;' . "\n" . ' }, \'skipOnEmpty\' => true]'; $rules[] = '[' . Helper::implode($booleanAttributes, 3) . ', \'boolean\']'; } if (count($integerAttributes)) { $rules[] = '[' . Helper::implode($integerAttributes, 3) . ', \'integer\']'; } if (count($uIntegerAttributes)) { $rules[] = '[' . Helper::implode($uIntegerAttributes, 3) . ', \'integer\', \'min\' => 0]'; } if (count($numberAttributes)) { $rules[] = '[' . Helper::implode($numberAttributes, 3) . ', \'number\']'; } if (count($uNumberAttributes)) { $rules[] = '[' . Helper::implode($uNumberAttributes, 3) . ', \'number\', \'min\' => 0]'; } foreach ($dateFormats as $dateFormat => $attributes) { $rules[] = '[' . Helper::implode($attributes, 3) . ', \'filter\', \'filter\' => function ($value) { return is_int($value) ? date(\'' . substr($dateFormat, 4) . '\', $value) : $value; }]'; } foreach ($dateFormats as $dateFormat => $attributes) { $rules[] = '[' . Helper::implode($attributes, 3) . ', \'date\', \'format\' => \'' . $dateFormat . '\']'; } foreach ($matchPatterns as $matchPattern => $attributes) { $rules[] = '[' . Helper::implode($attributes, 3) . ', \'match\', \'pattern\' => \'' . $matchPattern . '\']'; } foreach (parent::generateRules($table) as $rule) { if (preg_match('~, \'(?:safe|boolean|integer|number)\'\\]$~', $rule)) { continue; } $rules[] = $rule; } foreach ($defaultExpressions as $defaultExpression => $attributes) { $rules[] = '[' . Helper::implode($attributes, 3) . ', \'default\', \'value\' => new Expression(\'' . $defaultExpression . '\')]'; } foreach ($defaultValues as $defaultValue => $attributes) { $rules[] = '[' . Helper::implode($attributes, 3) . ', \'default\', \'value\' => \'' . $defaultValue . '\']'; } if (count($defaultNullAttributes)) { $rules[] = '[' . Helper::implode($defaultNullAttributes, 3) . ', \'default\', \'value\' => null]'; } return $rules; }