Presence.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. use App\Http\Middleware\TenantMiddleware;
  5. class Presence extends Component
  6. {
  7. public $calendar;
  8. public $records;
  9. public $member_ids = [];
  10. public $court_id, $instructor_id, $motivation_id, $motivation_manual_id, $note, $manual;
  11. public $save_court_id, $save_instructor_id, $save_notes;
  12. public $newMemberFirstName, $newMemberLastName, $newMemberEmail, $newMemberToComplete, $newMemberFiscalCode, $newMemberFiscalCodeExist, $newMemberMotivationId;
  13. public $userName, $userEmail;
  14. public $added = false;
  15. public $filter = '';
  16. public $courts = [];
  17. public $instructors = [];
  18. public $motivations = [];
  19. public $motivations_add = [];
  20. public $insertUser = 'exist';
  21. public $course_limit;
  22. public $motivation_course_id = null;
  23. public $motivation_course_name = 0;
  24. public $motivation_course_level = 0;
  25. public $motivation_course_frequency = 0;
  26. public $course_names = [];
  27. public $course_levels = [];
  28. public $course_frequencies = [];
  29. public $members = [];
  30. public $newMembers = [];
  31. public $ids = [];
  32. public function boot()
  33. {
  34. app(TenantMiddleware::class)->setupTenantConnection();
  35. }
  36. public function mount()
  37. {
  38. setlocale(LC_ALL, 'it_IT');
  39. $this->calendar = \App\Models\Calendar::findOrFail($_GET["calendarId"]);
  40. $this->court_id = $this->calendar->court_id;
  41. $this->instructor_id = $this->calendar->instructor_id;
  42. $this->motivation_manual_id = $this->calendar->motivation_manual_id;
  43. $this->manual = $this->calendar->manual;
  44. $this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])
  45. ->where(function ($query) {
  46. $query->where('is_archived', false)
  47. ->orWhereNull('is_archived');
  48. })
  49. ->where(function ($query) {
  50. $query->where('is_deleted', false)
  51. ->orWhereNull('is_deleted');
  52. })->orderBy('last_name')->orderBy('first_name')->get();
  53. $this->note = $this->calendar->note;
  54. $this->courts = \App\Models\Court::select('*')->where('enabled', true)->get();
  55. $this->instructors = \App\Models\User::select('*')->where('level', 2)->where('enabled', true)->orderBy('name', 'asc')->get();
  56. $this->motivations = \App\Models\Motivation::select('*')->where('enabled', true)->where('type', 'del')->get();
  57. $this->motivations_add = \App\Models\Motivation::select('*')->where('enabled', true)->where('type', 'add')->get();
  58. $this->save_court_id = 0;
  59. $this->save_instructor_id = 0;
  60. $this->save_notes = '';
  61. $this->insertUser = 'exist';
  62. $this->course_limit = now()->endOfDay();
  63. $this->course_names = \App\Models\Course::whereDate('date_from', '<=', $this->course_limit)->whereDate('date_to', '>=', $this->course_limit)->where('active', true)->where('enabled', true)->orderBy('name')->groupBy('name')->pluck('name');
  64. $this->course_levels = [];
  65. $this->course_frequencies = [];
  66. }
  67. function updatedMotivationCourseName()
  68. {
  69. if ($this->motivation_course_name > 0 && $this->motivation_course_name != '') {
  70. $this->motivation_course_id = null;
  71. $this->motivation_course_level = 0;
  72. $this->motivation_course_frequency = 0;
  73. $levels_ids = [];
  74. $levels = \App\Models\Course::whereDate('date_from', '<=', $this->course_limit)->whereDate('date_to', '>=', $this->course_limit)->where('active', true)->where('enabled', true)->where('name', $this->motivation_course_name)->get();
  75. foreach ($levels as $l) {
  76. $levels_ids[] = $l->course_level_id;
  77. }
  78. $this->course_levels = \App\Models\CourseLevel::where('enabled', true)->whereIn('id', $levels_ids)->orderBy('name')->get();
  79. $this->course_frequencies = [];
  80. } else {
  81. $this->course_levels = [];
  82. $this->course_frequencies = [];
  83. }
  84. }
  85. function updatedMotivationCourseLevel()
  86. {
  87. if ($this->motivation_course_name > 0 && $this->motivation_course_name != '' && $this->motivation_course_level > 0 && $this->motivation_course_level != '') {
  88. $this->motivation_course_id = null;
  89. $this->motivation_course_frequency = 0;
  90. $frequency_ids = [];
  91. $frequencies = \App\Models\Course::whereDate('date_from', '<=', $this->course_limit)->whereDate('date_to', '>=', $this->course_limit)->where('active', true)->where('enabled', true)->where('name', $this->motivation_course_name)->where('course_level_id', $this->motivation_course_level)->get();
  92. foreach ($frequencies as $f) {
  93. $frequency_ids[] = $f->course_frequency_id;
  94. }
  95. $this->course_frequencies = \App\Models\CourseFrequency::where('enabled', true)->whereIn('id', $frequency_ids)->orderBy('name')->get();
  96. } else {
  97. $this->course_frequencies = [];
  98. }
  99. }
  100. function updatedMotivationCourseFrequency()
  101. {
  102. if ($this->motivation_course_name > 0 && $this->motivation_course_name != '' && $this->motivation_course_level > 0 && $this->motivation_course_level != '' && $this->motivation_course_frequency > 0 && $this->motivation_course_frequency != '') {
  103. $this->motivation_course_id = null;
  104. $course = \App\Models\Course::whereDate('date_from', '<=', $this->course_limit)->whereDate('date_to', '>=', $this->course_limit)->where('active', true)->where('enabled', true)->where('name', $this->motivation_course_name)->where('course_level_id', $this->motivation_course_level)->where('course_frequency_id', $this->motivation_course_frequency)->first();
  105. $this->motivation_course_id = $course->id;
  106. } else {
  107. $this->motivation_course_id = null;
  108. }
  109. }
  110. public function updatedNewMemberMotivationId()
  111. {
  112. $this->emit('reload');
  113. }
  114. public function render()
  115. {
  116. $this->records = [];
  117. setlocale(LC_ALL, 'it_IT');
  118. $presenceMembers = [];
  119. if (!$this->manual) {
  120. // Carco tutti gli iscritti a un corso padre in quel giorno con un range orario simile
  121. $days = ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'];
  122. $dow = date('w', strtotime($this->calendar->from));
  123. $d = $days[$dow];
  124. $h = date('H:i', strtotime($this->calendar->from));
  125. // Elenco corsi per tipologia in base al calendario
  126. $courses = \App\Models\Course::query()
  127. ->where('name', $this->calendar->name)
  128. ->where('date_from', '<=', $this->calendar->from)
  129. ->where('date_to', '>=', $this->calendar->to)
  130. ->get(['id', 'when']);
  131. $slotCourseIds = $courses
  132. ->filter(fn($c) => $this->courseMatchesSlot($c->when, $d, $h))
  133. ->pluck('id')
  134. ->all();
  135. if (empty($slotCourseIds)) {
  136. $members_courses = [];
  137. } else {
  138. $members_courses = \App\Models\MemberCourse::query()
  139. ->whereIn('course_id', $slotCourseIds)
  140. ->whereDate('date_from', '<=', $this->calendar->from)
  141. ->whereDate('date_to', '>=', $this->calendar->from)
  142. ->pluck('member_id')
  143. ->toArray();
  144. }
  145. if ($this->filter != '') {
  146. $filter = $this->filter;
  147. $members = \App\Models\Member::whereIn('id', $members_courses)->where(function ($query) use ($filter) {
  148. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $filter . "%'")
  149. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $filter . "%'");
  150. })
  151. ->where(function ($query) {
  152. $query->where('is_archived', false)
  153. ->orWhereNull('is_archived');
  154. })
  155. ->where(function ($query) {
  156. $query->where('is_deleted', false)
  157. ->orWhereNull('is_deleted');
  158. })->orderBy('last_name')->orderBy('first_name')->get();
  159. } else
  160. $members = \App\Models\Member::whereIn('id', $members_courses)
  161. ->where(function ($query) {
  162. $query->where('is_archived', false)
  163. ->orWhereNull('is_archived');
  164. })
  165. ->where(function ($query) {
  166. $query->where('is_deleted', false)
  167. ->orWhereNull('is_deleted');
  168. })->orderBy('last_name')->orderBy('first_name')->get();
  169. // $presences = \App\Models\Presence::where('calendar_id', $this->calendar->id)->pluck('member_id')->toArray();
  170. // $my_presences = \App\Models\Presence::where('calendar_id', $this->calendar->id)->where('user_id', \Auth::user()->id)->pluck('member_id')->toArray();
  171. foreach ($members as $member) {
  172. $presenceMembers[] = $member->id;
  173. //$this->member_ids[] = $member->id;
  174. $this->records[] = $this->getMember($member);
  175. }
  176. }
  177. // Aggiungo i membri iscritti
  178. $members_presences = \App\Models\Presence::where('calendar_id', $this->calendar->id)->whereNotIn('member_id', $presenceMembers)->pluck('member_id')->toArray();
  179. if ($this->filter != '') {
  180. $filter = $this->filter;
  181. $members = \App\Models\Member::whereIn('id', $members_presences)->where(function ($query) use ($filter) {
  182. $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $filter . "%'")
  183. ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $filter . "%'");
  184. })
  185. ->where(function ($query) {
  186. $query->where('is_archived', false)
  187. ->orWhereNull('is_archived');
  188. })
  189. ->where(function ($query) {
  190. $query->where('is_deleted', false)
  191. ->orWhereNull('is_deleted');
  192. })->get();
  193. } else
  194. $members = \App\Models\Member::whereIn('id', $members_presences)
  195. ->where(function ($query) {
  196. $query->where('is_archived', false)
  197. ->orWhereNull('is_archived');
  198. })
  199. ->where(function ($query) {
  200. $query->where('is_deleted', false)
  201. ->orWhereNull('is_deleted');
  202. })->get();
  203. foreach ($members as $member) {
  204. //$this->member_ids[] = $member->id;
  205. $this->records[] = $this->getMember($member);
  206. }
  207. foreach ($this->newMembers as $m) {
  208. $member = \App\Models\Member::findOrFail($m);
  209. //$this->member_ids[] = $member->id;
  210. $this->records[] = $this->getMember($member);
  211. }
  212. /*$calendars = \App\Models\Calendar::get();
  213. foreach($calendars as $c)
  214. {
  215. $this->records[] = array('id' => $c->id, 'title' => $c->course->name, 'start' => $c->from, 'end' => $c->to);
  216. }*/
  217. return view('livewire.presence');
  218. }
  219. private function courseMatchesSlot(?string $whenJson, string $day, string $hhmm): bool
  220. {
  221. if (!$whenJson) return false;
  222. $when = json_decode($whenJson, true);
  223. if (!is_array($when)) return false;
  224. foreach ($when as $period) {
  225. $days = $period['day'] ?? [];
  226. $from = $period['from'] ?? null;
  227. if (!$from || empty($days)) continue;
  228. $from = substr((string)$from, 0, 5);
  229. if ($from === $hhmm && in_array($day, $days, true)) {
  230. return true;
  231. }
  232. }
  233. return false;
  234. }
  235. public function getDateX()
  236. {
  237. setlocale(LC_ALL, 'it_IT');
  238. $days = ['Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato'];
  239. $months = ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'];
  240. return $days[date('w', strtotime($this->calendar->from))] . " " . date("d", strtotime($this->calendar->from)) . " " . $months[date("n", strtotime($this->calendar->from)) - 1];
  241. }
  242. public function getMember($member)
  243. {
  244. $latestCert = \App\Models\MemberCertificate::where('member_id', $member->id)
  245. ->orderBy('expire_date', 'desc')
  246. ->first();
  247. $certificate = '';
  248. $y = "|";
  249. if ($latestCert) {
  250. $latest_date = $latestCert->expire_date;
  251. $status = '';
  252. if ($latest_date < date("Y-m-d")) {
  253. $status = "0"; // Expired
  254. } else if ($latest_date <= date("Y-m-d", strtotime("+1 month"))) {
  255. $status = "1"; // Expiring soon
  256. } else {
  257. $status = "2"; // Valid
  258. }
  259. $y = $status . "|" . date("d/m/Y", strtotime($latest_date));
  260. }
  261. $presence = false;
  262. $my_presence = false;
  263. $motivation = '';
  264. $status = 0;
  265. $court = '';
  266. $instructor = '';
  267. $additional_instructor = '';
  268. $notes = '';
  269. $has_presence = \App\Models\Presence::where('calendar_id', $this->calendar->id)->where('member_id', $member->id)->first();
  270. if ($has_presence) {
  271. $presence = true;
  272. $my_presence = $has_presence->user_id == \Auth::user()->id;
  273. if ($has_presence->motivation_id > 0) {
  274. $motivation = \App\Models\Motivation::findOrFail($has_presence->motivation_id)->name;
  275. }
  276. $status = $has_presence->status;
  277. $instructor = \App\Models\User::find($has_presence->user_id)?->name;
  278. if ($has_presence->court_id > 0) {
  279. $court = \App\Models\Court::findOrFail($has_presence->court_id)->name;
  280. }
  281. if ($has_presence->instructor_id > 0 && $has_presence->instructor_id !== $has_presence->user_id) {
  282. $additional_instructor = \App\Models\User::find($has_presence->instructor_id)?->name;
  283. }
  284. if (!is_null($has_presence->notes)) {
  285. $notes = $has_presence->notes;
  286. }
  287. }
  288. if (in_array($member->id, $this->newMembers)) {
  289. $presence = true;
  290. $my_presence = true;
  291. }
  292. return array(
  293. 'id' => $member->id,
  294. 'first_name' => $member->first_name,
  295. 'last_name' => $member->last_name,
  296. 'certificate' => $y,
  297. 'presence' => $presence,
  298. 'my_presence' => $my_presence,
  299. 'status' => $status,
  300. 'motivation' => $motivation,
  301. 'court' => $court,
  302. 'instructor' => $instructor,
  303. 'additional_instructor' => $additional_instructor,
  304. 'notes' => $notes,
  305. );
  306. }
  307. public function save($ids)
  308. {
  309. $this->saveAndStay($ids);
  310. $last_date = explode(" ", $this->calendar->from)[0];
  311. return redirect()->to("/calendar?last_date={$last_date}");
  312. }
  313. public function saveAndStay($ids)
  314. {
  315. $this->calendar->court_id = $this->court_id;
  316. $this->calendar->instructor_id = $this->instructor_id;
  317. $this->calendar->note = $this->note;
  318. if ($this->motivation_id != "" && $this->motivation_id != null)
  319. $this->calendar->motivation_id = $this->motivation_id;
  320. if ($this->motivation_manual_id != "" && $this->motivation_manual_id != null)
  321. $this->calendar->motivation_manual_id = $this->motivation_manual_id;
  322. $this->calendar->save();
  323. // $x = \App\Models\Presence::where('calendar_id', $this->calendar->id)->where('user_id', \Auth::user()->id)->where('status', '<>', 99)->first();
  324. // $mid = null;
  325. // if ($x) {
  326. // $mid = $x->motivation_id;
  327. // $x->delete();
  328. // }
  329. // Mappa degli ultimi motivation_id per ogni member_id dell'utente e calendario correnti
  330. $userId = \Auth::user()->id;
  331. $calendarId = $this->calendar->id;
  332. $motivation_query = \App\Models\Presence::query()
  333. ->select('member_id', 'motivation_id', 'motivation_course_id')
  334. ->where('calendar_id', $calendarId)
  335. ->where('user_id', $userId)
  336. ->where('status', '<>', 99)
  337. ->whereIn('id', function ($q) use ($calendarId, $userId) {
  338. $q->selectRaw('MAX(id)')
  339. ->from('presences')
  340. ->where('calendar_id', $calendarId)
  341. ->where('user_id', $userId)
  342. ->where('status', '<>', 99)
  343. ->groupBy('member_id');
  344. })
  345. ->get()
  346. ->keyBy('member_id');
  347. $motivationMap = $motivation_query->map(fn($row) => $row->motivation_id)->toArray();
  348. $motivationCourseMap = $motivation_query->map(fn($row) => $row->motivation_course_id)->toArray();
  349. // Elimino tutti i dati correnti che devono essere sostituiti
  350. \App\Models\Presence::query()
  351. ->where('calendar_id', $calendarId)
  352. ->where('user_id', $userId)
  353. ->where('status', '<>', 99)
  354. ->delete();
  355. // Ricreo le presenze per ogni membro contenuto in $ids
  356. foreach ($ids as $id) {
  357. $p = new \App\Models\Presence();
  358. $p->member_id = $id;
  359. $p->calendar_id = $calendarId;
  360. // Se per quel membro esisteva un motivation_id, lo riuso, altrimenti lo lascio null
  361. $p->motivation_id = $motivationMap[$id] ?? null;
  362. $p->motivation_course_id = $motivationCourseMap[$id] ?? null;
  363. $p->user_id = $userId;
  364. $p->status = 0;
  365. // Salvo eventuale court_id (se presente e maggiore di 0)
  366. if ($this->save_court_id > 0) {
  367. $p->court_id = $this->save_court_id;
  368. }
  369. // Salvo eventuale instructor_id (se presente e maggiore di 0)
  370. if ($this->save_instructor_id > 0) {
  371. $p->instructor_id = $this->save_instructor_id;
  372. }
  373. // Salvo eventuali note (se non vuote)
  374. if ($this->save_notes != '') {
  375. $p->notes = $this->save_notes;
  376. }
  377. $p->save();
  378. }
  379. $this->emit('setSaving');
  380. }
  381. public function cancel($ids, $motivation_id)
  382. {
  383. $presences = \App\Models\Presence::where('calendar_id', $this->calendar->id)->whereIn('member_id', $ids)->get();
  384. foreach ($presences as $presence) {
  385. $presence->motivation_id = $motivation_id;
  386. $presence->status = 99;
  387. $presence->save();
  388. }
  389. return redirect()->to('/presences?calendarId=' . $this->calendar->id);
  390. }
  391. public function addMember($ids)
  392. {
  393. $this->added = true;
  394. //if (!in_array($id, $this->newMembers))
  395. // $this->newMembers[] = $id;
  396. $this->member_ids = $ids;
  397. $this->emit('reload');
  398. }
  399. public function cancelCalendar()
  400. {
  401. $this->calendar->motivation_id = $this->motivation_id;
  402. $this->calendar->status = 99;
  403. $this->calendar->save();
  404. return redirect()->to('/calendar');
  405. }
  406. public function createMember()
  407. {
  408. if (!$this->added) {
  409. $this->newMemberFiscalCodeExist = false;
  410. $this->validate([
  411. "newMemberMotivationId" => 'required',
  412. ]);
  413. /*$this->validate([
  414. // 'newMemberFiscalCode'=>'required|max:16',
  415. 'newMemberFirstName'=>'required',
  416. 'newMemberLastName'=>'required',
  417. //'newMemberEmail'=>'required',
  418. ]);*/
  419. // Check fiscal code exist
  420. $exist = false;
  421. if ($this->newMemberFiscalCode != '') {
  422. $check = \App\Models\Member::where('fiscal_code', $this->newMemberFiscalCode)->get();
  423. $exist = $check->count() > 0;
  424. }
  425. if (!$exist) {
  426. $member = \App\Models\Member::create([
  427. 'first_name' => strtoupper($this->newMemberFirstName),
  428. 'last_name' => strtoupper($this->newMemberLastName),
  429. 'email' => strtoupper($this->newMemberEmail),
  430. 'to_complete' => true,
  431. 'fiscal_code' => $this->newMemberFiscalCode,
  432. 'status' => true
  433. ]);
  434. //if (!in_array($member->id, $this->newMembers))
  435. // $this->newMembers[] = $member->id;
  436. $p = new \App\Models\Presence();
  437. $p->member_id = $member->id;
  438. $p->calendar_id = $this->calendar->id;
  439. $p->motivation_id = $this->newMemberMotivationId;
  440. $p->motivation_course_id = $this->motivation_course_id;
  441. $p->user_id = \Auth::user()->id;
  442. $p->status = 0;
  443. $p->court_id = null;
  444. $p->instructor_id = null;
  445. $p->notes = null;
  446. $p->save();
  447. $this->emit('reload');
  448. $this->emit('saved');
  449. /*$this->newMemberFirstName = '';
  450. $this->newMemberLastName = '';
  451. $this->newMemberEmail = '';
  452. $this->newMemberFiscalCode = '';*/
  453. } else {
  454. $this->newMemberFiscalCodeExist = true;
  455. }
  456. } else {
  457. if ($this->member_ids != null) {
  458. $this->validate([
  459. "newMemberMotivationId" => 'required',
  460. ]);
  461. foreach ($this->member_ids as $m) {
  462. //if ($this->manual)
  463. //{
  464. //\App\Models\Presence::where('calendar_id', $this->calendar->id)->where('user_id', \Auth::user()->id)->where('status', '<>', 99)->delete();
  465. //foreach($ids as $id)
  466. //{
  467. $p = new \App\Models\Presence();
  468. $p->member_id = $m;
  469. $p->calendar_id = $this->calendar->id;
  470. $p->motivation_id = $this->newMemberMotivationId;
  471. $p->motivation_course_id = $this->motivation_course_id;
  472. $p->user_id = \Auth::user()->id;
  473. $p->status = 0;
  474. $p->court_id = null;
  475. $p->instructor_id = null;
  476. $p->notes = null;
  477. $p->save();
  478. //}
  479. /*}
  480. else
  481. {
  482. if (!in_array($m, $this->newMembers))
  483. $this->newMembers[] = $m;
  484. }*/
  485. }
  486. }
  487. //$this->member_id = 0;
  488. $this->member_ids = [];
  489. $this->added = false;
  490. $this->emit('reload');
  491. $this->emit('saved');
  492. }
  493. $this->resetCreationFields();
  494. }
  495. public function resetCreationFields()
  496. {
  497. $this->insertUser = 'new';
  498. $this->motivation_course_id = null;
  499. $this->motivation_course_name = null;
  500. $this->motivation_course_level = null;
  501. $this->motivation_course_frequency = null;
  502. $this->newMemberMotivationId = null;
  503. $this->newMemberFirstName = null;
  504. $this->newMemberLastName = null;
  505. $this->newMemberEmail = null;
  506. $this->newMemberFiscalCode = null;
  507. $this->emit('resetCreationForm');
  508. }
  509. public function createInstructor()
  510. {
  511. $user = \App\Models\User::create([
  512. 'name' => $this->userName,
  513. 'email' => $this->userEmail,
  514. 'password' => '',
  515. 'level' => 2,
  516. 'enabled' => true
  517. ]);
  518. $this->instructor_id = $user->id;
  519. $this->instructors = \App\Models\User::select('*')->where('level', 2)->where('enabled', true)->orderBy('name', 'asc')->get();
  520. $this->emit('saved');
  521. }
  522. public function removeSingle($id)
  523. {
  524. \App\Models\Presence::where('calendar_id', $this->calendar->id)->where('member_id', $id)->delete();
  525. $this->emit('reload');
  526. }
  527. public function revert($id)
  528. {
  529. $p = \App\Models\Presence::where('calendar_id', $this->calendar->id)->where('member_id', $id)->first();
  530. $p->motivation_id = null;
  531. $p->status = 0;
  532. $p->save();
  533. $this->emit('reload');
  534. }
  535. }