Browse Source

calendar - calendar_name ora è il nome della disciplina (prima corso)

ferrari 1 month ago
parent
commit
1063c8bbcb

+ 1 - 1
app/Http/Livewire/Calendar.php

@@ -79,7 +79,7 @@ class Calendar extends Component
         foreach($calendars as $c)
         {
             $s = $c->motivation ? $c->motivation->name : '';
-            $data = array('id' => $c->id, 'title' => ($c->course ? $c->course->name : $c->name) . ($c->status == 99 ? ' (annullata - ' . $s . ')' : ''), 'start' => $c->from, 'end' => $c->to);
+            $data = array('id' => $c->id, 'title' => ($c->course ? ($c->course->discipline->name ?? $c->course->name) : $c->name) . ($c->status == 99 ? ' (annullata - ' . $s . ')' : ''), 'start' => $c->from, 'end' => $c->to);
             // if ($c->course && $c->course->color != '')
             //     $data['color'] = $c->course->color;
             if (isset($this->course_colors[$c->name]))

+ 3 - 2
app/Http/Livewire/Course.php

@@ -278,6 +278,7 @@ class Course extends Component
                 $mTo = getMonthName(date("n", strtotime($this->date_to)));
 
                 $course_name = $course->name;
+                $discipline_name = $course->discipline?->name ?? $course_name;
 
                 // creo il calendario
                 $from = date("Y-m-d", strtotime($this->date_from));
@@ -327,7 +328,7 @@ class Course extends Component
                             {
 
                                 // Controllo che non esiste un corso così
-                                $exist = \App\Models\Calendar::where('from', date('Y-m-d ' . $d["from"] . ":00", $i))->where('to', date('Y-m-d ' . $d["to"] . ":00", $i))->where('name', $course_name)->first();
+                                $exist = \App\Models\Calendar::where('from', date('Y-m-d ' . $d["from"] . ":00", $i))->where('to', date('Y-m-d ' . $d["to"] . ":00", $i))->where('name', $discipline_name)->first();
 
                                 if (!$exist && !in_array(date('Y-m-d', $i), $this->festivita))
                                 {
@@ -336,7 +337,7 @@ class Course extends Component
                                     $calendar = new \App\Models\Calendar();
                                     $calendar->course_id = $course->id;
                                     $calendar->court_id = null;
-                                    $calendar->name = $course_name;
+                                    $calendar->name = $discipline_name;
                                     $calendar->course_type_id = null;
                                     $calendar->course_duration_id = null;
                                     $calendar->course_frequency_id = null;

+ 8 - 1
app/Http/Livewire/Presence.php

@@ -255,8 +255,15 @@ class Presence extends Component
             $h = date('H:i', strtotime($this->calendar->from));
 
             // Elenco corsi per tipologia in base al calendario
-            $courses = \App\Models\Course::query()
+            $discipline = \App\Models\Discipline::query()
                 ->where('name', $this->calendar->name)
+                ->pluck('id')
+                ->all();
+            $courses = \App\Models\Course::query()
+                ->where(function($q) use($discipline){
+                    $q->where('name', $this->calendar->name)
+                    ->orWhereIn('discipline_id', $discipline);
+                })
                 ->where('date_from', '<=', $this->calendar->from)
                 ->where('date_to', '>=', $this->calendar->to)
                 ->get(['id', 'when']);

+ 8 - 1
app/Http/Livewire/PresenceReport.php

@@ -120,8 +120,15 @@ class PresenceReport extends Component
             $dow = (int) Carbon::parse($calendar->from)->format('w'); // 0..6
             $d = $days[$dow];
 
-            $courseIds = \App\Models\Course::query()
+            $discipline = \App\Models\Discipline::query()
                 ->where('name', $calendar->name)
+                ->pluck('id')
+                ->all();
+            $courseIds = \App\Models\Course::query()
+                ->where(function($q) use($discipline, $calendar){
+                    $q->where('name', $calendar->name)
+                    ->orWhereIn('discipline_id', $discipline);
+                })
                 ->where('date_from', '<=', $calendar->from)
                 ->where('date_to', '>=', $calendar->to)
                 ->when(!empty($this->course_name), fn($q) => $q->where('name', $this->course_name))

+ 2 - 1
resources/views/livewire/course_member.blade.php

@@ -14,6 +14,7 @@
 
     @if ($course)
     @php
+        $courseDiscipline = $course->discipline?->name ?? '';
         $courseName = $course->name ?? 'Corso Sconosciuto';
         $levelName = is_object($course->level) ? $course->level->name : '';
         $frequencyName = is_object($course->frequency) ? $course->frequency->name : '';
@@ -24,7 +25,7 @@
 
         $courseInfo = implode(' - ', $courseInfoParts);
     @endphp
-        <h3>{{$courseName}}</h3>
+        <h3>@if($courseDiscipline){{$courseDiscipline}} - @endif{{$courseName}}</h3>
         <p>{{$courseInfo}}</p>
     @endif