--- /dev/null
+<?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
+++ /dev/null
-<?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
--- /dev/null
+<?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
+++ /dev/null
-<?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
--- /dev/null
+<?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
+++ /dev/null
-<?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
*/
class m241010_150710_create_table_weekly_report_subscribtion extends Migration
{
- const TABLE_NAME = 'erp24.weekly_report_subscription';
+ const TABLE_NAME = 'erp24.tg_subscription';
/**
* {@inheritdoc}
--- /dev/null
+<?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',
+ ];
+ }
+}
+++ /dev/null
-<?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',
- ];
- }
-}
--- /dev/null
+<?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>
+++ /dev/null
-<?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>