diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index 6c040c9..65be193 100644 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -3,12 +3,14 @@ namespace backend\modules\card\controllers; use common\classes\Debug; +use common\models\AdditionalFields; use common\models\CardSkill; use common\models\FieldsValue; use Yii; use backend\modules\card\models\UserCard; use backend\modules\card\models\UserCardSearch; use yii\data\ActiveDataProvider; +use yii\db\Expression; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -119,7 +121,12 @@ class UserCardController extends Controller */ public function actionDelete($id) { - $this->findModel($id)->delete(); + //CardSkill::deleteAll(['card_id' => $id]); + //FieldsValue::deleteAll(['card_id' => $id]); + $model = $this->findModel($id); + $d = new \DateTime(); + $model->deleted_at = $d->format('Y-m-d H:i'); + $model->save(); return $this->redirect(['index']); } diff --git a/backend/modules/card/models/UserCard.php b/backend/modules/card/models/UserCard.php index 049c23e..f1ead04 100644 --- a/backend/modules/card/models/UserCard.php +++ b/backend/modules/card/models/UserCard.php @@ -54,28 +54,38 @@ class UserCard extends \common\models\UserCard { $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(); + if($post['fields']){ + 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(); + } } - 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(); + + 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(); + } } + parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub } } \ No newline at end of file diff --git a/backend/modules/card/models/UserCardSearch.php b/backend/modules/card/models/UserCardSearch.php index e0e7bd2..29a2ebe 100644 --- a/backend/modules/card/models/UserCardSearch.php +++ b/backend/modules/card/models/UserCardSearch.php @@ -57,6 +57,8 @@ class UserCardSearch extends UserCard return $dataProvider; } + $query->where(['deleted_at' => null]); + // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, diff --git a/backend/modules/card/views/user-card/view.php b/backend/modules/card/views/user-card/view.php index 5ae20e3..21944d6 100644 --- a/backend/modules/card/views/user-card/view.php +++ b/backend/modules/card/views/user-card/view.php @@ -53,7 +53,7 @@ $this->params['breadcrumbs'][] = $this->title; 'salary', [ 'attribute' => 'position_id', - 'value' => $model->position->name, + 'value' => (isset($model->position->name)) ? $model->position->name : 'Без должности', ], 'created_at', 'updated_at', diff --git a/backend/modules/settings/controllers/AdditionalFieldsController.php b/backend/modules/settings/controllers/AdditionalFieldsController.php index 7b53832..fa157af 100644 --- a/backend/modules/settings/controllers/AdditionalFieldsController.php +++ b/backend/modules/settings/controllers/AdditionalFieldsController.php @@ -2,6 +2,7 @@ namespace backend\modules\settings\controllers; +use common\models\UseField; use Yii; use backend\modules\settings\models\AdditionalFields; use backend\modules\settings\models\AdditionalFieldsSearch; @@ -109,6 +110,7 @@ class AdditionalFieldsController extends Controller */ public function actionDelete($id) { + UseField::deleteAll(['field_id' => $id]); $this->findModel($id)->delete(); return $this->redirect(['index']); diff --git a/backend/modules/settings/controllers/StatusController.php b/backend/modules/settings/controllers/StatusController.php index fcc9fcb..f2da4c4 100644 --- a/backend/modules/settings/controllers/StatusController.php +++ b/backend/modules/settings/controllers/StatusController.php @@ -2,6 +2,7 @@ namespace backend\modules\settings\controllers; +use common\models\UseStatus; use Yii; use backend\modules\settings\models\Status; use backend\modules\settings\models\StatusSearch; @@ -110,6 +111,7 @@ class StatusController extends Controller */ public function actionDelete($id) { + UseStatus::deleteAll(['status_id' => $id]); $this->findModel($id)->delete(); return $this->redirect(['index']); diff --git a/common/models/UserCard.php b/common/models/UserCard.php index 85997fb..cfe477a 100644 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -19,6 +19,7 @@ use yii\db\Expression; * @property int $status * @property string $created_at * @property string $updated_at + * @property string $deleted_at * @property string $resume * @property string $salary * @property int $position_id @@ -59,9 +60,9 @@ class UserCard extends \yii\db\ActiveRecord public function rules() { return [ - [['fio', 'status'], 'required'], + [['fio', 'status', 'gender'], 'required'], [['gender', 'status', 'position_id'], 'integer'], - [['dob', 'created_at', 'updated_at'], 'safe'], + [['dob', 'created_at', 'updated_at', 'deleted_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']], @@ -85,6 +86,7 @@ class UserCard extends \yii\db\ActiveRecord 'status' => 'Статус', 'created_at' => 'Дата создания', 'updated_at' => 'Дата редактирование', + 'deleted_at' => 'Дата удаления', 'resume' => 'Резюме', 'salary' => 'Зарплата', 'position_id' => 'Должность', diff --git a/console/migrations/m181106_082016_add_deleted_at_column_to_user_card_table.php b/console/migrations/m181106_082016_add_deleted_at_column_to_user_card_table.php new file mode 100644 index 0000000..e4746c2 --- /dev/null +++ b/console/migrations/m181106_082016_add_deleted_at_column_to_user_card_table.php @@ -0,0 +1,25 @@ +addColumn('user_card', 'deleted_at', $this->datetime()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('user_card', 'deleted_at'); + } +}