Merge branch 'master' into config-smtp

This commit is contained in:
iIronside 2023-10-16 15:08:57 +03:00
commit 5469a209a5
14 changed files with 199 additions and 77 deletions

View File

@ -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', [

View File

@ -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;
}

View File

@ -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' => 'Выберите'
]
) ?>
<div class="form-group">
<?= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?>
</div>

View File

@ -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 */
?>

View File

@ -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']

View File

@ -1,5 +1,6 @@
<?php
use backend\modules\task\models\ProjectTask;
use common\helpers\StatusHelper;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;
@ -60,6 +61,12 @@ YiiAsset::register($this);
],
'description',
'priority',
[
'attribute' => 'execution_priority',
'value' => function($model){
return ProjectTask::getPriority($model->status);
}
],
],
]) ?>

View File

@ -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']],

View File

@ -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']],

View File

@ -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'
];
}

View File

@ -2,8 +2,8 @@
namespace common\services;
use common\models\ProjectTask;
use common\models\ProjectTaskUser;
use frontend\modules\api\models\ProjectTask;
class TaskService
{

View File

@ -0,0 +1,31 @@
<?php
use yii\db\Migration;
/**
* Class m231013_122324_add_foreign_key_in_project_from_owner_id_to_user_id
*/
class m231013_122324_add_foreign_key_in_project_from_owner_id_to_user_id extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addForeignKey(
'project_user',
'project',
'owner_id',
'user',
'id'
);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('project_user', 'project');
}
}

View File

@ -0,0 +1,25 @@
<?php
use yii\db\Migration;
/**
* Handles adding columns to table `{{%project_task}}`.
*/
class m231013_144526_add_execution_priority_column_to_project_task_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('project_task', 'execution_priority', $this->integer(1));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('project_task', 'execution_priority');
}
}

View File

@ -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",

View File

@ -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'
];
}
}