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 78%
rename from backend/modules/task/models/TaskSearch.php
rename to backend/modules/task/models/ProjectTaskSearch.php
index 54513c7..9c20656 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}
@@ -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.execution_priority' => $this->execution_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..f8c8e20 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;
@@ -59,6 +60,13 @@ use yii\widgets\ActiveForm;
= $form->field($model, 'priority')->input('number') ?>
+ = $form->field($model, 'execution_priority')->dropDownList(
+ ProjectTask::priorityList(),
+ [
+ 'prompt' => 'Выберите'
+ ]
+ ) ?>
+
= Html::submitButton('Создать', ['class' => '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..538f42c 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' => '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 c5a1ed6..0f458b1 100644
--- a/backend/modules/task/views/task/view.php
+++ b/backend/modules/task/views/task/view.php
@@ -1,5 +1,6 @@
'execution_priority',
+ 'value' => function($model){
+ return ProjectTask::getPriority($model->status);
+ }
+ ],
],
]) ?>
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/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']],
diff --git a/common/models/ProjectTask.php b/common/models/ProjectTask.php
index be19aac..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,6 +38,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}
*/
@@ -64,8 +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'],
+ ['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],
@@ -94,6 +122,69 @@ class ProjectTask extends ActiveRecord
'executor_id' => 'Исполнитель',
'priority' => 'Приоритет',
'dead_line' => 'Срок выполнения задачи',
+ 'execution_priority' => 'Приоритет выполнения',
+ ];
+ }
+
+ /**
+ * @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',
+ 'execution_priority'
+ ];
+ }
+
+ /**
+ * @return string[]
+ */
+ public function extraFields(): array
+ {
+ return [
+ 'timers',
+ 'column' => function () {
+ return [
+ 'column_title' => $this->column->title ?? null
+ ];
+ },
+ 'mark'
];
}
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/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');
+ }
+}
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 75db62d..77d830c 100644
--- a/frontend/modules/api/controllers/TaskController.php
+++ b/frontend/modules/api/controllers/TaskController.php
@@ -72,7 +72,12 @@ class TaskController extends ApiController
* @OA\Property(
* property="priority",
* type="integer",
- * description="Приоритет задачи",
+ * description="Приоритет задачи.",
+ * ),
+ * @OA\Property(
+ * property="execution_priority",
+ * type="integer",
+ * description="Приоритет выполнения задачи (0 - low, 1 - medium, 2 - high)",
* ),
* @OA\Property(
* property="column_id",
diff --git a/frontend/modules/api/models/ProjectTask.php b/frontend/modules/api/models/ProjectTask.php
index ed80fd9..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",
@@ -152,63 +158,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