update foreign key in task in task

This commit is contained in:
iIronside 2021-12-20 17:49:11 +03:00
parent ef0889aac6
commit e07dd0eff6
14 changed files with 132 additions and 78 deletions

View File

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

View File

@ -72,22 +72,20 @@ class ProjectUserController extends Controller
$post = \Yii::$app->request->post('ProjectUser'); $post = \Yii::$app->request->post('ProjectUser');
if (!empty($post)) { if (!empty($post)) {
$user_id_arr = ArrayHelper::getValue($post, 'user_id'); $card_id_arr = ArrayHelper::getValue($post, 'card_id');
$project_id = $post['project_id']; $project_id = $post['project_id'];
foreach ($user_id_arr as $user_id) { foreach ($card_id_arr as $card_id) {
$emtModel = new ProjectUser(); $emtModel = new ProjectUser();
$emtModel->project_id = $project_id; $emtModel->project_id = $project_id;
$emtModel->user_id = $user_id; $emtModel->card_id = $card_id;
$emtModel->card_id = UserCard::getIdByUserId($user_id); $emtModel->user_id = UserCard::getUserIdByCardId($card_id);
$emtModel->save(); if (!$emtModel->save()) {
return $this->render('create', [
// if (!$emtModel->save()) { 'model' => $emtModel,
// return $this->render('create', [ ]);
// 'model' => $emtModel, }
// ]);
// }
} }
return $this->redirect(['index']); return $this->redirect(['index']);
} }
@ -110,7 +108,7 @@ class ProjectUserController extends Controller
$model = $this->findModel($id); $model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) ) { if ($model->load(Yii::$app->request->post()) ) {
$model->card_id = UserCard::getIdByUserId($model->user_id); $model->user_id = UserCard::getUserIdByCardId($model->card_id);//UserCard::getIdByUserId($model->user_id);
if ($model->save()) { if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect(['view', 'id' => $model->id]);
} }

View File

@ -1,5 +1,6 @@
<?php <?php
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project; use backend\modules\project\models\Project;
use common\models\User; use common\models\User;
use kartik\select2\Select2; use kartik\select2\Select2;
@ -25,9 +26,9 @@ use yii\widgets\ActiveForm;
] ]
) ?> ) ?>
<?= $form->field($model, 'user_id')->widget(Select2::className(), <?= $form->field($model, 'card_id')->widget(Select2::className(),
[ [
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'], 'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,

View File

@ -1,5 +1,6 @@
<?php <?php
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project; use backend\modules\project\models\Project;
use common\models\User; use common\models\User;
use kartik\select2\Select2; use kartik\select2\Select2;
@ -25,9 +26,9 @@ use yii\widgets\ActiveForm;
] ]
) ?> ) ?>
<?= $form->field($model, 'user_id')->widget(Select2::className(), <?= $form->field($model, 'card_id')->widget(Select2::className(),
[ [
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'], 'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,

View File

@ -2,6 +2,7 @@
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
use yii\web\YiiAsset;
use yii\widgets\DetailView; use yii\widgets\DetailView;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
@ -10,7 +11,7 @@ use yii\widgets\DetailView;
$this->title = 'Сотрудник проекта: ' . $model->project->name; $this->title = 'Сотрудник проекта: ' . $model->project->name;
$this->params['breadcrumbs'][] = ['label' => 'Project Users', 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => 'Project Users', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this); YiiAsset::register($this);
?> ?>
<div class="project-user-view"> <div class="project-user-view">
@ -38,6 +39,10 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'user_id', 'attribute' => 'user_id',
'value' => ArrayHelper::getValue($model, 'user.username' ), 'value' => ArrayHelper::getValue($model, 'user.username' ),
], ],
[
'attribute' => 'card_id',
'value' => ArrayHelper::getValue($model, 'card.fio' ),
],
], ],
]) ?> ]) ?>

View File

