rename task to project task, task_user to project_task_user, fix behavior

This commit is contained in:
iIronside 2023-01-18 15:30:38 +03:00
parent c9ce085289
commit 8b2bb7468c
29 changed files with 169 additions and 92 deletions

View File

@ -84,7 +84,7 @@ return [
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
'baseUrl' => '/secure',
'baseUrl' => '', // /secure
'parsers' => [
'application/json' => 'yii\web\JsonParser',
'text/xml' => 'yii/web/XmlParser',

View File

@ -2,12 +2,10 @@
namespace backend\modules\project\models;
use common\classes\Debug;
use common\models\FieldsValue;
use common\models\FieldsValueNew;
use common\models\ProjectUser;
use yii\helpers\ArrayHelper;
use Yii;
use yii\helpers\ArrayHelper;
class Project extends \common\models\Project
{
@ -59,13 +57,14 @@ class Project extends \common\models\Project
public function behaviors()
{
return [
'log' => [
$behaviors = parent::behaviors();
$behaviors['log'] = [
'class' => \common\behaviors\LogBehavior::class,
]
];
return $behaviors;
}
public function afterSave($insert, $changedAttributes)
{
$post = \Yii::$app->request->post('Project');

View File

@ -3,11 +3,11 @@
namespace backend\modules\task\controllers;
use backend\modules\project\models\ProjectUser;
use backend\modules\task\models\TaskUser;
use backend\modules\task\models\ProjectTaskUser;
use yii\data\ActiveDataProvider;
use yii\web\Response;
use Yii;
use backend\modules\task\models\Task;
use backend\modules\task\models\ProjectTask;
use backend\modules\task\models\TaskSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
@ -80,7 +80,7 @@ class TaskController extends Controller
*/
public function actionCreate()
{
$model = new Task();
$model = new ProjectTask();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
@ -129,12 +129,12 @@ class TaskController extends Controller
* Finds the Task model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Task the loaded model
* @return ProjectTask the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Task::findOne($id)) !== null) {
if (($model = ProjectTask::findOne($id)) !== null) {
return $model;
}

View File

@ -7,7 +7,7 @@ use yii\base\Model;
use yii\helpers\ArrayHelper;
use yii\web\Response;
use Yii;
use backend\modules\task\models\TaskUser;
use backend\modules\task\models\ProjectTaskUser;
use backend\modules\task\models\TaskUserSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
@ -78,7 +78,7 @@ class TaskUserController extends Controller
$project_user_id_arr = ArrayHelper::getValue($post, 'project_user_id');
foreach ($project_user_id_arr as $project_user_id) {
$emtModel = new TaskUser();
$emtModel = new ProjectTaskUser();
$emtModel->task_id = $post['task_id'];
$emtModel->project_user_id = $project_user_id;
@ -99,7 +99,7 @@ class TaskUserController extends Controller
}
$model = new TaskUser();
$model = new ProjectTaskUser();
return $this->render('create', [
'model' => $model,
'task_id' => $task_id,
@ -156,12 +156,12 @@ class TaskUserController extends Controller
* Finds the TaskUser model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return TaskUser the loaded model
* @return ProjectTaskUser the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = TaskUser::findOne($id)) !== null) {
if (($model = ProjectTaskUser::findOne($id)) !== null) {
return $model;
}

View File

@ -0,0 +1,8 @@
<?php
namespace backend\modules\task\models;
class ProjectTask extends \common\models\ProjectTask
{
}

View File

@ -0,0 +1,8 @@
<?php
namespace backend\modules\task\models;
class ProjectTaskUser extends \common\models\ProjectTaskUser
{
}

View File

@ -1,8 +0,0 @@
<?php
namespace backend\modules\task\models;
class Task extends \common\models\Task
{
}

View File

@ -5,12 +5,12 @@ namespace backend\modules\task\models;
use backend\modules\project\models\ProjectUser;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\task\models\Task;
use backend\modules\task\models\ProjectTask;
/**
* TaskSearch represents the model behind the search form of `backend\modules\task\models\Task`.
*/
class TaskSearch extends Task
class TaskSearch extends ProjectTask
{
/**
* {@inheritdoc}
@ -41,7 +41,7 @@ class TaskSearch extends Task
*/
public function search($params)
{
$query = Task::find();//->joinWith(['user_card', 'project']);
$query = ProjectTask::find();//->joinWith(['user_card', 'project']);
// add conditions that should always apply here

View File

@ -1,8 +0,0 @@
<?php
namespace backend\modules\task\models;
class TaskUser extends \common\models\TaskUser
{
}

View File

@ -4,12 +4,12 @@ namespace backend\modules\task\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\task\models\TaskUser;
use backend\modules\task\models\ProjectTaskUser;
/**
* TaskUserSearch represents the model behind the search form of `backend\modules\task\models\TaskUser`.
*/
class TaskUserSearch extends TaskUser
class TaskUserSearch extends ProjectTaskUser
{
public $projectId;
/**
@ -41,7 +41,7 @@ class TaskUserSearch extends TaskUser
*/
public function search($params)
{
$query = TaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project', 'projectUser.user']);
$query = ProjectTaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project', 'projectUser.user']);
// add conditions that should always apply here

View File

@ -1,6 +1,6 @@
<?php
use backend\modules\task\models\Task;
use backend\modules\task\models\ProjectTask;
use kartik\depdrop\DepDrop;
use kartik\select2\Select2;
use yii\helpers\Html;
@ -8,7 +8,7 @@ use yii\helpers\Url;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\TaskUser */
/* @var $model backend\modules\task\models\ProjectTaskUser */
/* @var $form yii\widgets\ActiveForm */
/* @var $task_id */
?>
@ -18,7 +18,7 @@ use yii\widgets\ActiveForm;
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'task_id')->widget(Select2::className(),[
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
'data' => ProjectTask::find()->select(['title', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => 'Выберите проект', 'value' => $task_id, 'id' => 'task-id',],
'pluginOptions' => [
'allowClear' => false,

View File

@ -1,6 +1,6 @@
<?php
use backend\modules\task\models\Task;
use backend\modules\task\models\ProjectTask;
use kartik\depdrop\DepDrop;
use kartik\select2\Select2;
use yii\helpers\Html;
@ -8,7 +8,7 @@ use yii\helpers\Url;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\TaskUser */
/* @var $model backend\modules\task\models\ProjectTaskUser */
/* @var $form yii\widgets\ActiveForm */
/* @var $task_id */
?>
@ -18,7 +18,7 @@ use yii\widgets\ActiveForm;
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'task_id')->widget(Select2::className(),[
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
'data' => ProjectTask::find()->select(['title', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => 'Выберите проект', 'value' => $task_id, 'id' => 'task-id',],
'pluginOptions' => [
'allowClear' => false,

View File

@ -2,7 +2,7 @@
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\TaskUser */
/* @var $model backend\modules\task\models\ProjectTaskUser */
/* @var $task_id */
$this->title = 'Назначить сотрудника';

View File

@ -1,8 +1,8 @@
<?php
use backend\modules\project\models\ProjectUser;
use backend\modules\task\models\Task;
use backend\modules\task\models\TaskUser;
use backend\modules\task\models\ProjectTask;
use backend\modules\task\models\ProjectTaskUser;
use kartik\select2\Select2;
use yii\helpers\Html;
use yii\grid\GridView;
@ -36,7 +36,7 @@ $this->params['breadcrumbs'][] = $this->title;
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'task_id',
'data' => TaskUser::find()->joinWith('task')
'data' => ProjectTaskUser::find()->joinWith('task')
->select(['task.title', 'task.id'])->indexBy('task.id')->column(),
'pluginOptions' => [
'allowClear' => true,
@ -54,7 +54,7 @@ $this->params['breadcrumbs'][] = $this->title;
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'project_user_id',
'data' => TaskUser::find()->joinWith('projectUser.card')
'data' => ProjectTaskUser::find()->joinWith('projectUser.card')
->select(['user_card.fio', 'task_user.id'])->column(),
'pluginOptions' => [
'allowClear' => true,

View File

@ -2,7 +2,7 @@
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\TaskUser */
/* @var $model backend\modules\task\models\ProjectTaskUser */
/* @var $task_id */
$this->title = 'Изменить назначение';

View File

@ -5,7 +5,7 @@ use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\TaskUser */
/* @var $model backend\modules\task\models\ProjectTaskUser */
$this->title = 'Изменить назначение сотрудника';
$this->params['breadcrumbs'][] = ['label' => 'Task Users', 'url' => ['index']];

View File

@ -8,7 +8,7 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\Task */
/* @var $model backend\modules\task\models\ProjectTask */
/* @var $form yii\widgets\ActiveForm */
?>

View File

@ -1,7 +1,7 @@
<?php
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\Task */
/* @var $model backend\modules\task\models\ProjectTask */
$this->title = 'Создать задачу';
$this->params['breadcrumbs'][] = ['label' => 'Tasks', 'url' => ['index']];

View File

@ -3,7 +3,7 @@
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project;
use backend\modules\project\models\ProjectUser;
use backend\modules\task\models\Task;
use backend\modules\task\models\ProjectTask;
use common\helpers\StatusHelper;
use common\models\User;
use kartik\select2\Select2;
@ -36,7 +36,7 @@ $this->params['breadcrumbs'][] = $this->title;
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'project_id',
'data' => Task::find()->joinWith('project')
'data' => ProjectTask::find()->joinWith('project')
->select(['project.name', 'project.id'])->indexBy('project.id')->column(),
'pluginOptions' => [
'allowClear' => true,
@ -55,7 +55,7 @@ $this->params['breadcrumbs'][] = $this->title;
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'card_id_creator',
'data' => Task::find()->joinWith('userCardCreator')
'data' => ProjectTask::find()->joinWith('userCardCreator')
->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(),
'pluginOptions' => [
'allowClear' => true,
@ -73,7 +73,7 @@ $this->params['breadcrumbs'][] = $this->title;
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'card_id',
'data' => Task::find()->joinWith('userCard')
'data' => ProjectTask::find()->joinWith('userCard')
->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(),
'pluginOptions' => [
'allowClear' => true,

View File

@ -3,7 +3,7 @@
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\Task */
/* @var $model backend\modules\task\models\ProjectTask */
$this->title = 'Исполнители задачи: ' . $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Tasks', 'url' => ['index']];

View File

@ -8,7 +8,7 @@ use yii\web\YiiAsset;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\Task */
/* @var $model backend\modules\task\models\ProjectTask */
/* @var $taskDataProvider yii\data\ActiveDataProvider */
$this->title = 'Задача: ' . $model->title;

View File

@ -24,16 +24,16 @@ use yii\helpers\ArrayHelper;
* @property Project $project
* @property UserCard $card
* @property UserCard $cardIdCreator
* @property TaskUser[] $taskUsers
* @property ProjectTaskUser[] $taskUsers
*/
class Task extends ActiveRecord
class ProjectTask extends ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'task';
return 'project_task';
}
public function behaviors()
@ -123,7 +123,7 @@ class Task extends ActiveRecord
*/
public function getTaskUsers()
{
return $this->hasMany(TaskUser::className(), ['task_id' => 'id']);
return $this->hasMany(ProjectTaskUser::className(), ['task_id' => 'id']);
}
public static function usersByTaskArr($task_id): array

View File

@ -2,8 +2,6 @@
namespace common\models;
use Yii;
use yii\base\InvalidConfigException;
use yii\db\ActiveQuery;
/**
@ -14,16 +12,16 @@ use yii\db\ActiveQuery;
* @property int $project_user_id
*
* @property ProjectUser $projectUser
* @property Task $task
* @property ProjectTask $task
*/
class TaskUser extends \yii\db\ActiveRecord
class ProjectTaskUser extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'task_user';
return 'project_task_user';
}
/**
@ -35,7 +33,7 @@ class TaskUser extends \yii\db\ActiveRecord
[['task_id', 'project_user_id'], 'required'],
['project_user_id', 'unique', 'targetAttribute' => ['task_id', 'project_user_id'], 'message'=>'Уже закреплён(ы) за задачей'],
[['project_user_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectUser::className(), 'targetAttribute' => ['project_user_id' => 'id']],
[['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => Task::className(), 'targetAttribute' => ['task_id' => 'id']],
[['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectTask::className(), 'targetAttribute' => ['task_id' => 'id']],
];
}
@ -64,6 +62,6 @@ class TaskUser extends \yii\db\ActiveRecord
*/
public function getTask()
{
return $this->hasOne(Task::className(), ['id' => 'task_id']);
return $this->hasOne(ProjectTask::className(), ['id' => 'task_id']);
}
}

View File

@ -18,7 +18,7 @@ use yii\helpers\ArrayHelper;
* @property Project $project
* @property UserCard $card
* @property User $user
* @property TaskUser[] $taskUsers
* @property ProjectTaskUser[] $taskUsers
*/
class ProjectUser extends \yii\db\ActiveRecord
{
@ -88,7 +88,7 @@ class ProjectUser extends \yii\db\ActiveRecord
*/
public function getTasks()
{
return $this->hasMany(Task::className(), ['project_user_id' => 'id']);
return $this->hasMany(ProjectTask::className(), ['project_user_id' => 'id']);
}
/**
@ -96,7 +96,7 @@ class ProjectUser extends \yii\db\ActiveRecord
*/
public function getTasksByProject()
{
return $this->hasMany(Task::className(), ['project_id' => 'project_id']);
return $this->hasMany(ProjectTask::className(), ['project_id' => 'project_id']);
}
/**
@ -104,7 +104,7 @@ class ProjectUser extends \yii\db\ActiveRecord
*/
public function getTaskUsers()
{
return $this->hasMany(TaskUser::className(), ['project_user_id' => 'id']);
return $this->hasMany(ProjectTaskUser::className(), ['project_user_id' => 'id']);
}
public static function usersByProjectArr($project_id): array

View File

@ -2,36 +2,36 @@
namespace common\services;
use common\models\Task;
use common\models\ProjectTask;
class TaskService
{
public static function createTask($taskParams)
{
$task = new Task();
$task = new ProjectTask();
$task->load($taskParams, '');
$task->save();
return $task;
}
public static function getTask($task_id): ?Task
public static function getTask($task_id): ?ProjectTask
{
return Task::findOne($task_id);
return ProjectTask::findOne($task_id);
}
public static function getTaskList($task_id): array
{
return Task::find()->asArray()->all();
return ProjectTask::find()->asArray()->all();
}
public static function getTaskListByProject($project_id): array
{
return Task::find()->where(['project_id' => $project_id])->asArray()->all();
return ProjectTask::find()->where(['project_id' => $project_id])->asArray()->all();
}
public static function updateTask($task_params): ?Task
public static function updateTask($task_params): ?ProjectTask
{
$modelTask = Task::findOne($task_params['task_id']);
$modelTask = ProjectTask::findOne($task_params['task_id']);
$modelTask->load($task_params, '');
$modelTask->save();
@ -41,6 +41,6 @@ class TaskService
public static function taskExists($task_id): bool
{
return Task::find()->where(['id' => $task_id])->exists();
return ProjectTask::find()->where(['id' => $task_id])->exists();
}
}

View File

@ -0,0 +1,40 @@
<?php
use yii\db\Migration;
/**
* Class m230118_120338_rename_task_table_to_project_task
*/
class m230118_120338_rename_task_table_to_project_task extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->renameTable('task', 'project_task');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->renameTable('project_task', 'task');
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m230118_120338_rename_task_table_to_project_task cannot be reverted.\n";
return false;
}
*/
}

View File

@ -0,0 +1,40 @@
<?php
use yii\db\Migration;
/**
* Class m230118_120405_rename_task_user_table_to_project_task_user
*/
class m230118_120405_rename_task_user_table_to_project_task_user extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->renameTable('task_user', 'project_task_user');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->renameTable('project_task_user', 'task_user');
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m230118_120405_rename_task_user_table_to_project_task_user cannot be reverted.\n";
return false;
}
*/
}

View File

@ -2,7 +2,7 @@
namespace frontend\modules\api\controllers;
use common\models\Task;
use common\models\ProjectTask;
use common\services\TaskService;
use Yii;
use yii\base\InvalidConfigException;
@ -25,7 +25,7 @@ class TaskController extends ApiController
* @throws InvalidConfigException
* @throws ServerErrorHttpException
*/
public function actionCreateTask(): Task
public function actionCreateTask(): ProjectTask
{
$taskModel = TaskService::createTask(Yii::$app->getRequest()->getBodyParams());
if ($taskModel->errors) {
@ -59,7 +59,7 @@ class TaskController extends ApiController
/**
* @throws NotFoundHttpException
*/
public function actionGetTask($task_id): Task
public function actionGetTask($task_id): ProjectTask
{
if (empty($task_id) or !is_numeric($task_id)) {
throw new NotFoundHttpException('Incorrect task ID');
@ -78,7 +78,7 @@ class TaskController extends ApiController
* @throws ServerErrorHttpException
* @throws NotFoundHttpException
*/
public function actionUpdate(): ?Task
public function actionUpdate(): ?ProjectTask
{
$params = Yii::$app->request->getBodyParams();
if (empty ($params['task_id']) or !TaskService::taskExists($params['task_id'])) {

View File

@ -2,7 +2,7 @@
namespace frontend\modules\api\controllers;
use common\models\TaskUser;
use common\models\ProjectTaskUser;
use Yii;
use yii\filters\auth\HttpBearerAuth;
use yii\rest\Controller;
@ -21,7 +21,7 @@ class TaskUserController extends ApiController
public function actionSetTaskUser()
{
$taskUserModel = new TaskUser();
$taskUserModel = new ProjectTaskUser();
$params = Yii::$app->request->post();
$taskUserModel->attributes = $params;
@ -57,6 +57,6 @@ class TaskUserController extends ApiController
private function findUsers($project_id): array
{
return TaskUser::find()->where(['task_id' => $project_id])->all();
return ProjectTaskUser::find()->where(['task_id' => $project_id])->all();
}
}