mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 02:39:10 -04:00
112 lines
3.5 KiB
PHP
112 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* App\OCOM
|
|
*
|
|
* @property int $id
|
|
* @property string $ocom
|
|
* @property string $objectif_competence
|
|
* @property string $nbPeriode
|
|
* @property string $objectif_rendement
|
|
* @property string $oren
|
|
* @property int $complementary
|
|
* @property string $course_id
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM whereComplementary($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM whereCourseId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM whereNbPeriode($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM whereObjectifCompetence($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM whereObjectifRendement($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM whereOcom($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM whereOren($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\OCOM whereUpdatedAt($value)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class OCOM extends Model
|
|
{
|
|
public function courses()
|
|
{
|
|
$courses_id = explode(',',$this->course_id);
|
|
$courses = collect();
|
|
foreach ($courses_id as $course_id)
|
|
{
|
|
$courses->push(\App\Course::find($course_id));
|
|
}
|
|
return $courses;
|
|
}
|
|
|
|
public function saveCourses($courses)
|
|
{
|
|
$courses_id = explode(',',$this->course_id);
|
|
foreach ($courses as $cours)
|
|
{
|
|
if ($cours != null){
|
|
array_push($courses_id,$cours->id);
|
|
}
|
|
}
|
|
$courses_id = array_unique($courses_id);
|
|
$courses_id = array_filter($courses_id);
|
|
$this->course_id = implode(',',$courses_id);
|
|
$this->save();
|
|
}
|
|
|
|
public function saveCourse($course)
|
|
{
|
|
$courses_id = explode(',',$this->course_id);
|
|
array_push($courses_id,$course->id);
|
|
$courses_id = array_unique($courses_id);
|
|
$courses_id = array_filter($courses_id);
|
|
$this->course_id = implode(',',$courses_id);
|
|
$this->save();
|
|
}
|
|
|
|
public function wasGiven()
|
|
{
|
|
$courses = $this->courses();
|
|
$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;
|
|
}
|
|
if (strtotime($event->date_begin) >= $from)
|
|
{
|
|
if (strtotime($event->date_begin) <= $to)
|
|
{
|
|
$result->push($event);
|
|
}
|
|
}
|
|
}
|
|
if ($result->isEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public static function findByOCOM($ocom)
|
|
{
|
|
return OCOM::where('ocom','=',$ocom)->first();
|
|
}
|
|
}
|