diff --git a/backend/config/main.php b/backend/config/main.php index 0be21e7..f87721d 100644 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -13,11 +13,8 @@ return [ 'bootstrap' => ['log'], 'modules' => [ - 'status' => [ - 'class' => 'backend\modules\status\Status', - ], - 'fields' => [ - 'class' => 'backend\modules\fields\Fields', + 'settings' => [ + 'class' => 'backend\modules\settings\Settings', ], 'card' => [ 'class' => 'backend\modules\card\Card', diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index 1561c30..6c040c9 100644 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -3,6 +3,7 @@ namespace backend\modules\card\controllers; use common\classes\Debug; +use common\models\CardSkill; use common\models\FieldsValue; use Yii; use backend\modules\card\models\UserCard; @@ -62,9 +63,12 @@ class UserCardController extends Controller ], ]); + $skills = CardSkill::find()->where(['card_id' => $id])->with('skill')->all(); + return $this->render('view', [ 'model' => $this->findModel($id), 'modelFildValue' => $dataProvider, + 'skills' => $skills, ]); } diff --git a/backend/modules/card/models/UserCard.php b/backend/modules/card/models/UserCard.php index 07c8b70..049c23e 100644 --- a/backend/modules/card/models/UserCard.php +++ b/backend/modules/card/models/UserCard.php @@ -2,11 +2,15 @@ namespace backend\modules\card\models; +use backend\modules\settings\models\Skill; +use common\models\CardSkill; use common\models\FieldsValue; +use yii\helpers\ArrayHelper; class UserCard extends \common\models\UserCard { public $fields; + public $skill; public function init() { @@ -35,6 +39,15 @@ class UserCard extends \common\models\UserCard ], ]; } + + $skill = ArrayHelper::getColumn(CardSkill::find()->where(['card_id' => \Yii::$app->request->get('id')])->all(), + 'skill_id'); + + if (!empty($skill)) { + $this->skill = $skill; + + } + } public function afterSave($insert, $changedAttributes) @@ -53,6 +66,16 @@ class UserCard extends \common\models\UserCard $fildsValue->save(); } + CardSkill::deleteAll(['card_id' => $this->id]); + + foreach ( $post['skill'] as $item) { + $skill = new CardSkill(); + $skill->skill_id = $item; + $skill->card_id = $this->id; + + $skill->save(); + } + parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub } } \ No newline at end of file diff --git a/backend/modules/card/views/user-card/_form.php b/backend/modules/card/views/user-card/_form.php index 69e2dd5..4bb0359 100644 --- a/backend/modules/card/views/user-card/_form.php +++ b/backend/modules/card/views/user-card/_form.php @@ -1,5 +1,6 @@
- field($model, 'salary')->textInput(['maxlength' => true]) ?> + field($model, 'salary')->textInput(['maxlength' => true]) ?> +
+
+ field($model, 'position_id')->dropDownList( + \yii\helpers\ArrayHelper::map(\backend\modules\settings\models\Position::find()->all(), 'id', 'name'), + ['prompt' => '...'] + ) ?>
+
+
+ field($model, 'skill')->widget(Select2::class, + [ + 'data' => \yii\helpers\ArrayHelper::map(\common\models\Skill::find()->all(),'id', 'name'), + 'options' => ['placeholder' => '...','class' => 'form-control', 'multiple' => true], + 'pluginOptions' => [ + 'allowClear' => true + ], + ] + )->label('Навыки'); ?> +
+
+
field($model, 'fields')->widget(MultipleInput::class, [ @@ -119,7 +140,7 @@ use yii\widgets\ActiveForm; 'type' => 'dropDownList', 'title' => 'Поле', 'defaultValue' => null, - 'items' => \yii\helpers\ArrayHelper::map(\backend\modules\fields\models\AdditionalFields::find() + 'items' => \yii\helpers\ArrayHelper::map(\backend\modules\settings\models\AdditionalFields::find() ->joinWith('useFields') ->where(['`use_field`.`use`' => \common\models\UseStatus::USE_PROFILE]) ->all(), diff --git a/backend/modules/card/views/user-card/view.php b/backend/modules/card/views/user-card/view.php index caef680..5ae20e3 100644 --- a/backend/modules/card/views/user-card/view.php +++ b/backend/modules/card/views/user-card/view.php @@ -6,6 +6,8 @@ use yii\widgets\DetailView; /* @var $this yii\web\View */ /* @var $model backend\modules\card\models\UserCard */ +/* @var $skills \common\models\CardSkill */ +/* @var $skill \common\models\Skill */ $this->title = $model->fio; $this->params['breadcrumbs'][] = ['label' => 'User Cards', 'url' => ['index']]; @@ -23,21 +25,21 @@ $this->params['breadcrumbs'][] = $this->title; 'fio', 'passport', [ - 'label' => 'Photo', + 'attribute' => 'Photo', 'format' => 'raw', 'value' => function($model){ return Html::tag('img', null, ['src' => $model->photo, 'width' => '100px']); } ], [ - 'label' => 'Resume', + 'attribute' => 'Resume', 'format' => 'raw', 'value' => function($model){ return Html::a('Скачать', $model->resume, ['target' => '_blank']); } ], [ - 'label' => 'gender', + 'attribute' => 'gender', 'value' => $model->gendersText, ], @@ -45,15 +47,24 @@ $this->params['breadcrumbs'][] = $this->title; 'dob', [ - 'label' => 'status', + 'attribute' => 'status', 'value' => $model->status0->name, ], 'salary', + [ + 'attribute' => 'position_id', + 'value' => $model->position->name, + ], 'created_at', 'updated_at', ], ]) ?> +

Навыки

+ + + name; ?> +

Дополнительные сведения

'dropDownList', 'title' => 'Поле', 'defaultValue' => null, - 'items' => \yii\helpers\ArrayHelper::map(\backend\modules\fields\models\AdditionalFields::find() + 'items' => \yii\helpers\ArrayHelper::map(\backend\modules\settings\models\AdditionalFields::find() ->joinWith('useFields') ->where(['`use_field`.`use`' => \common\models\UseStatus::USE_PROJECT]) ->all(), diff --git a/backend/modules/fields/Fields.php b/backend/modules/settings/Settings.php similarity index 52% rename from backend/modules/fields/Fields.php rename to backend/modules/settings/Settings.php index 9c04946..134e017 100644 --- a/backend/modules/fields/Fields.php +++ b/backend/modules/settings/Settings.php @@ -1,16 +1,16 @@ [ + 'class' => VerbFilter::class, + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Position models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new PositionSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Position model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Position model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Position(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['index']); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Position model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['index']); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Position model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Position model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Position the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Position::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/backend/modules/settings/controllers/SkillController.php b/backend/modules/settings/controllers/SkillController.php new file mode 100644 index 0000000..5bced31 --- /dev/null +++ b/backend/modules/settings/controllers/SkillController.php @@ -0,0 +1,127 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Skill models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SkillSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Skill model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Skill model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Skill(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['index']); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Skill model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['index']); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Skill model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Skill model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Skill the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Skill::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/backend/modules/status/controllers/StatusController.php b/backend/modules/settings/controllers/StatusController.php similarity index 96% rename from backend/modules/status/controllers/StatusController.php rename to backend/modules/settings/controllers/StatusController.php index b3fdbc4..fcc9fcb 100644 --- a/backend/modules/status/controllers/StatusController.php +++ b/backend/modules/settings/controllers/StatusController.php @@ -1,10 +1,10 @@ $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/backend/modules/settings/models/Skill.php b/backend/modules/settings/models/Skill.php new file mode 100644 index 0000000..35ee474 --- /dev/null +++ b/backend/modules/settings/models/Skill.php @@ -0,0 +1,8 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/backend/modules/status/models/Status.php b/backend/modules/settings/models/Status.php similarity index 92% rename from backend/modules/status/models/Status.php rename to backend/modules/settings/models/Status.php index 3e1b932..58d84c4 100644 --- a/backend/modules/status/models/Status.php +++ b/backend/modules/settings/models/Status.php @@ -1,6 +1,6 @@ + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/settings/views/position/_search.php b/backend/modules/settings/views/position/_search.php new file mode 100644 index 0000000..619fc4e --- /dev/null +++ b/backend/modules/settings/views/position/_search.php @@ -0,0 +1,29 @@ + + + diff --git a/backend/modules/settings/views/position/create.php b/backend/modules/settings/views/position/create.php new file mode 100644 index 0000000..4d6e232 --- /dev/null +++ b/backend/modules/settings/views/position/create.php @@ -0,0 +1,19 @@ +title = 'Новая должность'; +$this->params['breadcrumbs'][] = ['label' => 'Должности', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/settings/views/position/index.php b/backend/modules/settings/views/position/index.php new file mode 100644 index 0000000..339f266 --- /dev/null +++ b/backend/modules/settings/views/position/index.php @@ -0,0 +1,33 @@ +title = 'Должность'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'name', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/modules/settings/views/position/update.php b/backend/modules/settings/views/position/update.php new file mode 100644 index 0000000..4c29736 --- /dev/null +++ b/backend/modules/settings/views/position/update.php @@ -0,0 +1,18 @@ +title = 'Редактирование: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Должности', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/settings/views/position/view.php b/backend/modules/settings/views/position/view.php new file mode 100644 index 0000000..9c1ba67 --- /dev/null +++ b/backend/modules/settings/views/position/view.php @@ -0,0 +1,35 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Должности', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'name', + ], + ]) ?> + +
diff --git a/backend/modules/settings/views/skill/_form.php b/backend/modules/settings/views/skill/_form.php new file mode 100644 index 0000000..b85532e --- /dev/null +++ b/backend/modules/settings/views/skill/_form.php @@ -0,0 +1,23 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/settings/views/skill/_search.php b/backend/modules/settings/views/skill/_search.php new file mode 100644 index 0000000..ad822a3 --- /dev/null +++ b/backend/modules/settings/views/skill/_search.php @@ -0,0 +1,29 @@ + + + diff --git a/backend/modules/settings/views/skill/create.php b/backend/modules/settings/views/skill/create.php new file mode 100644 index 0000000..e5e6d14 --- /dev/null +++ b/backend/modules/settings/views/skill/create.php @@ -0,0 +1,19 @@ +title = 'Добавить'; +$this->params['breadcrumbs'][] = ['label' => 'Навыки', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/settings/views/skill/index.php b/backend/modules/settings/views/skill/index.php new file mode 100644 index 0000000..90f50b2 --- /dev/null +++ b/backend/modules/settings/views/skill/index.php @@ -0,0 +1,33 @@ +title = 'Навыки'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'name', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/modules/settings/views/skill/update.php b/backend/modules/settings/views/skill/update.php new file mode 100644 index 0000000..9e55bff --- /dev/null +++ b/backend/modules/settings/views/skill/update.php @@ -0,0 +1,18 @@ +title = 'Редактирование: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Навыки', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/settings/views/skill/view.php b/backend/modules/settings/views/skill/view.php new file mode 100644 index 0000000..2e6796d --- /dev/null +++ b/backend/modules/settings/views/skill/view.php @@ -0,0 +1,35 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Навыки', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'name', + ], + ]) ?> + +
diff --git a/backend/modules/status/views/status/_form.php b/backend/modules/settings/views/status/_form.php similarity index 100% rename from backend/modules/status/views/status/_form.php rename to backend/modules/settings/views/status/_form.php diff --git a/backend/modules/status/views/status/_search.php b/backend/modules/settings/views/status/_search.php similarity index 100% rename from backend/modules/status/views/status/_search.php rename to backend/modules/settings/views/status/_search.php diff --git a/backend/modules/status/views/status/create.php b/backend/modules/settings/views/status/create.php similarity index 100% rename from backend/modules/status/views/status/create.php rename to backend/modules/settings/views/status/create.php diff --git a/backend/modules/status/views/status/index.php b/backend/modules/settings/views/status/index.php similarity index 95% rename from backend/modules/status/views/status/index.php rename to backend/modules/settings/views/status/index.php index a28ebd9..1628e22 100644 --- a/backend/modules/status/views/status/index.php +++ b/backend/modules/settings/views/status/index.php @@ -7,7 +7,7 @@ use yii\grid\GridView; /* @var $searchModel backend\modules\status\models\StatusSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ -$this->title = 'Statuses'; +$this->title = 'Статусы'; $this->params['breadcrumbs'][] = $this->title; ?>
diff --git a/backend/modules/status/views/status/update.php b/backend/modules/settings/views/status/update.php similarity index 63% rename from backend/modules/status/views/status/update.php rename to backend/modules/settings/views/status/update.php index 95993bd..fb85bd2 100644 --- a/backend/modules/status/views/status/update.php +++ b/backend/modules/settings/views/status/update.php @@ -3,10 +3,9 @@ /* @var $this yii\web\View */ /* @var $model backend\modules\status\models\Status */ -$this->title = 'Update Status: ' . $model->name; -$this->params['breadcrumbs'][] = ['label' => 'Statuses', 'url' => ['index']]; +$this->title = 'Редактирование: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Статусы', 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; -$this->params['breadcrumbs'][] = 'Update'; ?>
diff --git a/backend/modules/status/views/status/view.php b/backend/modules/settings/views/status/view.php similarity index 100% rename from backend/modules/status/views/status/view.php rename to backend/modules/settings/views/status/view.php diff --git a/backend/modules/status/Status.php b/backend/modules/status/Status.php deleted file mode 100644 index 69976c9..0000000 --- a/backend/modules/status/Status.php +++ /dev/null @@ -1,24 +0,0 @@ - ['class' => 'sidebar-menu tree', 'data-widget' => 'tree'], 'items' => [ - ['label' => 'Статусы', 'icon' => 'anchor', 'url' => ['/status/status']], - ['label' => 'Доп. поля', 'icon' => 'file-text-o', 'url' => ['/fields/additional-fields']], + [ + 'label' => 'Настройки', 'icon' => 'gears', 'url' => '#', + 'items' => [ + ['label' => 'Статусы', 'icon' => 'anchor', 'url' => ['/settings/status']], + ['label' => 'Доп. поля', 'icon' => 'file-text-o', 'url' => ['/settings/additional-fields']], + ['label' => 'Должность', 'icon' => 'spotify', 'url' => ['/settings/position']], + ['label' => 'Навыки', 'icon' => 'flask', 'url' => ['/settings/skill']], + ] + ], + ['label' => 'Профили', 'icon' => 'users', 'url' => ['/card/user-card']], ['label' => 'Пректы', 'icon' => 'files-o', 'url' => ['/project/project']], ['label' => 'Компании', 'icon' => 'files-o', 'url' => ['/company/company']], diff --git a/common/models/CardSkill.php b/common/models/CardSkill.php new file mode 100644 index 0000000..f7ac974 --- /dev/null +++ b/common/models/CardSkill.php @@ -0,0 +1,67 @@ + true, 'targetClass' => Skill::className(), 'targetAttribute' => ['skill_id' => 'id']], + [['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'card_id' => 'Card ID', + 'skill_id' => 'Skill ID', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSkill() + { + return $this->hasOne(Skill::className(), ['id' => 'skill_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCard() + { + return $this->hasOne(UserCard::className(), ['id' => 'card_id']); + } +} diff --git a/common/models/Position.php b/common/models/Position.php new file mode 100644 index 0000000..3f64691 --- /dev/null +++ b/common/models/Position.php @@ -0,0 +1,44 @@ + 100], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Название', + ]; + } +} diff --git a/common/models/Skill.php b/common/models/Skill.php new file mode 100644 index 0000000..90cbfb7 --- /dev/null +++ b/common/models/Skill.php @@ -0,0 +1,54 @@ + 100], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Name', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCardSkills() + { + return $this->hasMany(CardSkill::className(), ['skill_id' => 'id']); + } +} diff --git a/common/models/UserCard.php b/common/models/UserCard.php index 6efb8e4..85997fb 100644 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -21,10 +21,11 @@ use yii\db\Expression; * @property string $updated_at * @property string $resume * @property string $salary + * @property int $position_id * - * @property array $genders - * @property string $gendersText - * + * @property FieldsValue[] $fieldsValues + * @property ProjectUser[] $projectUsers + * @property Position $position * @property Status $status0 */ class UserCard extends \yii\db\ActiveRecord @@ -59,11 +60,11 @@ class UserCard extends \yii\db\ActiveRecord { return [ [['fio', 'status'], 'required'], - [['status'], 'integer'], - [['gender'], 'in', 'range' => array_keys($this->genders)], + [['gender', 'status', 'position_id'], 'integer'], [['dob', 'created_at', 'updated_at'], 'safe'], [['fio', 'passport', 'photo', 'email', 'resume'], 'string', 'max' => 255], [['salary'], 'string', 'max' => 100], + [['position_id'], 'exist', 'skipOnError' => true, 'targetClass' => Position::class, 'targetAttribute' => ['position_id' => 'id']], [['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']], ]; } @@ -86,6 +87,7 @@ class UserCard extends \yii\db\ActiveRecord 'updated_at' => 'Дата редактирование', 'resume' => 'Резюме', 'salary' => 'Зарплата', + 'position_id' => 'Должность', ]; } @@ -105,6 +107,14 @@ class UserCard extends \yii\db\ActiveRecord return $this->hasMany(ProjectUser::class, ['card_id' => 'id']); } + /** + * @return \yii\db\ActiveQuery + */ + public function getPosition() + { + return $this->hasOne(Position::class, ['id' => 'position_id']); + } + /** * @return \yii\db\ActiveQuery */ diff --git a/console/migrations/m181012_082916_create_position_table.php b/console/migrations/m181012_082916_create_position_table.php new file mode 100644 index 0000000..33eaf0b --- /dev/null +++ b/console/migrations/m181012_082916_create_position_table.php @@ -0,0 +1,33 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + $this->createTable('position', [ + 'id' => $this->primaryKey(), + 'name' => $this->string(100)->notNull(), + ], $tableOptions); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('position'); + } +} diff --git a/console/migrations/m181012_093626_add_position_id_column_to_user_card_table.php b/console/migrations/m181012_093626_add_position_id_column_to_user_card_table.php new file mode 100644 index 0000000..f1db353 --- /dev/null +++ b/console/migrations/m181012_093626_add_position_id_column_to_user_card_table.php @@ -0,0 +1,36 @@ +addColumn('user_card', 'position_id', $this->integer(11)); + $this->addForeignKey( + 'user_card_ibfk_position', + 'user_card', + 'position_id', + 'position', + 'id', + 'RESTRICT', + 'CASCADE' + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('user_card_ibfk_position', 'user_card'); + + $this->dropColumn('project', 'company_id'); + } +} diff --git a/console/migrations/m181012_102422_create_skill_table.php b/console/migrations/m181012_102422_create_skill_table.php new file mode 100644 index 0000000..c98b2d2 --- /dev/null +++ b/console/migrations/m181012_102422_create_skill_table.php @@ -0,0 +1,62 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable('skill', [ + 'id' => $this->primaryKey(), + 'name' => $this->string(100)->notNull(), + ], $tableOptions); + + $this->createTable('card_skill', [ + 'id' => $this->primaryKey(), + 'card_id' => $this->integer(11)->notNull(), + 'skill_id' => $this->integer(11)->notNull(), + ], $tableOptions); + + $this->addForeignKey( + 'card_skill_ibfk_user_card', + 'card_skill', + 'card_id', + 'user_card', + 'id', + 'RESTRICT', + 'CASCADE' + ); + + $this->addForeignKey( + 'card_skill_ibfk_skill', + 'card_skill', + 'skill_id', + 'skill', + 'id', + 'RESTRICT', + 'CASCADE' + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + + $this->dropTable('card_skill'); + $this->dropTable('skill'); + } +}