@ -18,7 +18,7 @@ class TaskSearch extends Task
public function rules() public function rules()
{ {
return [ return [
[['id', 'project_id', 'status', 'user_id_creator', 'user_id'], 'integer'], [['id', 'project_id', 'status', 'card_id_creator', 'card_id'], 'integer'], // 'card_id_creator', 'card_id'
[['title', 'created_at', 'updated_at', 'description'], 'safe'], [['title', 'created_at', 'updated_at', 'description'], 'safe'],
]; ];
} }
@ -41,10 +41,7 @@ class TaskSearch extends Task
*/ */
public function search($params) public function search($params)
{ {
$query = Task::find()->joinWith(['user', 'project']); $query = Task::find();//->joinWith(['user_card', 'project']);
// => function($query){
// $query->from(ProjectUser::tableName() . ' pt');
// }]); //,
// add conditions that should always apply here // add conditions that should always apply here
@ -67,8 +64,8 @@ class TaskSearch extends Task
'task.status' => $this->status, 'task.status' => $this->status,
'task.created_at' => $this->created_at, 'task.created_at' => $this->created_at,
'task.updated_at' => $this->updated_at, 'task.updated_at' => $this->updated_at,
'user_id_creator' => $this->user_id_creator, 'task.card_id_creator' => $this->card_id_creator,
'task.user_id' => $this->user_id, 'task.card_id' => $this->card_id,
]); ]);
$query->andFilterWhere(['like', 'title', $this->title]) $query->andFilterWhere(['like', 'title', $this->title])

View File

