fix parent, teacher and admin pages
This commit is contained in:
@@ -3,11 +3,16 @@
|
||||
namespace App\Services\Settings\SchoolCalendar;
|
||||
|
||||
use App\Models\CalendarEvent;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonInterface;
|
||||
|
||||
class SchoolCalendarFormatterService
|
||||
{
|
||||
public function formatEvent(CalendarEvent|array $event, ?string $audience = null): array
|
||||
{
|
||||
$eventDate = $event instanceof CalendarEvent
|
||||
? $this->extractDateValue($event)
|
||||
: $this->normalizeDateValue($event['date'] ?? null);
|
||||
$event = $event instanceof CalendarEvent ? $event->toArray() : $event;
|
||||
$audience = $audience !== null ? strtolower(trim($audience)) : null;
|
||||
|
||||
@@ -36,8 +41,9 @@ class SchoolCalendarFormatterService
|
||||
return [
|
||||
'id' => (int) ($event['id'] ?? 0),
|
||||
'title' => $title,
|
||||
'start' => (string) ($event['date'] ?? ''),
|
||||
'start' => $eventDate,
|
||||
'description' => (string) ($event['description'] ?? ''),
|
||||
'backgroundColor' => $backgroundColor,
|
||||
'extendedProps' => [
|
||||
'semester' => (string) ($event['semester'] ?? ''),
|
||||
'school_year' => (string) ($event['school_year'] ?? ''),
|
||||
@@ -51,6 +57,43 @@ class SchoolCalendarFormatterService
|
||||
];
|
||||
}
|
||||
|
||||
private function extractDateValue(CalendarEvent $event): string
|
||||
{
|
||||
$raw = $event->getRawOriginal('date');
|
||||
if (is_string($raw) && trim($raw) !== '') {
|
||||
return $this->normalizeDateValue($raw);
|
||||
}
|
||||
|
||||
$value = $event->getAttribute('date');
|
||||
if ($value instanceof CarbonInterface) {
|
||||
return $value->toDateString();
|
||||
}
|
||||
|
||||
return $this->normalizeDateValue($value);
|
||||
}
|
||||
|
||||
private function normalizeDateValue(mixed $value): string
|
||||
{
|
||||
if ($value instanceof CarbonInterface) {
|
||||
return $value->toDateString();
|
||||
}
|
||||
|
||||
$value = trim((string) $value);
|
||||
if ($value === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}/', $value, $matches) === 1) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
try {
|
||||
return Carbon::parse($value)->toDateString();
|
||||
} catch (\Throwable) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function formatMeetingEvent(array $row, ?string $audience = null): array
|
||||
{
|
||||
$audience = $audience !== null ? strtolower(trim($audience)) : null;
|
||||
@@ -83,6 +126,7 @@ class SchoolCalendarFormatterService
|
||||
'title' => $title,
|
||||
'start' => $start,
|
||||
'description' => implode("\n", $descParts),
|
||||
'backgroundColor' => '#6f42c1',
|
||||
'extendedProps' => [
|
||||
'semester' => (string) ($row['semester'] ?? ''),
|
||||
'school_year' => (string) ($row['school_year'] ?? ''),
|
||||
|
||||
Reference in New Issue
Block a user