62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use App\Enums\Planning\TableRow;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Support\Carbon;
|
||
|
|
|
||
|
|
class WeekPlanning extends Model
|
||
|
|
{
|
||
|
|
use HasFactory;
|
||
|
|
|
||
|
|
public $casts = [
|
||
|
|
'start' => 'date',
|
||
|
|
'planning' => 'array'
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'start', 'planning', 'user_id'
|
||
|
|
];
|
||
|
|
|
||
|
|
public static function getWeekBlock(Carbon $start): array
|
||
|
|
{
|
||
|
|
$start = $start->copy();
|
||
|
|
$out = [];
|
||
|
|
$daysOfWeek = 5;
|
||
|
|
for ($i = 1; $i <= $daysOfWeek; $i++) {
|
||
|
|
$out[$start->timestamp] = [];
|
||
|
|
foreach (TableRow::toArray() as $tableRow) {
|
||
|
|
$out[$start->timestamp][$tableRow->value] = \array_replace(
|
||
|
|
self::getCell(),
|
||
|
|
[
|
||
|
|
'row' => $tableRow->value
|
||
|
|
]
|
||
|
|
);
|
||
|
|
}
|
||
|
|
$day = $start->addDay();
|
||
|
|
}
|
||
|
|
return $out;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getCell(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
/** @var \App\Enums\Planning\CellType */
|
||
|
|
'type' => null,
|
||
|
|
/** @var \App\Enums\Planning\TableRow */
|
||
|
|
'row' => null,
|
||
|
|
'foreign' => null,
|
||
|
|
/** @var \App\Enums\Planning\CellModel */
|
||
|
|
'cellModel' => null,
|
||
|
|
'text' => ''
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function user()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(User::class);
|
||
|
|
}
|
||
|
|
}
|