71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Enums\MacroSchedule\Activity;
|
|
use App\Models\MacroSchedule\Activity as MacroScheduleActivity;
|
|
use App\Models\Project;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class MacroScheduleSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Seed the application's database.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
/** Reset all Activities */
|
|
DB::table((new MacroScheduleActivity())->getTable())->truncate();
|
|
|
|
\mt_srand();
|
|
|
|
$startDate = Carbon::now()->subWeeks(1)->setTime(0, 0);
|
|
$activityDays = function () {
|
|
return \mt_rand(1, 3);
|
|
};
|
|
$activityGutter = function () {
|
|
return mt_rand(0, 6);
|
|
};
|
|
|
|
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Project> $projects */
|
|
$projects = Project::all();
|
|
|
|
$projects->map(function (Project $project) use ($startDate, $activityDays, $activityGutter) {
|
|
|
|
$projectStart = $startDate->clone();
|
|
|
|
/** @var \Kwaadpepper\Enum\BaseEnum[]<\App\Enums\MacroSchedule\Activity> */
|
|
$activities = Activity::toArray();
|
|
|
|
foreach ($activities as $activityEnum) {
|
|
|
|
/** @var integer Activity length in days */
|
|
$activityLength = $activityDays();
|
|
|
|
/** @var integer Activity gutter length in days */
|
|
$activityGutterLength = $activityGutter();
|
|
|
|
/** @var \App\Models\MacroSchedule\Activity */
|
|
$modelPlanning = MacroScheduleActivity::factory(1)->make()->first();
|
|
|
|
$activityModel = new MacroScheduleActivity();
|
|
$activityModel->setStartDate($projectStart, rand(0, 1));
|
|
$projectStart = $projectStart->addDays($activityLength);
|
|
$activityModel->setEndDate($projectStart, rand(0, 1));
|
|
|
|
$activityModel->comment = $modelPlanning->comment;
|
|
$activityModel->load = $modelPlanning->load;
|
|
$activityModel->activity = $activityEnum;
|
|
$activityModel->project()->associate($project);
|
|
$activityModel->saveOrFail();
|
|
|
|
// * Sub Gutter to period
|
|
$projectStart = $projectStart->addDays($activityGutterLength);
|
|
} //end foreach
|
|
});
|
|
}
|
|
}
|