]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
added motivation_values migration model controller and views
authorvladfo <fvv2011@gmail.com>
Fri, 19 Jul 2024 13:07:07 +0000 (16:07 +0300)
committervladfo <fvv2011@gmail.com>
Fri, 19 Jul 2024 13:07:07 +0000 (16:07 +0300)
erp24/migrations/m240719_090134_create_motivation_values_table.php
erp24/records/MotivationValue.php
erp24/views/motivation/_form.php

index a489719325e527d1126972f7e3366c5ccb28d8c3..f87eb3ed52a6aadbb0a93f0e9f9f4efb84bf2481 100644 (file)
@@ -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
index 0d08527fff6b0980ff306fe35ca72266f3b27700..51cfd79de59392ba7814f725a41b8cfd2854cc62 100644 (file)
@@ -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
index 5b02a98b4c16d2c45acde172d895e80195bda0b2..a8deb6c62c488eef223a580f7a535a9867f8e753 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 use yii\helpers\Html;
 use yii\widgets\ActiveForm;
 
@@ -13,7 +12,10 @@ 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() ?>