feat: add app and database modules

This commit is contained in:
2026-05-21 16:05:11 +07:00
parent 37b7e783f5
commit fad70d096b
212 changed files with 23901 additions and 0 deletions
+87
View File
@@ -0,0 +1,87 @@
<?php
/**
* ============================================================
*
* @project biiproject
*
* @author Andika Debi Putra
*
* @email andikadebiputra@gmail.com
*
* @website https://biiproject.com
*
* @copyright Copyright (c) 2026 Andika Debi Putra
* @license Proprietary - All Rights Reserved
*
* @version 1.0.0
*
* @created 2026-05-01
* ============================================================
*/
namespace App\Events;
use App\Services\System\ActivityFormatter;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Spatie\Activitylog\Models\Activity;
class ActivityLogCreated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $log;
/**
* Create a new event instance.
*/
public function __construct(Activity $activity)
{
// Format the activity for the dashboard table
$this->log = [
'time' => $activity->created_at->diffForHumans(),
'datetime' => $activity->created_at->format('Y-m-d H:i:s'),
'level' => $this->getLevel($activity->description),
'manifest' => ActivityFormatter::getFriendlyModelName($activity->subject_type),
'description' => ucfirst($activity->description),
'causer' => $activity->causer ? $activity->causer->name : 'System',
];
}
private function getLevel(string $description): string
{
if (str_contains($description, 'deleted') || str_contains($description, 'failed')) {
return '<span class="badge text-bg-danger rounded-pill">CRIT</span>';
}
if (str_contains($description, 'updated')) {
return '<span class="badge text-bg-warning rounded-pill">MODI</span>';
}
return '<span class="badge text-bg-success rounded-pill">INFO</span>';
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('admin.monitoring'),
];
}
/**
* The event's broadcast name.
*/
public function broadcastAs(): string
{
return 'activity.created';
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class AiHealingLogCreated
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct()
{
//
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class DashboardStatsUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct(public readonly array $stats) {}
public function broadcastOn(): array
{
return [new PrivateChannel('admin.monitoring')];
}
public function broadcastAs(): string
{
return 'stats.updated';
}
public function broadcastWith(): array
{
return $this->stats;
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class ImpersonationStatusChanged implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct(
public int $userId,
public bool $isImpersonated,
public string $message = ''
) {}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('App.Models.User.'.$this->userId),
];
}
/**
* The event's broadcast name.
*/
public function broadcastAs(): string
{
return 'impersonation.updated';
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace App\Events;
use App\Models\Notification;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class NotificationSent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $notification;
/**
* Create a new event instance.
*/
public function __construct(Notification $notification)
{
$this->notification = $notification;
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, Channel>
*/
public function broadcastOn(): array
{
$recipient = $this->notification->recipient;
// 1. GLOBAL / PUBLIC
if ($recipient === 'all') {
return [new Channel('notifications')];
}
// 2. SPECIFIC USER (ID is numeric)
if (is_numeric($recipient)) {
return [new PrivateChannel('App.Models.User.'.$recipient)];
}
// 3. BY ROLE (Default fallback for strings like 'admin', 'superadmin', 'user', etc.)
return [new PrivateChannel('roles.'.$recipient)];
}
/**
* The event's broadcast name.
*/
public function broadcastAs(): string
{
return 'notification.sent';
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class SettingUpdated
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct()
{
//
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}
+59
View File
@@ -0,0 +1,59 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class SystemNotification implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
public $type;
public $title;
public $data;
/**
* Create a new event instance.
*
* @param string $type (success, error, warning, info)
*/
public function __construct(string $message, string $type = 'info', ?string $title = null)
{
$this->message = $message;
$this->type = $type;
$this->title = $title ?? 'System Notification';
$this->data = [
'message' => $this->message,
'type' => $this->type,
'title' => $this->title,
];
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, Channel>
*/
public function broadcastOn(): array
{
return [
new Channel('system-notifications'),
];
}
/**
* The event's broadcast name.
*/
public function broadcastAs(): string
{
return 'message.sent';
}
}