62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Notifications;
|
|
|
|
use App\Models\Project;
|
|
use App\Models\Ticket;
|
|
use App\Models\TicketStatus;
|
|
use App\Models\User;
|
|
use Carbon\CarbonImmutable;
|
|
|
|
class BuildTicketAssigneeChangedPayload
|
|
{
|
|
public function handle(
|
|
Project $project,
|
|
Ticket $ticket,
|
|
?User $actor,
|
|
?int $fromAssigneeId,
|
|
?string $fromAssigneeName,
|
|
?int $toAssigneeId,
|
|
?string $toAssigneeName,
|
|
CarbonImmutable $occurredAt,
|
|
): TicketAssigneeChangedPayload {
|
|
$ticket->loadMissing('ticketStatus.boardColumn');
|
|
|
|
return new TicketAssigneeChangedPayload(
|
|
projectId: $project->id,
|
|
projectKey: $project->key,
|
|
projectName: $project->name,
|
|
ticketId: $ticket->id,
|
|
ticketKey: $ticket->ticket_key,
|
|
ticketTitle: $ticket->title,
|
|
ticketUrl: route('projects.tickets.show', [$project, $ticket]),
|
|
actorId: $actor?->id,
|
|
actorName: $actor?->name,
|
|
fromStatusId: null,
|
|
fromStatusLabel: null,
|
|
toStatusId: $ticket->ticket_status_id,
|
|
toStatusLabel: $this->statusLabel($ticket->ticketStatus),
|
|
occurredAt: $occurredAt,
|
|
fromAssigneeId: $fromAssigneeId,
|
|
fromAssigneeName: $fromAssigneeName,
|
|
toAssigneeId: $toAssigneeId,
|
|
toAssigneeName: $toAssigneeName,
|
|
);
|
|
}
|
|
|
|
private function statusLabel(?TicketStatus $ticketStatus): string
|
|
{
|
|
if ($ticketStatus === null) {
|
|
return 'Unknown status';
|
|
}
|
|
|
|
$ticketStatus->loadMissing('boardColumn');
|
|
|
|
if ($ticketStatus->boardColumn === null || $ticketStatus->boardColumn->name === $ticketStatus->name) {
|
|
return $ticketStatus->name;
|
|
}
|
|
|
|
return "{$ticketStatus->boardColumn->name} / {$ticketStatus->name}";
|
|
}
|
|
}
|