diff --git a/backend/modules/balance/controllers/BalanceController.php b/backend/modules/balance/controllers/BalanceController.php index 56332c7..f0f04d0 100755 --- a/backend/modules/balance/controllers/BalanceController.php +++ b/backend/modules/balance/controllers/BalanceController.php @@ -73,9 +73,17 @@ class BalanceController extends Controller ], ]); + $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), - 'dataProviderF' => $dataProviderF + 'dataProviderF' => $dataProviderF, + 'changeDataProvider' => $changeDataProvider, ]); } diff --git a/backend/modules/balance/models/Balance.php b/backend/modules/balance/models/Balance.php index 98556a8..def26ea 100755 --- a/backend/modules/balance/models/Balance.php +++ b/backend/modules/balance/models/Balance.php @@ -20,5 +20,12 @@ use yii\helpers\ArrayHelper; */ class Balance extends \common\models\Balance { - + public function behaviors() + { + return [ + 'log' => [ + 'class' => \common\behaviors\LogBehavior::class, + ] + ]; + } } \ No newline at end of file diff --git a/backend/modules/balance/views/balance/view.php b/backend/modules/balance/views/balance/view.php index daf144a..5413d98 100755 --- a/backend/modules/balance/views/balance/view.php +++ b/backend/modules/balance/views/balance/view.php @@ -54,4 +54,16 @@ $this->params['breadcrumbs'][] = $this->title; ], ]); ?> +

История изменений

+ + $changeDataProvider, + 'columns' => [ + 'label', + 'old_value', + 'new_value', + 'created_at', + ], + ]); ?> + 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;

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

$modelFildValue, + 'dataProvider' => $modelFieldValue, 'layout' => "{items}", 'columns' => [ 'field.name:text:Поле', @@ -89,4 +90,16 @@ $this->params['breadcrumbs'][] = $this->title; ], ]); ?> +

История изменений

+ + $changeDataProvider, + 'columns' => [ + 'label', + 'old_value', + 'new_value', + 'created_at', + ], + ]); ?> + \ No newline at end of file diff --git a/backend/modules/company/controllers/CompanyController.php b/backend/modules/company/controllers/CompanyController.php index 62587e7..9b56a05 100755 --- a/backend/modules/company/controllers/CompanyController.php +++ b/backend/modules/company/controllers/CompanyController.php @@ -38,6 +38,9 @@ class CompanyController extends Controller ], ], ], + 'log' => [ + 'class' => \common\behaviors\LogBehavior::class, + ] ]; } @@ -72,9 +75,18 @@ class CompanyController extends Controller 'pageSize' => 200, ], ]); + + $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), - 'dataProviderF' => $dataProviderF + 'dataProviderF' => $dataProviderF, + 'changeDataProvider' => $changeDataProvider, ]); } diff --git a/backend/modules/company/models/Company.php b/backend/modules/company/models/Company.php index 19f6d7f..f0a4c52 100755 --- a/backend/modules/company/models/Company.php +++ b/backend/modules/company/models/Company.php @@ -43,6 +43,15 @@ class Company extends \common\models\Company } } + public function behaviors() + { + return [ + 'log' => [ + 'class' => \common\behaviors\LogBehavior::class, + ] + ]; + } + public function afterSave($insert, $changedAttributes) { $post = \Yii::$app->request->post('Company'); diff --git a/backend/modules/company/views/company/view.php b/backend/modules/company/views/company/view.php index df256a4..a96aa83 100755 --- a/backend/modules/company/views/company/view.php +++ b/backend/modules/company/views/company/view.php @@ -50,4 +50,16 @@ $this->params['breadcrumbs'][] = $this->title; ], ]); ?> +

История изменений

