]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-222] рефактор weekly_report_subscription в tg_subscription
authorAlexander Smirnov <fredeom@mail.ru>
Fri, 11 Oct 2024 11:20:08 +0000 (14:20 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Fri, 11 Oct 2024 11:20:08 +0000 (14:20 +0300)
erp24/actions/tg/SubscriptionAction.php [new file with mode: 0644]
erp24/actions/weeklyReport/SubscriptionAction.php [deleted file]
erp24/api3/modules/v1/controllers/TgController.php [new file with mode: 0644]
erp24/api3/modules/v1/controllers/WeeklyReportController.php [deleted file]
erp24/controllers/TgController.php [new file with mode: 0644]
erp24/controllers/WeeklyReportController.php [deleted file]
erp24/migrations/m241010_150710_create_table_weekly_report_subscribtion.php
erp24/records/TgSubscription.php [new file with mode: 0644]
erp24/records/WeeklyReportSubscription.php [deleted file]
erp24/views/tg/subscription.php [new file with mode: 0644]
erp24/views/weekly-report/subscription.php [deleted file]

diff --git a/erp24/actions/tg/SubscriptionAction.php b/erp24/actions/tg/SubscriptionAction.php
new file mode 100644 (file)
index 0000000..9a99f04
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+
+namespace yii_app\actions\tg;
+
+use Yii;
+use yii\base\Action;
+use yii\helpers\Json;
+use yii_app\records\TgSubscription;
+
+class SubscriptionAction extends Action
+{
+    public function run() {
+
+        if (Yii::$app->request->isPost) {
+            $action = Yii::$app->request->post('action');
+            if ($action == "addNew") {
+                $name = Yii::$app->request->post('name');
+                $chatId = Yii::$app->request->post('chat_id');
+
+                $sub = new TgSubscription;
+                $sub->name = $name;
+                $sub->chat_id = $chatId;
+                $sub->active = 0;
+
+                $sub->save();
+                if ($sub->getErrors()) {
+                    throw new \Exception(Json::encode($sub->getErrors()));
+                }
+                return $this->controller->redirect('subscription');
+            }
+            if ($action == "changeSub") {
+                $subId = Yii::$app->request->post('id');
+                $name = Yii::$app->request->post('name');
+                $chatId = Yii::$app->request->post('chatId');
+                $active = Yii::$app->request->post('active');
+
+                $sub = TgSubscription::findOne($subId);
+                $sub->name = $name;
+                $sub->chat_id = $chatId;
+                $sub->active = $active;
+                $sub->save();
+                if ($sub->getErrors()) {
+                    throw new \Exception(Json::encode($sub->getErrors()));
+                }
+
+                return 'ok';
+            }
+        }
+
+        $subscriptions = TgSubscription::find()->orderBy(['id' => SORT_DESC])->all();
+
+        return $this->controller->render('subscription', compact('subscriptions'));
+    }
+}
\ No newline at end of file
diff --git a/erp24/actions/weeklyReport/SubscriptionAction.php b/erp24/actions/weeklyReport/SubscriptionAction.php
deleted file mode 100644 (file)
index a960a50..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-
-namespace yii_app\actions\weeklyReport;
-
-use Yii;
-use yii\base\Action;
-use yii\helpers\Json;
-use yii_app\records\WeeklyReportSubscription;
-
-class SubscriptionAction extends Action
-{
-    public function run() {
-
-        if (Yii::$app->request->isPost) {
-            $action = Yii::$app->request->post('action');
-            if ($action == "addNew") {
-                $name = Yii::$app->request->post('name');
-                $chatId = Yii::$app->request->post('chat_id');
-
-                $sub = new WeeklyReportSubscription;
-                $sub->name = $name;
-                $sub->chat_id = $chatId;
-                $sub->active = 0;
-
-                $sub->save();
-                if ($sub->getErrors()) {
-                    throw new \Exception(Json::encode($sub->getErrors()));
-                }
-                return $this->controller->redirect('subscription');
-            }
-            if ($action == "changeSub") {
-                $subId = Yii::$app->request->post('id');
-                $name = Yii::$app->request->post('name');
-                $chatId = Yii::$app->request->post('chatId');
-                $active = Yii::$app->request->post('active');
-
-                $sub = WeeklyReportSubscription::findOne($subId);
-                $sub->name = $name;
-                $sub->chat_id = $chatId;
-                $sub->active = $active;
-                $sub->save();
-                if ($sub->getErrors()) {
-                    throw new \Exception(Json::encode($sub->getErrors()));
-                }
-
-                return 'ok';
-            }
-        }
-
-        $subscriptions = WeeklyReportSubscription::find()->orderBy(['id' => SORT_DESC])->all();
-
-        return $this->controller->render('subscription', compact('subscriptions'));
-    }
-}
\ No newline at end of file
diff --git a/erp24/api3/modules/v1/controllers/TgController.php b/erp24/api3/modules/v1/controllers/TgController.php
new file mode 100644 (file)
index 0000000..6b83bde
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace yii_app\api3\modules\v1\controllers;
+
+use yii_app\records\TgSubscription;
+
+class TgController extends \yii_app\api3\controllers\NoActiveController
+{
+    public function actionSubscription() {
+        return TgSubscription::find()->where(['active' => 1])->all();
+    }
+}
\ No newline at end of file
diff --git a/erp24/api3/modules/v1/controllers/WeeklyReportController.php b/erp24/api3/modules/v1/controllers/WeeklyReportController.php
deleted file mode 100644 (file)
index d114d78..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-
-namespace yii_app\api3\modules\v1\controllers;
-
-use yii_app\records\WeeklyReportSubscription;
-
-class WeeklyReportController extends \yii_app\api3\controllers\NoActiveController
-{
-    public function actionSubscription() {
-        return WeeklyReportSubscription::find()->where(['active' => 1])->all();
-    }
-}
\ No newline at end of file
diff --git a/erp24/controllers/TgController.php b/erp24/controllers/TgController.php
new file mode 100644 (file)
index 0000000..61750e0
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+namespace app\controllers;
+
+use yii\web\Controller;
+
+class TgController extends Controller
+{
+    public function actions()
+    {
+        return [
+            'subscription' => \yii_app\actions\tg\SubscriptionAction::class,
+        ];
+    }
+}
\ No newline at end of file
diff --git a/erp24/controllers/WeeklyReportController.php b/erp24/controllers/WeeklyReportController.php
deleted file mode 100644 (file)
index 377ee09..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-namespace app\controllers;
-
-use yii\web\Controller;
-
-class WeeklyReportController extends Controller
-{
-    public function actions()
-    {
-        return [
-            'subscription' => \yii_app\actions\weeklyReport\SubscriptionAction::class,
-        ];
-    }
-}
\ No newline at end of file
index eadf90160fedb14d74ae410ce83a0210ffa5ced2..6b007b86414cd4e467f125f934b6eb00a516e665 100755 (executable)
@@ -7,7 +7,7 @@ use yii\db\Migration;
  */
 class m241010_150710_create_table_weekly_report_subscribtion extends Migration
 {
-    const TABLE_NAME = 'erp24.weekly_report_subscription';
+    const TABLE_NAME = 'erp24.tg_subscription';
 
     /**
      * {@inheritdoc}
diff --git a/erp24/records/TgSubscription.php b/erp24/records/TgSubscription.php
new file mode 100644 (file)
index 0000000..00bc9d3
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "tg_subscription".
+ *
+ * @property int $id
+ * @property string $name Имя пользователя
+ * @property int $chat_id chat_id пользователя
+ * @property int $active 0 - не активен, 1 - активен
+ */
+class TgSubscription extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'tg_subscription';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['name', 'chat_id'], 'required'],
+            [['chat_id', 'active'], 'default', 'value' => null],
+            [['chat_id', 'active'], 'integer'],
+            [['name'], 'string', 'max' => 36],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'name' => 'Name',
+            'chat_id' => 'Chat ID',
+            'active' => 'Active',
+        ];
+    }
+}
diff --git a/erp24/records/WeeklyReportSubscription.php b/erp24/records/WeeklyReportSubscription.php
deleted file mode 100644 (file)
index a4522d0..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-
-namespace yii_app\records;
-
-use Yii;
-
-/**
- * This is the model class for table "weekly_report_subscription".
- *
- * @property int $id
- * @property string $name Имя пользователя
- * @property int $chat_id chat_id пользователя
- * @property int $active 0 - не активен, 1 - активен
- */
-class WeeklyReportSubscription extends \yii\db\ActiveRecord
-{
-    /**
-     * {@inheritdoc}
-     */
-    public static function tableName()
-    {
-        return 'weekly_report_subscription';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function rules()
-    {
-        return [
-            [['name', 'chat_id'], 'required'],
-            [['chat_id', 'active'], 'default', 'value' => null],
-            [['chat_id', 'active'], 'integer'],
-            [['name'], 'string', 'max' => 36],
-        ];
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function attributeLabels()
-    {
-        return [
-            'id' => 'ID',
-            'name' => 'Name',
-            'chat_id' => 'Chat ID',
-            'active' => 'Active',
-        ];
-    }
-}
diff --git a/erp24/views/tg/subscription.php b/erp24/views/tg/subscription.php
new file mode 100644 (file)
index 0000000..f784b38
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+use yii_app\records\TgSubscription;
+
+/** @var $subscriptions []WeeklyReportSubscription */
+
+$this->registerJsFile('/js/weekly-report/subscription.js', ['position' => \yii\web\View::POS_END]);
+
+?>
+
+<div class="weeklyReportSubscription m-5">
+
+    <?php ActiveForm::begin() ?>
+
+    <div class="row">
+        <div class="col-2">
+            Имя: <?= Html::textInput('name') ?>
+        </div>
+        <div class="col-2">
+            chat_id: <?= Html::textInput('chat_id', null, ['type' => 'number'])?>
+        </div>
+        <div class="col-1">
+            <?= Html::submitButton('Добавить', ['class' => 'btn btn-success btn-sm', 'name' => 'action', 'value' => 'addNew'])?>
+        </div>
+    </div>
+
+    <?php ActiveForm::end() ?>
+
+    <div class="row mt-2">
+        <div class="col-4">
+            <table id="subscriptionTable">
+                <thead>
+                    <tr>
+                        <th>Имя</th>
+                        <th>chat_id</th>
+                        <th>Активен</th>
+                    </tr>
+                </thead>
+                <tbody>
+                    <?php foreach($subscriptions as $sub): /** @var $sub TgSubscription */ ?>
+                        <tr data-id="<?= $sub->id ?>">
+                            <td><input type="text" value="<?= $sub->name ?>" onchange="saveChanges(this)" /></td>
+                            <td><input type="number" value="<?= $sub->chat_id ?>" onchange="saveChanges(this)" /></td>
+                            <td><input type="checkbox" <?= $sub->active == 1 ? 'checked="checked"' : '' ?> onclick="saveChanges(this)" /> </td>
+                        </tr>
+                    <?php endforeach; ?>
+                </tbody>
+            </table>
+        </div>
+    </div>
+
+</div>
diff --git a/erp24/views/weekly-report/subscription.php b/erp24/views/weekly-report/subscription.php
deleted file mode 100644 (file)
index 36a13ce..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-
-use yii\helpers\Html;
-use yii\widgets\ActiveForm;
-
-use yii_app\records\WeeklyReportSubscription;
-
-/** @var $subscriptions []WeeklyReportSubscription */
-
-$this->registerJsFile('/js/weekly-report/subscription.js', ['position' => \yii\web\View::POS_END]);
-
-?>
-
-<div class="weeklyReportSubscription m-5">
-
-    <?php ActiveForm::begin() ?>
-
-    <div class="row">
-        <div class="col-2">
-            Имя: <?= Html::textInput('name') ?>
-        </div>
-        <div class="col-2">
-            chat_id: <?= Html::textInput('chat_id', null, ['type' => 'number'])?>
-        </div>
-        <div class="col-1">
-            <?= Html::submitButton('Добавить', ['class' => 'btn btn-success btn-sm', 'name' => 'action', 'value' => 'addNew'])?>
-        </div>
-    </div>
-
-    <?php ActiveForm::end() ?>
-
-    <div class="row mt-2">
-        <div class="col-4">
-            <table id="subscriptionTable">
-                <thead>
-                    <tr>
-                        <th>Имя</th>
-                        <th>chat_id</th>
-                        <th>Активен</th>
-                    </tr>
-                </thead>
-                <tbody>
-                    <?php foreach($subscriptions as $sub): /** @var $sub WeeklyReportSubscription */ ?>
-                        <tr data-id="<?= $sub->id ?>">
-                            <td><input type="text" value="<?= $sub->name ?>" onchange="saveChanges(this)" /></td>
-                            <td><input type="number" value="<?= $sub->chat_id ?>" onchange="saveChanges(this)" /></td>
-                            <td><input type="checkbox" <?= $sub->active == 1 ? 'checked="checked"' : '' ?> onclick="saveChanges(this)" /> </td>
-                        </tr>
-                    <?php endforeach; ?>
-                </tbody>
-            </table>
-        </div>
-    </div>
-
-</div>