/**
* Handles the creation of table `{{%motivation_values}}`.
*/
+
class m240719_090134_create_motivation_values_table extends Migration
{
/**
*/
public function safeUp()
{
-
$this->execute('SET search_path TO erp24');
+ // Создаем тип ENUM
+ $this->execute("CREATE TYPE data_type_enum AS ENUM ('int', 'float', 'string')");
+
$this->createTable('{{%motivation_values}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull(),
- 'data_type' => $this->string()->notNull(),
+ 'data_type' => "data_type_enum NOT NULL",
'is_active' => $this->boolean()->defaultValue(true),
'created_at' => $this->timestamp()->defaultExpression('CURRENT_TIMESTAMP'),
'updated_at' => $this->timestamp()->defaultExpression('CURRENT_TIMESTAMP'),
]);
$this->createIndex('idx-motivation_values-name', '{{%motivation_values}}', 'name', true);
-
-
}
/**
$this->execute('SET search_path TO erp24');
$this->dropTable('{{%motivation_values}}');
+
+ // Удаляем тип ENUM
+ $this->execute('DROP TYPE data_type_enum');
}
-}
+}
\ No newline at end of file
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
+/**
+ * This is the model class for table "{{%motivation_values}}".
+ *
+ * @property int $id
+ * @property string $name
+ * @property string $data_type
+ * @property bool $is_active
+ * @property string $created_at
+ * @property string $updated_at
+ */
class MotivationValue extends ActiveRecord
{
+ const DATA_TYPE_INT = 'int';
+ const DATA_TYPE_FLOAT = 'float';
+ const DATA_TYPE_STRING = 'string';
+
+ /**
+ * {@inheritdoc}
+ */
public static function tableName()
{
return '{{%motivation_values}}';
}
+ /**
+ * {@inheritdoc}
+ */
public function rules()
{
return [
[['name', 'data_type'], 'required'],
- [['name', 'data_type'], 'string', 'max' => 255],
- [['is_active'], 'boolean'],
+ ['name', 'string', 'max' => 255],
+ ['data_type', 'in', 'range' => [self::DATA_TYPE_INT, self::DATA_TYPE_FLOAT, self::DATA_TYPE_STRING]],
+ ['is_active', 'boolean'],
];
}
+ /**
+ * {@inheritdoc}
+ */
public function behaviors()
{
return [
];
}
+ /**
+ * {@inheritdoc}
+ */
public function attributeLabels()
{
return [
'updated_at' => 'Обновлен',
];
}
+
+ /**
+ * Get list of available data types
+ *
+ * @return array
+ */
+ public static function getDataTypeList()
+ {
+ return [
+ self::DATA_TYPE_INT => 'Целое число',
+ self::DATA_TYPE_FLOAT => 'Число с плавающей точкой',
+ self::DATA_TYPE_STRING => 'Строка',
+ ];
+ }
}
\ No newline at end of file
<?php
-
use yii\helpers\Html;
use yii\widgets\ActiveForm;
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
- <?= $form->field($model, 'data_type')->textInput(['maxlength' => true]) ?>
+ <?= $form->field($model, 'data_type')->dropDownList(
+ $model::getDataTypeList(),
+ ['prompt' => 'Выберите тип данных']
+ ) ?>
<?= $form->field($model, 'is_active')->checkbox() ?>