From c4139baeb23d6ee01c2e3f74eae841b1826be7b0 Mon Sep 17 00:00:00 2001 From: anatolidew Date: Thu, 25 Nov 2021 14:04:14 +0300 Subject: [PATCH 1/5] =?UTF-8?q?*=20=D0=B1=D0=B0=D0=B3=20=D1=81=20=D0=BC?= =?UTF-8?q?=D0=B8=D0=BD=D1=83=D1=82=D0=B0=D0=BC=D0=B8=20*=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=D1=80=D1=82=D1=84=D0=BE=D0=BB=D0=B8=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/models/Reports.php | 1 + .../card/controllers/UserCardController.php | 7 ++++++- frontend/modules/card/views/user-card/view.php | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/common/models/Reports.php b/common/models/Reports.php index 8536b1a..76b6f4f 100755 --- a/common/models/Reports.php +++ b/common/models/Reports.php @@ -75,6 +75,7 @@ class Reports extends \yii\db\ActiveRecord foreach ($this->task as $task) { $this->_task[$i]['task'] = $task->task; $this->_task[$i]['hours_spent'] = $task->hours_spent; + $this->_task[$i]['minutes_spent'] = $task->minutes_spent; $i++; } } diff --git a/frontend/modules/card/controllers/UserCardController.php b/frontend/modules/card/controllers/UserCardController.php index f9f7d54..b22cf28 100755 --- a/frontend/modules/card/controllers/UserCardController.php +++ b/frontend/modules/card/controllers/UserCardController.php @@ -51,6 +51,11 @@ class UserCardController extends Controller $result = UserCard::find()->where(['id_user' => $id_user])->asArray()->all(); if($result) { $id = $result[0]['id']; + $model = $this->findModel($id); + if ($model->load(Yii::$app->request->post())) { + $model->updated_at = date('Y-m-d h:i:s'); + $model->save(); + } $dataProvider = new ActiveDataProvider([ 'query' => FieldsValueNew::find() ->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_PROFILE]) @@ -69,7 +74,7 @@ class UserCardController extends Controller ->all(); return $this->render('view', [ - 'model' => $this->findModel($id), + 'model' => $model, 'modelFildValue' => $dataProvider, 'skills' => $skills, 'achievements' => $achievements, diff --git a/frontend/modules/card/views/user-card/view.php b/frontend/modules/card/views/user-card/view.php index 22e3943..8aadba5 100755 --- a/frontend/modules/card/views/user-card/view.php +++ b/frontend/modules/card/views/user-card/view.php @@ -1,7 +1,9 @@ title = 'Профиль'; return $model->value; } ], + 'vc_text' ], ]); ?> + + + field($model, 'vc_text')->widget(EditorClassic::className(), [ + 'clientOptions' => [ + 'language' => 'ru', + ] + ]); ?> +
+ 'btn btn-success']) ?> +
+ From 8400da1033ce0e5968001bddfd7e2f6b299af56a Mon Sep 17 00:00:00 2001 From: anatolidew Date: Thu, 25 Nov 2021 14:19:38 +0300 Subject: [PATCH 2/5] =?UTF-8?q?*=20=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=88=D0=BD=D0=B5=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/modules/card/views/user-card/view.php | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/modules/card/views/user-card/view.php b/frontend/modules/card/views/user-card/view.php index 8aadba5..80bb663 100755 --- a/frontend/modules/card/views/user-card/view.php +++ b/frontend/modules/card/views/user-card/view.php @@ -67,7 +67,6 @@ $this->title = 'Профиль'; return $model->value; } ], - 'vc_text' ], ]); ?> From e742c582bc7967fd2dbe66d48c84a40170c6eae6 Mon Sep 17 00:00:00 2001 From: anatolidew Date: Mon, 29 Nov 2021 13:22:25 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D1=80=D1=83=D1=81=D1=81=D0=BA=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=B4=D0=B0=D1=82=D0=B0=D0=BF=D0=B8=D0=BA=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/reports/views/reports/_form.php | 1 + frontend/modules/reports/views/reports/_form.php | 1 + 2 files changed, 2 insertions(+) diff --git a/backend/modules/reports/views/reports/_form.php b/backend/modules/reports/views/reports/_form.php index 1d61d9c..3140590 100755 --- a/backend/modules/reports/views/reports/_form.php +++ b/backend/modules/reports/views/reports/_form.php @@ -29,6 +29,7 @@ $this->registerCss('.list-cell__task{width:73%}') echo 'Дата заполнения отчета:'; echo DatePicker::widget([ 'model' => $model, + 'language' => 'ru', 'attribute' => 'created_at', 'options' => [], 'pluginOptions' => [ diff --git a/frontend/modules/reports/views/reports/_form.php b/frontend/modules/reports/views/reports/_form.php index 61c040e..90dca96 100755 --- a/frontend/modules/reports/views/reports/_form.php +++ b/frontend/modules/reports/views/reports/_form.php @@ -28,6 +28,7 @@ $this->registerCss('.list-cell__task{width:73%}') echo 'Дата заполнения отчета:'; echo DatePicker::widget([ 'model' => $model, + 'language' => 'ru', 'attribute' => 'created_at', 'options' => [], 'pluginOptions' => [ From 8ae7b9a12585790a1a7da1adaeb7c7813c802b0e Mon Sep 17 00:00:00 2001 From: anatolidew Date: Mon, 29 Nov 2021 18:16:28 +0300 Subject: [PATCH 4/5] =?UTF-8?q?*=20=D0=9F=D1=80=D0=BE=D1=81=D0=BC=D0=BE?= =?UTF-8?q?=D1=82=D1=80=201=20=D1=80=D0=B5=D0=BF=D0=BE=D1=80=D1=82=D0=B0?= =?UTF-8?q?=20*=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=82=D0=B0=D1=81=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/models/Reports.php | 1 + common/models/ReportsTask.php | 11 +++++- frontend/config/main.php | 1 + .../api/controllers/ReportsController.php | 34 ++++++++++++++++--- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/common/models/Reports.php b/common/models/Reports.php index 8536b1a..76b6f4f 100755 --- a/common/models/Reports.php +++ b/common/models/Reports.php @@ -75,6 +75,7 @@ class Reports extends \yii\db\ActiveRecord foreach ($this->task as $task) { $this->_task[$i]['task'] = $task->task; $this->_task[$i]['hours_spent'] = $task->hours_spent; + $this->_task[$i]['minutes_spent'] = $task->minutes_spent; $i++; } } diff --git a/common/models/ReportsTask.php b/common/models/ReportsTask.php index 061f09c..b86fcf0 100755 --- a/common/models/ReportsTask.php +++ b/common/models/ReportsTask.php @@ -19,6 +19,15 @@ use Yii; */ class ReportsTask extends \yii\db\ActiveRecord { + const SCENARIO_WITHOUT_REPORT_ID = 'withoutReportID'; + + public function scenarios() + { + $scenarios = parent::scenarios(); + $scenarios[self::SCENARIO_WITHOUT_REPORT_ID] = self::attributes(); + return $scenarios; + } + /** * {@inheritdoc} */ @@ -33,7 +42,7 @@ class ReportsTask extends \yii\db\ActiveRecord public function rules() { return [ - [['report_id'], 'required'], + [['report_id'], 'required', 'on' => self::SCENARIO_DEFAULT], [['report_id', 'created_at', 'status', 'minutes_spent'], 'integer'], [['hours_spent'], 'number'], ['minutes_spent', 'compare', 'compareValue' => 60, 'operator' => '<'], diff --git a/frontend/config/main.php b/frontend/config/main.php index 5cbe40f..6bf6071 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -84,6 +84,7 @@ return [ 'rules' => [ 'site/index' => 'card/user-card/index', 'api/profile/' => 'api/profile/index', + 'api/reports/' => 'api/reports/view', '' => 'card/user-card/index', ['class' => 'yii\rest\UrlRule', 'controller' => 'skills'], ], diff --git a/frontend/modules/api/controllers/ReportsController.php b/frontend/modules/api/controllers/ReportsController.php index 11333c7..3f5d191 100755 --- a/frontend/modules/api/controllers/ReportsController.php +++ b/frontend/modules/api/controllers/ReportsController.php @@ -5,6 +5,7 @@ namespace frontend\modules\api\controllers; use common\behaviors\GsCors; use common\classes\Debug; use common\models\Reports; +use common\models\ReportsTask; use frontend\modules\api\models\ReportSearchForm; use JsonException; use Yii; @@ -48,7 +49,7 @@ class ReportsController extends Controller 'authenticator' => [ 'class' => CompositeAuth::class, 'authMethods' => [ - HttpBearerAuth::class, +// HttpBearerAuth::class, ], ] ]; @@ -67,20 +68,43 @@ class ReportsController extends Controller return $reportsModel->byParams(); } + public function actionView($id): array{ + $report = Reports::findOne($id); + return array_merge($report->toArray(), ['tasks' => $report->_task]); + } + public function actionCreate() { - $reportsModel = new Reports(); - $params = Yii::$app->request->post(); + if (!isset($params['tasks'])){ + throw new BadRequestHttpException('Нет параметра tasks'); + } + + $reportsModel = new Reports(); $reportsModel->attributes = $params; if(!$reportsModel->validate()){ throw new BadRequestHttpException(json_encode($reportsModel->errors)); } - $reportsModel->save(); + $tasks = []; + foreach (json_decode($params['tasks'], true) as $jsonTask){ + $task = new ReportsTask(); + $task->scenario = ReportsTask::SCENARIO_WITHOUT_REPORT_ID; + $task->attributes = $jsonTask; + if (!$task->validate()) { + throw new BadRequestHttpException(json_encode($task->errors)); + } + $tasks []= $task->attributes; + } + $attributes = $task->attributes(); - return $reportsModel->toArray(); + $reportsModel->save(); + $tasks = array_map(function ($task)use($reportsModel){$task['report_id'] = $reportsModel->id; return $task;}, $tasks); + + Yii::$app->db->createCommand()->batchInsert(ReportsTask::tableName(), $attributes, $tasks)->execute(); + + return array_merge($reportsModel->toArray(), ['tasks' => $tasks]); } public function actionDelete() From d00c93d4bee3f4ee03ce967abf1abb7cc6fd2637 Mon Sep 17 00:00:00 2001 From: anatolidew Date: Mon, 29 Nov 2021 18:17:23 +0300 Subject: [PATCH 5/5] =?UTF-8?q?*=20=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=88=D0=BD=D0=B5=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/modules/api/controllers/ReportsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/modules/api/controllers/ReportsController.php b/frontend/modules/api/controllers/ReportsController.php index 3f5d191..fa643d5 100755 --- a/frontend/modules/api/controllers/ReportsController.php +++ b/frontend/modules/api/controllers/ReportsController.php @@ -49,7 +49,7 @@ class ReportsController extends Controller 'authenticator' => [ 'class' => CompositeAuth::class, 'authMethods' => [ -// HttpBearerAuth::class, + HttpBearerAuth::class, ], ] ];