25 lines
704 B
PHP
25 lines
704 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\User;
|
|
use App\Services\InsForge\InsForgeClient;
|
|
|
|
class ActivityLogger
|
|
{
|
|
public function __construct(private readonly InsForgeClient $client) {}
|
|
|
|
public function log(string $action, string $entityType, ?string $entityId, string $description, ?User $actor = null): void
|
|
{
|
|
$entry = array_filter([
|
|
'user_id' => $actor?->id,
|
|
'action' => $action,
|
|
'entity_type' => $entityType,
|
|
'entity_id' => $entityId,
|
|
'description' => $description,
|
|
], fn ($value) => $value !== null && $value !== '');
|
|
|
|
$this->client->insertRecord('activity_logs', [$entry], asUser: false);
|
|
}
|
|
}
|