From 61f43493af170d30b8758a640036515a3a9e9830 Mon Sep 17 00:00:00 2001 From: Witse P Date: Tue, 26 Nov 2024 12:52:11 +0100 Subject: [PATCH] Shiften en openingsuren/tijdsloten zijn nu van verschillende duur. Waarschijnlijk niet de meest elegante oplossing maar het werkt :)) --- .../Sale/Session/OpeningHourController.php | 74 +++++++++++++------ .../Sale/Session/OpeningHour/Schedule.php | 16 ++-- 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/module/CudiBundle/Controller/Admin/Sale/Session/OpeningHourController.php b/module/CudiBundle/Controller/Admin/Sale/Session/OpeningHourController.php index 6e1d4760f..7867d4625 100644 --- a/module/CudiBundle/Controller/Admin/Sale/Session/OpeningHourController.php +++ b/module/CudiBundle/Controller/Admin/Sale/Session/OpeningHourController.php @@ -142,56 +142,82 @@ public function scheduleAction() foreach ($formData as $formKey => $formValue) { $split = explode('_', $formKey); if ($split[0] == 'interval' && $formValue) { - $startHour = explode('-', $split[1])[0]; - $endHour = explode('-', $split[1])[1]; + $openingTime = $split[1]; // 'noon' of 'evening' + if ($openingTime == 'noon') { + $startHour = '12:35'; + $endHour = '13:55'; + $shiftStartHour = '12:30'; + $shiftEndHour = '14:00'; + } else { + $startHour = '18:05'; + $endHour = '19:00'; + $shiftStartHour = '18:00'; + $shiftEndHour = '19:00'; + } + $startDate = $split[2] . ' ' . $startHour; $endDate = $split[2] . ' ' . $endHour; + $shiftStartDate = $split[2] . ' ' . $shiftStartHour; + $shiftEndDate = $split[2] . ' ' . $shiftEndHour; - $reward = $startHour == '12:35' ? 2 : 1; // 1 of 2 shiftersbonnen adhv middag- of avondshift + $reward = $openingTime == 'noon' ? 2 : 1; // 1 of 2 shiftersbonnen adhv middag- of avondshift $signoutDate = DateTime::createFromFormat('d/m/Y', $split[2])->modify('+1 day')->format('d/m/Y') . ' 00:00'; - $data = array( + $data = array( //opening uren en registratie shiften // OPENING HOURS 'start_date' => $startDate, 'end_date' => $endDate, + // REGISTRATION SHIFTS + 'name' => 'Boekenverkoop', + 'description' => 'Kom samen met ons de cursusdienst openhouden en leer ondertussen veel nieuwe mensen kennen! Er is altijd begeleiding aanwezig dus geen enkel probleem als je voor de eerste keer komt ;))', + 'visible_date' => $now, + 'signout_date' => $signoutDate, + 'nb_registered' => $formData['nb-registered_' . $openingTime . '_' . $split[2]], + 'members_only' => false, + 'members_visible' => true, + 'final_signin_date' => $endDate, + 'is_cudi_timeslot' => true, + 'manager' => false, + 'unit' => 1, + 'edit_roles' => array('cursusdienst',), + 'event' => '', + 'location' => 1, + 'handled_on_event' => false, + 'ticket_needed' => false, + 'points' => 0, + ); + + $shiftData = array( // enkel shiften + // OPENING HOURS + 'start_date' => $shiftStartDate, + 'end_date' => $shiftEndDate, // SHIFTS 'name' => 'Boeken verkopen', - 'description' => 'Kom samen met ons de cursusdienst openhouden en leer ondertussen veel nieuwe mensen kennen! Er is altijd begeleiding aanwezig dus geen enkel probleem als je voor de eerste keer komt ;))', + 'description' => 'Kom je boeken ophalen ;)', 'manager' => false, 'unit' => 1, 'edit_roles' => array('cursusdienst',), 'event' => '', 'location' => 1, 'nb_responsibles' => 0, - 'nb_volunteers' => $formData['volunteers_' . $startHour . '-' . $endHour . '_' . $split[2]], - 'nb_volunteers_min' => $formData['volunteers-min_' . $startHour . '-' . $endHour . '_' . $split[2]], + 'nb_volunteers' => $formData['volunteers_' . $openingTime . '_' . $split[2]], + 'nb_volunteers_min' => $formData['volunteers-min_' . $openingTime . '_' . $split[2]], 'reward' => $reward, 'handled_on_event' => false, - 'ticket_needed' => false, + 'ticket_needed' => true, 'points' => 0, - // REGISTRATION SHIFTS - 'visible_date' => $now, - 'signout_date' => $signoutDate, - 'nb_registered' => $formData['nb-registered_' . $startHour . '-' . $endHour . '_' . $split[2]], - 'members_only' => false, - 'members_visible' => true, - 'final_signin_date' => $endDate, - 'is_cudi_timeslot' => true, ); // OPENING HOURS $this->getEntityManager()->persist( - $form->getHydrator()->hydrate($data) + $form->getHydrator()->hydrate($data) //send opening hours data to database ); // SHIFTS $this->getEntityManager()->persist( - $shiftForm->getHydrator()->hydrate($data) + $shiftForm->getHydrator()->hydrate($shiftData) //send Shift DATA to database ); // REGISTRATION SHIFTS - $data['name'] = 'Boekenverkoop'; - $data['description'] = 'Kom je boeken ophalen ;)'; - $data['ticket_needed'] = true; $count = 0; $startHour_ = $startHour; // creating dummy variable that is updated while ($count != 5 && $startHour_ != $endHour) { @@ -200,7 +226,7 @@ public function scheduleAction() $data['end_date'] = $split[2] . ' ' . $nextTime; $this->getEntityManager()->persist( - $registrationForm->getHydrator()->hydrate($data) + $registrationForm->getHydrator()->hydrate($data) // send registration shift data to database ); $startHour_ = $nextTime; @@ -209,7 +235,7 @@ public function scheduleAction() } } - $this->getEntityManager()->flush(); + $this->getEntityManager()->flush(); // finalize all database changes $this->flashMessenger()->success( 'Succes', @@ -283,7 +309,7 @@ private function getOpeningHourEntity() /** * @return string */ - private function calculateNextTime($time, $endTime) + private function calculateNextTime($time, $endTime) //TODO generalize this function to work in all cases { $hour = explode(':', $time)[0]; $minute = explode(':', $time)[1]; diff --git a/module/CudiBundle/Form/Admin/Sale/Session/OpeningHour/Schedule.php b/module/CudiBundle/Form/Admin/Sale/Session/OpeningHour/Schedule.php index 8b5530f3b..d55e1e464 100644 --- a/module/CudiBundle/Form/Admin/Sale/Session/OpeningHour/Schedule.php +++ b/module/CudiBundle/Form/Admin/Sale/Session/OpeningHour/Schedule.php @@ -25,7 +25,7 @@ public function init() $this->add( array( 'type' => 'checkbox', - 'name' => 'interval_12:35-13:55_' . $day->format('d/m/Y'), + 'name' => 'interval_noon_' . $day->format('d/m/Y'), 'label' => $day->format('l') . ' 12:05 - 13:55', 'required' => true, 'attributes' => array( @@ -38,7 +38,7 @@ public function init() $this->add( array( 'type' => 'text', - 'name' => 'volunteers_12:35-13:55_' . $day->format('d/m/Y'), + 'name' => 'volunteers_noon_' . $day->format('d/m/Y'), 'label' => 'Volunteers', 'attributes' => array( 'value' => '4', @@ -60,7 +60,7 @@ public function init() $this->add( array( 'type' => 'text', - 'name' => 'volunteers-min_12:35-13:55_' . $day->format('d/m/Y'), + 'name' => 'volunteers-min_noon_' . $day->format('d/m/Y'), 'label' => 'Min. Volunteers', 'attributes' => array( 'value' => '3', @@ -82,7 +82,7 @@ public function init() $this->add( array( 'type' => 'text', - 'name' => 'nb-registered_12:35-13:55_' . $day->format('d/m/Y'), + 'name' => 'nb-registered_noon_' . $day->format('d/m/Y'), 'label' => 'Registries', 'attributes' => array( 'value' => '60', @@ -104,7 +104,7 @@ public function init() $this->add( array( 'type' => 'checkbox', - 'name' => 'interval_18:05-19:00_' . $day->format('d/m/Y'), + 'name' => 'interval_evening_' . $day->format('d/m/Y'), 'label' => '18:05 - 19:00', 'required' => true, 'attributes' => array( @@ -117,7 +117,7 @@ public function init() $this->add( array( 'type' => 'text', - 'name' => 'volunteers_18:05-19:00_' . $day->format('d/m/Y'), + 'name' => 'volunteers_evening_' . $day->format('d/m/Y'), 'label' => 'Volunteers', 'attributes' => array( 'value' => '4', @@ -139,7 +139,7 @@ public function init() $this->add( array( 'type' => 'text', - 'name' => 'volunteers-min_18:05-19:00_' . $day->format('d/m/Y'), + 'name' => 'volunteers-min_evening_' . $day->format('d/m/Y'), 'label' => 'Min. Volunteers', 'attributes' => array( 'value' => '3', @@ -161,7 +161,7 @@ public function init() $this->add( array( 'type' => 'text', - 'name' => 'nb-registered_18:05-19:00_' . $day->format('d/m/Y'), + 'name' => 'nb-registered_evening_' . $day->format('d/m/Y'), 'label' => 'Registries', 'attributes' => array( 'value' => '60',