diff --git a/backend/config/main.php b/backend/config/main.php index bdd19d8..8a4b951 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -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', diff --git a/backend/modules/project/models/Project.php b/backend/modules/project/models/Project.php index c56b7f8..41608de 100755 --- a/backend/modules/project/models/Project.php +++ b/backend/modules/project/models/Project.php @@ -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' => [ - 'class' => \common\behaviors\LogBehavior::class, - ] + $behaviors = parent::behaviors(); + $behaviors['log'] = [ + 'class' => \common\behaviors\LogBehavior::class, ]; + return $behaviors; } + public function afterSave($insert, $changedAttributes) { $post = \Yii::$app->request->post('Project'); diff --git a/backend/modules/task/controllers/TaskController.php b/backend/modules/task/controllers/TaskController.php index 6629f55..52e48e2 100644 --- a/backend/modules/task/controllers/TaskController.php +++ b/backend/modules/task/controllers/TaskController.php @@ -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; } diff --git a/backend/modules/task/controllers/TaskUserController.php b/backend/modules/task/controllers/TaskUserController.php index 7ee8865..47d15f6 100644 --- a/backend/modules/task/controllers/TaskUserController.php +++ b/backend/modules/task/controllers/TaskUserController.php @@ -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; } diff --git a/backend/modules/task/models/ProjectTask.php b/backend/modules/task/models/ProjectTask.php new file mode 100644 index 0000000..ad07041 --- /dev/null +++ b/backend/modules/task/models/ProjectTask.php @@ -0,0 +1,8 @@ +joinWith(['user_card', 'project']); + $query = ProjectTask::find();//->joinWith(['user_card', 'project']); // add conditions that should always apply here diff --git a/backend/modules/task/models/TaskUser.php b/backend/modules/task/models/TaskUser.php deleted file mode 100644 index 81eb21e..0000000 --- a/backend/modules/task/models/TaskUser.php +++ /dev/null @@ -1,8 +0,0 @@ -joinWith(['task', 'projectUser', 'projectUser.project', 'projectUser.user']); + $query = ProjectTaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project', 'projectUser.user']); // add conditions that should always apply here diff --git a/backend/modules/task/views/task-user/_form.php b/backend/modules/task/views/task-user/_form.php index f6484e0..1400066 100644 --- a/backend/modules/task/views/task-user/_form.php +++ b/backend/modules/task/views/task-user/_form.php @@ -1,6 +1,6 @@ @@ -18,7 +18,7 @@ use yii\widgets\ActiveForm; 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, diff --git a/backend/modules/task/views/task-user/_form_update.php b/backend/modules/task/views/task-user/_form_update.php index f2fd752..5cc5a9a 100644 --- a/backend/modules/task/views/task-user/_form_update.php +++ b/backend/modules/task/views/task-user/_form_update.php @@ -1,6 +1,6 @@ @@ -18,7 +18,7 @@ use yii\widgets\ActiveForm; 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, diff --git a/backend/modules/task/views/task-user/create.php b/backend/modules/task/views/task-user/create.php index 18eca3e..8d0411d 100644 --- a/backend/modules/task/views/task-user/create.php +++ b/backend/modules/task/views/task-user/create.php @@ -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 = 'Назначить сотрудника'; diff --git a/backend/modules/task/views/task-user/index.php b/backend/modules/task/views/task-user/index.php index 6aab952..7ea484f 100644 --- a/backend/modules/task/views/task-user/index.php +++ b/backend/modules/task/views/task-user/index.php @@ -1,8 +1,8 @@ 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, diff --git a/backend/modules/task/views/task-user/update.php b/backend/modules/task/views/task-user/update.php index 2db4aa9..be3e2e8 100644 --- a/backend/modules/task/views/task-user/update.php +++ b/backend/modules/task/views/task-user/update.php @@ -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 = 'Изменить назначение'; diff --git a/backend/modules/task/views/task-user/view.php b/backend/modules/task/views/task-user/view.php index 79b0f98..fd4fa54 100644 --- a/backend/modules/task/views/task-user/view.php +++ b/backend/modules/task/views/task-user/view.php @@ -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']]; diff --git a/backend/modules/task/views/task/_form.php b/backend/modules/task/views/task/_form.php index d61b040..8c47482 100644 --- a/backend/modules/task/views/task/_form.php +++ b/backend/modules/task/views/task/_form.php @@ -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 */ ?> diff --git a/backend/modules/task/views/task/create.php b/backend/modules/task/views/task/create.php index 4ee1ea6..2336a86 100644 --- a/backend/modules/task/views/task/create.php +++ b/backend/modules/task/views/task/create.php @@ -1,7 +1,7 @@ title = 'Создать задачу'; $this->params['breadcrumbs'][] = ['label' => 'Tasks', 'url' => ['index']]; diff --git a/backend/modules/task/views/task/index.php b/backend/modules/task/views/task/index.php index 8623242..812c9a5 100644 --- a/backend/modules/task/views/task/index.php +++ b/backend/modules/task/views/task/index.php @@ -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, diff --git a/backend/modules/task/views/task/update.php b/backend/modules/task/views/task/update.php index 305e332..f94878c 100644 --- a/backend/modules/task/views/task/update.php +++ b/backend/modules/task/views/task/update.php @@ -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']]; diff --git a/backend/modules/task/views/task/view.php b/backend/modules/task/views/task/view.php index 693f824..61c6da6 100644 --- a/backend/modules/task/views/task/view.php +++ b/backend/modules/task/views/task/view.php @@ -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; diff --git a/common/models/Task.php b/common/models/ProjectTask.php similarity index 94% rename from common/models/Task.php rename to common/models/ProjectTask.php index e80ca3d..249cf12 100644 --- a/common/models/Task.php +++ b/common/models/ProjectTask.php @@ -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 diff --git a/common/models/TaskUser.php b/common/models/ProjectTaskUser.php similarity index 82% rename from common/models/TaskUser.php rename to common/models/ProjectTaskUser.php index b276ab4..30cb621 100644 --- a/common/models/TaskUser.php +++ b/common/models/ProjectTaskUser.php @@ -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']); } } diff --git a/common/models/ProjectUser.php b/common/models/ProjectUser.php index 7974f18..6b4bcf8 100644 --- a/common/models/ProjectUser.php +++ b/common/models/ProjectUser.php @@ -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 diff --git a/common/services/TaskService.php b/common/services/TaskService.php index f837a62..bbe373e 100644 --- a/common/services/TaskService.php +++ b/common/services/TaskService.php @@ -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(); } } \ No newline at end of file diff --git a/console/migrations/m230118_120338_rename_task_table_to_project_task.php b/console/migrations/m230118_120338_rename_task_table_to_project_task.php new file mode 100644 index 0000000..d332b25 --- /dev/null +++ b/console/migrations/m230118_120338_rename_task_table_to_project_task.php @@ -0,0 +1,40 @@ +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; + } + */ +} diff --git a/console/migrations/m230118_120405_rename_task_user_table_to_project_task_user.php b/console/migrations/m230118_120405_rename_task_user_table_to_project_task_user.php new file mode 100644 index 0000000..b823d2c --- /dev/null +++ b/console/migrations/m230118_120405_rename_task_user_table_to_project_task_user.php @@ -0,0 +1,40 @@ +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; + } + */ +} diff --git a/frontend/modules/api/controllers/TaskController.php b/frontend/modules/api/controllers/TaskController.php index dd9a3ef..4bd1642 100644 --- a/frontend/modules/api/controllers/TaskController.php +++ b/frontend/modules/api/controllers/TaskController.php @@ -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'])) { diff --git a/frontend/modules/api/controllers/TaskUserController.php b/frontend/modules/api/controllers/TaskUserController.php index 60951a8..066709e 100644 --- a/frontend/modules/api/controllers/TaskUserController.php +++ b/frontend/modules/api/controllers/TaskUserController.php @@ -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(); } } \ No newline at end of file