Initial commit

This commit is contained in:
root
2026-05-09 17:28:23 +02:00
commit 9d73f82529
5575 changed files with 281989 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class StaffActivity extends Model
{
protected $table = 'staff_activities';
protected $fillable = [
'user_id',
'action',
'target_type',
'target_id',
'description',
'ip_address',
'metadata',
];
protected $casts = [
'metadata' => 'array',
'created_at' => 'datetime',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public static function log(int $userId, string $action, string $description, ?string $targetType = null, ?int $targetId = null, array $metadata = []): self
{
return static::create([
'user_id' => $userId,
'action' => $action,
'target_type' => $targetType,
'target_id' => $targetId,
'description' => $description,
'ip_address' => request()->ip() ?? 'unknown',
'metadata' => $metadata,
]);
}
public static function logLogin(int $userId): self
{
return self::log($userId, 'login', 'Staff logged into housekeeping', null, null, [
'browser' => request()->userAgent() ?? 'unknown',
]);
}
public static function logAction(int $userId, string $action, string $targetType, int $targetId, string $description): self
{
return self::log($userId, $action, $description, $targetType, $targetId);
}
public static function getActionIcon(string $action): string
{
return match ($action) {
'login' => '🔓',
'logout' => '🔒',
'user_ban' => '🚫',
'user_unban' => '✅',
'user_edit' => '✏️',
'user_delete' => '🗑️',
'rank_change' => '⬆️',
'settings_update' => '⚙️',
'content_delete' => '🗑️',
'content_create' => '',
'content_edit' => '✏️',
default => '📝',
};
}
public static function getActionColor(string $action): string
{
return match ($action) {
'login', 'logout' => '#22c55e',
'user_ban', 'content_delete' => '#ef4444',
'user_unban', 'content_create' => '#22c55e',
'user_edit', 'content_edit', 'rank_change' => '#f59e0b',
'settings_update' => '#3b82f6',
default => '#9ca3af',
};
}
}