This commit is contained in:
glambertessa 2020-09-09 14:58:06 +03:00
commit b919aa0367
22 changed files with 360 additions and 55 deletions

View File

@ -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,
]);
}

View File

@ -20,5 +20,12 @@ use yii\helpers\ArrayHelper;
*/
class Balance extends \common\models\Balance
{
public function behaviors()
{
return [
'log' => [
'class' => \common\behaviors\LogBehavior::class,
]
];
}
}

View File

@ -54,4 +54,16 @@ $this->params['breadcrumbs'][] = $this->title;
],
]); ?>
<h2>История изменений</h2>
<?= GridView::widget([
'dataProvider' => $changeDataProvider,
'columns' => [
'label',
'old_value',
'new_value',
'created_at',
],
]); ?>
</div>

View File

@ -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,
]);
}

View File

@ -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,17 +65,29 @@ class UserCard extends \common\models\UserCard
}
}
public function behaviors()
{
return [
'log' => [
'class' => \common\behaviors\LogBehavior::class,
]
];
}
public function beforeSave($insert)
{
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['fields']) {
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']);
@ -85,19 +98,18 @@ class UserCard extends \common\models\UserCard
$fieldsValue->order = $item['order'];
$fieldsValue->item_id = $this->id;
$fieldsValue->item_type = FieldsValueNew::TYPE_PROFILE;
if(is_file(Yii::getAlias('@frontend') . '/web/' . $item['value'])){
if (is_file(Yii::getAlias('@frontend') . '/web/' . $item['value'])) {
$fieldsValue->type_file = 'file';
}else{
} else {
$fieldsValue->type_file = 'text';
}
$fieldsValue->save();
}
}
if ($post['skill']) {
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;
@ -106,10 +118,9 @@ class UserCard extends \common\models\UserCard
$skill->save();
}
}
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
}
}
public static function getParameter($params, $key)
{

View File

@ -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;
<h2>Дополнительные сведения</h2>
<?= GridView::widget([
'dataProvider' => $modelFildValue,
'dataProvider' => $modelFieldValue,
'layout' => "{items}",
'columns' => [
'field.name:text:Поле',
@ -89,4 +90,16 @@ $this->params['breadcrumbs'][] = $this->title;
],
]); ?>
<h2>История изменений</h2>
<?= GridView::widget([
'dataProvider' => $changeDataProvider,
'columns' => [
'label',
'old_value',
'new_value',
'created_at',
],
]); ?>
</div>

View File

@ -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,
]);
}

View File

@ -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');

View File

@ -50,4 +50,16 @@ $this->params['breadcrumbs'][] = $this->title;
],
]); ?>
<h2>История изменений</h2>
<?= GridView::widget([
'dataProvider' => $changeDataProvider,
'columns' => [
'label',
'old_value',
'new_value',
'created_at',
],
]); ?>
</div>

View File

@ -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,
]);
}

View File

@ -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,
]
];
}
}

View File

@ -7,7 +7,7 @@ $this->title = 'Отпуск №' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Список отпусков', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="balance-view">
<div class="balance-view">
<p>
<?= 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;
]) ?>
</p>
<?= DetailView::widget([
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'label' => 'ФИО',
'value' => function($model)
{
'value' => function ($model) {
return $model->users->fio;
},
],
'dt_start',
'dt_end'
],
]) ?>
]) ?>
<h2>История изменений</h2>
<?= \yii\grid\GridView::widget([
'dataProvider' => $changeDataProvider,
'columns' => [
'label',
'old_value',
'new_value',
'created_at',
],
]);
?>

View File

@ -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,
]);
}

View File

@ -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');

View File

@ -52,4 +52,16 @@ $this->params['breadcrumbs'][] = $this->title;
],
]); ?>
<h2>История изменений</h2>
<?= GridView::widget([
'dataProvider' => $changeDataProvider,
'columns' => [
'label',
'old_value',
'new_value',
'created_at',
],
]); ?>
</div>

View File

@ -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,
]);
}

View File

@ -54,6 +54,15 @@ class Project extends \common\models\Project
}
}
public function behaviors()
{
return [
'log' => [
'class' => \common\behaviors\LogBehavior::class,
]
];
}
public function afterSave($insert, $changedAttributes)
{
$post = \Yii::$app->request->post('Project');

View File

@ -104,4 +104,16 @@ $this->params['breadcrumbs'][] = $this->title;
],
]); ?>
<?php endif; ?>
<h2>История изменений</h2>
<?= GridView::widget([
'dataProvider' => $changeDataProvider,
'columns' => [
'label',
'old_value',
'new_value',
'created_at',
],
]); ?>
</div>

View File

@ -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;
}

View File

@ -0,0 +1,41 @@
<?php
namespace Common\Behaviors;
use yii\base\Event;
use yii\db\ActiveRecord;
use yii\base\Behavior;
class LogBehavior extends Behavior
{
public function events()
{
return[
ActiveRecord::EVENT_BEFORE_UPDATE => '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();
}
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace common\Models;
class ChangeHistory extends \yii\db\ActiveRecord
{
public static function tableName()
{
return 'change_history';
}
public function attributeLabels()
{
return [
'table' => 'Таблица',
'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);
}
}
}

View File

@ -0,0 +1,40 @@
<?php
use yii\db\Migration;
/**
* Handles the creation of table `{{%change_history}}`.
*/
class m200729_104128_create_change_history_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$tableOptions = null;
if ($this->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}}');
}
}