@ -1,13 +1,10 @@
<?php <?php
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project; use backend\modules\project\models\Project;
use backend\modules\project\models\ProjectUser;
use common\helpers\StatusHelper; use common\helpers\StatusHelper;
use common\models\User;
use kartik\depdrop\DepDrop;
use kartik\select2\Select2; use kartik\select2\Select2;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
@ -27,9 +24,9 @@ use yii\widgets\ActiveForm;
); );
?> ?>
<?= $form->field($model, 'user_id_creator')->widget(Select2::class, <?= $form->field($model, 'card_id_creator')->widget(Select2::class,
[ [
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control', 'value' => Yii::$app->user->id], 'options' => ['placeholder' => '...','class' => 'form-control', 'value' => Yii::$app->user->id],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,
@ -47,9 +44,9 @@ use yii\widgets\ActiveForm;
] ]
) ?> ) ?>
<?= $form->field($model, 'user_id')->widget(Select2::class, <?= $form->field($model, 'card_id')->widget(Select2::class,
[ [
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'], 'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,

View File

@ -1,5 +1,6 @@
<?php <?php
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project; use backend\modules\project\models\Project;
use backend\modules\project\models\ProjectUser; use backend\modules\project\models\ProjectUser;
use backend\modules\task\models\Task; use backend\modules\task\models\Task;
@ -35,7 +36,8 @@ $this->params['breadcrumbs'][] = $this->title;
'filter' => Select2::widget([ 'filter' => Select2::widget([
'model' => $searchModel, 'model' => $searchModel,
'attribute' => 'project_id', 'attribute' => 'project_id',
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(), 'data' => Task::find()->joinWith('project')
->select(['project.name', 'project.id'])->indexBy('project.id')->column(),
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,
'width' => '150px', 'width' => '150px',
@ -48,12 +50,13 @@ $this->params['breadcrumbs'][] = $this->title;
], ],
'title', 'title',
[ [
'attribute' => 'user_id_creator', 'attribute' => 'card_id_creator',
'value' => 'userIdCreator.username', 'value' => 'userCardCreator.fio',
'filter' => Select2::widget([ 'filter' => Select2::widget([
'model' => $searchModel, 'model' => $searchModel,
'attribute' => 'user_id_creator', 'attribute' => 'card_id_creator',
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => Task::find()->joinWith('userCardCreator')
->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(),
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,
'width' => '150px', 'width' => '150px',
@ -65,12 +68,13 @@ $this->params['breadcrumbs'][] = $this->title;
]) ])
], ],
[ [
'attribute' => 'user_id', 'attribute' => 'card_id',
'value' => 'user.username', 'value' => 'userCard.fio',
'filter' => Select2::widget([ 'filter' => Select2::widget([
'model' => $searchModel, 'model' => $searchModel,
'attribute' => 'user_id', 'attribute' => 'card_id',
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => Task::find()->joinWith('userCard')
->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(),
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,
'width' => '150px', 'width' => '150px',

View File

@ -47,12 +47,12 @@ YiiAsset::register($this);
'created_at', 'created_at',
'updated_at', 'updated_at',
[ [
'attribute' => 'project_user_id', 'attribute' => 'card_id_creator',
'value' => ArrayHelper::getValue($model, 'projectUser.user.username'), 'value' => ArrayHelper::getValue($model, 'userCardCreator.fio'),
], ],
[ [
'attribute' => 'user_id', 'attribute' => 'card_id',
'value' => ArrayHelper::getValue($model, 'user.username'), 'value' => ArrayHelper::getValue($model, 'userCard.fio'),
], ],
'description', 'description',
], ],

View File

@ -27,7 +27,7 @@
['label' => 'Должность', 'icon' => 'spotify', 'url' => ['/settings/position'], 'active' => \Yii::$app->controller->id == 'position'], ['label' => 'Должность', 'icon' => 'spotify', 'url' => ['/settings/position'], 'active' => \Yii::$app->controller->id == 'position'],
['label' => 'Навыки', 'icon' => 'flask', 'url' => ['/settings/skill'], 'active' => \Yii::$app->controller->id == 'skill'], ['label' => 'Навыки', 'icon' => 'flask', 'url' => ['/settings/skill'], 'active' => \Yii::$app->controller->id == 'skill'],
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
[ [
'label' => 'Профили', 'icon' => 'address-book-o', 'url' => '#', 'active' => \Yii::$app->controller->id == 'user-card', 'label' => 'Профили', 'icon' => 'address-book-o', 'url' => '#', 'active' => \Yii::$app->controller->id == 'user-card',
@ -39,12 +39,12 @@
['label' => 'Менеджеры', 'icon' => 'user-circle-o', 'url' => ['/employee/manager'], 'active' => \Yii::$app->controller->id == 'manager'], ['label' => 'Менеджеры', 'icon' => 'user-circle-o', 'url' => ['/employee/manager'], 'active' => \Yii::$app->controller->id == 'manager'],
['label' => 'Работники', 'icon' => 'user', 'url' => ['/employee/manager-employee'], 'active' => \Yii::$app->controller->id == 'manager-employee'], ['label' => 'Работники', 'icon' => 'user', 'url' => ['/employee/manager-employee'], 'active' => \Yii::$app->controller->id == 'manager-employee'],
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
[ [
'label' => 'Проекты', 'icon' => 'cubes', 'url' => ['#'], //'active' => \Yii::$app->controller->id == 'project', 'label' => 'Проекты', 'icon' => 'cubes', 'url' => ['#'], //'active' => \Yii::$app->controller->id == 'project',
'items' => $projectItems, 'items' => $projectItems,
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
[ [
'label' => 'Задачи', 'icon' => 'tasks', 'url' => '#', 'label' => 'Задачи', 'icon' => 'tasks', 'url' => '#',
@ -53,7 +53,7 @@
['label' => 'Исполнители задачи', 'icon' => 'users', 'url' => ['/task/task-user'], 'active' => \Yii::$app->controller->id == 'task-user'], ['label' => 'Исполнители задачи', 'icon' => 'users', 'url' => ['/task/task-user'], 'active' => \Yii::$app->controller->id == 'task-user'],
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
['label' => 'Компании', 'icon' => 'building', 'url' => ['/company/company'], 'active' => \Yii::$app->controller->id == 'company', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Компании', 'icon' => 'building', 'url' => ['/company/company'], 'active' => \Yii::$app->controller->id == 'company', 'visible' => Yii::$app->user->can('confidential_information')],
[ [
@ -62,7 +62,7 @@
['label' => 'Компании', 'icon' => 'building', 'url' => ['/hh/hh'], 'active' => \Yii::$app->controller->id == 'hh'], ['label' => 'Компании', 'icon' => 'building', 'url' => ['/hh/hh'], 'active' => \Yii::$app->controller->id == 'hh'],
['label' => 'Вакансии', 'icon' => 'user-md', 'url' => ['/hh/hh-job'], 'active' => \Yii::$app->controller->id == 'hh-job'], ['label' => 'Вакансии', 'icon' => 'user-md', 'url' => ['/hh/hh-job'], 'active' => \Yii::$app->controller->id == 'hh-job'],
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
['label' => 'Баланс', 'icon' => 'dollar', 'url' => ['/balance/balance'], 'active' => \Yii::$app->controller->id == 'balance', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Баланс', 'icon' => 'dollar', 'url' => ['/balance/balance'], 'active' => \Yii::$app->controller->id == 'balance', 'visible' => Yii::$app->user->can('confidential_information')],
['label' => 'Отпуска', 'icon' => 'plane', 'url' => ['/holiday/holiday'], 'active' => \Yii::$app->controller->id == 'holiday', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Отпуска', 'icon' => 'plane', 'url' => ['/holiday/holiday'], 'active' => \Yii::$app->controller->id == 'holiday', 'visible' => Yii::$app->user->can('confidential_information')],
@ -77,7 +77,7 @@
'icon' => 'list-alt', 'icon' => 'list-alt',
'url' => ['/interview/interview'], 'url' => ['/interview/interview'],
'active' => \Yii::$app->controller->id == 'interview', 'active' => \Yii::$app->controller->id == 'interview',
'visible' => Yii::$app->user->can('confidential_information'), //TODO 'visible' => Yii::$app->user->can('confidential_information'),
'badge' => '<span class="badge badge-info right">4</span>' 'badge' => '<span class="badge badge-info right">4</span>'
], ],
[ [
@ -91,7 +91,7 @@
['label' => 'Анкеты пользователей', 'icon' => 'drivers-license', 'url' => ['/questionnaire/user-questionnaire'], 'active' => \Yii::$app->controller->id == 'user-questionnaire'], ['label' => 'Анкеты пользователей', 'icon' => 'drivers-license', 'url' => ['/questionnaire/user-questionnaire'], 'active' => \Yii::$app->controller->id == 'user-questionnaire'],
['label' => 'Ответы пользователей', 'icon' => 'comments', 'url' => ['/questionnaire/user-response'], 'active' => \Yii::$app->controller->id == 'user-response'], ['label' => 'Ответы пользователей', 'icon' => 'comments', 'url' => ['/questionnaire/user-response'], 'active' => \Yii::$app->controller->id == 'user-response'],
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
/*['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii']], /*['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii']],

View File

@ -36,9 +36,10 @@ class ProjectUser extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['user_id', 'project_id'], 'required'], [['user_id', 'project_id', 'card_id'], 'required'],
['user_id', 'unique', 'targetAttribute' => ['user_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'], ['user_id', 'unique', 'targetAttribute' => ['user_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'],
// [['card_id', 'project_id', 'user_id'], 'integer'], ['card_id', 'unique', 'targetAttribute' => ['card_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'],
[['card_id', 'project_id', 'user_id'], 'integer'],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']], [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
[['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_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']], [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],

View File

@ -2,10 +2,9 @@
namespace common\models; namespace common\models;
use phpDocumentor\Reflection\Types\This;
use Yii;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use yii\db\Expression; use yii\db\Expression;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -18,16 +17,16 @@ use yii\helpers\ArrayHelper;
* @property int $status * @property int $status
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
* @property int $user_id_creator * @property int $card_id_creator
* @property int $user_id * @property int $card_id
* @property string $description * @property string $description
* *
* @property Project $project * @property Project $project
* @property User $userIdCreator * @property UserCard $card
* @property User $user * @property UserCard $cardIdCreator
* @property TaskUser[] $taskUsers * @property TaskUser[] $taskUsers
*/ */
class Task extends \yii\db\ActiveRecord class Task extends ActiveRecord
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -55,14 +54,15 @@ class Task extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['project_id', 'status', 'title', 'description', 'user_id_creator',], 'required'], [['project_id', 'status', 'title', 'description', 'card_id_creator',], 'required'],
[['project_id', 'status', 'user_id_creator', 'user_id'], 'integer'], [['project_id', 'status', 'card_id_creator', 'card_id'], 'integer'],
[['created_at', 'updated_at'], 'safe'], [['created_at', 'updated_at'], 'safe'],
['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message'=>'Такая задача уже создана'],
[['title'], 'string', 'max' => 255], [['title'], 'string', 'max' => 255],
[['description'], 'string', 'max' => 500], [['description'], 'string', 'max' => 500],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']], [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
[['user_id_creator'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id_creator' => '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']], [['card_id_creator'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id_creator' => 'id']],
]; ];
} }
@ -78,9 +78,9 @@ class Task extends \yii\db\ActiveRecord
'status' => 'Статус', 'status' => 'Статус',
'created_at' => 'Дата создания', 'created_at' => 'Дата создания',
'updated_at' => 'Дата обновления', 'updated_at' => 'Дата обновления',
'user_id_creator' => 'Создатель задачи',
'user_id' => 'Наблюдатель',
'description' => 'Описание', 'description' => 'Описание',
'card_id_creator' => 'Создатель задачи',
'card_id' => 'Наблюдатель',
]; ];
} }
@ -108,9 +108,14 @@ class Task extends \yii\db\ActiveRecord
return $this->hasOne(User::className(), ['id' => 'user_id']); return $this->hasOne(User::className(), ['id' => 'user_id']);
} }
public function getUserIdCreator() public function getUserCard()
{ {
return $this->hasOne(User::className(), ['id' => 'user_id_creator']); return $this->hasOne(UserCard::className(), ['id' => 'card_id']);
}
public function getUserCardCreator()
{
return $this->hasOne(UserCard::className(), ['id' => 'card_id_creator']);
} }
/** /**

View File

@ -104,6 +104,7 @@ class UserCard extends \yii\db\ActiveRecord
[['fio', 'status', 'gender', 'email', 'level', 'position_id'], 'required'], [['fio', 'status', 'gender', 'email', 'level', 'position_id'], 'required'],
[['gender', 'status', 'position_id', 'id_user', 'level', 'years_of_exp'], 'integer'], [['gender', 'status', 'position_id', 'id_user', 'level', 'years_of_exp'], 'integer'],
[['dob', 'created_at', 'updated_at', 'deleted_at', 'vc_text', 'vc_text_short'], 'safe'], [['dob', 'created_at', 'updated_at', 'deleted_at', 'vc_text', 'vc_text_short'], 'safe'],
['email', 'unique', 'message'=>'Почтовый адрес уже используется'],
[['fio', 'passport', 'photo', 'email', 'resume', 'city', 'link_vk', 'link_telegram', 'specification'], 'string', 'max' => 255], [['fio', 'passport', 'photo', 'email', 'resume', 'city', 'link_vk', 'link_telegram', 'specification'], 'string', 'max' => 255],
[['salary'], 'string', 'max' => 100], [['salary'], 'string', 'max' => 100],
[['position_id'], 'exist', 'skipOnError' => true, 'targetClass' => Position::class, 'targetAttribute' => ['position_id' => 'id']], [['position_id'], 'exist', 'skipOnError' => true, 'targetClass' => Position::class, 'targetAttribute' => ['position_id' => 'id']],
@ -214,14 +215,6 @@ class UserCard extends \yii\db\ActiveRecord
return $this->hasOne(User::class, ['id' => 'id_user']); return $this->hasOne(User::class, ['id' => 'id_user']);
} }
/**
* @throws Exception
*/
public static function getIdByUserId($user_id)
{
return ArrayHelper::getValue(self::find()->where(['id_user' => $user_id])->one(), 'id');
}
public static function getUserList() public static function getUserList()
{ {
return ArrayHelper::map(self::find()->all(), 'id', 'fio'); return ArrayHelper::map(self::find()->all(), 'id', 'fio');

View File

@ -0,0 +1,52 @@
<?php
use yii\db\Migration;
/**
* Class m211220_105942_change_foreign_keys_in_task_from_user_id_to_user_card_id
*/
class m211220_105942_change_foreign_keys_in_task_from_user_id_to_user_card_id extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->dropForeignKey('creator_task', 'task');
$this->dropColumn('task', 'user_id_creator');
$this->dropForeignKey('task_user', 'task');
$this->dropColumn('task', 'user_id');
$this->addColumn('task', 'card_id_creator', $this->integer(11)->defaultValue(null));
$this->addForeignKey('task_user_card_creator', 'task', 'card_id_creator',
'user_card', 'id');
$this->addColumn('task', 'card_id', $this->integer(11)->defaultValue(null));
$this->addForeignKey('task_user_card', 'task', 'card_id', 'user_card', 'id');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('task_user_card', 'task');
$this->dropColumn('task', 'card_id');
$this->dropForeignKey('task_user_card_creator', 'task');
$this->dropColumn('task', 'card_id_creator');
$this->addColumn('task', 'user_id_creator', $this->integer());
$this->addForeignKey('creator_task', 'task',
'user_id_creator', 'user', 'id');
$this->addColumn('task', 'user_id', $this->integer());
$this->addForeignKey('task_user', 'task',
'user_id', 'user', 'id');
}
}