2018-10-11 11:15:09 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace backend\modules\card\models;
|
|
|
|
|
2018-10-12 14:52:08 +03:00
|
|
|
use backend\modules\settings\models\Skill;
|
|
|
|
use common\models\CardSkill;
|
2018-10-11 11:15:09 +03:00
|
|
|
use common\models\FieldsValue;
|
2018-10-12 14:52:08 +03:00
|
|
|
use yii\helpers\ArrayHelper;
|
2018-10-11 11:15:09 +03:00
|
|
|
|
|
|
|
class UserCard extends \common\models\UserCard
|
|
|
|
{
|
|
|
|
public $fields;
|
2018-10-12 14:52:08 +03:00
|
|
|
public $skill;
|
2018-10-11 11:15:09 +03:00
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
|
|
|
|
$fieldValue = FieldsValue::find()->where(
|
|
|
|
[
|
|
|
|
'card_id' => \Yii::$app->request->get('id'),
|
|
|
|
'project_id' => null,
|
2018-10-11 17:45:35 +03:00
|
|
|
'company_id' => null,
|
2018-10-11 11:15:09 +03:00
|
|
|
])
|
|
|
|
->all();
|
|
|
|
$array = [];
|
|
|
|
if(!empty($fieldValue)){
|
|
|
|
foreach ($fieldValue as $item){
|
|
|
|
array_push($array, ['field_id' => $item->field_id, 'value' => $item->value, 'order' => $item->order]);
|
|
|
|
}
|
|
|
|
$this->fields = $array;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$this->fields = [
|
|
|
|
[
|
|
|
|
'field_id' => null,
|
|
|
|
'value' => null,
|
|
|
|
'order' => null,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2018-10-12 14:52:08 +03:00
|
|
|
|
|
|
|
$skill = ArrayHelper::getColumn(CardSkill::find()->where(['card_id' => \Yii::$app->request->get('id')])->all(),
|
|
|
|
'skill_id');
|
|
|
|
|
|
|
|
if (!empty($skill)) {
|
|
|
|
$this->skill = $skill;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-11 11:15:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function afterSave($insert, $changedAttributes)
|
|
|
|
{
|
|
|
|
$post = \Yii::$app->request->post('UserCard');
|
|
|
|
|
|
|
|
FieldsValue::deleteAll(['card_id' => $this->id]);
|
|
|
|
|
|
|
|
foreach ( $post['fields'] as $item) {
|
|
|
|
$fildsValue = new FieldsValue();
|
|
|
|
$fildsValue->field_id = $item['field_id'];
|
|
|
|
$fildsValue->value = $item['value'];
|
|
|
|
$fildsValue->order = $item['order'];
|
|
|
|
$fildsValue->card_id = $this->id;
|
|
|
|
|
|
|
|
$fildsValue->save();
|
|
|
|
}
|
|
|
|
|
2018-10-12 14:52:08 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-10-11 11:15:09 +03:00
|
|
|
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
|
|
|
|
}
|
|
|
|
}
|