From ca23d41241808cc923ee9b50db06cdae6bbf2486 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Thu, 3 Oct 2024 08:57:56 +0200 Subject: [PATCH] refs #724. New field . RemotePc --- config/api_platform/Trace.yaml | 3 +++ config/services/api_platform.yaml | 12 +++++++++++ migrations/Version20241002062742.php | 31 ++++++++++++++++++++++++++++ src/Entity/RemoteCalendar.php | 31 ++++++++++++++++++++-------- 4 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 migrations/Version20241002062742.php diff --git a/config/api_platform/Trace.yaml b/config/api_platform/Trace.yaml index c7e74db..115c1f0 100644 --- a/config/api_platform/Trace.yaml +++ b/config/api_platform/Trace.yaml @@ -12,6 +12,9 @@ resources: ApiPlatform\Metadata\Get: provider: App\State\Provider\TraceProvider + order: + createdAt: DESC + properties: App\Entity\Trace: id: diff --git a/config/services/api_platform.yaml b/config/services/api_platform.yaml index 07306b4..8b1dc40 100644 --- a/config/services/api_platform.yaml +++ b/config/services/api_platform.yaml @@ -127,6 +127,18 @@ services: arguments: [ { 'synchronized': ~ } ] tags: [ 'api_platform.filter' ] + api_platform.filter.remote_calendar.order: + parent: 'api_platform.doctrine.orm.order_filter' + arguments: + $properties: { 'id': ~, 'name': ~ } + $orderParameterName: 'order' + tags: [ 'api_platform.filter' ] + + api_platform.filter.remote_calendar.search: + parent: 'api_platform.doctrine.orm.search_filter' + arguments: [ { 'id': 'exact', 'name': 'partial', } ] + tags: [ 'api_platform.filter' ] + api_platform.filter.user.order: parent: 'api_platform.doctrine.orm.order_filter' arguments: diff --git a/migrations/Version20241002062742.php b/migrations/Version20241002062742.php new file mode 100644 index 0000000..d867007 --- /dev/null +++ b/migrations/Version20241002062742.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE organizational_unit ADD remote_pc TINYINT(1) NOT NULL, ADD reserved TINYINT(1) NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE organizational_unit DROP remote_pc, DROP reserved'); + } +} diff --git a/src/Entity/RemoteCalendar.php b/src/Entity/RemoteCalendar.php index c06e599..66348bc 100644 --- a/src/Entity/RemoteCalendar.php +++ b/src/Entity/RemoteCalendar.php @@ -84,20 +84,33 @@ class RemoteCalendar extends AbstractEntity return $this; } - public function isRemoteAvailable(): bool + public function isAvailable(): bool { $now = new \DateTime(); foreach ($this->getRules() as $rule) { - $dayOfWeek = (int) $now->format('w'); - $adjustedDayOfWeek = ($dayOfWeek + 6) % 7; - if (!in_array($adjustedDayOfWeek, $rule->getBusyWeekdays())) { - return false; + if ($rule->isRemoteAvailable()) { + $fromDate = $rule->getAvailableFromDate(); + $toDate = $rule->getAvailableToDate(); + + if ($fromDate && $toDate && $fromDate <= $now && $now <= $toDate) { + return true; + } + } else { + $dayOfWeek = (int) $now->format('w'); + $adjustedDayOfWeek = ($dayOfWeek + 6) % 7; + + if (!in_array($adjustedDayOfWeek, $rule->getBusyWeekdays())) { + return true; + } + + $currentTime = $now->format('H:i'); + if (!($currentTime >= $rule->getBusyFromHour() && $currentTime <= $rule->getBusyToHour())) { + return true; + } } - - $currentTime = $now->format('H:i'); - - return ($currentTime >= $rule->getBusyFromHour() && $currentTime <= $rule->getBusyToHour()); } + + return false; } }