--- /dev/null
+<?php
+
+namespace yii_app\actions\motivation;
+
+use yii\base\Action;
+use yii_app\records\MotivationCostsItem;
+use yii\web\NotFoundHttpException;
+
+abstract class BaseMotivationAction extends Action
+{
+ protected function findModel($id)
+ {
+ if (($model = MotivationCostsItem::findOne($id)) !== null) {
+ return $model;
+ }
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+}
\ No newline at end of file
use yii\web\NotFoundHttpException;
use yii\base\Action;
-class DeleteValueAction extends Action
+class DeleteValueAction extends BaseMotivationAction
{
public function run($id)
{
return $this->controller->redirect(['values']);
}
- private function findModel($id)
- {
- if (($model = MotivationCostsItem::findOne($id)) !== null) {
- return $model;
- }
-
- throw new NotFoundHttpException('Данной записи не существует');
- }
+
}
\ No newline at end of file
use yii\web\NotFoundHttpException;
use yii\base\Action;
-class UpdateValueAction extends Action
+class UpdateValueAction extends BaseMotivationAction
{
public function run($id)
{
]);
}
- private function findModel($id)
- {
- if (($model = MotivationCostsItem::findOne($id)) !== null) {
- return $model;
- }
-
- throw new NotFoundHttpException('Данной записи не существует');
- }
+
}
\ No newline at end of file
+++ /dev/null
-<?php
-
-use yii\db\Migration;
-
-/**
- * Handles the creation of table `{{%motivation_costs_items}}`.
- */
-
-class m240719_090134_create_motivation_values_table extends Migration
-{
- /**
- * {@inheritdoc}
- */
- 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(),
- // 'code' => $this->string()->notNull(),
- // 'data_type' => "data_type_enum NOT NULL",
- // 'order' => $this->integer()->notNull(),
- // 'is_active' => $this->boolean()->defaultValue(true),
- // 'created_at' => $this->datetime()->notNull()->comment('дата создания записи'),
- // 'updated_at' => $this->datetime()->notNull()->comment('дата изменения записи'),
- // ]);
-
- //$this->createIndex('idx-motivation_values-name', '{{%motivation_values}}', 'name', true);
- }
-
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- //$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
'updated_at' => $this->datetime()->notNull()->comment('дата изменения записи'),
]);
- $this->createIndex('idx-motivation_costs_items-name', '{{%motivation_costs_items}}', 'name', true);
- $this->createIndex('idx-motivation_costs_items-code', '{{%motivation_costs_items}}', 'code', true);
+
}
/**
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'name',
- 'data_type',
+ [
+ 'attribute' => 'data_type',
+ 'value' => function ($model) {
+ $dataTypeList = $model::getDataTypeList();
+ return isset($dataTypeList[$model->data_type]) ? $dataTypeList[$model->data_type] : $model->data_type;
+ },
+ ],
'code',
'order',
'is_active:boolean',