mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 02:39:10 -04:00
202 lines
8.5 KiB
PHP
202 lines
8.5 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* App\Event
|
|
*
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $date_begin
|
|
* @property string $date_end
|
|
* @property string $type
|
|
* @property string $user_id
|
|
* @property string $location
|
|
* @property int $is_mandatory
|
|
* @property int $use_weekly_msg
|
|
* @property int $use_schedule
|
|
* @property string $desc
|
|
* @property array $msg
|
|
* @property array $weekly_msg_file
|
|
* @property array $schedule
|
|
* @property string $calendar_color
|
|
* @property string $calendar_icon
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Booking[] $bookings
|
|
* @property-read int|null $bookings_count
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Course[] $courses
|
|
* @property-read int|null $courses_count
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Log[] $logs
|
|
* @property-read int|null $logs_count
|
|
* @property-read \App\User $user
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereCalendarColor($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereCalendarIcon($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereDateBegin($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereDateEnd($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereDesc($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereIsMandatory($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereLocation($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereMsg($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereSchedule($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereType($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereUseSchedule($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereUseWeeklyMsg($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereUserId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Event whereWeeklyMsgFile($value)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class Event extends Model
|
|
{
|
|
protected $casts = [
|
|
'schedule' => '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 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;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
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 static function checkForError()
|
|
{
|
|
$events = Event::all();
|
|
|
|
$warning = [];
|
|
$danger = [];
|
|
|
|
foreach ($events as $event)
|
|
{
|
|
if($event->date_begin == null)
|
|
{
|
|
array_push($warning,'Évènement ID:'.$event->id.' - "date_begin", Incorrect');
|
|
}
|
|
if($event->date_end == null)
|
|
{
|
|
array_push($warning,'Évènement ID:'.$event->id.' - "date_end", Incorrect');
|
|
}
|
|
if($event->type == null || $event->type == "" || !\App\EventType::all()->has($event->type))
|
|
{
|
|
$event->type = 1;
|
|
//$event->save();
|
|
array_push($warning,'Évènement ID:'.$event->id.' - "type", Incorrect... Réinitialisé à la valeur par défaut');
|
|
clog('error','danger','Évènement ID:'.$event->id.' - "type", Incorrect... Réinitialisé à la valeur par défaut');
|
|
}
|
|
if($event->is_mandatory == null && $event->is_mandatory != 0)
|
|
{
|
|
array_push($warning,'Évènement ID:'.$event->id.' - "is_mandatory", Incorrect... Réinitialisé à la valeur par défaut');
|
|
clog('error','danger','Évènement ID:'.$event->id.' - "is_mandatory", Incorrect... Réinitialisé à la valeur par défaut');
|
|
}
|
|
if($event->use_weekly_msg == null && $event->use_weekly_msg != 0)
|
|
{
|
|
array_push($warning,'Évènement ID:'.$event->id.' - "use_weekly_msg", Incorrect... Réinitialisé à la valeur par défaut');
|
|
clog('error','danger','Évènement ID:'.$event->id.' - "use_weekly_msg", Incorrect... Réinitialisé à la valeur par défaut');
|
|
}
|
|
if($event->use_schedule == null && $event->use_schedule != 0)
|
|
{
|
|
array_push($warning,'Évènement ID:'.$event->id.' - "use_schedule", Incorrect... Réinitialisé à la valeur par défaut');
|
|
clog('error','danger','Évènement ID:'.$event->id.' - "use_schedule", Incorrect... Réinitialisé à la valeur par défaut');
|
|
}
|
|
if($event->schedule == null)
|
|
{
|
|
$event->schedule = '{"periodes":[{"name":"Periode 1","begin_time":"19:00","end_time":"20:10"},{"name":"Periode 2","begin_time":"20:30","end_time":"21:20"}],"niveaux":[{"name":"Niveau 1"},{"name":"Niveau 2"},{"name":"Niveau 3"}]}';
|
|
$event->save();
|
|
array_push($warning,'Évènement ID:'.$event->id.' - "schedule", Incorrect... Réinitialisé à la valeur par défaut');
|
|
clog('error','danger','Évènement ID:'.$event->id.' - "schedule", Incorrect... Réinitialisé à la valeur par défaut');
|
|
}
|
|
if($event->location == null || $event->location == "")
|
|
{
|
|
array_push($warning,'Évènement ID:'.$event->id.' - "location", Incorrect... Réinitialisé à la valeur par défaut');
|
|
clog('error','danger','Évènement ID:'.$event->id.' - "location", Incorrect... Réinitialisé à la valeur par défaut');
|
|
}
|
|
if($event->calendar_color == null || $event->calendar_color == "")
|
|
{
|
|
$event->calendar_color = '#A4A4A4';
|
|
$event->save();
|
|
array_push($warning,'Évènement ID:'.$event->id.' - "calendar_color", Incorrect... Réinitialisé à la valeur par défaut');
|
|
clog('error','danger','Évènement ID:'.$event->id.' - "calendar_color", Incorrect... Réinitialisé à la valeur par défaut');
|
|
}
|
|
if($event->calendar_icon == null || $event->calendar_icon == "")
|
|
{
|
|
$event->calendar_icon = 'fas fa-book';
|
|
$event->save();
|
|
array_push($warning,'Évènement ID:'.$event->id.' - "calendar_icon", Incorrect... Réinitialisé à la valeur par défaut');
|
|
clog('error','danger','Évènement ID:'.$event->id.' - "calendar_icon", Incorrect... Réinitialisé à la valeur par défaut');
|
|
}
|
|
}
|
|
|
|
return [$warning,$danger];
|
|
}
|
|
}
|