soft delete user

This commit is contained in:
Kavalar 2018-11-06 11:44:27 +03:00
parent 51952e8c0d
commit 0895403f39
8 changed files with 68 additions and 18 deletions

View File

@ -3,12 +3,14 @@
namespace backend\modules\card\controllers; namespace backend\modules\card\controllers;
use common\classes\Debug; use common\classes\Debug;
use common\models\AdditionalFields;
use common\models\CardSkill; use common\models\CardSkill;
use common\models\FieldsValue; use common\models\FieldsValue;
use Yii; use Yii;
use backend\modules\card\models\UserCard; use backend\modules\card\models\UserCard;
use backend\modules\card\models\UserCardSearch; use backend\modules\card\models\UserCardSearch;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use yii\db\Expression;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
@ -119,7 +121,12 @@ class UserCardController extends Controller
*/ */
public function actionDelete($id) 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']); return $this->redirect(['index']);
} }

View File

@ -54,6 +54,9 @@ class UserCard extends \common\models\UserCard
{ {
$post = \Yii::$app->request->post('UserCard'); $post = \Yii::$app->request->post('UserCard');
if($post['fields']){
FieldsValue::deleteAll(['card_id' => $this->id]); FieldsValue::deleteAll(['card_id' => $this->id]);
foreach ( $post['fields'] as $item) { foreach ( $post['fields'] as $item) {
@ -65,7 +68,12 @@ class UserCard extends \common\models\UserCard
$fildsValue->save(); $fildsValue->save();
} }
}
if($post['skill']){
CardSkill::deleteAll(['card_id' => $this->id]); CardSkill::deleteAll(['card_id' => $this->id]);
foreach ( $post['skill'] as $item) { foreach ( $post['skill'] as $item) {
@ -75,6 +83,8 @@ class UserCard extends \common\models\UserCard
$skill->save(); $skill->save();
} }
}
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
} }

View File

@ -57,6 +57,8 @@ class UserCardSearch extends UserCard
return $dataProvider; return $dataProvider;
} }
$query->where(['deleted_at' => null]);
// grid filtering conditions // grid filtering conditions
$query->andFilterWhere([ $query->andFilterWhere([
'id' => $this->id, 'id' => $this->id,

View File

@ -53,7 +53,7 @@ $this->params['breadcrumbs'][] = $this->title;
'salary', 'salary',
[ [
'attribute' => 'position_id', 'attribute' => 'position_id',
'value' => $model->position->name, 'value' => (isset($model->position->name)) ? $model->position->name : 'Без должности',
], ],
'created_at', 'created_at',
'updated_at', 'updated_at',

View File

@ -2,6 +2,7 @@
namespace backend\modules\settings\controllers; namespace backend\modules\settings\controllers;
use common\models\UseField;
use Yii; use Yii;
use backend\modules\settings\models\AdditionalFields; use backend\modules\settings\models\AdditionalFields;
use backend\modules\settings\models\AdditionalFieldsSearch; use backend\modules\settings\models\AdditionalFieldsSearch;
@ -109,6 +110,7 @@ class AdditionalFieldsController extends Controller
*/ */
public function actionDelete($id) public function actionDelete($id)
{ {
UseField::deleteAll(['field_id' => $id]);
$this->findModel($id)->delete(); $this->findModel($id)->delete();
return $this->redirect(['index']); return $this->redirect(['index']);

View File

@ -2,6 +2,7 @@
namespace backend\modules\settings\controllers; namespace backend\modules\settings\controllers;
use common\models\UseStatus;
use Yii; use Yii;
use backend\modules\settings\models\Status; use backend\modules\settings\models\Status;
use backend\modules\settings\models\StatusSearch; use backend\modules\settings\models\StatusSearch;
@ -110,6 +111,7 @@ class StatusController extends Controller
*/ */
public function actionDelete($id) public function actionDelete($id)
{ {
UseStatus::deleteAll(['status_id' => $id]);
$this->findModel($id)->delete(); $this->findModel($id)->delete();
return $this->redirect(['index']); return $this->redirect(['index']);

View File

@ -19,6 +19,7 @@ use yii\db\Expression;
* @property int $status * @property int $status
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
* @property string $deleted_at
* @property string $resume * @property string $resume
* @property string $salary * @property string $salary
* @property int $position_id * @property int $position_id
@ -59,9 +60,9 @@ class UserCard extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['fio', 'status'], 'required'], [['fio', 'status', 'gender'], 'required'],
[['gender', 'status', 'position_id'], 'integer'], [['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], [['fio', 'passport', 'photo', 'email', 'resume'], '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']],
@ -85,6 +86,7 @@ class UserCard extends \yii\db\ActiveRecord
'status' => 'Статус', 'status' => 'Статус',
'created_at' => 'Дата создания', 'created_at' => 'Дата создания',
'updated_at' => 'Дата редактирование', 'updated_at' => 'Дата редактирование',
'deleted_at' => 'Дата удаления',
'resume' => 'Резюме', 'resume' => 'Резюме',
'salary' => 'Зарплата', 'salary' => 'Зарплата',
'position_id' => 'Должность', 'position_id' => 'Должность',

View File

@ -0,0 +1,25 @@
<?php
use yii\db\Migration;
/**
* Handles adding deleted_at to table `user_card`.
*/
class m181106_082016_add_deleted_at_column_to_user_card_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('user_card', 'deleted_at', $this->datetime());
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('user_card', 'deleted_at');
}
}