+ + $changeDataProvider, + 'columns' => [ + 'label', + 'old_value', + 'new_value', + 'created_at', + ], + ]); ?> + diff --git a/backend/modules/holiday/controllers/HolidayController.php b/backend/modules/holiday/controllers/HolidayController.php index 908a606..4c12df8 100755 --- a/backend/modules/holiday/controllers/HolidayController.php +++ b/backend/modules/holiday/controllers/HolidayController.php @@ -6,6 +6,7 @@ use backend\modules\holiday\models\Holiday; use backend\modules\holiday\models\HolidaySearch; use common\classes\Debug; use Yii; +use yii\data\ActiveDataProvider; use yii\filters\AccessControl; use yii\filters\VerbFilter; use yii\web\Controller; @@ -52,8 +53,16 @@ class HolidayController extends Controller { $model = $this->findModel($id); + $changeDataProvider = new ActiveDataProvider([ + 'query' => \common\models\ChangeHistory::find()->where(['type_id' => $this->findModel($id)->id]), + 'pagination' => [ + 'pageSize' => 200, + ] + ]); + return $this->render('view', [ 'model' => $model, + 'changeDataProvider' => $changeDataProvider, ]); } diff --git a/backend/modules/holiday/models/Holiday.php b/backend/modules/holiday/models/Holiday.php index 4a491d0..f478824 100755 --- a/backend/modules/holiday/models/Holiday.php +++ b/backend/modules/holiday/models/Holiday.php @@ -4,5 +4,12 @@ namespace backend\modules\holiday\models; class Holiday extends \common\models\Holiday { - + public function behaviors() + { + return [ + 'log' => [ + 'class' => \common\behaviors\LogBehavior::class, + ] + ]; + } } \ No newline at end of file diff --git a/backend/modules/holiday/views/holiday/view.php b/backend/modules/holiday/views/holiday/view.php index a79784e..e8833ec 100755 --- a/backend/modules/holiday/views/holiday/view.php +++ b/backend/modules/holiday/views/holiday/view.php @@ -7,7 +7,7 @@ $this->title = 'Отпуск №' . $model->id; $this->params['breadcrumbs'][] = ['label' => 'Список отпусков', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> -
+

'btn btn-primary']) ?> $model->id], ['class' => 'btn btn-primary']) ?> @@ -20,17 +20,28 @@ $this->params['breadcrumbs'][] = $this->title; ]) ?>

- $model, - 'attributes' => [ - [ - 'label' => 'ФИО', - 'value' => function($model) - { - return $model->users->fio; - }, + $model, + 'attributes' => [ + [ + 'label' => 'ФИО', + 'value' => function ($model) { + return $model->users->fio; + }, + ], + 'dt_start', + 'dt_end' ], - 'dt_start', - 'dt_end' - ], -]) ?> \ No newline at end of file + ]) ?> +

История изменений

+ + $changeDataProvider, + 'columns' => [ + 'label', + 'old_value', + 'new_value', + 'created_at', + ], + ]); + ?> diff --git a/backend/modules/notes/controllers/NotesController.php b/backend/modules/notes/controllers/NotesController.php index 74bff12..dcdaf2e 100755 --- a/backend/modules/notes/controllers/NotesController.php +++ b/backend/modules/notes/controllers/NotesController.php @@ -91,9 +91,17 @@ class NotesController extends Controller ], ]); + $changeDataProvider = new ActiveDataProvider([ + 'query' => \common\models\ChangeHistory::find()->where(['type_id' => $this->findModel($id)->id]), + 'pagination' => [ + 'pageSize' => 200, + ] + ]); + return $this->render('view', [ 'model' => Note::findOne($id), - 'additionalDataProvider' => $additionalDataProvider + 'additionalDataProvider' => $additionalDataProvider, + 'changeDataProvider' => $changeDataProvider, ]); } diff --git a/backend/modules/notes/models/Note.php b/backend/modules/notes/models/Note.php index 4dc2258..1e5ce46 100755 --- a/backend/modules/notes/models/Note.php +++ b/backend/modules/notes/models/Note.php @@ -44,6 +44,15 @@ class Note extends \common\models\Note } } + public function behaviors() + { + return [ + 'log' => [ + 'class' => \common\behaviors\LogBehavior::class, + ] + ]; + } + public function afterSave($insert, $changedAttributes) { $post = \Yii::$app->request->post('Note'); diff --git a/backend/modules/notes/views/notes/view.php b/backend/modules/notes/views/notes/view.php index dc27b37..c250b9a 100755 --- a/backend/modules/notes/views/notes/view.php +++ b/backend/modules/notes/views/notes/view.php @@ -52,4 +52,16 @@ $this->params['breadcrumbs'][] = $this->title; ], ]); ?> +

История изменений

