]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
admin position
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 28 Oct 2025 13:59:47 +0000 (16:59 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 28 Oct 2025 13:59:47 +0000 (16:59 +0300)
erp24/controllers/AdminPositionsController.php [new file with mode: 0644]
erp24/views/admin-positions/_form.php [new file with mode: 0644]
erp24/views/admin-positions/create.php [new file with mode: 0644]
erp24/views/admin-positions/index.php [new file with mode: 0644]
erp24/views/admin-positions/update.php [new file with mode: 0644]
erp24/views/admin-positions/view.php [new file with mode: 0644]

diff --git a/erp24/controllers/AdminPositionsController.php b/erp24/controllers/AdminPositionsController.php
new file mode 100644 (file)
index 0000000..a1868f9
--- /dev/null
@@ -0,0 +1,144 @@
+<?php
+
+namespace app\controllers;
+
+use yii_app\records\AdminPositions;
+use yii\data\ActiveDataProvider;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii\filters\VerbFilter;
+
+/**
+ * AdminPositionsController implements the CRUD actions for AdminPositions model.
+ */
+class AdminPositionsController extends Controller
+{
+    /**
+     * @inheritDoc
+     */
+    public function behaviors()
+    {
+        return array_merge(
+            parent::behaviors(),
+            [
+                'verbs' => [
+                    'class' => VerbFilter::className(),
+                    'actions' => [
+                        'delete' => ['POST'],
+                    ],
+                ],
+            ]
+        );
+    }
+
+    /**
+     * Lists all AdminPositions models.
+     *
+     * @return string
+     */
+    public function actionIndex()
+    {
+        $dataProvider = new ActiveDataProvider([
+            'query' => AdminPositions::find(),
+            /*
+            'pagination' => [
+                'pageSize' => 50
+            ],
+            'sort' => [
+                'defaultOrder' => [
+                    'id' => SORT_DESC,
+                ]
+            ],
+            */
+        ]);
+
+        return $this->render('index', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
+
+    /**
+     * Displays a single AdminPositions model.
+     * @param int $id ID
+     * @return string
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    public function actionView($id)
+    {
+        return $this->render('view', [
+            'model' => $this->findModel($id),
+        ]);
+    }
+
+    /**
+     * Creates a new AdminPositions model.
+     * If creation is successful, the browser will be redirected to the 'view' page.
+     * @return string|\yii\web\Response
+     */
+    public function actionCreate()
+    {
+        $model = new AdminPositions();
+
+        if ($this->request->isPost) {
+            if ($model->load($this->request->post()) && $model->save()) {
+                return $this->redirect(['view', 'id' => $model->id]);
+            }
+        } else {
+            $model->loadDefaultValues();
+        }
+
+        return $this->render('create', [
+            'model' => $model,
+        ]);
+    }
+
+    /**
+     * Updates an existing AdminPositions model.
+     * If update is successful, the browser will be redirected to the 'view' page.
+     * @param int $id ID
+     * @return string|\yii\web\Response
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    public function actionUpdate($id)
+    {
+        $model = $this->findModel($id);
+
+        if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
+            return $this->redirect(['view', 'id' => $model->id]);
+        }
+
+        return $this->render('update', [
+            'model' => $model,
+        ]);
+    }
+
+    /**
+     * Deletes an existing AdminPositions model.
+     * If deletion is successful, the browser will be redirected to the 'index' page.
+     * @param int $id ID
+     * @return \yii\web\Response
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    public function actionDelete($id)
+    {
+        $this->findModel($id)->delete();
+
+        return $this->redirect(['index']);
+    }
+
+    /**
+     * Finds the AdminPositions model based on its primary key value.
+     * If the model is not found, a 404 HTTP exception will be thrown.
+     * @param int $id ID
+     * @return AdminPositions the loaded model
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    protected function findModel($id)
+    {
+        if (($model = AdminPositions::findOne(['id' => $id])) !== null) {
+            return $model;
+        }
+
+        throw new NotFoundHttpException('The requested page does not exist.');
+    }
+}
diff --git a/erp24/views/admin-positions/_form.php b/erp24/views/admin-positions/_form.php
new file mode 100644 (file)
index 0000000..f55150e
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AdminPositions $model */
+/** @var yii\widgets\ActiveForm $form */
+?>
+
+<div class="admin-positions-form">
+
+    <?php $form = ActiveForm::begin(); ?>
+
+    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
+
+    <?= $form->field($model, 'alias')->hiddenInput()->label(false) ?>
+
+    <?= $form->field($model, 'salary')->textInput() ?>
+
+    <div class="form-group">
+        <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
+    </div>
+
+    <?php ActiveForm::end(); ?>
+
+</div>
+
+<?php
+$this->registerJs("
+$(document).ready(function() {
+    // Функция транслитерации русского текста в латиницу
+    function transliterate(text) {
+        var translitMap = {
+            'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'e',
+            'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'y', 'к': 'k', 'л': 'l', 'м': 'm',
+            'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
+            'ф': 'f', 'х': 'kh', 'ц': 'ts', 'ч': 'ch', 'ш': 'sh', 'щ': 'shch',
+            'ъ': '', 'ы': 'y', 'ь': '', 'э': 'e', 'ю': 'yu', 'я': 'ya',
+            'А': 'A', 'Б': 'B', 'В': 'V', 'Г': 'G', 'Д': 'D', 'Е': 'E', 'Ё': 'E',
+            'Ж': 'Zh', 'З': 'Z', 'И': 'I', 'Й': 'Y', 'К': 'K', 'Л': 'L', 'М': 'M',
+            'Н': 'N', 'О': 'O', 'П': 'P', 'Р': 'R', 'С': 'S', 'Т': 'T', 'У': 'U',
+            'Ф': 'F', 'Х': 'Kh', 'Ц': 'Ts', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Shch',
+            'Ъ': '', 'Ы': 'Y', 'Ь': '', 'Э': 'E', 'Ю': 'Yu', 'Я': 'Ya'
+        };
+
+        return text.split('').map(function(char) {
+            return translitMap[char] || char;
+        }).join('').replace(/[^a-zA-Z0-9-_]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
+    }
+
+    // Обработчик изменения поля name
+    $('#adminpositions-name').on('input', function() {
+        var nameValue = $(this).val();
+        var aliasValue = transliterate(nameValue);
+        $('#adminpositions-alias').val(aliasValue);
+    });
+});
+");
+?>
diff --git a/erp24/views/admin-positions/create.php b/erp24/views/admin-positions/create.php
new file mode 100644 (file)
index 0000000..1f45d4f
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AdminPositions $model */
+
+$this->title = 'Создание должности сотрудников';
+$this->params['breadcrumbs'][] = ['label' => 'Admin Positions', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="admin-positions-create p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+
+</div>
diff --git a/erp24/views/admin-positions/index.php b/erp24/views/admin-positions/index.php
new file mode 100644 (file)
index 0000000..38ada63
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+use yii_app\records\AdminPositions;
+use yii\helpers\Html;
+use yii\helpers\Url;
+use yii\grid\ActionColumn;
+use yii\grid\GridView;
+
+/** @var yii\web\View $this */
+/** @var yii\data\ActiveDataProvider $dataProvider */
+
+$this->title = 'Должности сотрудников';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="admin-positions-index p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Добавить должность', ['create'], ['class' => 'btn btn-success']) ?>
+    </p>
+
+
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'columns' => [
+            ['class' => 'yii\grid\SerialColumn'],
+
+            'id',
+            'name',
+            'alias',
+            'salary',
+            'created_at',
+            'created_by',
+            'updated_at',
+            'updated_by',
+            [
+                'class' => ActionColumn::class,
+                'urlCreator' => function ($action, AdminPositions $model, $key, $index, $column) {
+                    return Url::toRoute([$action, 'id' => $model->id]);
+                 }
+            ],
+        ],
+    ]); ?>
+
+
+</div>
diff --git a/erp24/views/admin-positions/update.php b/erp24/views/admin-positions/update.php
new file mode 100644 (file)
index 0000000..1321d77
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AdminPositions $model */
+
+$this->title = 'Изменение должности: ' . $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Admin Positions', 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
+$this->params['breadcrumbs'][] = 'Update';
+?>
+<div class="admin-positions-update p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+
+</div>
diff --git a/erp24/views/admin-positions/view.php b/erp24/views/admin-positions/view.php
new file mode 100644 (file)
index 0000000..7cd6bfd
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\DetailView;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AdminPositions $model */
+
+$this->title = $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Admin Positions', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+\yii\web\YiiAsset::register($this);
+?>
+<div class="admin-positions-view p-4">
+<?= Html::a('Назад', ['index'], ['class' => 'btn btn-primary mb-4']) ?>
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
+        <?= Html::a('Удалить', ['delete', 'id' => $model->id], [
+            'class' => 'btn btn-danger',
+            'data' => [
+                'confirm' => 'Вы уверены что хотите удалить?',
+                'method' => 'post',
+            ],
+        ]) ?>
+    </p>
+
+    <?= DetailView::widget([
+        'model' => $model,
+        'attributes' => [
+            'id',
+            'name',
+            'alias',
+            'salary',
+            'created_at',
+            'created_by',
+            'updated_at',
+            'updated_by',
+        ],
+    ]) ?>
+
+</div>