mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 02:39:10 -04:00
122 lines
2.7 KiB
PHP
122 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Course extends Model
|
|
{
|
|
public function bookings()
|
|
{
|
|
return $this->morphMany('App\Booking', 'bookable');
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo('App\User');
|
|
}
|
|
|
|
public function instructor()
|
|
{
|
|
if (\App\User::find($this->user_id))
|
|
{
|
|
return \App\User::find($this->user_id)->fullname();
|
|
}
|
|
else
|
|
{
|
|
return $this->user_id;
|
|
}
|
|
}
|
|
|
|
public function event()
|
|
{
|
|
return $this->belongsTo('App\Event');
|
|
}
|
|
|
|
public function logs()
|
|
{
|
|
return $this->morphMany('App\Log', 'logable');
|
|
}
|
|
|
|
public function use_course()
|
|
{
|
|
return $this->name == "" && $this->ocom == "";
|
|
}
|
|
|
|
public function lessonPlan()
|
|
{
|
|
return $this->hasOne('App\LessonPlan');
|
|
}
|
|
|
|
public static function allFuture()
|
|
{
|
|
$courses = Course::all();
|
|
foreach ($courses as $key => $course)
|
|
{
|
|
if (date('c',strtotime($course->event->date_begin)) <= date('c'))
|
|
{
|
|
$courses->forget($key);
|
|
}
|
|
}
|
|
return $courses;
|
|
}
|
|
|
|
public static function allThisYear()
|
|
{
|
|
$courses = Course::all();
|
|
foreach ($courses as $key => $course)
|
|
{
|
|
if (date('c',strtotime($course->event->date_begin)) <= date('c',strtotime(\App\Config::getData('instruction_year_begin'))))
|
|
{
|
|
$courses->forget($key);
|
|
}
|
|
if (date('c',strtotime($course->event->date_begin)) >= date('c',strtotime(\App\Config::getData('instruction_year_end'))))
|
|
{
|
|
$courses->forget($key);
|
|
}
|
|
}
|
|
return $courses;
|
|
}
|
|
|
|
public static function allForUser($user_id)
|
|
{
|
|
$courses = Course::all();
|
|
foreach ($courses as $key => $course)
|
|
{
|
|
if ($course->user_id != $user_id)
|
|
{
|
|
$courses->forget($key);
|
|
}
|
|
}
|
|
return $courses;
|
|
}
|
|
|
|
public static function allForAuthUser()
|
|
{
|
|
return self::allForUser(\Auth::user()->id);
|
|
}
|
|
|
|
public static function allFutureForUser($user_id)
|
|
{
|
|
$courses = Course::all();
|
|
foreach ($courses as $key => $course)
|
|
{
|
|
if (date('c',strtotime($course->event->date_begin)) <= date('c'))
|
|
{
|
|
$courses->forget($key);
|
|
}
|
|
if ($course->user_id != $user_id)
|
|
{
|
|
$courses->forget($key);
|
|
}
|
|
}
|
|
return $courses;
|
|
}
|
|
|
|
public static function allFutureForAuthUser()
|
|
{
|
|
return self::allFutureForUser(\Auth::user()->id);
|
|
}
|
|
|
|
}
|