From 6aff5567c4bf2d28987331660e50a22b3fc60a89 Mon Sep 17 00:00:00 2001 From: vladrigos Date: Thu, 6 Aug 2020 13:19:20 +0300 Subject: [PATCH] add history of changes to all entitys --- .../balance/controllers/BalanceController.php | 10 ++++- backend/modules/balance/models/Balance.php | 9 ++++- .../modules/balance/views/balance/view.php | 12 ++++++ .../company/controllers/CompanyController.php | 14 ++++++- backend/modules/company/models/Company.php | 9 +++++ .../modules/company/views/company/view.php | 12 ++++++ .../holiday/controllers/HolidayController.php | 9 +++++ backend/modules/holiday/models/Holiday.php | 9 ++++- .../modules/holiday/views/holiday/view.php | 39 ++++++++++++------- .../notes/controllers/NotesController.php | 10 ++++- backend/modules/notes/models/Note.php | 9 +++++ backend/modules/notes/views/notes/view.php | 12 ++++++ .../project/controllers/ProjectController.php | 8 ++++ backend/modules/project/models/Project.php | 9 +++++ .../modules/project/views/project/view.php | 12 ++++++ common/models/ChangeHistory.php | 10 +++++ 16 files changed, 174 insertions(+), 19 deletions(-) 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/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/common/models/ChangeHistory.php b/common/models/ChangeHistory.php index 1c9c96e..88cf463 100644 --- a/common/models/ChangeHistory.php +++ b/common/models/ChangeHistory.php @@ -25,4 +25,14 @@ class ChangeHistory extends \yii\db\ActiveRecord { } + + 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