From: vladfo Date: Fri, 19 Jul 2024 11:33:00 +0000 (+0300) Subject: added motivation_values migration model controller and views X-Git-Tag: 1.4~18^2^2~6 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ed1957094062ac0830ff1bf78db238d45ac69ec7;p=erp24_rep%2Fyii-erp24%2F.git added motivation_values migration model controller and views --- diff --git a/erp24/actions/motivation/CreateValueAction.php b/erp24/actions/motivation/CreateValueAction.php new file mode 100644 index 00000000..5fdabf2c --- /dev/null +++ b/erp24/actions/motivation/CreateValueAction.php @@ -0,0 +1,21 @@ +load(Yii::$app->request->post()) && $model->save()) { + return $this->controller->redirect(['values']); + } + return $this->controller->render('create-value', [ + 'model' => $model, + ]); + } +} \ No newline at end of file diff --git a/erp24/actions/motivation/DeleteValueAction.php b/erp24/actions/motivation/DeleteValueAction.php new file mode 100644 index 00000000..4976ca3c --- /dev/null +++ b/erp24/actions/motivation/DeleteValueAction.php @@ -0,0 +1,27 @@ +findModel($id)->delete(); + + return $this->controller->redirect(['values']); + } + + private function findModel($id) + { + if (($model = MotivationValue::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('Данной записи не существует'); + } +} \ No newline at end of file diff --git a/erp24/actions/motivation/UpdateValueAction.php b/erp24/actions/motivation/UpdateValueAction.php new file mode 100644 index 00000000..8a776454 --- /dev/null +++ b/erp24/actions/motivation/UpdateValueAction.php @@ -0,0 +1,33 @@ +findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->controller->redirect(['values']); + } + + return $this->controller->render('update-value', [ + 'model' => $model, + ]); + } + + private function findModel($id) + { + if (($model = MotivationValue::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('Данной записи не существует'); + } +} \ No newline at end of file diff --git a/erp24/actions/motivation/ValuesAction.php b/erp24/actions/motivation/ValuesAction.php new file mode 100644 index 00000000..90396f7c --- /dev/null +++ b/erp24/actions/motivation/ValuesAction.php @@ -0,0 +1,20 @@ + MotivationValue::find(), + ]); + return $this->controller->render('values', [ + 'dataProvider' => $dataProvider, + ]); + } +} \ No newline at end of file diff --git a/erp24/controllers/MotivationController.php b/erp24/controllers/MotivationController.php index 8175a6e3..f81c287b 100644 --- a/erp24/controllers/MotivationController.php +++ b/erp24/controllers/MotivationController.php @@ -4,12 +4,18 @@ namespace app\controllers; use yii\filters\AccessControl; use yii\web\Controller; +use yii\filters\VerbFilter; + class MotivationController extends Controller { public function actions() { return [ 'index' => \yii_app\actions\motivation\IndexAction::class, + 'values' => \yii_app\actions\motivation\ValuesAction::class, + 'create-value' => \yii_app\actions\motivation\CreateValueAction::class, + 'update-value' => \yii_app\actions\motivation\UpdateValueAction::class, + 'delete-value' => \yii_app\actions\motivation\DeleteValueAction::class, ]; } @@ -21,10 +27,16 @@ class MotivationController extends Controller 'rules' => [ [ 'allow' => true, - 'permissions' => ['menu/motivation'], + // 'permissions' => ['menu/motivation'], ] ] - ] + ], + 'verbs' => [ + 'class' => VerbFilter::class, + 'actions' => [ + 'delete-value' => ['POST'], + ], + ], ]; } } \ No newline at end of file diff --git a/erp24/migrations/m240719_090134_create_motivation_values_table.php b/erp24/migrations/m240719_090134_create_motivation_values_table.php new file mode 100644 index 00000000..a4897193 --- /dev/null +++ b/erp24/migrations/m240719_090134_create_motivation_values_table.php @@ -0,0 +1,41 @@ +execute('SET search_path TO erp24'); + + $this->createTable('{{%motivation_values}}', [ + 'id' => $this->primaryKey(), + 'name' => $this->string()->notNull(), + 'data_type' => $this->string()->notNull(), + '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); + + + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->execute('SET search_path TO erp24'); + + $this->dropTable('{{%motivation_values}}'); + } +} diff --git a/erp24/records/MotivationValue.php b/erp24/records/MotivationValue.php new file mode 100644 index 00000000..0d08527f --- /dev/null +++ b/erp24/records/MotivationValue.php @@ -0,0 +1,46 @@ + 255], + [['is_active'], 'boolean'], + ]; + } + + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::class, + 'value' => new Expression('NOW()'), + ], + ]; + } + + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Наименование', + 'data_type' => 'Тип данных', + 'is_active' => 'Активен', + 'created_at' => 'Создан', + 'updated_at' => 'Обновлен', + ]; + } +} \ No newline at end of file diff --git a/erp24/views/motivation/_form.php b/erp24/views/motivation/_form.php new file mode 100644 index 00000000..5b02a98b --- /dev/null +++ b/erp24/views/motivation/_form.php @@ -0,0 +1,25 @@ + + +
+ + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'data_type')->textInput(['maxlength' => true]) ?> + + field($model, 'is_active')->checkbox() ?> + +
+ 'btn btn-primary']) ?> +
+ + +
\ No newline at end of file diff --git a/erp24/views/motivation/create-value.php b/erp24/views/motivation/create-value.php new file mode 100644 index 00000000..ecb60a14 --- /dev/null +++ b/erp24/views/motivation/create-value.php @@ -0,0 +1,19 @@ +title = 'Создать значение мотивации'; +$this->params['breadcrumbs'][] = ['label' => 'Значения мотивации', 'url' => ['values']]; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> +
\ No newline at end of file diff --git a/erp24/views/motivation/update-value.php b/erp24/views/motivation/update-value.php new file mode 100644 index 00000000..1ef89a9a --- /dev/null +++ b/erp24/views/motivation/update-value.php @@ -0,0 +1,20 @@ +title = 'Обновить значение мотивации: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Значения мотивации', 'url' => ['values']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Обновить'; +?> + +
+

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> +
\ No newline at end of file diff --git a/erp24/views/motivation/values.php b/erp24/views/motivation/values.php new file mode 100644 index 00000000..6cff73e6 --- /dev/null +++ b/erp24/views/motivation/values.php @@ -0,0 +1,55 @@ +title = 'Значения мотивации'; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+

title) ?>

+ +

+ 'btn btn-primary']) ?> +

+ + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + 'name', + 'data_type', + 'is_active:boolean', + [ + 'attribute' => 'created_at', + 'format' => ['datetime', 'php:d.m.Y H:i:s'], + ], + [ + 'attribute' => 'updated_at', + 'format' => ['datetime', 'php:d.m.Y H:i:s'], + ], + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{update} {delete}', + 'buttons' => [ + 'update' => function ($url, $model, $key) { + return Html::a('Изменить', ['update-value', 'id' => $model->id], ['class' => 'btn btn-primary btn-sm']); + }, + 'delete' => function ($url, $model, $key) { + return Html::a('Удалить', ['delete-value', 'id' => $model->id], [ + 'class' => 'btn btn-danger btn-sm', + 'data' => [ + 'confirm' => 'Вы уверены, что хотите удалить этот элемент?', + 'method' => 'post', + ], + ]); + }, + ], + ], + ], + ]); ?> +
\ No newline at end of file