Files
awo-hamburg-intranet/module/tasks/repo/TaskCategoryChangeLogRepository.php

44 lines
1.1 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
class TaskCategoryChangeLogRepository
{
public function create(
int $categoryId,
string $action,
int $changedBy,
?array $beforeSnapshot,
?array $afterSnapshot,
?array $diff
): int {
return TaskCertDb::insert(
'INSERT INTO task_category_change_log (
category_id,
action,
changed_by,
before_json,
after_json,
diff_json
) VALUES (?, ?, ?, ?, ?, ?)',
'isisss',
[
$categoryId,
$action,
$changedBy,
$this->encodeJsonOrNull($beforeSnapshot),
$this->encodeJsonOrNull($afterSnapshot),
$this->encodeJsonOrNull($diff),
]
);
}
private function encodeJsonOrNull(?array $value): ?string
{
if ($value === null) {
return null;
}
return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
}