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;
],
]); ?>
+
+
= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?>
= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
@@ -20,17 +20,28 @@ $this->params['breadcrumbs'][] = $this->title;
]) ?>
-= DetailView::widget([
- 'model' => $model,
- 'attributes' => [
- [
- 'label' => 'ФИО',
- 'value' => function($model)
- {
- return $model->users->fio;
- },
+ = DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ [
+ 'label' => 'ФИО',
+ 'value' => function ($model) {
+ return $model->users->fio;
+ },
+ ],
+ 'dt_start',
+ 'dt_end'
],
- 'dt_start',
- 'dt_end'
- ],
-]) ?>
\ No newline at end of file
+ ]) ?>
+
История изменений
+
+ = \yii\grid\GridView::widget([
+ 'dataProvider' => $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;
],
]); ?>
+
История изменений
+
+ = GridView::widget([
+ 'dataProvider' => $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;
],
]); ?>
+
+
История изменений
+
+ = GridView::widget([
+ 'dataProvider' => $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}}');
+ }
+}