|
|
@@ -0,0 +1,59 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Livewire;
|
|
|
+
|
|
|
+use Livewire\Component;
|
|
|
+
|
|
|
+class CalendarRemove extends Component
|
|
|
+{
|
|
|
+ public $records;
|
|
|
+
|
|
|
+ public function render()
|
|
|
+ {
|
|
|
+
|
|
|
+ $this->records = [];
|
|
|
+
|
|
|
+ $calendars = \App\Models\Calendar::orderBy('from')->get();
|
|
|
+ foreach($calendars as $calendar)
|
|
|
+ {
|
|
|
+ $days = ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'];
|
|
|
+ $dow = date('w', strtotime($calendar->from));
|
|
|
+ $d = $days[$dow];
|
|
|
+
|
|
|
+ $h = date('H:i', strtotime($calendar->from));
|
|
|
+
|
|
|
+ // Elenco corsi per tipologia in base al calendario
|
|
|
+ $courses = \App\Models\Course::where('name', $calendar->name)->where('date_from', '<=', $calendar->from)->where('date_to', '>=', $calendar->to)->pluck('id')->toArray();
|
|
|
+
|
|
|
+ $months = date("n", strtotime($calendar->from));
|
|
|
+
|
|
|
+ $members_count = \App\Models\MemberCourse::query()
|
|
|
+ ->whereRaw("JSON_CONTAINS(`when`, JSON_OBJECT('day', JSON_ARRAY(?), 'from', ?), '$')", [$d, $h])
|
|
|
+ ->whereRaw("JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED)), '$')", [$months])
|
|
|
+ ->whereRaw("NOT JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED), 'status', 2), '$')", [$months])
|
|
|
+ ->whereRaw("NOT JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED), 'status', '2'), '$')", [$months])
|
|
|
+ ->whereIn('course_id', $courses)
|
|
|
+ ->count();
|
|
|
+
|
|
|
+ if ($members_count == 0)
|
|
|
+ {
|
|
|
+ $this->records[] = array('id' => $calendar->id, 'date' => date("d/m/Y", strtotime($calendar->from)), "name" => $calendar->name, "hour" => date("H:i", strtotime($calendar->from)));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return view('livewire.calendar_remove');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function removeSelected($ids)
|
|
|
+ {
|
|
|
+
|
|
|
+ foreach($ids as $id)
|
|
|
+ {
|
|
|
+ \App\Models\Calendar::findOrFail($id)->delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|