From: vladfo Date: Fri, 19 Jul 2024 13:07:07 +0000 (+0300) Subject: added motivation_values migration model controller and views X-Git-Tag: 1.4~18^2^2~5 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=cb9011034f01662c3ab33ea8cdd0297fb9d36557;p=erp24_rep%2Fyii-erp24%2F.git added motivation_values migration model controller and views --- diff --git a/erp24/migrations/m240719_090134_create_motivation_values_table.php b/erp24/migrations/m240719_090134_create_motivation_values_table.php index a4897193..f87eb3ed 100644 --- a/erp24/migrations/m240719_090134_create_motivation_values_table.php +++ b/erp24/migrations/m240719_090134_create_motivation_values_table.php @@ -5,6 +5,7 @@ use yii\db\Migration; /** * Handles the creation of table `{{%motivation_values}}`. */ + class m240719_090134_create_motivation_values_table extends Migration { /** @@ -12,21 +13,21 @@ 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); - - } /** @@ -37,5 +38,8 @@ class m240719_090134_create_motivation_values_table extends Migration $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 diff --git a/erp24/records/MotivationValue.php b/erp24/records/MotivationValue.php index 0d08527f..51cfd79d 100644 --- a/erp24/records/MotivationValue.php +++ b/erp24/records/MotivationValue.php @@ -6,22 +6,46 @@ use yii\db\ActiveRecord; 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 [ @@ -32,6 +56,9 @@ class MotivationValue extends ActiveRecord ]; } + /** + * {@inheritdoc} + */ public function attributeLabels() { return [ @@ -43,4 +70,18 @@ class MotivationValue extends ActiveRecord '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 diff --git a/erp24/views/motivation/_form.php b/erp24/views/motivation/_form.php index 5b02a98b..a8deb6c6 100644 --- a/erp24/views/motivation/_form.php +++ b/erp24/views/motivation/_form.php @@ -1,5 +1,4 @@ field($model, 'name')->textInput(['maxlength' => true]) ?> - field($model, 'data_type')->textInput(['maxlength' => true]) ?> + field($model, 'data_type')->dropDownList( + $model::getDataTypeList(), + ['prompt' => 'Выберите тип данных'] + ) ?> field($model, 'is_active')->checkbox() ?>