complete story 3.5 with qa test
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Consultation;
|
||||
use Carbon\Carbon;
|
||||
use Spatie\IcalendarGenerator\Components\Calendar;
|
||||
use Spatie\IcalendarGenerator\Components\Event;
|
||||
use Spatie\IcalendarGenerator\Enums\ParticipationStatus;
|
||||
|
||||
class CalendarService
|
||||
{
|
||||
/**
|
||||
* Generate an ICS calendar file for a consultation.
|
||||
*/
|
||||
public function generateIcs(Consultation $consultation): string
|
||||
{
|
||||
$consultation->load('user');
|
||||
|
||||
$startDateTime = Carbon::parse($consultation->booking_date)
|
||||
->setTimeFromTimeString($consultation->booking_time);
|
||||
$endDateTime = $startDateTime->copy()->addHour();
|
||||
|
||||
$locale = $consultation->user?->preferred_language ?? 'ar';
|
||||
|
||||
$eventName = $locale === 'ar'
|
||||
? 'استشارة قانونية - مكتب ليبرا للمحاماة'
|
||||
: 'Legal Consultation - Libra Law Firm';
|
||||
|
||||
$description = $this->buildDescription($consultation, $locale);
|
||||
|
||||
$event = Event::create()
|
||||
->name($eventName)
|
||||
->description($description)
|
||||
->uniqueIdentifier("consultation-{$consultation->id}@libra.ps")
|
||||
->createdAt(now())
|
||||
->startsAt($startDateTime)
|
||||
->endsAt($endDateTime)
|
||||
->organizer('info@libra.ps', 'Libra Law Firm');
|
||||
|
||||
if ($consultation->user?->email) {
|
||||
$event->attendee(
|
||||
$consultation->user->email,
|
||||
$consultation->user->full_name,
|
||||
ParticipationStatus::Accepted
|
||||
);
|
||||
}
|
||||
|
||||
$calendar = Calendar::create('Libra Law Firm')
|
||||
->productIdentifier('-//Libra Law Firm//Consultation Booking//EN')
|
||||
->event($event);
|
||||
|
||||
return $calendar->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the event description based on locale.
|
||||
*/
|
||||
private function buildDescription(Consultation $consultation, string $locale): string
|
||||
{
|
||||
if ($locale === 'ar') {
|
||||
$description = "استشارة قانونية مع مكتب ليبرا للمحاماة\n\n";
|
||||
$description .= "العميل: {$consultation->user?->full_name}\n";
|
||||
$description .= 'التاريخ: '.Carbon::parse($consultation->booking_date)->translatedFormat('l, d M Y')."\n";
|
||||
$description .= 'الوقت: '.Carbon::parse($consultation->booking_time)->format('g:i A')."\n";
|
||||
|
||||
if ($consultation->consultation_type?->value === 'paid' && $consultation->payment_amount) {
|
||||
$description .= "المبلغ: {$consultation->payment_amount} شيكل\n";
|
||||
}
|
||||
|
||||
$description .= "\nللتواصل: info@libra.ps";
|
||||
} else {
|
||||
$description = "Legal Consultation with Libra Law Firm\n\n";
|
||||
$description .= "Client: {$consultation->user?->full_name}\n";
|
||||
$description .= 'Date: '.Carbon::parse($consultation->booking_date)->format('l, d M Y')."\n";
|
||||
$description .= 'Time: '.Carbon::parse($consultation->booking_time)->format('g:i A')."\n";
|
||||
|
||||
if ($consultation->consultation_type?->value === 'paid' && $consultation->payment_amount) {
|
||||
$description .= "Amount: {$consultation->payment_amount} ILS\n";
|
||||
}
|
||||
|
||||
$description .= "\nContact: info@libra.ps";
|
||||
}
|
||||
|
||||
return $description;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user