'array', 'msg' => 'array', 'weekly_msg_file' => 'array' ]; public function bookings() { return $this->morphMany('App\Booking', 'bookable'); } public function courses() { return $this->hasMany('App\Course'); } public function type() { return \App\EventType::find($this->type); } public function user() { return $this->belongsTo('App\User'); } public function course($p,$l) { $courses = $this->courses; foreach ($courses as $c) { if ($c->periode == $p && $c->level == $l) { return $c; } } $error = new \App\Course(); $error->name = "Cours manquant dans la BD"; $error->ocom = "ERREUR"; $error->periode = $p; $error->level = $l; $error->location = ""; $error->desc = ""; $error->comment = "Le cours est manquant dans la base de données"; $error->comment_officier = "Le cours est manquant dans la base de données"; $error->event_id = $this->id; $error->user_id = 1; return $error; } public function logs() { return $this->morphMany('App\Log', 'logable'); } public static function future() { $events = collect(); foreach (Event::all() as $event) { if (date('U',strtotime($event->date_begin)) >= time()) { $events->push($event); } } return $events; } public static function allThisYear() { $events = Event::all(); foreach ($events as $key => $event) { if (date('c',strtotime($event->date_begin)) <= date('c',strtotime(\App\Config::getData('instruction_year_begin')))) { $events->forget($key); } if (date('c',strtotime($event->date_begin)) >= date('c',strtotime(\App\Config::getData('instruction_year_end')))) { $events->forget($key); } } return $events; } public function nbPeriode() { return (count($this->schedule["periodes"])); } public function nbNiveau() { return count($this->schedule["niveaux"]); } static function getMaxLevels($events) { $maxlevel = 0; foreach ($events as $e) { if ($e->nbNiveau() > $maxlevel) { $maxlevel = $e->nbNiveau(); } } return $maxlevel; } }