From e712f2fc36ffec7fde96c8343be0c1a69788961c Mon Sep 17 00:00:00 2001 From: iIronside Date: Fri, 13 Oct 2023 14:25:40 +0300 Subject: [PATCH 1/7] fix tasks --- common/models/ProjectTask.php | 61 +++++++++++++++++++++ common/services/TaskService.php | 2 +- frontend/modules/api/models/ProjectTask.php | 58 -------------------- 3 files changed, 62 insertions(+), 59 deletions(-) diff --git a/common/models/ProjectTask.php b/common/models/ProjectTask.php index be19aac..a717f54 100644 --- a/common/models/ProjectTask.php +++ b/common/models/ProjectTask.php @@ -97,6 +97,67 @@ class ProjectTask extends ActiveRecord ]; } + /** + * @return string[] + */ + public function fields(): array + { + return [ + 'id', + 'project_id', + 'project_name' => function () { + return $this->project->name ?? null; + }, + 'title', + 'created_at', + 'updated_at', + 'dead_line', + 'description', + 'status', + 'column_id', + 'user_id', + 'user' => function () { + return [ + "fio" => $this->user->userCard->fio ?? $this->user->id, + "avatar" => $this->user->userCard->photo ?? '', + ]; + }, + 'executor_id', + 'priority', + 'executor' => function () { + if ($this->executor) { + return [ + "fio" => $this->executor->userCard->fio ?? $this->executor->username, + "avatar" => $this->executor->userCard->photo ?? '', + ]; + } + + return null; + }, + 'comment_count' => function () { + return Comment::find()->where(['entity_id' => $this->id, 'entity_type' => 2, 'status' => Comment::STATUS_ACTIVE])->count(); + }, + 'taskUsers', + 'mark' + ]; + } + + /** + * @return string[] + */ + public function extraFields(): array + { + return [ + 'timers', + 'column' => function () { + return [ + 'column_title' => $this->column->title ?? null + ]; + }, + 'mark' + ]; + } + /** * @return string[] */ diff --git a/common/services/TaskService.php b/common/services/TaskService.php index c2a9b92..835cd82 100644 --- a/common/services/TaskService.php +++ b/common/services/TaskService.php @@ -2,8 +2,8 @@ namespace common\services; +use common\models\ProjectTask; use common\models\ProjectTaskUser; -use frontend\modules\api\models\ProjectTask; class TaskService { diff --git a/frontend/modules/api/models/ProjectTask.php b/frontend/modules/api/models/ProjectTask.php index ed80fd9..78d6de0 100644 --- a/frontend/modules/api/models/ProjectTask.php +++ b/frontend/modules/api/models/ProjectTask.php @@ -152,63 +152,5 @@ namespace frontend\modules\api\models; */ class ProjectTask extends \common\models\ProjectTask { - /** - * @return string[] - */ - public function fields(): array - { - return [ - 'id', - 'project_id', - 'project_name' => function () { - return $this->project->name ?? null; - }, - 'title', - 'created_at', - 'updated_at', - 'dead_line', - 'description', - 'status', - 'column_id', - 'user_id', - 'user' => function () { - return [ - "fio" => $this->user->userCard->fio ?? $this->user->id, - "avatar" => $this->user->userCard->photo ?? '', - ]; - }, - 'executor_id', - 'priority', - 'executor' => function () { - if ($this->executor) { - return [ - "fio" => $this->executor->userCard->fio ?? $this->executor->username, - "avatar" => $this->executor->userCard->photo ?? '', - ]; - } - return null; - }, - 'comment_count' => function () { - return Comment::find()->where(['entity_id' => $this->id, 'entity_type' => 2, 'status' => Comment::STATUS_ACTIVE])->count(); - }, - 'taskUsers', - ]; - } - - /** - * @return string[] - */ - public function extraFields(): array - { - return [ - 'timers', - 'column' => function () { - return [ - 'column_title' => $this->column->title ?? null - ]; - }, - 'mark' - ]; - } } \ No newline at end of file From b004f6e21b876cd980316c25fb3701e9ff1bc6f0 Mon Sep 17 00:00:00 2001 From: iIronside Date: Fri, 13 Oct 2023 15:44:16 +0300 Subject: [PATCH 2/7] Updated validation for the project --- common/models/Project.php | 5 +-- ...ey_in_project_from_owner_id_to_user_id.php | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 console/migrations/m231013_122324_add_foreign_key_in_project_from_owner_id_to_user_id.php diff --git a/common/models/Project.php b/common/models/Project.php index 21a56e8..8f59342 100755 --- a/common/models/Project.php +++ b/common/models/Project.php @@ -23,6 +23,7 @@ use yii\helpers\ArrayHelper; * * @property FieldsValue[] $fieldsValues * @property Company $company + * @property User $owner * @property ProjectUser[] $projectUsers * @property Mark[] $mark * @property MarkEntity[] $markEntity @@ -55,8 +56,8 @@ class Project extends \yii\db\ActiveRecord public function rules() { return [ - ['name', 'unique'], - [['name', 'status'], 'required'], + [['name', 'owner_id', 'status'], 'required'], + [['owner_id', 'name'], 'unique', 'targetAttribute' => ['owner_id', 'name']], [['description'], 'string'], [['created_at', 'updated_at'], 'safe'], [['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']], diff --git a/console/migrations/m231013_122324_add_foreign_key_in_project_from_owner_id_to_user_id.php b/console/migrations/m231013_122324_add_foreign_key_in_project_from_owner_id_to_user_id.php new file mode 100644 index 0000000..1a7c014 --- /dev/null +++ b/console/migrations/m231013_122324_add_foreign_key_in_project_from_owner_id_to_user_id.php @@ -0,0 +1,31 @@ +addForeignKey( + 'project_user', + 'project', + 'owner_id', + 'user', + 'id' + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('project_user', 'project'); + } +} From 1c3eeb4cf39c9bfadd7dfc8bdff3002d0ab33e44 Mon Sep 17 00:00:00 2001 From: iIronside Date: Fri, 13 Oct 2023 15:52:39 +0300 Subject: [PATCH 3/7] Updated validation for the project column --- common/models/ProjectColumn.php | 1 + 1 file changed, 1 insertion(+) diff --git a/common/models/ProjectColumn.php b/common/models/ProjectColumn.php index b3d91c0..cc8795e 100644 --- a/common/models/ProjectColumn.php +++ b/common/models/ProjectColumn.php @@ -65,6 +65,7 @@ class ProjectColumn extends \yii\db\ActiveRecord return [ [['title', 'project_id'], 'required'], [['project_id', 'status', 'priority'], 'integer'], + [['project_id', 'title'], 'unique', 'targetAttribute' => ['project_id', 'title']], [['created_at', 'updated_at'], 'safe'], [['title'], 'string', 'max' => 255], [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']], From 5ce77f2ef0db70489cce752e55517b2c56f8b4f0 Mon Sep 17 00:00:00 2001 From: iIronside Date: Fri, 13 Oct 2023 16:31:22 +0300 Subject: [PATCH 4/7] Add the ability to select a priority when creating a task (low, medium, high) --- .../task/controllers/TaskController.php | 8 ++---- .../{TaskSearch.php => ProjectTaskSearch.php} | 15 ++++++----- backend/modules/task/views/task/_form.php | 8 +++++- backend/modules/task/views/task/_search.php | 2 +- backend/modules/task/views/task/index.php | 10 ++++++- backend/modules/task/views/task/view.php | 8 +++++- common/models/ProjectTask.php | 27 +++++++++++++++++++ .../api/controllers/TaskController.php | 2 +- 8 files changed, 62 insertions(+), 18 deletions(-) rename backend/modules/task/models/{TaskSearch.php => ProjectTaskSearch.php} (74%) diff --git a/backend/modules/task/controllers/TaskController.php b/backend/modules/task/controllers/TaskController.php index 0d718d2..735e2db 100644 --- a/backend/modules/task/controllers/TaskController.php +++ b/backend/modules/task/controllers/TaskController.php @@ -2,14 +2,10 @@ namespace backend\modules\task\controllers; -use backend\modules\project\models\ProjectUser; -use backend\modules\task\models\ProjectTaskUser; -use common\classes\Debug; use yii\data\ActiveDataProvider; -use yii\web\Response; use Yii; use backend\modules\task\models\ProjectTask; -use backend\modules\task\models\TaskSearch; +use backend\modules\task\models\ProjectTaskSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -43,7 +39,7 @@ class TaskController extends Controller */ public function actionIndex() { - $searchModel = new TaskSearch(); + $searchModel = new ProjectTaskSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ diff --git a/backend/modules/task/models/TaskSearch.php b/backend/modules/task/models/ProjectTaskSearch.php similarity index 74% rename from backend/modules/task/models/TaskSearch.php rename to backend/modules/task/models/ProjectTaskSearch.php index 54513c7..7fe8958 100644 --- a/backend/modules/task/models/TaskSearch.php +++ b/backend/modules/task/models/ProjectTaskSearch.php @@ -10,7 +10,7 @@ use backend\modules\task\models\ProjectTask; /** * TaskSearch represents the model behind the search form of `backend\modules\task\models\Task`. */ -class TaskSearch extends ProjectTask +class ProjectTaskSearch extends ProjectTask { /** * {@inheritdoc} @@ -18,7 +18,7 @@ class TaskSearch extends ProjectTask public function rules() { return [ - [['id', 'project_id', 'status'], 'integer'], // 'card_id_creator', 'card_id' + [['id', 'project_id', 'status', 'priority'], 'integer'], // 'card_id_creator', 'card_id' [['title', 'created_at', 'updated_at', 'description'], 'safe'], ]; } @@ -60,14 +60,15 @@ class TaskSearch extends ProjectTask // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, - 'task.project_id' => $this->project_id, - 'task.status' => $this->status, - 'task.created_at' => $this->created_at, - 'task.updated_at' => $this->updated_at, + 'project_task.project_id' => $this->project_id, + 'project_task.status' => $this->status, + 'project_task.priority' => $this->priority, + 'project_task.created_at' => $this->created_at, + 'project_task.updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'title', $this->title]) - ->andFilterWhere(['like', 'task.description', $this->description]); + ->andFilterWhere(['like', 'project_task.description', $this->description]); return $dataProvider; } diff --git a/backend/modules/task/views/task/_form.php b/backend/modules/task/views/task/_form.php index ac6327b..93661fd 100644 --- a/backend/modules/task/views/task/_form.php +++ b/backend/modules/task/views/task/_form.php @@ -2,6 +2,7 @@ use backend\modules\card\models\UserCard; use backend\modules\project\models\Project; +use backend\modules\task\models\ProjectTask; use common\helpers\StatusHelper; use kartik\select2\Select2; use yii\helpers\Html; @@ -57,7 +58,12 @@ use yii\widgets\ActiveForm; field($model, 'description')->textarea(['rows' => '6']) ?> - field($model, 'priority')->input('number') ?> + field($model, 'priority')->dropDownList( + ProjectTask::priorityList(), + [ + 'prompt' => 'Выберите' + ] + ) ?>
'btn btn-success']) ?> diff --git a/backend/modules/task/views/task/_search.php b/backend/modules/task/views/task/_search.php index f42ac3b..acb1a83 100644 --- a/backend/modules/task/views/task/_search.php +++ b/backend/modules/task/views/task/_search.php @@ -4,7 +4,7 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ -/* @var $model backend\modules\task\models\TaskSearch */ +/* @var $model backend\modules\task\models\ProjectTaskSearch */ /* @var $form yii\widgets\ActiveForm */ ?> diff --git a/backend/modules/task/views/task/index.php b/backend/modules/task/views/task/index.php index 7978a72..c5038e3 100644 --- a/backend/modules/task/views/task/index.php +++ b/backend/modules/task/views/task/index.php @@ -12,7 +12,7 @@ use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ -/* @var $searchModel backend\modules\task\models\TaskSearch */ +/* @var $searchModel backend\modules\task\models\ProjectTaskSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Задачи'; @@ -58,6 +58,14 @@ $this->params['breadcrumbs'][] = $this->title; return StatusHelper::statusLabel($model->status); } ], + [ + 'attribute' => 'priority', + 'format' => 'raw', + 'filter' => ProjectTask::priorityList(), + 'value' => function($model){ + return ProjectTask::getPriority($model->status); + } + ], [ 'attribute' => 'created_at', 'format' => ['datetime', 'php:d.m.Y H:i'] diff --git a/backend/modules/task/views/task/view.php b/backend/modules/task/views/task/view.php index c5a1ed6..77487e3 100644 --- a/backend/modules/task/views/task/view.php +++ b/backend/modules/task/views/task/view.php @@ -1,5 +1,6 @@ ArrayHelper::getValue($model, 'executor.userCard.fio'), ], 'description', - 'priority', + [ + 'attribute' => 'priority', + 'value' => function($model){ + return ProjectTask::getPriority($model->status); + } + ], ], ]) ?> diff --git a/common/models/ProjectTask.php b/common/models/ProjectTask.php index a717f54..70eae57 100644 --- a/common/models/ProjectTask.php +++ b/common/models/ProjectTask.php @@ -37,6 +37,32 @@ class ProjectTask extends ActiveRecord const STATUS_ACTIVE = 1; const STATUS_DISABLE = 0; + const PRIORITY_LOW = 0; + const PRIORITY_MEDIUM = 1; + const PRIORITY_HIGH = 2; + + /** + * @return string[] + */ + public static function priorityList() :array + { + return [ + self::PRIORITY_LOW => 'Низкий', + self::PRIORITY_MEDIUM => 'Средний', + self::PRIORITY_HIGH => 'Высокий', + ]; + } + + /** + * @param $priority + * @return string + * @throws \Exception + */ + public static function getPriority($priority): string + { + return ArrayHelper::getValue(self::priorityList(), $priority); + } + /** * {@inheritdoc} */ @@ -66,6 +92,7 @@ class ProjectTask extends ActiveRecord [['project_id', 'status', 'title', 'description',], 'required'], [['project_id', 'status', 'column_id', 'user_id', 'executor_id', 'priority'], 'integer'], [['created_at', 'updated_at', 'dead_line'], 'safe'], + ['status', 'in', 'range' => [self::PRIORITY_LOW, self::PRIORITY_MEDIUM, self::PRIORITY_HIGH]], ['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'], [['title'], 'string', 'max' => 255], [['description'], 'string', 'max' => 1500], diff --git a/frontend/modules/api/controllers/TaskController.php b/frontend/modules/api/controllers/TaskController.php index 75db62d..5ca190a 100644 --- a/frontend/modules/api/controllers/TaskController.php +++ b/frontend/modules/api/controllers/TaskController.php @@ -72,7 +72,7 @@ class TaskController extends ApiController * @OA\Property( * property="priority", * type="integer", - * description="Приоритет задачи", + * description="Приоритет задачи. (0 -low, 1 - medium, 2 - high)", * ), * @OA\Property( * property="column_id", From 5b3f6518dcb9845b08cacee6bec93e451de6fe35 Mon Sep 17 00:00:00 2001 From: iIronside Date: Fri, 13 Oct 2023 17:00:01 +0300 Subject: [PATCH 5/7] rollback last changes --- .../modules/task/models/ProjectTaskSearch.php | 3 +- backend/modules/task/views/task/_form.php | 14 +++--- backend/modules/task/views/task/index.php | 16 +++--- backend/modules/task/views/task/view.php | 13 ++--- common/models/ProjectTask.php | 50 +++++++++---------- .../api/controllers/TaskController.php | 2 +- 6 files changed, 50 insertions(+), 48 deletions(-) diff --git a/backend/modules/task/models/ProjectTaskSearch.php b/backend/modules/task/models/ProjectTaskSearch.php index 7fe8958..6b60bee 100644 --- a/backend/modules/task/models/ProjectTaskSearch.php +++ b/backend/modules/task/models/ProjectTaskSearch.php @@ -18,7 +18,7 @@ class ProjectTaskSearch extends ProjectTask public function rules() { return [ - [['id', 'project_id', 'status', 'priority'], 'integer'], // 'card_id_creator', 'card_id' + [['id', 'project_id', 'status'], 'integer'], // 'card_id_creator', 'card_id' [['title', 'created_at', 'updated_at', 'description'], 'safe'], ]; } @@ -62,7 +62,6 @@ class ProjectTaskSearch extends ProjectTask 'id' => $this->id, 'project_task.project_id' => $this->project_id, 'project_task.status' => $this->status, - 'project_task.priority' => $this->priority, 'project_task.created_at' => $this->created_at, 'project_task.updated_at' => $this->updated_at, ]); diff --git a/backend/modules/task/views/task/_form.php b/backend/modules/task/views/task/_form.php index 93661fd..7ae2466 100644 --- a/backend/modules/task/views/task/_form.php +++ b/backend/modules/task/views/task/_form.php @@ -58,12 +58,14 @@ use yii\widgets\ActiveForm; field($model, 'description')->textarea(['rows' => '6']) ?> - field($model, 'priority')->dropDownList( - ProjectTask::priorityList(), - [ - 'prompt' => 'Выберите' - ] - ) ?> + field($model, 'priority')->input('number') ?> + +field($model, 'priority')->dropDownList( +// ProjectTask::priorityList(), +// [ +// 'prompt' => 'Выберите' +// ] +// ) ?>
'btn btn-success']) ?> diff --git a/backend/modules/task/views/task/index.php b/backend/modules/task/views/task/index.php index c5038e3..b130a43 100644 --- a/backend/modules/task/views/task/index.php +++ b/backend/modules/task/views/task/index.php @@ -58,14 +58,14 @@ $this->params['breadcrumbs'][] = $this->title; return StatusHelper::statusLabel($model->status); } ], - [ - 'attribute' => 'priority', - 'format' => 'raw', - 'filter' => ProjectTask::priorityList(), - 'value' => function($model){ - return ProjectTask::getPriority($model->status); - } - ], +// [ +// 'attribute' => 'priority', +// 'format' => 'raw', +// 'filter' => ProjectTask::priorityList(), +// 'value' => function($model){ +// return ProjectTask::getPriority($model->status); +// } +// ], [ 'attribute' => 'created_at', 'format' => ['datetime', 'php:d.m.Y H:i'] diff --git a/backend/modules/task/views/task/view.php b/backend/modules/task/views/task/view.php index 77487e3..c13a900 100644 --- a/backend/modules/task/views/task/view.php +++ b/backend/modules/task/views/task/view.php @@ -60,12 +60,13 @@ YiiAsset::register($this); 'value' => ArrayHelper::getValue($model, 'executor.userCard.fio'), ], 'description', - [ - 'attribute' => 'priority', - 'value' => function($model){ - return ProjectTask::getPriority($model->status); - } - ], + 'priority', +// [ +// 'attribute' => 'priority', +// 'value' => function($model){ +// return ProjectTask::getPriority($model->status); +// } +// ], ], ]) ?> diff --git a/common/models/ProjectTask.php b/common/models/ProjectTask.php index 70eae57..37f94e4 100644 --- a/common/models/ProjectTask.php +++ b/common/models/ProjectTask.php @@ -37,31 +37,31 @@ class ProjectTask extends ActiveRecord const STATUS_ACTIVE = 1; const STATUS_DISABLE = 0; - const PRIORITY_LOW = 0; - const PRIORITY_MEDIUM = 1; - const PRIORITY_HIGH = 2; +// const PRIORITY_LOW = 0; +// const PRIORITY_MEDIUM = 1; +// const PRIORITY_HIGH = 2; +// +// /** +// * @return string[] +// */ +// public static function priorityList() :array +// { +// return [ +// self::PRIORITY_LOW => 'Низкий', +// self::PRIORITY_MEDIUM => 'Средний', +// self::PRIORITY_HIGH => 'Высокий', +// ]; +// } - /** - * @return string[] - */ - public static function priorityList() :array - { - return [ - self::PRIORITY_LOW => 'Низкий', - self::PRIORITY_MEDIUM => 'Средний', - self::PRIORITY_HIGH => 'Высокий', - ]; - } - - /** - * @param $priority - * @return string - * @throws \Exception - */ - public static function getPriority($priority): string - { - return ArrayHelper::getValue(self::priorityList(), $priority); - } +// /** +// * @param $priority +// * @return string +// * @throws \Exception +// */ +// public static function getPriority($priority): string +// { +// return ArrayHelper::getValue(self::priorityList(), $priority); +// } /** * {@inheritdoc} @@ -92,7 +92,7 @@ class ProjectTask extends ActiveRecord [['project_id', 'status', 'title', 'description',], 'required'], [['project_id', 'status', 'column_id', 'user_id', 'executor_id', 'priority'], 'integer'], [['created_at', 'updated_at', 'dead_line'], 'safe'], - ['status', 'in', 'range' => [self::PRIORITY_LOW, self::PRIORITY_MEDIUM, self::PRIORITY_HIGH]], +// ['status', 'in', 'range' => [self::PRIORITY_LOW, self::PRIORITY_MEDIUM, self::PRIORITY_HIGH]], ['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'], [['title'], 'string', 'max' => 255], [['description'], 'string', 'max' => 1500], diff --git a/frontend/modules/api/controllers/TaskController.php b/frontend/modules/api/controllers/TaskController.php index 5ca190a..89cdde9 100644 --- a/frontend/modules/api/controllers/TaskController.php +++ b/frontend/modules/api/controllers/TaskController.php @@ -72,7 +72,7 @@ class TaskController extends ApiController * @OA\Property( * property="priority", * type="integer", - * description="Приоритет задачи. (0 -low, 1 - medium, 2 - high)", + * description="Приоритет задачи.", * ), * @OA\Property( * property="column_id", From c20d7fbe777db87c2c4648d898967debbb6fc183 Mon Sep 17 00:00:00 2001 From: iIronside Date: Fri, 13 Oct 2023 17:58:58 +0300 Subject: [PATCH 6/7] Add execution_priority to task --- .../modules/task/models/ProjectTaskSearch.php | 1 + backend/modules/task/views/task/_form.php | 12 ++-- backend/modules/task/views/task/index.php | 16 +++--- backend/modules/task/views/task/view.php | 12 ++-- common/models/ProjectTask.php | 57 ++++++++++--------- ..._priority_column_to_project_task_table.php | 25 ++++++++ .../api/controllers/TaskController.php | 5 ++ 7 files changed, 81 insertions(+), 47 deletions(-) create mode 100644 console/migrations/m231013_144526_add_execution_priority_column_to_project_task_table.php diff --git a/backend/modules/task/models/ProjectTaskSearch.php b/backend/modules/task/models/ProjectTaskSearch.php index 6b60bee..9c20656 100644 --- a/backend/modules/task/models/ProjectTaskSearch.php +++ b/backend/modules/task/models/ProjectTaskSearch.php @@ -62,6 +62,7 @@ class ProjectTaskSearch extends ProjectTask 'id' => $this->id, 'project_task.project_id' => $this->project_id, 'project_task.status' => $this->status, + 'project_task.execution_priority' => $this->execution_priority, 'project_task.created_at' => $this->created_at, 'project_task.updated_at' => $this->updated_at, ]); diff --git a/backend/modules/task/views/task/_form.php b/backend/modules/task/views/task/_form.php index 7ae2466..f8c8e20 100644 --- a/backend/modules/task/views/task/_form.php +++ b/backend/modules/task/views/task/_form.php @@ -60,12 +60,12 @@ use yii\widgets\ActiveForm; field($model, 'priority')->input('number') ?> -field($model, 'priority')->dropDownList( -// ProjectTask::priorityList(), -// [ -// 'prompt' => 'Выберите' -// ] -// ) ?> + field($model, 'execution_priority')->dropDownList( + ProjectTask::priorityList(), + [ + 'prompt' => 'Выберите' + ] + ) ?>
'btn btn-success']) ?> diff --git a/backend/modules/task/views/task/index.php b/backend/modules/task/views/task/index.php index b130a43..538f42c 100644 --- a/backend/modules/task/views/task/index.php +++ b/backend/modules/task/views/task/index.php @@ -58,14 +58,14 @@ $this->params['breadcrumbs'][] = $this->title; return StatusHelper::statusLabel($model->status); } ], -// [ -// 'attribute' => 'priority', -// 'format' => 'raw', -// 'filter' => ProjectTask::priorityList(), -// 'value' => function($model){ -// return ProjectTask::getPriority($model->status); -// } -// ], + [ + 'attribute' => 'execution_priority', + 'format' => 'raw', + 'filter' => ProjectTask::priorityList(), + 'value' => function($model){ + return ProjectTask::getPriority($model->status); + } + ], [ 'attribute' => 'created_at', 'format' => ['datetime', 'php:d.m.Y H:i'] diff --git a/backend/modules/task/views/task/view.php b/backend/modules/task/views/task/view.php index c13a900..0f458b1 100644 --- a/backend/modules/task/views/task/view.php +++ b/backend/modules/task/views/task/view.php @@ -61,12 +61,12 @@ YiiAsset::register($this); ], 'description', 'priority', -// [ -// 'attribute' => 'priority', -// 'value' => function($model){ -// return ProjectTask::getPriority($model->status); -// } -// ], + [ + 'attribute' => 'execution_priority', + 'value' => function($model){ + return ProjectTask::getPriority($model->status); + } + ], ], ]) ?> diff --git a/common/models/ProjectTask.php b/common/models/ProjectTask.php index 37f94e4..7321c9b 100644 --- a/common/models/ProjectTask.php +++ b/common/models/ProjectTask.php @@ -21,6 +21,7 @@ use yii\helpers\ArrayHelper; * @property int $user_id * @property int $executor_id * @property int $priority + * @property int $execution_priority * @property string $description * @property string $dead_line * @@ -37,31 +38,31 @@ class ProjectTask extends ActiveRecord const STATUS_ACTIVE = 1; const STATUS_DISABLE = 0; -// const PRIORITY_LOW = 0; -// const PRIORITY_MEDIUM = 1; -// const PRIORITY_HIGH = 2; -// -// /** -// * @return string[] -// */ -// public static function priorityList() :array -// { -// return [ -// self::PRIORITY_LOW => 'Низкий', -// self::PRIORITY_MEDIUM => 'Средний', -// self::PRIORITY_HIGH => 'Высокий', -// ]; -// } + const PRIORITY_LOW = 0; + const PRIORITY_MEDIUM = 1; + const PRIORITY_HIGH = 2; -// /** -// * @param $priority -// * @return string -// * @throws \Exception -// */ -// public static function getPriority($priority): string -// { -// return ArrayHelper::getValue(self::priorityList(), $priority); -// } + /** + * @return string[] + */ + public static function priorityList() :array + { + return [ + self::PRIORITY_LOW => 'Низкий', + self::PRIORITY_MEDIUM => 'Средний', + self::PRIORITY_HIGH => 'Высокий', + ]; + } + + /** + * @param $priority + * @return string + * @throws \Exception + */ + public static function getPriority($priority): string + { + return ArrayHelper::getValue(self::priorityList(), $priority); + } /** * {@inheritdoc} @@ -90,9 +91,9 @@ class ProjectTask extends ActiveRecord { return [ [['project_id', 'status', 'title', 'description',], 'required'], - [['project_id', 'status', 'column_id', 'user_id', 'executor_id', 'priority'], 'integer'], + [['project_id', 'status', 'column_id', 'user_id', 'executor_id', 'priority', 'execution_priority'], 'integer'], [['created_at', 'updated_at', 'dead_line'], 'safe'], -// ['status', 'in', 'range' => [self::PRIORITY_LOW, self::PRIORITY_MEDIUM, self::PRIORITY_HIGH]], + ['execution_priority', 'in', 'range' => [self::PRIORITY_LOW, self::PRIORITY_MEDIUM, self::PRIORITY_HIGH]], ['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'], [['title'], 'string', 'max' => 255], [['description'], 'string', 'max' => 1500], @@ -121,6 +122,7 @@ class ProjectTask extends ActiveRecord 'executor_id' => 'Исполнитель', 'priority' => 'Приоритет', 'dead_line' => 'Срок выполнения задачи', + 'execution_priority' => 'Приоритет выполнения', ]; } @@ -165,7 +167,8 @@ class ProjectTask extends ActiveRecord return Comment::find()->where(['entity_id' => $this->id, 'entity_type' => 2, 'status' => Comment::STATUS_ACTIVE])->count(); }, 'taskUsers', - 'mark' + 'mark', + 'execution_priority' ]; } diff --git a/console/migrations/m231013_144526_add_execution_priority_column_to_project_task_table.php b/console/migrations/m231013_144526_add_execution_priority_column_to_project_task_table.php new file mode 100644 index 0000000..8dea2cd --- /dev/null +++ b/console/migrations/m231013_144526_add_execution_priority_column_to_project_task_table.php @@ -0,0 +1,25 @@ +addColumn('project_task', 'execution_priority', $this->integer(1)); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('project_task', 'execution_priority'); + } +} diff --git a/frontend/modules/api/controllers/TaskController.php b/frontend/modules/api/controllers/TaskController.php index 89cdde9..77d830c 100644 --- a/frontend/modules/api/controllers/TaskController.php +++ b/frontend/modules/api/controllers/TaskController.php @@ -75,6 +75,11 @@ class TaskController extends ApiController * description="Приоритет задачи.", * ), * @OA\Property( + * property="execution_priority", + * type="integer", + * description="Приоритет выполнения задачи (0 - low, 1 - medium, 2 - high)", + * ), + * @OA\Property( * property="column_id", * type="integer", * description="Колонка к которой относится задача", From 0e2bd930101a94ad4ab13c116ace931004c0b08c Mon Sep 17 00:00:00 2001 From: iIronside Date: Fri, 13 Oct 2023 18:03:36 +0300 Subject: [PATCH 7/7] update doc --- frontend/modules/api/models/ProjectTask.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/modules/api/models/ProjectTask.php b/frontend/modules/api/models/ProjectTask.php index 78d6de0..6258115 100644 --- a/frontend/modules/api/models/ProjectTask.php +++ b/frontend/modules/api/models/ProjectTask.php @@ -71,6 +71,12 @@ namespace frontend\modules\api\models; * description="Приоритет задачи" * ), * @OA\Property( + * property="execution_priority", + * type="integer", + * example="2", + * description="Приоритет выполнения задачи (0 - low, 1 - medium, 2 - high)", + * ), + * @OA\Property( * property="status", * type="int", * example="1",