]> 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 11:33:00 +0000 (14:33 +0300)
committervladfo <fvv2011@gmail.com>
Fri, 19 Jul 2024 11:33:00 +0000 (14:33 +0300)
erp24/actions/motivation/CreateValueAction.php [new file with mode: 0644]
erp24/actions/motivation/DeleteValueAction.php [new file with mode: 0644]
erp24/actions/motivation/UpdateValueAction.php [new file with mode: 0644]
erp24/actions/motivation/ValuesAction.php [new file with mode: 0644]
erp24/controllers/MotivationController.php
erp24/migrations/m240719_090134_create_motivation_values_table.php [new file with mode: 0644]
erp24/records/MotivationValue.php [new file with mode: 0644]
erp24/views/motivation/_form.php [new file with mode: 0644]
erp24/views/motivation/create-value.php [new file with mode: 0644]
erp24/views/motivation/update-value.php [new file with mode: 0644]
erp24/views/motivation/values.php [new file with mode: 0644]

diff --git a/erp24/actions/motivation/CreateValueAction.php b/erp24/actions/motivation/CreateValueAction.php
new file mode 100644 (file)
index 0000000..5fdabf2
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+namespace yii_app\actions\motivation;
+
+use Yii;
+use yii\base\Action;
+use yii_app\records\MotivationValue;
+
+class CreateValueAction extends Action
+{
+    public function run()
+    {
+        $model = new MotivationValue();
+        if ($model->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 (file)
index 0000000..4976ca3
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+namespace yii_app\actions\motivation;
+
+use Yii;
+use yii_app\records\MotivationValue;
+use yii\web\NotFoundHttpException;
+use yii\base\Action;
+
+class DeleteValueAction extends Action
+{
+    public function run($id)
+    {
+        $this->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 (file)
index 0000000..8a77645
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace yii_app\actions\motivation;
+
+use Yii;
+use yii_app\records\MotivationValue;
+use yii\web\NotFoundHttpException;
+use yii\base\Action;
+
+class UpdateValueAction extends Action
+{
+    public function run($id)
+    {
+        $model = $this->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 (file)
index 0000000..90396f7
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+namespace yii_app\actions\motivation;
+
+use yii\base\Action;
+use yii\data\ActiveDataProvider;
+use yii_app\records\MotivationValue;
+
+class ValuesAction extends Action
+{
+    public function run()
+    {
+        $dataProvider = new ActiveDataProvider([
+            'query' => MotivationValue::find(),
+        ]);
+        return $this->controller->render('values', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
+}
\ No newline at end of file
index 8175a6e3d7720583df8b68f038801552bfccaea8..f81c287b1ea0a236d5b7568d2d636b96200be6f7 100644 (file)
@@ -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 (file)
index 0000000..a489719
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%motivation_values}}`.
+ */
+class m240719_090134_create_motivation_values_table extends Migration
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+
+        $this->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 (file)
index 0000000..0d08527
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+namespace yii_app\records;
+
+use yii\db\ActiveRecord;
+use yii\behaviors\TimestampBehavior;
+use yii\db\Expression;
+
+class MotivationValue extends ActiveRecord
+{
+    public static function tableName()
+    {
+        return '{{%motivation_values}}';
+    }
+
+    public function rules()
+    {
+        return [
+            [['name', 'data_type'], 'required'],
+            [['name', 'data_type'], 'string', 'max' => 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 (file)
index 0000000..5b02a98
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+/** @var $this yii\web\View */
+/** @var $model app\models\MotivationValue */
+/** @var $form yii\widgets\ActiveForm */
+?>
+
+<div class="motivation-value-form">
+    <?php $form = ActiveForm::begin(); ?>
+
+    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
+
+    <?= $form->field($model, 'data_type')->textInput(['maxlength' => true]) ?>
+
+    <?= $form->field($model, 'is_active')->checkbox() ?>
+
+    <div class="form-group">
+        <?= Html::submitButton('Сохранить', ['class' => 'btn btn-primary']) ?>
+    </div>
+
+    <?php ActiveForm::end(); ?>
+</div>
\ 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 (file)
index 0000000..ecb60a1
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var $this yii\web\View */
+/** @var $model app\models\MotivationValue */
+
+$this->title = 'Создать значение мотивации';
+$this->params['breadcrumbs'][] = ['label' => 'Значения мотивации', 'url' => ['values']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+<div class="motivation-create-value m-5">
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+</div>
\ 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 (file)
index 0000000..1ef89a9
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var $this yii\web\View */
+/** @var $model app\models\MotivationValue */
+
+$this->title = 'Обновить значение мотивации: ' . $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Значения мотивации', 'url' => ['values']];
+$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
+$this->params['breadcrumbs'][] = 'Обновить';
+?>
+
+<div class="motivation-update-value m-5">
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+</div>
\ No newline at end of file
diff --git a/erp24/views/motivation/values.php b/erp24/views/motivation/values.php
new file mode 100644 (file)
index 0000000..6cff73e
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+use yii\helpers\Html;
+use yii\grid\GridView;
+
+/** @var $this yii\web\View */
+/** @var $dataProvider yii\data\ActiveDataProvider */
+
+$this->title = 'Значения мотивации';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+<div class="motivation-values m-5">
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Создать новое значение', ['create-value'], ['class' => 'btn btn-primary']) ?>
+    </p>
+
+    <?= GridView::widget([
+        'dataProvider' => $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',
+                            ],
+                        ]);
+                    },
+                ],
+            ],
+        ],
+    ]); ?>
+</div>
\ No newline at end of file