|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Command; |
|
4
|
|
|
|
|
5
|
|
|
use App\Book\EntryOverviewHelper; |
|
6
|
|
|
use App\Book\Lesson\LessonCancelHelper; |
|
7
|
|
|
use App\Entity\TimetableLesson; |
|
8
|
|
|
use App\Repository\TimetableLessonRepositoryInterface; |
|
9
|
|
|
use SchulIT\CommonBundle\Helper\DateHelper; |
|
10
|
|
|
use Shapecode\Bundle\CronBundle\Attribute\AsCronJob; |
|
11
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
|
12
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
16
|
|
|
|
|
17
|
|
|
#[AsCronJob('@daily')] |
|
18
|
|
|
#[AsCommand(name: 'app:book:auto_cancel', description: 'Markiert alle Stunden an einem Tag als Entfall, wenn es einen Entfallgrund gibt.')] |
|
19
|
|
|
class CancelLessonsOnFreeDaysCommand extends Command { |
|
20
|
|
|
|
|
21
|
|
|
public function __construct(private readonly DateHelper $dateHelper, private readonly LessonCancelHelper $cancelHelper, |
|
22
|
|
|
private readonly TimetableLessonRepositoryInterface $lessonRepository, private readonly EntryOverviewHelper $overviewHelper, string $name = null) { |
|
23
|
|
|
parent::__construct($name); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function execute(InputInterface $input, OutputInterface $output) { |
|
27
|
|
|
$io = new SymfonyStyle($input, $output); |
|
28
|
|
|
$today = $this->dateHelper->getToday(); |
|
29
|
|
|
|
|
30
|
|
|
$io->section(sprintf('Betrachte %s', $today->format('d.m.Y'))); |
|
31
|
|
|
|
|
32
|
|
|
$freeTimespans = $this->overviewHelper->computeFreeTimespans($today, $today); |
|
33
|
|
|
$io->text(sprintf('Anzahl der freien Zeitbereiche: %d', count($freeTimespans))); |
|
34
|
|
|
|
|
35
|
|
|
$lessons = $this->lessonRepository->findAllByDate($today); |
|
36
|
|
|
$io->text(sprintf('Anzahl der Unterrichtsstunden am Tag: %d', count($lessons))); |
|
37
|
|
|
|
|
38
|
|
|
foreach($freeTimespans as $timespan) { |
|
39
|
|
|
$io->section(sprintf('Markiere %d.-%d. Stunde als Entfall: %s', $timespan->getLessonStart(), $timespan->getLessonEnd(), $timespan->getReason())); |
|
40
|
|
|
|
|
41
|
|
|
/** @var TimetableLesson[] $affectedLessons */ |
|
42
|
|
|
$affectedLessons = array_filter($lessons, fn(TimetableLesson $lesson) => $lesson->getTuition() !== null && $lesson->getLessonStart() >= $timespan->getLessonStart() && $timespan->getLessonEnd() >= $lesson->getLessonEnd()); |
|
43
|
|
|
|
|
44
|
|
|
$io->text(sprintf('Betroffene Stunden: %d', count($affectedLessons))); |
|
45
|
|
|
$count = 0; |
|
46
|
|
|
|
|
47
|
|
|
foreach($affectedLessons as $affectedLesson) { |
|
48
|
|
|
if($affectedLesson->getEntries()->count() === 0) { |
|
49
|
|
|
$this->cancelHelper->cancelLesson($affectedLesson, $timespan->getReason()); |
|
50
|
|
|
$count++; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$io->success(sprintf('%d Stunde(n) als Entfall markiert', $count)); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return Command::SUCCESS; |
|
58
|
|
|
} |
|
59
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths