diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index e748257..f5c7501 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -5,6 +5,7 @@ namespace backend\modules\card\controllers; use common\classes\Debug; use common\models\AdditionalFields; use common\models\CardSkill; +use common\Models\ChangeHistory; use common\models\User; use common\models\FieldsValue; use common\models\FieldsValueNew; @@ -105,12 +106,19 @@ class UserCardController extends Controller $skills = CardSkill::find()->where(['card_id' => $id])->with('skill')->all(); $id_current_user = $this->findModel($id)->id_user; + $changeDataProvider = new ActiveDataProvider([ + 'query' => \common\models\ChangeHistory::find()->where(['type_id' => $this->findModel($id)->id]), + 'pagination' => [ + 'pageSize' => 200, + ] + ]); return $this->render('view', [ 'model' => $this->findModel($id), - 'modelFildValue' => $dataProvider, + 'modelFieldValue' => $dataProvider, 'skills' => $skills, 'userData' => User::findOne($id_current_user), + 'changeDataProvider' => $changeDataProvider, ]); } diff --git a/backend/modules/card/models/UserCard.php b/backend/modules/card/models/UserCard.php index ce3bd54..7fcc09f 100755 --- a/backend/modules/card/models/UserCard.php +++ b/backend/modules/card/models/UserCard.php @@ -2,6 +2,7 @@ namespace backend\modules\card\models; +use Common\Behaviors\LogBehavior; use Yii; use backend\modules\settings\models\Skill; use common\classes\Debug; @@ -64,51 +65,61 @@ class UserCard extends \common\models\UserCard } } + public function behaviors() + { + return [ + 'log' => [ + 'class' => \common\behaviors\LogBehavior::class, + ] + ]; + } + public function beforeSave($insert) { - $this->salary = str_replace(' ', '', \Yii::$app->request->post('UserCard')['salary']); + if(is_array(\Yii::$app->request->post('UserCard'))) + { + $this->salary = str_replace(' ', '', \Yii::$app->request->post('UserCard')['salary']); + } return parent::beforeSave($insert); // TODO: Change the autogenerated stub } public function afterSave($insert, $changedAttributes) { $post = \Yii::$app->request->post('UserCard'); + if($post) { + if (isset($post['fields'])) { + FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROFILE]); + foreach ($post['fields'] as $item) { + $item['value'] = urldecode($item['value']); - if ($post['fields']) { - FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROFILE]); - foreach ($post['fields'] as $item) { - $item['value'] = urldecode($item['value']); + $fieldsValue = new FieldsValueNew(); + $fieldsValue->field_id = $item['field_id']; + $fieldsValue->value = $item['value']; + $fieldsValue->order = $item['order']; + $fieldsValue->item_id = $this->id; + $fieldsValue->item_type = FieldsValueNew::TYPE_PROFILE; + if (is_file(Yii::getAlias('@frontend') . '/web/' . $item['value'])) { + $fieldsValue->type_file = 'file'; + } else { + $fieldsValue->type_file = 'text'; + } - $fieldsValue = new FieldsValueNew(); - $fieldsValue->field_id = $item['field_id']; - $fieldsValue->value = $item['value']; - $fieldsValue->order = $item['order']; - $fieldsValue->item_id = $this->id; - $fieldsValue->item_type = FieldsValueNew::TYPE_PROFILE; - if(is_file(Yii::getAlias('@frontend') . '/web/' . $item['value'])){ - $fieldsValue->type_file = 'file'; - }else{ - $fieldsValue->type_file = 'text'; + $fieldsValue->save(); } - - $fieldsValue->save(); } - } + if (is_array($post['fields'])) { + CardSkill::deleteAll(['card_id' => $this->id]); + if (is_array($post['skill'])) + foreach ($post['skill'] as $item) { + $skill = new CardSkill(); + $skill->skill_id = $item; + $skill->card_id = $this->id; - if ($post['skill']) { - 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(); + $skill->save(); + } } + parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub } - - - parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub } public static function getParameter($params, $key) diff --git a/backend/modules/card/views/user-card/view.php b/backend/modules/card/views/user-card/view.php index 0b1baef..7b2765e 100755 --- a/backend/modules/card/views/user-card/view.php +++ b/backend/modules/card/views/user-card/view.php @@ -9,7 +9,8 @@ use yii\widgets\DetailView; /* @var $userData common\models\User */ /* @var $skills \common\models\CardSkill */ /* @var $skill \common\models\Skill */ -/* @var $modelFildValue yii\data\ActiveDataProvider */ +/* @var $modelFieldValue yii\data\ActiveDataProvider */ +/* @var $changeDataProvider yii\data\ActiveDataProvider */ $this->title = $model->fio; $this->params['breadcrumbs'][] = ['label' => 'Профили', 'url' => ['index']]; @@ -75,7 +76,7 @@ $this->params['breadcrumbs'][] = $this->title;