+ + $changeDataProvider, + 'columns' => [ + 'label', + 'old_value', + 'new_value', + 'created_at', + ], + ]); ?> +
diff --git a/backend/modules/project/controllers/ProjectController.php b/backend/modules/project/controllers/ProjectController.php index 1cdd5c7..b19086c 100755 --- a/backend/modules/project/controllers/ProjectController.php +++ b/backend/modules/project/controllers/ProjectController.php @@ -98,11 +98,19 @@ class ProjectController extends Controller ], ]); + $changeDataProvider = new ActiveDataProvider([ + 'query' => \common\models\ChangeHistory::find()->where(['type_id' => $this->findModel($id)->id]), + 'pagination' => [ + 'pageSize' => 200, + ] + ]); + return $this->render('view', [ 'model' => $model, 'modelFildValue' => $dataProvider, 'modelUser' => $dataProviderUser, 'jobsProvider' => $jobsProvider, + 'changeDataProvider' => $changeDataProvider, ]); } diff --git a/backend/modules/project/models/Project.php b/backend/modules/project/models/Project.php index 57fc08a..7613189 100755 --- a/backend/modules/project/models/Project.php +++ b/backend/modules/project/models/Project.php @@ -53,6 +53,15 @@ class Project extends \common\models\Project } } + + public function behaviors() + { + return [ + 'log' => [ + 'class' => \common\behaviors\LogBehavior::class, + ] + ]; + } public function afterSave($insert, $changedAttributes) { diff --git a/backend/modules/project/views/project/view.php b/backend/modules/project/views/project/view.php index fbaabb4..8b4676d 100755 --- a/backend/modules/project/views/project/view.php +++ b/backend/modules/project/views/project/view.php @@ -104,4 +104,16 @@ $this->params['breadcrumbs'][] = $this->title; ], ]); ?> + +

История изменений

+ + $changeDataProvider, + 'columns' => [ + 'label', + 'old_value', + 'new_value', + 'created_at', + ], + ]); ?>
diff --git a/backend/web/css/site.css b/backend/web/css/site.css index db97cf9..a909de9 100755 --- a/backend/web/css/site.css +++ b/backend/web/css/site.css @@ -12,7 +12,7 @@ .itemImg, .itemImgs{ float: left !important; display: inline-block; - width: 30%!important; + /*width: 30%!important;*/ } .media__upload_img img{ @@ -28,12 +28,21 @@ flex-direction: column; } -.field-usercard-fields-0-value{ +/*.field-usercard-fields-0-value{*/ +/* display: flex;*/ +/* width: auto;*/ +/*}*/ + +tr td div input{ + width: 100% !important; +} + +.list-cell__value div{ display: flex; width: auto; } -.field-usercard-fields-0-value .itemImg { +input .itemImg{ width: 100% !important; } diff --git a/common/behaviors/LogBehavior.php b/common/behaviors/LogBehavior.php new file mode 100644 index 0000000..6af22ac --- /dev/null +++ b/common/behaviors/LogBehavior.php @@ -0,0 +1,41 @@ + 'beforeUpdate', + ]; + } + + public function beforeUpdate(Event $event) + { + $model = $event->sender; + $dirtyAttributes = $model->getDirtyAttributes(); + + foreach ($dirtyAttributes as $key => $value) + { + if($model->getOldAttribute($key) == $value) + { + continue; + } + $change = new \common\models\ChangeHistory([ + 'type' => get_class($model), + 'type_id' => $model->getAttribute('id'), + 'field_name' => $key, + 'label' => $model->getAttributeLabel($key), + 'old_value' => $model->getOldAttribute($key), + 'new_value' => $value, + 'created_at' => date('Y-m-d-H:i:s', time()), + ]); + $change->save(); + } + } +} \ No newline at end of file diff --git a/common/models/ChangeHistory.php b/common/models/ChangeHistory.php new file mode 100644 index 0000000..88cf463 --- /dev/null +++ b/common/models/ChangeHistory.php @@ -0,0 +1,38 @@ + 'Таблица', + 'row_id' => 'ID строки', + 'field_name' => 'Имя поля', + 'old_value' => 'Старое значение', + 'new_value' => 'Новое значение', + 'label' => 'Поле', + ]; + } + + public function translate() + { + + } + + public function afterFind() + { + parent::afterFind(); // TODO: Change the autogenerated stub + //milliseconds to date + if ($this->field_name == 'dt_start' || $this->field_name == 'dt_end' || $this->field_name == 'dt_add') { + $this->old_value = date('d-m-Y', $this->old_value); + $this->new_value = date('d-m-Y', $this->new_value); + } + } +} \ No newline at end of file diff --git a/console/migrations/m200729_104128_create_change_history_table.php b/console/migrations/m200729_104128_create_change_history_table.php new file mode 100644 index 0000000..1d5dabf --- /dev/null +++ b/console/migrations/m200729_104128_create_change_history_table.php @@ -0,0 +1,40 @@ +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('{{%change_history}}', [ + 'id' => $this->primaryKey(), + 'type' => $this->string(255), + 'type_id' => $this->integer(), + 'field_name' => $this->string(255), + 'label' => $this->string(255), + 'old_value' => $this->string(255), + 'new_value' => $this->string(255), + 'created_at' => $this->dateTime(), + ], $tableOptions); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('{{%change_history}}'); + } +}