mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 02:39:10 -04:00
Working schedule v2
This commit is contained in:
40
app/OCOM.php
40
app/OCOM.php
@@ -3,6 +3,7 @@
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use function GuzzleHttp\Promise\all;
|
||||
|
||||
/**
|
||||
* App\OCOM
|
||||
@@ -72,40 +73,47 @@ class OCOM extends Model
|
||||
|
||||
public function wasGiven()
|
||||
{
|
||||
$courses = $this->courses();
|
||||
$courses = Course::where('ocom',$this->ocom)->get();
|
||||
$result = collect();
|
||||
|
||||
$from = strtotime(\App\Config::getData('instruction_year_begin'));
|
||||
$to = strtotime(\App\Config::getData('instruction_year_end'));
|
||||
|
||||
foreach ($courses as $course)
|
||||
{
|
||||
$event = null;
|
||||
try {
|
||||
$event = $course->event;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
// Nettoyer ?
|
||||
break;
|
||||
}
|
||||
$event = $course->event;
|
||||
if (strtotime($event->date_begin) >= $from)
|
||||
{
|
||||
if (strtotime($event->date_begin) <= $to)
|
||||
{
|
||||
$result->push($event);
|
||||
$result->push($course->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($result->isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function updateWasGiven()
|
||||
{
|
||||
$this->course_id = implode(",",$this->wasGiven()->toArray());
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public static function wasUpdateGivenAll()
|
||||
{
|
||||
$ocoms = OCOM::all();
|
||||
foreach ($ocoms as $o)
|
||||
{
|
||||
$o->updateWasGiven();
|
||||
}
|
||||
}
|
||||
|
||||
public static function findByOCOM($ocom)
|
||||
{
|
||||
return OCOM::where('ocom','=',$ocom)->first();
|
||||
}
|
||||
|
||||
public function getDurationInMin()
|
||||
{
|
||||
return $this->nbPeriode * 30;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user