Working schedule v2

This commit is contained in:
Mathieu Lagace
2020-07-30 17:46:11 -04:00
parent 8d22092ea8
commit 4c5d635d5b
25 changed files with 1174 additions and 497 deletions

View File

@@ -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;
}
}