62 lines
2.7 KiB
PHP
62 lines
2.7 KiB
PHP
<?php
|
|
|
|
class WarehouseHistoryController {
|
|
|
|
public function create($postData, $mod) {
|
|
$modelClass = $mod . 'Model';
|
|
$modelClass = new $modelClass();
|
|
$currentData = $modelClass::get($postData['id']);
|
|
$me = new User();
|
|
$me->loadMe();
|
|
|
|
foreach ($postData as $key => $value) {
|
|
if (is_array($value)) {
|
|
$postData[$key] = json_encode($value);
|
|
}
|
|
}
|
|
|
|
foreach (array_diff_assoc($postData, (array) $currentData) as $key => $value) {
|
|
WarehouseHistoryModel::create(['table' => $mod,
|
|
'row_id' => $postData['id'],
|
|
'key' => $key,
|
|
'old_value' => $currentData->$key,
|
|
'new_value' => $value,
|
|
'note' => '',
|
|
'user_id' => $me->id,
|
|
'create' => date('U')]);
|
|
}
|
|
}
|
|
|
|
public function getHistory($id, string $mod, $columns): array {
|
|
$history = WarehouseHistoryModel::getByRowId($id, $mod);
|
|
|
|
|
|
return array_map(function ($item) use ($columns) {
|
|
$item = (array) $item;
|
|
|
|
if (isset($columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['type'])) {
|
|
|
|
if ($columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['type'] === 'checkbox') {
|
|
$item['old_value'] = $item['old_value'] === '1' ? 'Ja' : 'Nein';
|
|
$item['new_value'] = $item['new_value'] === '1' ? 'Ja' : 'Nein';
|
|
}
|
|
|
|
if ($columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['type'] === 'select') {
|
|
$column = $columns[array_search($item['key'], array_column($columns, 'key'))];
|
|
|
|
if (isset($column['modal']['items'][array_search($item['old_value'], array_column($column['modal']['items'], 'value'))]) &&
|
|
isset($column['modal']['items'][array_search($item['new_value'], array_column($column['modal']['items'], 'value'))])) {
|
|
$item['old_value'] = $column['modal']['items'][array_search($item['old_value'], array_column($column['modal']['items'], 'value'))]['text'];
|
|
$item['new_value'] = $column['modal']['items'][array_search($item['new_value'], array_column($column['modal']['items'], 'value'))]['text'];
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
$item['columnHeader'] = $columns[array_search($item['key'], array_column($columns, 'key'))]['text'];
|
|
return $item;
|
|
}, $history);
|
|
}
|
|
|
|
} |