merge
This commit is contained in:
commit
da9334dcf6
@ -75,7 +75,7 @@ return [
|
||||
'components' => [
|
||||
'request' => [
|
||||
'csrfParam' => '_csrf-backend',
|
||||
'baseUrl' => '/secure', // TODO /secure
|
||||
'baseUrl' => '/secure',
|
||||
'parsers' => [
|
||||
'application/json' => 'yii\web\JsonParser',
|
||||
'text/xml' => 'yii/web/XmlParser',
|
||||
|
@ -2,12 +2,16 @@
|
||||
|
||||
namespace backend\modules\project\controllers;
|
||||
|
||||
use common\models\UserCard;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use backend\modules\project\models\ProjectUserSearch;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\Response;
|
||||
|
||||
/**
|
||||
* ProjectUserController implements the CRUD actions for ProjectUser model.
|
||||
@ -60,16 +64,35 @@ class ProjectUserController extends Controller
|
||||
/**
|
||||
* Creates a new ProjectUser model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
* @return string|Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new ProjectUser();
|
||||
$post = \Yii::$app->request->post('ProjectUser');
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
if (!empty($post)) {
|
||||
$user_id_arr = ArrayHelper::getValue($post, 'user_id');
|
||||
$project_id = $post['project_id'];
|
||||
|
||||
foreach ($user_id_arr as $user_id) {
|
||||
$emtModel = new ProjectUser();
|
||||
$emtModel->project_id = $project_id;
|
||||
$emtModel->user_id = $user_id;
|
||||
$emtModel->card_id = UserCard::getIdByUserId($user_id);
|
||||
|
||||
$emtModel->save();
|
||||
|
||||
// if (!$emtModel->save()) {
|
||||
// return $this->render('create', [
|
||||
// 'model' => $emtModel,
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
$model = new ProjectUser();
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
@ -86,8 +109,12 @@ class ProjectUserController extends Controller
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
if ($model->load(Yii::$app->request->post()) ) {
|
||||
$model->card_id = UserCard::getIdByUserId($model->user_id);
|
||||
if ($model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
@ -124,4 +151,18 @@ class ProjectUserController extends Controller
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
public function actionSetUserFields(): Response
|
||||
{
|
||||
ProjectUser::setUsersByCardId();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
public function actionSetCardFields(): Response
|
||||
{
|
||||
ProjectUser::setCardsByUsersId();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
}
|
||||
|
@ -96,6 +96,7 @@ class Project extends \common\models\Project
|
||||
$prUser = new ProjectUser();
|
||||
$prUser->project_id = $this->id;
|
||||
$prUser->card_id = $item;
|
||||
$prUser->user_id = $prUser->card->user->id;
|
||||
|
||||
$prUser->save();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class ProjectUserSearch extends ProjectUser
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'project_id', 'user_id'], 'integer'],
|
||||
[['id', 'project_id', 'user_id', 'card_id'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ class ProjectUserSearch extends ProjectUser
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = ProjectUser::find()->joinWith(['project', 'user']);
|
||||
$query = ProjectUser::find()->joinWith(['project', 'user', 'card']);
|
||||
|
||||
// add conditions that should always apply here
|
||||
|
||||
@ -60,6 +60,7 @@ class ProjectUserSearch extends ProjectUser
|
||||
'id' => $this->id,
|
||||
'project_id' => $this->project_id,
|
||||
'user_id' => $this->user_id,
|
||||
'card_id' => $this->card_id,
|
||||
]);
|
||||
|
||||
return $dataProvider;
|
||||
|
@ -30,7 +30,8 @@ use yii\widgets\ActiveForm;
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
'allowClear' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
]
|
||||
) ?>
|
||||
|
45
backend/modules/project/views/project-user/_form_update.php
Normal file
45
backend/modules/project/views/project-user/_form_update.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\project\models\Project;
|
||||
use common\models\User;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\project\models\ProjectUser */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="project-user-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'project_id')->widget(Select2::className(),
|
||||
[
|
||||
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
]
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'user_id')->widget(Select2::className(),
|
||||
[
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'multiple' => false,
|
||||
],
|
||||
]
|
||||
) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\card\models\UserCard;
|
||||
use backend\modules\project\models\Project;
|
||||
use common\models\User;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
@ -16,6 +18,8 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
<p>
|
||||
<?= Html::a('Назначить сотрудника на проект', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
<?= Html::a('Установить значения поля "Сотрудник"', ['set-user-fields'], ['class' => 'btn btn-secondary']) ?>
|
||||
<?= Html::a('Установить значения поля "Карточка"', ['set-card-fields'], ['class' => 'btn btn-secondary']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
@ -26,13 +30,54 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
[
|
||||
'attribute' => 'project_id',
|
||||
'filter' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'project.name'
|
||||
'value' => 'project.name',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'project_id',
|
||||
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
[
|
||||
'attribute' => 'user_id',
|
||||
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'user.username'
|
||||
'value' => 'user.username',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'user_id',
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
[
|
||||
'attribute' => 'card_id',
|
||||
'value' => 'card.fio',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'card_id',
|
||||
'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
|
@ -12,7 +12,7 @@ $this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="project-user-update">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
<?= $this->render('_form_update', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace backend\modules\task\controllers;
|
||||
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use yii\base\Model;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\Response;
|
||||
use Yii;
|
||||
use backend\modules\task\models\TaskUser;
|
||||
@ -63,41 +65,39 @@ class TaskUserController extends Controller
|
||||
* Creates a new TaskUser model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function actionCreate($task_id = null)
|
||||
{
|
||||
$model = new TaskUser();
|
||||
$post = \Yii::$app->request->post('TaskUser');
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
if (!empty($post)) {
|
||||
$project_user_id_arr = ArrayHelper::getValue($post, 'project_user_id');
|
||||
|
||||
foreach ($project_user_id_arr as $project_user_id) {
|
||||
$emtModel = new TaskUser();
|
||||
$emtModel->task_id = $post['task_id'];
|
||||
$emtModel->project_user_id = $project_user_id;
|
||||
|
||||
if (!$emtModel->save()) {
|
||||
return $this->render('create', [
|
||||
'model' => $emtModel,
|
||||
'task_id' => $task_id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($task_id !== null)
|
||||
{
|
||||
return $this->redirect(['task/view', 'id' => $task_id]);
|
||||
}
|
||||
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
'task_id' => $task_id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new TaskUser model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreateForCurrentTask($task_id = null)
|
||||
{
|
||||
$model = new TaskUser();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['task/view', 'id' => $task_id]);
|
||||
}
|
||||
|
||||
return $this->render('create_for_current_task', [
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
'task_id' => $task_id,
|
||||
]);
|
||||
@ -185,4 +185,9 @@ class TaskUserController extends Controller
|
||||
}
|
||||
return ['output'=>'', 'selected'=>''];
|
||||
}
|
||||
|
||||
public function actionDynamicProjectUser()
|
||||
{
|
||||
var_dump('hhh'); die;
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class TaskUserSearch extends TaskUser
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = TaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project']);
|
||||
$query = TaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project', 'projectUser.user']);
|
||||
|
||||
// add conditions that should always apply here
|
||||
|
||||
|
@ -21,19 +21,27 @@ use yii\widgets\ActiveForm;
|
||||
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => 'Выберите проект', 'value' => $task_id, 'id' => 'task-id',],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'allowClear' => false,
|
||||
],
|
||||
]);
|
||||
?>
|
||||
|
||||
<?= $form->field($model, 'project_user_id')->widget(DepDrop::className(),
|
||||
[
|
||||
'options' => ['id' => 'project-user-id'],
|
||||
'type' => DepDrop::TYPE_SELECT2,
|
||||
'options' => ['id' => 'project-user-id', 'allowClear' => true, 'multiple' => true], // , 'multiple' => true
|
||||
'select2Options' => [
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'closeOnSelect' => false,
|
||||
],
|
||||
'showToggleAll' => false,
|
||||
],
|
||||
'pluginOptions' => [
|
||||
'depends' => ['task-id'],
|
||||
'placeholder' => 'Выберите',
|
||||
'initialize' => true,
|
||||
'url' => Url::to(['/task/task-user/executor'])
|
||||
'url' => Url::to(['/task/task-user/executor']),
|
||||
]
|
||||
]
|
||||
); ?>
|
||||
|
47
backend/modules/task/views/task-user/_form_update.php
Normal file
47
backend/modules/task/views/task-user/_form_update.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\task\models\Task;
|
||||
use kartik\depdrop\DepDrop;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\task\models\TaskUser */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
/* @var $task_id */
|
||||
?>
|
||||
|
||||
<div class="task-user-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'task_id')->widget(Select2::className(),[
|
||||
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => 'Выберите проект', 'value' => $task_id, 'id' => 'task-id',],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => false,
|
||||
],
|
||||
]);
|
||||
?>
|
||||
|
||||
<?= $form->field($model, 'project_user_id')->widget(DepDrop::className(),
|
||||
[
|
||||
'options' => ['id' => 'project-user-id', 'allowClear' => true],
|
||||
'pluginOptions' => [
|
||||
'depends' => ['task-id'],
|
||||
'placeholder' => 'Выберите',
|
||||
'initialize' => true,
|
||||
'url' => Url::to(['/task/task-user/executor']),
|
||||
]
|
||||
]
|
||||
); ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Назначить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
@ -2,6 +2,7 @@
|
||||
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use backend\modules\task\models\Task;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
@ -30,14 +31,38 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
[
|
||||
'attribute' => 'task_id',
|
||||
'filter' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'task.title'
|
||||
'value' => 'task.title',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'task_id',
|
||||
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
[
|
||||
'attribute' => 'project_user_id',
|
||||
'filter' => ProjectUser::find()->select(['user.username', 'project_user.id'])
|
||||
->joinWith('user')->indexBy('project_user.id')->column(),
|
||||
'value' => 'projectUser.user.username'
|
||||
'value' => 'projectUser.user.username',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'project_user_id',
|
||||
'data' => ProjectUser::find()->select(['user.username', 'project_user.id'])
|
||||
->joinWith('user')->indexBy('project_user.id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
|
@ -12,7 +12,7 @@ $this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="task-user-update">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
<?= $this->render('_form_update', [
|
||||
'model' => $model,
|
||||
'task_id' => $task_id,
|
||||
]) ?>
|
||||
|
@ -30,7 +30,7 @@ use yii\widgets\ActiveForm;
|
||||
<?= $form->field($model, 'user_id_creator')->widget(Select2::class,
|
||||
[
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'options' => ['placeholder' => '...','class' => 'form-control', 'value' => Yii::$app->user->id],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'prompt' => 'Выберите'
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
use backend\modules\project\models\Project;
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use backend\modules\task\models\Task;
|
||||
use common\helpers\StatusHelper;
|
||||
use common\models\User;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
@ -29,19 +31,55 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
[
|
||||
'attribute' => 'project_id',
|
||||
'filter' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'project.name'
|
||||
'value' => 'project.name',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'project_id',
|
||||
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '150px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
'title',
|
||||
[
|
||||
'attribute' => 'user_id_creator',
|
||||
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'userIdCreator.username'
|
||||
'value' => 'userIdCreator.username',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'user_id_creator',
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '150px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
[
|
||||
'attribute' => 'user_id',
|
||||
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'user.username'
|
||||
'value' => 'user.username',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'user_id',
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '150px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
'description',
|
||||
[
|
||||
@ -58,7 +96,6 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
],
|
||||
[
|
||||
'attribute' => 'updated_at',
|
||||
'filter' => User::find()->select(['updated_at', 'updated_at'])->indexBy('updated_at')->column(),
|
||||
'format' => ['datetime', 'php:d.m.Y H:i']
|
||||
],
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Exception;
|
||||
use Yii;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
@ -9,12 +11,13 @@ use yii\helpers\ArrayHelper;
|
||||
* This is the model class for table "project_user".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $card_id
|
||||
* @property int $project_id
|
||||
* @property int $user_id
|
||||
*
|
||||
* @property Project $project
|
||||
* @property UserCard $card
|
||||
* @property User $user
|
||||
* @property Task[] $tasks
|
||||
* @property TaskUser[] $taskUsers
|
||||
*/
|
||||
class ProjectUser extends \yii\db\ActiveRecord
|
||||
@ -33,10 +36,11 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['project_id', 'user_id'], 'required'],
|
||||
['user_id', 'unique', 'targetAttribute' => ['user_id', 'project_id'], 'message'=>'Сотрудник уже занят на этом проекте'],
|
||||
[['project_id', 'user_id'], 'integer'],
|
||||
[['user_id', 'project_id'], 'required'],
|
||||
['user_id', 'unique', 'targetAttribute' => ['user_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'],
|
||||
// [['card_id', 'project_id', 'user_id'], 'integer'],
|
||||
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
|
||||
[['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']],
|
||||
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
|
||||
];
|
||||
}
|
||||
@ -48,6 +52,7 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'card_id' => 'Карточка',
|
||||
'project_id' => 'Проект',
|
||||
'user_id' => 'Сотрудник',
|
||||
];
|
||||
@ -64,17 +69,17 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
/**
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getUser()
|
||||
public function getCard()
|
||||
{
|
||||
return $this->hasOne(User::className(), ['id' => 'user_id']);
|
||||
return $this->hasOne(UserCard::className(), ['id' => 'card_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getCard()
|
||||
public function getUser()
|
||||
{
|
||||
return $this->hasOne(UserCard::className(), ['id_user' => 'user_id']);
|
||||
return $this->hasOne(User::className(), ['id' => 'user_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,4 +117,30 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
return ArrayHelper::map(
|
||||
self::find()->joinWith(['tasksByProject', 'user'])->where(['task.id' => $task_id])->all(), 'id', 'user.username');
|
||||
}
|
||||
|
||||
public static function setUsersByCardId()
|
||||
{
|
||||
$projectUserModels = self::findAll(['user_id' => null]);
|
||||
|
||||
foreach ($projectUserModels as $projectUser)
|
||||
{
|
||||
$projectUser->user_id = UserCard::getUserIdByCardId($projectUser->card_id);
|
||||
if ($projectUser->user_id !== null) {
|
||||
$projectUser->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function setCardsByUsersId()
|
||||
{
|
||||
$projectUserModels = self::findAll(['card_id' => null]);
|
||||
|
||||
foreach ($projectUserModels as $projectUser)
|
||||
{
|
||||
$projectUser->card_id = UserCard::getCardIdByUserId($projectUser->user_id);
|
||||
if ($projectUser->card_id !== null) {
|
||||
$projectUser->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ class TaskUser extends \yii\db\ActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['task_id', 'project_user_id'], 'integer'],
|
||||
['project_user_id', 'unique', 'targetAttribute' => ['task_id', 'project_user_id'], 'message'=>'Этот сотрудник уже назначен на эту задачу'],
|
||||
[['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']],
|
||||
];
|
||||
|
@ -3,8 +3,11 @@
|
||||
namespace common\models;
|
||||
|
||||
use common\classes\Debug;
|
||||
use Exception;
|
||||
use phpDocumentor\Reflection\Types\This;
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\Expression;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
@ -141,7 +144,7 @@ class UserCard extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getFieldsValues()
|
||||
{
|
||||
@ -149,7 +152,7 @@ class UserCard extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getProjectUsers()
|
||||
{
|
||||
@ -157,7 +160,7 @@ class UserCard extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
@ -165,7 +168,7 @@ class UserCard extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getStatus0()
|
||||
{
|
||||
@ -173,9 +176,9 @@ class UserCard extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getAchievements(): \yii\db\ActiveQuery
|
||||
public function getAchievements(): ActiveQuery
|
||||
{
|
||||
return $this->hasMany(AchievementUserCard::class, ['user_card_id' => 'id'])->with('achievement');
|
||||
}
|
||||
@ -201,14 +204,22 @@ class UserCard extends \yii\db\ActiveRecord
|
||||
return $this->hasMany(CardSkill::class, ['card_id' => 'id'])->with('skill');
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
public static function getNameSkills()
|
||||
{
|
||||
return ArrayHelper::map(Skill::find()->all(), 'id', 'name');
|
||||
}
|
||||
|
||||
public function getUser(): ActiveQuery
|
||||
{
|
||||
return $this->hasOne(User::class, ['id' => 'id_user']);
|
||||
}
|
||||
|
||||
public static function getNameSkills()
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getIdByUserId($user_id)
|
||||
{
|
||||
return ArrayHelper::map(Skill::find()->all(), 'id', 'name');
|
||||
return ArrayHelper::getValue(self::find()->where(['id_user' => $user_id])->one(), 'id');
|
||||
}
|
||||
|
||||
public static function getUserList()
|
||||
@ -274,5 +285,23 @@ class UserCard extends \yii\db\ActiveRecord
|
||||
$user_card->save();
|
||||
}
|
||||
|
||||
public static function getUserIdByCardId ($card_id)
|
||||
{
|
||||
$userCard = self::findOne(['id' => $card_id]);
|
||||
if (empty($userCard)) {
|
||||
return null;
|
||||
}
|
||||
return $userCard['id_user'];
|
||||
}
|
||||
|
||||
public static function getCardIdByUserId ($user_id)
|
||||
{
|
||||
$userCard = self::findOne(['id_user' => $user_id]);
|
||||
if (empty($userCard)) {
|
||||
return null;
|
||||
}
|
||||
return $userCard['id'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,19 +3,19 @@
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m211123_082634_change_foreign_key_in_project_user_from_user_card_table_to_user_table
|
||||
* Class m211123_082634_add_foreign_key_from_project_user_to_user_table
|
||||
*/
|
||||
class m211123_082634_change_foreign_key_in_project_user_from_user_card_table_to_user_table extends Migration
|
||||
class m211123_082634_add_foreign_key_from_project_user_to_user_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->dropForeignKey('project_user_ibfk_user_card', 'project_user');
|
||||
$this->dropColumn('project_user', 'card_id');
|
||||
$this->addColumn('project_user', 'user_id', $this->integer(11)->notNull());
|
||||
// $this->addForeignKey('user_project_user', 'project_user', 'user_id', 'user', 'id');
|
||||
$this->alterColumn('project_user', 'card_id', $this->integer()->defaultValue(null));
|
||||
$this->addColumn('project_user', 'user_id', $this->integer(11)->notNull()->defaultValue(null));
|
||||
$this->addForeignKey('user_project_user', 'project_user', 'user_id', 'user', 'id');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -23,9 +23,11 @@ class m211123_082634_change_foreign_key_in_project_user_from_user_card_table_to_
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->alterColumn('project_user', 'card_id', $this->integer()->notNull());
|
||||
$this->dropForeignKey('user_project_user', 'project_user');
|
||||
$this->dropColumn('project_user', 'user_id');
|
||||
$this->addColumn('project_user', 'card_id', $this->integer(11)->notNull());
|
||||
|
||||
// $this->addColumn('project_user', 'card_id', $this->integer(11)->notNull());
|
||||
// $this->addForeignKey(
|
||||
// 'project_user_ibfk_user_card',
|
||||
// 'project_user',
|
||||
@ -46,7 +48,7 @@ class m211123_082634_change_foreign_key_in_project_user_from_user_card_table_to_
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m211123_082634_change_foreign_key_in_project_user_from_user_card_table_to_user_table cannot be reverted.\n";
|
||||
echo "m211123_082634_add_foreign_key__from_project_user__to_user_table cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
9076
frontend-access.log
9076
frontend-access.log
File diff suppressed because it is too large
Load Diff
4362
frontend-error.log
4362
frontend-error.log
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user