You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

<?php
use App\Models\Course;
use App\Models\CourseType;
require __DIR__ . '/../vendor/autoload.php';
$app = require_once __DIR__ . '/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
$start = '2022-01-01';
$end = date('Y-m-d', strtotime('+10 year'));
$otherTypes = CourseType::where('is_chart', 0)
->where('is_history', 0)
->whereNull('deleted_at')
->orderBy('sort', 'asc')
->get(['id', 'name', 'is_chart', 'is_history', 'sort']);
echo "range: {$start} .. {$end}\n";
echo "other course types count: " . $otherTypes->count() . "\n";
foreach ($otherTypes as $t) {
echo "type_id={$t->id}\tname={$t->name}\tsort={$t->sort}\n";
}
$typeIds = $otherTypes->pluck('id')->values();
echo "\n";
echo "type ids for 'other': " . $typeIds->implode(',') . "\n";
$courses = collect();
if ($typeIds->count() > 0) {
$courses = Course::with('typeDetail:id,name')
->whereIn('type', $typeIds)
->where('is_chart', 1)
->whereNull('deleted_at')
->where(function ($q) use ($start, $end) {
$q->where('start_date', '<=', $end)
->where('end_date', '>=', $start);
})
->orderBy('type', 'asc')
->orderBy('start_date', 'asc')
->get(['id', 'name', 'type', 'is_chart', 'start_date', 'end_date']);
}
echo "courses in 'other' (overlap range) count: " . $courses->count() . "\n\n";
foreach ($courses as $c) {
$typeName = $c->typeDetail ? $c->typeDetail->name : '';
echo "course_id={$c->id}\ttype={$c->type}\ttype_name={$typeName}\tname={$c->name}\t{$c->start_date}~{$c->end_date}\n";
}
echo "\nDone.\n";