56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Enums\Tickets\TicketStatusEnum;
|
|
use App\Enums\Tickets\TicketTypeEnum;
|
|
use App\Models\Site;
|
|
use App\Models\Ticket;
|
|
use App\Models\User;
|
|
|
|
class AutomaticTicketCreator
|
|
{
|
|
public function __construct(
|
|
private readonly BrevoWebookParser $parser
|
|
) {}
|
|
|
|
public function createTicket(
|
|
Site $forSite,
|
|
User $withProjectManager,
|
|
string $withRawHtmlContent,
|
|
): Ticket {
|
|
|
|
$parsedContent = $this->parser->parseRawHtml($withRawHtmlContent);
|
|
|
|
$textContent = "Bonjour,\n";
|
|
$textContent .= " Contenu :\n\n";
|
|
$textContent .= " {$parsedContent->plainTextContent},\n\n";
|
|
$textContent .= " Cordialement.";
|
|
|
|
$title = "Demande de mail en masse";
|
|
|
|
if (!empty($parsedContent->brand)) {
|
|
$title .= " pour {$parsedContent->brand}";
|
|
}
|
|
|
|
$ticket = new Ticket([
|
|
'site_id' => $forSite->id,
|
|
'type' => TicketTypeEnum::mailing->value,
|
|
'status' => TicketStatusEnum::estimateTodo->value,
|
|
'date_mep' => null,
|
|
'text' => $textContent,
|
|
'title' => $title,
|
|
'is_internal' => false
|
|
]);
|
|
|
|
$ticket->site()->associate($forSite);
|
|
$ticket->user()->associate($withProjectManager);
|
|
$ticket->assignedUser()->associate($withProjectManager);
|
|
|
|
$ticket->saveOrFail();
|
|
|
|
return $ticket;
|
|
}
|
|
}
|