From 45fcfe16d196fcc51cda2436af0589bc54924699 Mon Sep 17 00:00:00 2001 From: anatolidew Date: Tue, 23 Nov 2021 10:55:41 +0300 Subject: [PATCH 01/14] =?UTF-8?q?*=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BC=D0=B8=D0=BD=D1=83=D1=82=D1=8B=20*=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B1=D0=B0=D0=B3?= =?UTF-8?q?=20=D0=B2=20=D0=BA=D0=B0=D0=BB=D0=B5=D0=BD=D0=B4=D0=B0=D1=80?= =?UTF-8?q?=D0=B5=20=D1=81=2012=20=D0=BC=D0=B5=D1=81=D1=8F=D1=86=D0=B5?= =?UTF-8?q?=D0=BC=20('yyyy-00-dd'=20=3D>=20'yyyy-12-dd')?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/reports/views/ajax/_gridView.php | 2 +- .../reports/views/reports/_expand-row-details.php | 2 +- backend/modules/reports/views/reports/_form.php | 9 +++++++++ backend/modules/reports/views/reports/view.php | 2 +- .../widgets/Calendar/assets/js/src/DateHelper.js | 2 +- common/models/Reports.php | 1 + common/models/ReportsTask.php | 4 +++- frontend/modules/reports/views/reports/_form.php | 15 ++++++++++++++- frontend/modules/reports/views/reports/index.php | 2 +- frontend/modules/reports/views/reports/view.php | 2 +- 10 files changed, 33 insertions(+), 8 deletions(-) diff --git a/backend/modules/reports/views/ajax/_gridView.php b/backend/modules/reports/views/ajax/_gridView.php index 9d1a0e6..b946d1d 100644 --- a/backend/modules/reports/views/ajax/_gridView.php +++ b/backend/modules/reports/views/ajax/_gridView.php @@ -18,7 +18,7 @@ echo GridView::widget([ if ($model->task) { $i = 1; foreach ($model->task as $task) { - $text .= "

$i. ($task->hours_spent ч.) $task->task

"; + $text .= "

$i. ($task->hours_spent ч., $task->minutes_spent мин.) $task->task

"; $i++; } } diff --git a/backend/modules/reports/views/reports/_expand-row-details.php b/backend/modules/reports/views/reports/_expand-row-details.php index 14f9976..cf731db 100644 --- a/backend/modules/reports/views/reports/_expand-row-details.php +++ b/backend/modules/reports/views/reports/_expand-row-details.php @@ -20,7 +20,7 @@ echo GridView::widget([ if ($model->task) { $i = 1; foreach ($model->task as $task) { - $text .= "

$i. ($task->hours_spent ч.) $task->task

"; + $text .= "

$i. ($task->hours_spent ч., $task->minutes_spent мин.) $task->task

"; $i++; } } diff --git a/backend/modules/reports/views/reports/_form.php b/backend/modules/reports/views/reports/_form.php index 41cb8e4..1d61d9c 100644 --- a/backend/modules/reports/views/reports/_form.php +++ b/backend/modules/reports/views/reports/_form.php @@ -10,6 +10,8 @@ use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model common\models\Reports */ /* @var $form yii\widgets\ActiveForm */ + +$this->registerCss('.list-cell__task{width:73%}') ?>
@@ -52,6 +54,13 @@ use yii\widgets\ActiveForm; 'style' => 'width:100px' ], ], + [ + 'name' => 'minutes_spent', + 'title' => 'Кол-во минут', + 'options' => [ + 'type' => 'number', + ], + ], ], ])->label('Какие задачаи были выполнены:'); ?> diff --git a/backend/modules/reports/views/reports/view.php b/backend/modules/reports/views/reports/view.php index 8c07e30..6abd418 100644 --- a/backend/modules/reports/views/reports/view.php +++ b/backend/modules/reports/views/reports/view.php @@ -37,7 +37,7 @@ $this->params['breadcrumbs'][] = $this->title; if ($model->task) { $i = 1; foreach ($model->task as $task) { - $text .= "

$i. ($task->hours_spent ч.) $task->task

"; + $text .= "

$i. ($task->hours_spent ч., $task->minutes_spent мин.) $task->task

"; $i++; } } diff --git a/backend/widgets/Calendar/assets/js/src/DateHelper.js b/backend/widgets/Calendar/assets/js/src/DateHelper.js index c2a524a..f76eedc 100644 --- a/backend/widgets/Calendar/assets/js/src/DateHelper.js +++ b/backend/widgets/Calendar/assets/js/src/DateHelper.js @@ -68,7 +68,7 @@ class DateHelper { static dateToString(date) { let year = date.getFullYear() let day = this.intToDate(date.getDate()) - let month = this.intToDate(this.isDecember(date) ? 0 : date.getMonth() + 1) + let month = this.intToDate(date.getMonth() + 1) return year + '-' + month + '-' + day } diff --git a/common/models/Reports.php b/common/models/Reports.php index d2a24d3..8536b1a 100644 --- a/common/models/Reports.php +++ b/common/models/Reports.php @@ -102,6 +102,7 @@ class Reports extends \yii\db\ActiveRecord $taskModel->report_id = $this->id; $taskModel->task = $task['task']; $taskModel->hours_spent = (float)$task['hours_spent']; + $taskModel->minutes_spent = (int) $task['minutes_spent']; $taskModel->status = 1; $taskModel->created_at = time(); $taskModel->save(); diff --git a/common/models/ReportsTask.php b/common/models/ReportsTask.php index c97af05..061f09c 100644 --- a/common/models/ReportsTask.php +++ b/common/models/ReportsTask.php @@ -12,6 +12,7 @@ use Yii; * @property string $task * @property int $created_at * @property int $status + * @property int $minutes_spent * @property float $hours_spent * * @property Reports $report @@ -33,8 +34,9 @@ class ReportsTask extends \yii\db\ActiveRecord { return [ [['report_id'], 'required'], - [['report_id', 'created_at', 'status'], 'integer'], + [['report_id', 'created_at', 'status', 'minutes_spent'], 'integer'], [['hours_spent'], 'number'], + ['minutes_spent', 'compare', 'compareValue' => 60, 'operator' => '<'], [['task'], 'string'], [['report_id'], 'exist', 'skipOnError' => true, 'targetClass' => Reports::className(), 'targetAttribute' => ['report_id' => 'id']], ]; diff --git a/frontend/modules/reports/views/reports/_form.php b/frontend/modules/reports/views/reports/_form.php index eff9b57..1589c10 100644 --- a/frontend/modules/reports/views/reports/_form.php +++ b/frontend/modules/reports/views/reports/_form.php @@ -8,6 +8,8 @@ use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model common\models\Reports */ /* @var $form yii\widgets\ActiveForm */ + +$this->registerCss('.list-cell__task{width:73%}') ?>
@@ -42,13 +44,24 @@ use yii\widgets\ActiveForm; [ 'name' => 'task', 'title' => 'Задача', + 'options' => [ + ], ], [ 'name' => 'hours_spent', 'title' => 'Кол-во часов', 'options' => [ 'type' => 'number', - 'style' => 'width:100px' + 'min' => '0' + ], + ], + [ + 'name' => 'minutes_spent', + 'title' => 'Кол-во минут', + 'options' => [ + 'type' => 'number', + 'min' => '0', + 'max' => '59' ], ], ], diff --git a/frontend/modules/reports/views/reports/index.php b/frontend/modules/reports/views/reports/index.php index 9fd2aa1..73ad601 100644 --- a/frontend/modules/reports/views/reports/index.php +++ b/frontend/modules/reports/views/reports/index.php @@ -34,7 +34,7 @@ $this->params['breadcrumbs'][] = $this->title; if ($model->task) { $i = 1; foreach ($model->task as $task) { - $text .= "

$i. ($task->hours_spent ч.) $task->task

"; + $text .= "

$i. ($task->hours_spent ч., $task->minutes_spent мин.) $task->task

"; $i++; } } diff --git a/frontend/modules/reports/views/reports/view.php b/frontend/modules/reports/views/reports/view.php index 819f792..8092bbd 100644 --- a/frontend/modules/reports/views/reports/view.php +++ b/frontend/modules/reports/views/reports/view.php @@ -39,7 +39,7 @@ $this->params['breadcrumbs'][] = $this->title; if ($model->task) { $i = 1; foreach ($model->task as $task) { - $text .= "

$i. ($task->hours_spent ч.) $task->task

"; + $text .= "

$i. ($task->hours_spent ч., $task->minutes_spent мин.) $task->task

"; $i++; } } From 28294fc8ca18829a84cb5adc420d00163699ac9b Mon Sep 17 00:00:00 2001 From: anatolidew Date: Tue, 23 Nov 2021 11:01:35 +0300 Subject: [PATCH 02/14] =?UTF-8?q?*=20=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BB=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/reports/views/reports/_form.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/modules/reports/views/reports/_form.php b/frontend/modules/reports/views/reports/_form.php index 1589c10..6af727d 100644 --- a/frontend/modules/reports/views/reports/_form.php +++ b/frontend/modules/reports/views/reports/_form.php @@ -44,8 +44,6 @@ $this->registerCss('.list-cell__task{width:73%}') [ 'name' => 'task', 'title' => 'Задача', - 'options' => [ - ], ], [ 'name' => 'hours_spent', From b45e9a9033e196403e26ada45ef3d5581a65ffda Mon Sep 17 00:00:00 2001 From: anatolidew Date: Tue, 23 Nov 2021 11:03:19 +0300 Subject: [PATCH 03/14] =?UTF-8?q?*=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D0=BC=D0=B8=D0=BD=D1=83=D1=82?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...44548_add_column_to_reports_task_table.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 console/migrations/m211122_144548_add_column_to_reports_task_table.php diff --git a/console/migrations/m211122_144548_add_column_to_reports_task_table.php b/console/migrations/m211122_144548_add_column_to_reports_task_table.php new file mode 100644 index 0000000..7e3479e --- /dev/null +++ b/console/migrations/m211122_144548_add_column_to_reports_task_table.php @@ -0,0 +1,25 @@ +addColumn('reports_task', 'minutes_spent', $this->integer()->defaultValue(0)->notNull()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('reports_task', 'minutes_spent' ); + } +} From c4139baeb23d6ee01c2e3f74eae841b1826be7b0 Mon Sep 17 00:00:00 2001 From: anatolidew Date: Thu, 25 Nov 2021 14:04:14 +0300 Subject: [PATCH 04/14] =?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 05/14] =?UTF-8?q?*=20=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BB=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 06/14] =?UTF-8?q?=D1=80=D1=83=D1=81=D1=81=D0=BA=D0=B8?= =?UTF-8?q?=D0=B9=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 07/14] =?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 08/14] =?UTF-8?q?*=20=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BB=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, ], ] ]; From 57cb9df4bfd4717a89fe50ea5b569a6bc5699005 Mon Sep 17 00:00:00 2001 From: andrey Date: Mon, 29 Nov 2021 18:21:50 +0300 Subject: [PATCH 09/14] api cors --- .../modules/api/controllers/ApiController.php | 30 +++++++++++++++++++ .../api/controllers/ProfileController.php | 26 ++++++---------- .../api/controllers/ReportsController.php | 21 ++++--------- .../api/controllers/SkillsController.php | 26 ++++++---------- .../api/controllers/UserController.php | 26 ++++++++-------- 5 files changed, 66 insertions(+), 63 deletions(-) create mode 100644 frontend/modules/api/controllers/ApiController.php diff --git a/frontend/modules/api/controllers/ApiController.php b/frontend/modules/api/controllers/ApiController.php new file mode 100644 index 0000000..2d0e59e --- /dev/null +++ b/frontend/modules/api/controllers/ApiController.php @@ -0,0 +1,30 @@ + [ + 'class' => GsCors::class, + 'cors' => [ + 'Origin' => ['*'], + //'Access-Control-Allow-Credentials' => true, + 'Access-Control-Allow-Headers' => [ + 'Content-Type', + 'Access-Control-Allow-Headers', + 'Authorization', + 'X-Requested-With' + ], + ] + ], + ]; + } + +} \ No newline at end of file diff --git a/frontend/modules/api/controllers/ProfileController.php b/frontend/modules/api/controllers/ProfileController.php index 4e05e5e..4a7d745 100755 --- a/frontend/modules/api/controllers/ProfileController.php +++ b/frontend/modules/api/controllers/ProfileController.php @@ -12,17 +12,20 @@ use kavalar\TelegramBotService; use yii\filters\auth\CompositeAuth; use yii\filters\auth\HttpBearerAuth; use yii\filters\auth\QueryParamAuth; +use yii\filters\ContentNegotiator; +use yii\web\Response; -class ProfileController extends \yii\rest\Controller +class ProfileController extends ApiController { public function behaviors() { - return [ + $parent = parent::behaviors(); + $b = [ [ - 'class' => \yii\filters\ContentNegotiator::className(), + 'class' => ContentNegotiator::className(), 'formats' => [ - 'application/json' => \yii\web\Response::FORMAT_JSON, + 'application/json' => Response::FORMAT_JSON, ], ], 'authenticator' => [ @@ -31,20 +34,9 @@ class ProfileController extends \yii\rest\Controller HttpBearerAuth::class, ], ] -// 'corsFilter' => [ -// 'class' => GsCors::class, -// 'cors' => [ -// 'Origin' => ['https://itguild.info'], -// //'Access-Control-Allow-Credentials' => true, -// 'Access-Control-Allow-Headers' => [ -// 'Content-Type', -// 'Access-Control-Allow-Headers', -// 'Authorization', -// 'X-Requested-With' -// ], -// ] -// ] ]; + + return array_merge($parent, $b); } public function actionIndex($id = null) diff --git a/frontend/modules/api/controllers/ReportsController.php b/frontend/modules/api/controllers/ReportsController.php index 11333c7..b14be76 100755 --- a/frontend/modules/api/controllers/ReportsController.php +++ b/frontend/modules/api/controllers/ReportsController.php @@ -11,12 +11,11 @@ use Yii; use yii\filters\auth\CompositeAuth; use yii\filters\auth\HttpBearerAuth; use yii\filters\ContentNegotiator; -use yii\rest\Controller; use yii\web\BadRequestHttpException; use yii\web\NotFoundHttpException; use yii\web\Response; -class ReportsController extends Controller +class ReportsController extends ApiController { public function init() { @@ -25,26 +24,14 @@ class ReportsController extends Controller public function behaviors() { - return [ + $parent = parent::behaviors(); + $b = [ [ 'class' => ContentNegotiator::className(), 'formats' => [ 'application/json' => Response::FORMAT_JSON, ], ], -// 'corsFilter' => [ -// 'class' => GsCors::class, -// 'cors' => [ -// 'Origin' => ['*'], -// //'Access-Control-Allow-Credentials' => true, -// 'Access-Control-Allow-Headers' => [ -// 'Content-Type', -// 'Access-Control-Allow-Headers', -// 'Authorization', -// 'X-Requested-With' -// ], -// ] -// ], 'authenticator' => [ 'class' => CompositeAuth::class, 'authMethods' => [ @@ -52,6 +39,8 @@ class ReportsController extends Controller ], ] ]; + + return array_merge($parent, $b); } public function actionIndex(): array diff --git a/frontend/modules/api/controllers/SkillsController.php b/frontend/modules/api/controllers/SkillsController.php index c0bc06f..45a7780 100755 --- a/frontend/modules/api/controllers/SkillsController.php +++ b/frontend/modules/api/controllers/SkillsController.php @@ -8,16 +8,19 @@ use yii\filters\AccessControl; use yii\filters\auth\CompositeAuth; use yii\filters\auth\HttpBearerAuth; use yii\filters\auth\QueryParamAuth; +use yii\filters\ContentNegotiator; +use yii\web\Response; -class SkillsController extends \yii\rest\Controller +class SkillsController extends ApiController { public function behaviors() { - return [ + $parent = parent::behaviors(); + $b = [ [ - 'class' => \yii\filters\ContentNegotiator::className(), + 'class' => ContentNegotiator::className(), 'formats' => [ - 'application/json' => \yii\web\Response::FORMAT_JSON, + 'application/json' => Response::FORMAT_JSON, ], ], 'authenticator' => [ @@ -26,20 +29,9 @@ class SkillsController extends \yii\rest\Controller HttpBearerAuth::class, ], ] -// 'corsFilter' => [ -// 'class' => GsCors::class, -// 'cors' => [ -// 'Origin' => ['*'], -// //'Access-Control-Allow-Credentials' => true, -// 'Access-Control-Allow-Headers' => [ -// 'Content-Type', -// 'Access-Control-Allow-Headers', -// 'Authorization', -// 'X-Requested-With' -// ], -// ] -// ] ]; + + return array_merge($parent, $b); } public function actionIndex() diff --git a/frontend/modules/api/controllers/UserController.php b/frontend/modules/api/controllers/UserController.php index b8a9332..d725bbb 100755 --- a/frontend/modules/api/controllers/UserController.php +++ b/frontend/modules/api/controllers/UserController.php @@ -36,19 +36,19 @@ class UserController extends ActiveController // HttpBearerAuth::class, // ], // ], -// 'corsFilter' => [ -// 'class' => GsCors::class, -// 'cors' => [ -// 'Origin' => ['*'], -// //'Access-Control-Allow-Credentials' => true, -// 'Access-Control-Allow-Headers' => [ -// 'Content-Type', -// 'Access-Control-Allow-Headers', -// 'Authorization', -// 'X-Requested-With' -// ], -// ] -// ] + 'corsFilter' => [ + 'class' => GsCors::class, + 'cors' => [ + 'Origin' => ['*'], + //'Access-Control-Allow-Credentials' => true, + 'Access-Control-Allow-Headers' => [ + 'Content-Type', + 'Access-Control-Allow-Headers', + 'Authorization', + 'X-Requested-With' + ], + ] + ] ]); } From 234d5036fd3eb53bc705cb4af7bcfc3c533279ef Mon Sep 17 00:00:00 2001 From: anatolidew Date: Tue, 30 Nov 2021 11:29:43 +0300 Subject: [PATCH 10/14] =?UTF-8?q?*=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B0=D0=BF=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/main.md | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/docs/api/main.md b/docs/api/main.md index 73b53f3..3f149ea 100755 --- a/docs/api/main.md +++ b/docs/api/main.md @@ -258,6 +258,39 @@ `https://guild.craft-group.xyz/api/reports/index?fromDate=2021-08-01&toDate=2021-08-31&user_id=2limit=3&offset=2` +### Один отчет +`https://guild.craft-group.xyz/api/reports/{id}` +

+ Для получения отчета необходимо отправить GET запрос на URL https://guild.craft-group.xyz/api/reports/{id} +

+ +

+ Параметры: +

+ + + + + + + + + +
+ Параметры + + Значение +
+ id* + + ID отчета. +
+

+ Пример запроса на просмотр отчета с ID 13: +

+ +`https://guild.craft-group.xyz/api/reports/13` + ### Создать отчет `https://guild.craft-group.xyz/api/reports/create` @@ -295,10 +328,19 @@ - today + tasks* - Сделанное сегодня. + JSON массив содержащий объекты задач +
+[{ 
+    "task" : "Рефакторинг",
+    "created_at": 1638260728,
+    "status": 1,
+    "minutes_spent": 26,
+    "hours_spent" : 3
+}]
+
From 941a3964c666412be3923081567630feabd7f9c0 Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 30 Nov 2021 16:54:04 +0300 Subject: [PATCH 11/14] profile and reports fix --- common/models/UserCard.php | 7 ++++ .../api/controllers/ReportsController.php | 33 +++++++++--------- .../modules/api/models/ProfileSearchForm.php | 34 +++++++++++++++---- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/common/models/UserCard.php b/common/models/UserCard.php index 6fc5bb4..5e102eb 100755 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -201,6 +201,11 @@ class UserCard extends \yii\db\ActiveRecord return $this->hasMany(CardSkill::class, ['card_id' => 'id'])->with('skill'); } + public function getUser() + { + return $this->hasOne(User::class, ['id' => 'id_user']); + } + public static function getNameSkills() { return ArrayHelper::map(Skill::find()->all(), 'id', 'name'); @@ -268,4 +273,6 @@ class UserCard extends \yii\db\ActiveRecord $user_card->id_user = $user_id; $user_card->save(); } + + } diff --git a/frontend/modules/api/controllers/ReportsController.php b/frontend/modules/api/controllers/ReportsController.php index ca142df..46dbc3d 100755 --- a/frontend/modules/api/controllers/ReportsController.php +++ b/frontend/modules/api/controllers/ReportsController.php @@ -6,6 +6,7 @@ use common\behaviors\GsCors; use common\classes\Debug; use common\models\Reports; use common\models\ReportsTask; +use common\models\UserCard; use frontend\modules\api\models\ReportSearchForm; use JsonException; use Yii; @@ -49,6 +50,12 @@ class ReportsController extends ApiController $reportsModel = new ReportSearchForm(); $params = Yii::$app->request->get(); + if(!isset($params['user_card_id'])){ + $userCard = UserCard::find()->where(['id_user' => Yii::$app->user->id])->one(); + if($userCard){ + $params['user_card_id'] = $userCard->id; + } + } $reportsModel->attributes = $params; if(!$reportsModel->validate()){ @@ -69,31 +76,25 @@ class ReportsController extends ApiController throw new BadRequestHttpException('Нет параметра tasks'); } + if(!isset($params['user_card_id'])){ + $userCard = UserCard::find()->where(['id_user' => Yii::$app->user->id])->one(); + if($userCard){ + $params['user_card_id'] = $userCard->id; + } + } + $reportsModel = new Reports(); $reportsModel->attributes = $params; + $params['tasks'] = (is_array($params['tasks'])) ? $params['tasks'] : json_decode($params['tasks']); + if(!$reportsModel->validate()){ throw new BadRequestHttpException(json_encode($reportsModel->errors)); } - $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(); - $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]); + return array_merge($reportsModel->toArray()); } public function actionDelete() diff --git a/frontend/modules/api/models/ProfileSearchForm.php b/frontend/modules/api/models/ProfileSearchForm.php index 49a9652..6aa1711 100755 --- a/frontend/modules/api/models/ProfileSearchForm.php +++ b/frontend/modules/api/models/ProfileSearchForm.php @@ -32,6 +32,18 @@ class ProfileSearchForm extends Model ]; } + public function exclude($arr) + { + $ex = ['fio', 'passport', 'resume', 'link_vk', 'link_telegram', 'email', 'salary']; + foreach ($ex as $remove) { + if (isset($arr[$remove])) { + unset($arr[$remove]); + } + } + + return $arr; + } + public function checkIsArray() { @@ -43,12 +55,12 @@ class ProfileSearchForm extends Model public function byId() { if ($this->id) { - return UserCard::find() + return $this->exclude(UserCard::find() ->where(['id' => $this->id]) ->with(['skillValues']) ->with(['achievements']) ->asArray() - ->one(); + ->one()); } return null; @@ -59,13 +71,12 @@ class ProfileSearchForm extends Model $model = UserCard::find(); - if($this->skills){ + if ($this->skills) { $model->joinWith(['skillValues']); $this->skills = explode(',', $this->skills); $model->where(['card_skill.skill_id' => $this->skills]); $model->having('COUNT(DISTINCT skill_id) = ' . count($this->skills)); - } - else{ + } else { $model->joinWith('skillValues'); } @@ -78,8 +89,19 @@ class ProfileSearchForm extends Model $model->groupBy('card_skill.card_id'); - return $model->limit($this->limit) + $res = $model->limit($this->limit) ->offset($this->offset)->orderBy('updated_at DESC')->asArray()->all(); + + if(!$res){ + return []; + } + + $resArr = []; + foreach ($res as $re){ + $resArr[] = $this->exclude($re); + } + + return $resArr; } } \ No newline at end of file From 31c35676f356e1bd1b0894cda58846066aae4f1d Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 30 Nov 2021 17:18:07 +0300 Subject: [PATCH 12/14] profile search fix --- frontend/modules/api/models/ProfileSearchForm.php | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/modules/api/models/ProfileSearchForm.php b/frontend/modules/api/models/ProfileSearchForm.php index 6aa1711..e9d0f09 100755 --- a/frontend/modules/api/models/ProfileSearchForm.php +++ b/frontend/modules/api/models/ProfileSearchForm.php @@ -70,7 +70,6 @@ class ProfileSearchForm extends Model { $model = UserCard::find(); - if ($this->skills) { $model->joinWith(['skillValues']); $this->skills = explode(',', $this->skills); From 25377d272d7b0520e393ff099542015942b77b8f Mon Sep 17 00:00:00 2001 From: andrey Date: Mon, 6 Dec 2021 17:07:27 +0300 Subject: [PATCH 13/14] report by date --- .../modules/api/models/ReportSearchForm.php | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/frontend/modules/api/models/ReportSearchForm.php b/frontend/modules/api/models/ReportSearchForm.php index 0b03253..d1104d1 100755 --- a/frontend/modules/api/models/ReportSearchForm.php +++ b/frontend/modules/api/models/ReportSearchForm.php @@ -14,6 +14,10 @@ class ReportSearchForm extends Model public $fromDate; public $toDate; public $user_id; + /** + * @var false + */ + public $byDate; public function __construct($config = []) { @@ -23,6 +27,7 @@ class ReportSearchForm extends Model $this->toDate = date('Y-m-d', time()); $this->fromDate = date('Y-m-01', time()); + $this->byDate = false; parent::__construct($config); } @@ -30,20 +35,27 @@ class ReportSearchForm extends Model public function rules(): array { return [ - [['fromDate', 'toDate'], 'date', 'format' => 'php:Y-m-d'], - [['limit', 'offset', 'user_id'], 'integer', 'min' => 0], + [['byDate'], 'safe'], + [['fromDate', 'toDate'], 'date', 'format' => 'php:Y-m-d'], + [['limit', 'offset', 'user_id'], 'integer', 'min' => 0], ]; } public function byParams() { $queryBuilder = Reports::find() - ->with('task') - ->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate]) - ->limit($this->limit) + ->with('task'); + + if ($this->byDate) { + $queryBuilder->andWhere(['reports.created_at' => $this->byDate]); + } else { + $queryBuilder->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate]); + } + + $queryBuilder->limit($this->limit) ->offset($this->offset); - if(isset($this->user_id)) { + if (isset($this->user_id)) { $queryBuilder->andWhere(['user_card_id' => $this->user_id]); } From 5c80f72ee55f88f048fdad1cbad5c6e2919ff947 Mon Sep 17 00:00:00 2001 From: anatolidew Date: Fri, 10 Dec 2021 15:29:07 +0300 Subject: [PATCH 14/14] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B8=D0=BB=20=D1=80=D0=B5=D0=B7=D1=8E=D0=BC=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../card/controllers/UserCardController.php | 15 +++++++++++ .../modules/card/views/user-card/resume.php | 27 +++++++++++++++++++ .../modules/card/views/user-card/view.php | 13 ++------- 3 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 frontend/modules/card/views/user-card/resume.php diff --git a/frontend/modules/card/controllers/UserCardController.php b/frontend/modules/card/controllers/UserCardController.php index b22cf28..b031ba9 100755 --- a/frontend/modules/card/controllers/UserCardController.php +++ b/frontend/modules/card/controllers/UserCardController.php @@ -112,6 +112,21 @@ class UserCardController extends Controller ]); } + public function actionResume() + { + $id_user = Yii::$app->user->id; + $result = UserCard::find()->where(['id_user' => $id_user])->asArray()->all(); + if ($result) { + $id = $result[0]['id']; + $model = $this->findModel($id); + return $this->render('resume', [ + 'model' => $model + ]); + } else { + return $this->render('index', ['info' => '

Ваши личные данные не заненсены в базу.

']); + } + } + /** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/frontend/modules/card/views/user-card/resume.php b/frontend/modules/card/views/user-card/resume.php new file mode 100644 index 0000000..8fa4a07 --- /dev/null +++ b/frontend/modules/card/views/user-card/resume.php @@ -0,0 +1,27 @@ +title = 'Резюме'; +?> +
+

Резюме

+ + Url::base(true)]); ?> + field($model, 'vc_text')->widget(EditorClassic::className(), [ + 'clientOptions' => [ + 'language' => 'ru', + ] + ]); ?> +
+ Save', ['class' => 'btn btn-success']) ?> + Back', Url::base(true), ['class' => 'btn btn-primary', 'style' => 'float: right']) ?> +
+ +
\ No newline at end of file diff --git a/frontend/modules/card/views/user-card/view.php b/frontend/modules/card/views/user-card/view.php index 80bb663..da695f0 100755 --- a/frontend/modules/card/views/user-card/view.php +++ b/frontend/modules/card/views/user-card/view.php @@ -19,7 +19,8 @@ $this->title = 'Профиль';

Личная информация

'btn btn-success']) - . ' ' . Html::a('Изменить пароль', ['/card/user-card/password'], ['class' => 'btn btn-success']) . '

'; + . ' ' . Html::a('Изменить пароль', ['/card/user-card/password'], ['class' => 'btn btn-success']) + . ' ' . Html::a('Изменить резюме', ['/card/user-card/resume'], ['class' => 'btn btn-success']). '

'; echo DetailView::widget([ 'model' => $model, @@ -70,14 +71,4 @@ $this->title = 'Профиль'; ], ]); ?> - - field($model, 'vc_text')->widget(EditorClassic::className(), [ - 'clientOptions' => [ - 'language' => 'ru', - ] - ]); ?> -
- 'btn btn-success']) ?> -
-