2021-12-05 15:01:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2023-08-14 09:23:39 +00:00
|
|
|
use App\Enums\Planning\ActivityTypeEnum;
|
|
|
|
|
use App\Enums\Planning\CellModelEnum;
|
2021-12-05 15:01:32 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
|
2023-08-14 09:23:39 +00:00
|
|
|
/**
|
|
|
|
|
* @property User $user_id
|
|
|
|
|
* @property date $date
|
|
|
|
|
* @property integer $slot
|
|
|
|
|
* @property ActivityTypeEnum $activity
|
|
|
|
|
* @property string $description
|
|
|
|
|
* @property Ticket|Site|Projet $id_lie
|
|
|
|
|
* @property CellModelEnum $model_lie
|
|
|
|
|
*/
|
2021-12-05 15:01:32 +01:00
|
|
|
class Schedule extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
2022-08-30 13:21:07 +00:00
|
|
|
/**
|
2023-08-14 09:23:39 +00:00
|
|
|
* The attributes that are fillable.
|
2022-08-30 13:21:07 +00:00
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2021-12-05 15:01:32 +01:00
|
|
|
protected $fillable = [
|
|
|
|
|
'user_id',
|
|
|
|
|
'date',
|
|
|
|
|
'slot',
|
|
|
|
|
'activity',
|
|
|
|
|
'description',
|
|
|
|
|
'id_lie',
|
|
|
|
|
'model_lie'
|
|
|
|
|
];
|
|
|
|
|
|
2023-08-14 09:23:39 +00:00
|
|
|
/**
|
|
|
|
|
* The attributes that should be cast.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'date' => 'date',
|
|
|
|
|
'activity' => ActivityTypeEnum::class,
|
|
|
|
|
'model_lie' => CellModelEnum::class
|
|
|
|
|
];
|
|
|
|
|
|
2022-08-30 13:21:07 +00:00
|
|
|
// * RELATIONSHIPS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* BelongsTo User relation
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2021-12-05 15:01:32 +01:00
|
|
|
public function user()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 13:21:07 +00:00
|
|
|
/**
|
2023-08-14 09:23:39 +00:00
|
|
|
* Relationship to linked objet
|
2022-08-30 13:21:07 +00:00
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2021-12-05 15:01:32 +01:00
|
|
|
public function relatedModel()
|
|
|
|
|
{
|
2023-08-14 09:23:39 +00:00
|
|
|
switch ($this->model_lie->value) {
|
2021-12-05 15:01:32 +01:00
|
|
|
case 'sites':
|
|
|
|
|
return $this->belongsTo(Site::class, 'id_lie');
|
|
|
|
|
case 'projects':
|
|
|
|
|
return $this->belongsTo(Project::class, 'id_lie');
|
|
|
|
|
case 'tickets':
|
|
|
|
|
return $this->belongsTo(Ticket::class, 'id_lie');
|
|
|
|
|
default:
|
|
|
|
|
return new BelongsTo($this->newQuery(), $this, '', '', '');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|