From 91b3a628eadd8b88d97e7cc8592ca07a9c21ec80 Mon Sep 17 00:00:00 2001 From: pedrod Date: Sun, 15 Oct 2023 22:40:54 +0000 Subject: [PATCH] not entirely working --- migrations/Version20231015200531.php | 41 +++ .../Controller/IndexController.php | 9 +- .../Resources/views/common/index/index.twig | 8 +- .../Sale/Session/OpeningHourController.php | 3 +- .../Sale/Session/OpeningHour/Translation.php | 2 +- .../Resources/config/install/roles.config.php | 3 + .../Admin/OpeningHourController.php | 288 ++++++++++++++++++ .../ShopBundle/Entity/Session/OpeningHour.php | 199 ++++++++++++ .../Session/OpeningHour/Translation.php | 104 +++++++ .../Form/Admin/Session/OpeningHour/Add.php | 73 +++++ .../Form/Admin/Session/OpeningHour/Edit.php | 19 ++ .../Admin/Session/OpeningHour/Schedule.php | 152 +++++++++ .../Hydrator/Session/OpeningHour.php | 53 ++++ .../Repository/Session/OpeningHour.php | 173 +++++++++++ .../Session/OpeningHour/Translation.php | 13 + .../Resources/config/admin.config.php | 5 + .../Resources/config/assetic.config.php | 12 + .../Resources/config/install/acl.config.php | 3 + .../Resources/config/router.config.php | 18 ++ .../views/shop/admin/opening-hour/add.twig | 20 ++ .../views/shop/admin/opening-hour/delete.twig | 3 + .../views/shop/admin/opening-hour/edit.twig | 1 + .../views/shop/admin/opening-hour/manage.twig | 111 +++++++ .../views/shop/admin/opening-hour/old.twig | 1 + .../opening-hour/partials/navigation.twig | 19 ++ .../shop/admin/opening-hour/schedule.twig | 12 + 26 files changed, 1337 insertions(+), 8 deletions(-) create mode 100644 migrations/Version20231015200531.php create mode 100644 module/ShopBundle/Controller/Admin/OpeningHourController.php create mode 100644 module/ShopBundle/Entity/Session/OpeningHour.php create mode 100644 module/ShopBundle/Entity/Session/OpeningHour/Translation.php create mode 100644 module/ShopBundle/Form/Admin/Session/OpeningHour/Add.php create mode 100644 module/ShopBundle/Form/Admin/Session/OpeningHour/Edit.php create mode 100644 module/ShopBundle/Form/Admin/Session/OpeningHour/Schedule.php create mode 100644 module/ShopBundle/Hydrator/Session/OpeningHour.php create mode 100644 module/ShopBundle/Repository/Session/OpeningHour.php create mode 100644 module/ShopBundle/Repository/Session/OpeningHour/Translation.php create mode 100644 module/ShopBundle/Resources/views/shop/admin/opening-hour/add.twig create mode 100644 module/ShopBundle/Resources/views/shop/admin/opening-hour/delete.twig create mode 100644 module/ShopBundle/Resources/views/shop/admin/opening-hour/edit.twig create mode 100644 module/ShopBundle/Resources/views/shop/admin/opening-hour/manage.twig create mode 100644 module/ShopBundle/Resources/views/shop/admin/opening-hour/old.twig create mode 100644 module/ShopBundle/Resources/views/shop/admin/opening-hour/partials/navigation.twig create mode 100644 module/ShopBundle/Resources/views/shop/admin/opening-hour/schedule.twig diff --git a/migrations/Version20231015200531.php b/migrations/Version20231015200531.php new file mode 100644 index 0000000000..f28a5266aa --- /dev/null +++ b/migrations/Version20231015200531.php @@ -0,0 +1,41 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('CREATE SEQUENCE shop_sessions_opening_hours_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE shop_sessions_opening_hours_translations_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE shop_sessions_opening_hours (id BIGINT NOT NULL, person BIGINT DEFAULT NULL, start_date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, end_date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, creation_time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_B036599134DCD176 ON shop_sessions_opening_hours (person)'); + $this->addSql('CREATE TABLE shop_sessions_opening_hours_translations (id BIGINT NOT NULL, opening_hour BIGINT DEFAULT NULL, language BIGINT DEFAULT NULL, comment VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_BAEC889D969BD765 ON shop_sessions_opening_hours_translations (opening_hour)'); + $this->addSql('CREATE INDEX IDX_BAEC889DD4DB71B5 ON shop_sessions_opening_hours_translations (language)'); + $this->addSql('ALTER TABLE shop_sessions_opening_hours ADD CONSTRAINT FK_B036599134DCD176 FOREIGN KEY (person) REFERENCES users_people (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE shop_sessions_opening_hours_translations ADD CONSTRAINT FK_BAEC889D969BD765 FOREIGN KEY (opening_hour) REFERENCES shop_sessions_opening_hours (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE shop_sessions_opening_hours_translations ADD CONSTRAINT FK_BAEC889DD4DB71B5 FOREIGN KEY (language) REFERENCES general_languages (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + /** + * @param \Doctrine\DBAL\Schema\Schema $schema + * @return void + */ + public function down(Schema $schema) : void + { + $this->throwIrreversibleMigrationException(); + } +} diff --git a/module/CommonBundle/Controller/IndexController.php b/module/CommonBundle/Controller/IndexController.php index 94ea98116d..cb468a336e 100644 --- a/module/CommonBundle/Controller/IndexController.php +++ b/module/CommonBundle/Controller/IndexController.php @@ -214,12 +214,10 @@ private function getCudiInfo() ->getRepository('CudiBundle\Entity\Sale\Session\OpeningHour') ->findPeriodFromNow('P14D'); - $messages = $this->getEntityManager() + $cudi['messages'] = $this->getEntityManager() ->getRepository('CudiBundle\Entity\Sale\Session\Message') ->findAllActive(); - $cudi['messages'] = $messages; - return $cudi; } @@ -278,7 +276,10 @@ private function getShopInfo() ->getConfigValue('shop.url_reservations'), 'messages' => $this->getEntityManager() ->getRepository('ShopBundle\Entity\Session\Message') - ->findAllActive() + ->findAllActive(), + 'openingHours' => $this->getEntityManager() + ->getRepository('ShopBundle\Entity\Session\OpeningHour') + ->findPeriodFromNow('P14D'), ); } diff --git a/module/CommonBundle/Resources/views/common/index/index.twig b/module/CommonBundle/Resources/views/common/index/index.twig index 294fcd280e..9aab60ca0d 100644 --- a/module/CommonBundle/Resources/views/common/index/index.twig +++ b/module/CommonBundle/Resources/views/common/index/index.twig @@ -163,7 +163,7 @@

{{ dateLocalized(opening.getStart(), 'EEEE (d/M)')|capitalize }}

{{ opening.getStart().format('H:i') }} - -{{ opening.getEnd().format('H:i') }}

+ - {{ opening.getEnd().format('H:i') }}

{% endfor %} @@ -174,6 +174,12 @@
{{ message.getContent(language) }}
{% endfor %} + {% for opening in shop.openingHours %} +
+

{{ dateLocalized(opening.getStartDate(), 'EEEE (d/M)')|capitalize }}

+

{{ opening.getStartDate().format('H:i') }} + - {{ opening.getEndDate().format('H:i') }}

+ {% endfor %} diff --git a/module/CudiBundle/Controller/Admin/Sale/Session/OpeningHourController.php b/module/CudiBundle/Controller/Admin/Sale/Session/OpeningHourController.php index 3ce35e17a3..8ac91344e9 100644 --- a/module/CudiBundle/Controller/Admin/Sale/Session/OpeningHourController.php +++ b/module/CudiBundle/Controller/Admin/Sale/Session/OpeningHourController.php @@ -5,12 +5,12 @@ use DateTime; use CudiBundle\Entity\Sale\Session\OpeningHour; use Laminas\View\Model\ViewModel; -use ShiftBundle\Hydrator; /** * OpeningHourController * * @author Kristof Mariƫn + * @author Pedro Devogelaere */ class OpeningHourController extends \CudiBundle\Component\Controller\ActionController { @@ -56,7 +56,6 @@ public function addAction() $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { - error_log(json_encode($form->getData())); $this->getEntityManager()->persist( $form->hydrateObject() ); diff --git a/module/CudiBundle/Entity/Sale/Session/OpeningHour/Translation.php b/module/CudiBundle/Entity/Sale/Session/OpeningHour/Translation.php index 06d4dea2fa..c2e68cab40 100644 --- a/module/CudiBundle/Entity/Sale/Session/OpeningHour/Translation.php +++ b/module/CudiBundle/Entity/Sale/Session/OpeningHour/Translation.php @@ -15,7 +15,7 @@ class Translation { /** - * @var integer The ID of this tanslation + * @var integer The ID of this translation * * @ORM\Id * @ORM\GeneratedValue diff --git a/module/LogisticsBundle/Resources/config/install/roles.config.php b/module/LogisticsBundle/Resources/config/install/roles.config.php index da408d2247..2733fe3199 100644 --- a/module/LogisticsBundle/Resources/config/install/roles.config.php +++ b/module/LogisticsBundle/Resources/config/install/roles.config.php @@ -18,6 +18,9 @@ 'logistics_catalog' => array( 'overview', ), + 'logistics_inventory' => array( + 'index', + ), ), ), ); diff --git a/module/ShopBundle/Controller/Admin/OpeningHourController.php b/module/ShopBundle/Controller/Admin/OpeningHourController.php new file mode 100644 index 0000000000..c37aeaa519 --- /dev/null +++ b/module/ShopBundle/Controller/Admin/OpeningHourController.php @@ -0,0 +1,288 @@ + + */ +class OpeningHourController extends \CommonBundle\Component\Controller\ActionController\AdminController +{ + public function manageAction() + { + $paginator = $this->paginator()->createFromQuery( + $this->getEntityManager() + ->getRepository('ShopBundle\Entity\Session\OpeningHour') + ->findAllActiveQuery(), + $this->getParam('page') + ); + + return new ViewModel( + array( + 'paginator' => $paginator, + 'paginationControl' => $this->paginator()->createControl(true), + ) + ); + } + + public function oldAction() + { + $paginator = $this->paginator()->createFromQuery( + $this->getEntityManager() + ->getRepository('ShopBundle\Entity\Session\OpeningHour') + ->findAllOldQuery(), + $this->getParam('page') + ); + + return new ViewModel( + array( + 'paginator' => $paginator, + 'paginationControl' => $this->paginator()->createControl(true), + ) + ); + } + + public function addAction() + { + $form = $this->getForm('shop_session_opening-hour_add'); + + if ($this->getRequest()->isPost()) { + $form->setData($this->getRequest()->getPost()); + + if ($form->isValid()) { + $this->getEntityManager()->persist( + $form->hydrateObject() + ); + + $this->getEntityManager()->flush(); + + $this->flashMessenger()->success( + 'Succes', + 'The opening hour was successfully added!' + ); + + $this->redirect()->toRoute( + 'shop_admin_shop_openinghour', + array( + 'action' => 'manage', + ) + ); + + return new ViewModel(); + } + } + + return new ViewModel( + array( + 'form' => $form, + ) + ); + } + + public function editAction() + { + $openingHour = $this->getOpeningHourEntity(); + if ($openingHour === null) { + return new ViewModel(); + } + + $form = $this->getForm('shop_session_opening-hour_edit', $openingHour); + + if ($this->getRequest()->isPost()) { + $form->setData($this->getRequest()->getPost()); + + if ($form->isValid()) { + $this->getEntityManager()->flush(); + + $this->flashMessenger()->success( + 'Succes', + 'The opening hour was successfully updated!' + ); + + $this->redirect()->toRoute( + 'shop_admin_shop_openinghour', + array( + 'action' => 'manage', + ) + ); + + return new ViewModel(); + } + } + + return new ViewModel( + array( + 'form' => $form, + ) + ); + } + + public function scheduleAction() + { + $form = $this->getForm('shop_session_opening-hour_schedule'); + $shiftForm = $this->getForm('shift_shift_schedule'); + + $monday = new DateTime(); // create DateTime object with current time + $monday->setISODate($monday->format('o'), $monday->format('W') + 1); // set object to Monday on next week + + if ($this->getRequest()->isPost()) { + $form->setData($this->getRequest()->getPost()); + + if ($form->isValid()) { + $formData = $form->getData(); + foreach ($formData as $formKey => $formValue) { + $split = explode("_", $formKey); + if ($split[0] == 'interval' && $formValue) { + $startHour = explode('-', $split[1])[0]; + $endHour = explode('-', $split[1])[1]; + $startDate = $split[2] . ' ' . $startHour; + $endDate = $split[2] . ' ' . $endHour; + + $data = array( + // OPENING HOURS + 'start_date' => $startDate, + 'end_date' => $endDate, + // ALL SHIFTS + 'name' => '', + 'description' => '', + 'manager' => false, + 'unit' => 2, + 'event' => '', + 'location' => 1, + 'nb_responsibles' => 0, + 'nb_volunteers' => 4, + 'nb_volunteers_min' => 2, + 'reward' => 2, + 'handled_on_event' => false, + 'ticket_needed' => false, + 'points' => 0, + ); + + // OPENING HOURS + $this->getEntityManager()->persist( + $form->getHydrator()->hydrate($data) + ); + + // SHIFTS + // Broodjes smeren + $data['name'] = 'Broodjes smeren'; + $data['description'] = 'Kom broodjes smeren! (gratis degustaties inbegrepen)'; + $data['start_date'] = $split[2] . ' 10:30'; + $data['end_date'] = $split[2] . ' 12:30'; + $this->getEntityManager()->persist( + $shiftForm->getHydrator()->hydrate($data) + ); + // Broodjes verkopen + $data['name'] = 'Broodjes verkopen'; + $data['description'] = 'Kom broodjes verkopen en geniet van een zelfgemaakt broodje en de geweldige shiftersvoorzieningen!'; + $data['start_date'] = $split[2] . ' 12:30'; + $data['end_date'] = $split[2] . ' 14:00'; + $this->getEntityManager()->persist( + $shiftForm->getHydrator()->hydrate($data) + ); + // Namiddagverkoop + $data['name'] = 'Namiddagverkoop'; + $data['description'] = 'Help ons met de laatste broodjes te verkopen, maak en paar croques en geniet van een mooie namiddag.'; + $data['start_date'] = $split[2] . ' 14:00'; + $data['end_date'] = $split[2] . ' 16:00'; + $data['nb_volunteers'] = 2; + $data['nb_volunteers_min'] = 0; + $this->getEntityManager()->persist( + $shiftForm->getHydrator()->hydrate($data) + ); + } + } + + $this->getEntityManager()->flush(); + + $this->flashMessenger()->success( + 'Succes', + 'This schedule was successfully added!' + ); + + $this->redirect()->toRoute( + 'shop_admin_shop_openinghour', + array( + 'action' => 'manage', + ) + ); + + return new ViewModel(); + } + } + + return new ViewModel( + array( + 'form' => $form, + 'nextMonday' => $monday, + ) + ); + } + + public function deleteAction() + { + $this->initAjax(); + + $openingHour = $this->getOpeningHourEntity(); + if ($openingHour === null) { + return new ViewModel(); + } + + $this->getEntityManager()->remove($openingHour); + $this->getEntityManager()->flush(); + + return new ViewModel( + array( + 'result' => (object) array('status' => 'success'), + ) + ); + } + + /** + * @return OpeningHour|null + */ + private function getOpeningHourEntity() + { + $openingHour = $this->getEntityById('ShopBundle\Entity\Session\OpeningHour'); + + if (!($openingHour instanceof OpeningHour)) { + $this->flashMessenger()->error( + 'Error', + 'No opening hour was found!' + ); + + $this->redirect()->toRoute( + 'shop_admin_shop_openinghour', + array( + 'action' => 'manage', + ) + ); + + return; + } + + return $openingHour; + } + + /** + * @return string + */ + private function calculateNextTime($time) + { + $hour = explode(':', $time)[0]; + $minute = explode(':', $time)[1]; + if ($minute == '00') { + $minute = '30'; + } else { + $hour = strval($hour + 1); + $minute = '00'; + } + + return $hour . ':' . $minute; + } +} diff --git a/module/ShopBundle/Entity/Session/OpeningHour.php b/module/ShopBundle/Entity/Session/OpeningHour.php new file mode 100644 index 0000000000..411c5d4f27 --- /dev/null +++ b/module/ShopBundle/Entity/Session/OpeningHour.php @@ -0,0 +1,199 @@ +person = $person; + $this->creationTime = new DateTime(); + + $this->translations = new ArrayCollection(); + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @return DateTime + */ + public function getStartDate() + { + return $this->startDate; + } + + /** + * @param DateTime $startDate + * @return self + */ + public function setStartDate(DateTime $startDate) + { + $this->startDate = $startDate; + + return $this; + } + + /** + * @return DateTime + */ + public function getEndDate() + { + return $this->endDate; + } + + /** + * @param DateTime $endDate + * @return self + */ + public function setEndDate(DateTime $endDate) + { + $this->endDate = $endDate; + + return $this; + } + + /** + * @return Person + */ + public function getPerson() + { + return $this->person; + } + + /** + * @return DateTime + */ + public function getCreationTime() + { + return $this->creationTime; + } + + /** + * @param Language|null $language + * @param boolean $allowFallback + * @return Translation|null + */ + public function getTranslation(Language $language = null, $allowFallback = true) + { + foreach ($this->translations as $translation) { + if ($language !== null && $translation->getLanguage() == $language) { + return $translation; + } + + if ($translation->getLanguage()->getAbbrev() == Locale::getDefault()) { + $fallbackTranslation = $translation; + } + } + + if ($allowFallback && isset($fallbackTranslation)) { + return $fallbackTranslation; + } + + return null; + } + + /** + * @param Language $language + * @return string + */ + public function getComment(Language $language, $allowFallback = true) + { + $translation = $this->getTranslation($language, $allowFallback); + + if ($translation !== null) { + return $translation->getComment(); + } + + return ''; + } + + /** + * @param Language $language + * @param string|null $comment + * @return self + */ + public function setComment(Language $language, $comment = null) + { + $translation = $this->getTranslation($language, false); + + if ($comment === null) { + if ($translation !== null) { + $this->translations->removeElement($translation); + } + } else { + if ($translation === null) { + $this->translations->add(new Translation($this, $language, $comment)); + } else { + $translation->setComment($comment); + } + } + + return $this; + } +} diff --git a/module/ShopBundle/Entity/Session/OpeningHour/Translation.php b/module/ShopBundle/Entity/Session/OpeningHour/Translation.php new file mode 100644 index 0000000000..822ad8dbc1 --- /dev/null +++ b/module/ShopBundle/Entity/Session/OpeningHour/Translation.php @@ -0,0 +1,104 @@ +openingHour = $openingHour; + $this->language = $language; + $this->comment = $comment; + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @return OpeningHour + */ + public function getOpeningHour() + { + return $this->openingHour; + } + + /** + * @return Language + */ + public function getLanguage() + { + return $this->language; + } + + /** + * @return string + */ + public function getComment() + { + return $this->comment; + } + + /** + * @param string $comment + * + * @return self + */ + public function setComment($comment) + { + $this->comment = $comment; + + return $this; + } +} diff --git a/module/ShopBundle/Form/Admin/Session/OpeningHour/Add.php b/module/ShopBundle/Form/Admin/Session/OpeningHour/Add.php new file mode 100644 index 0000000000..6bbe050591 --- /dev/null +++ b/module/ShopBundle/Form/Admin/Session/OpeningHour/Add.php @@ -0,0 +1,73 @@ + + */ +class Add extends \CommonBundle\Component\Form\Admin\Form\Tabbable +{ + protected $hydrator = 'ShopBundle\Hydrator\Session\OpeningHour'; + + protected function initBeforeTabs() + { + $this->add( + array( + 'type' => 'datetime', + 'name' => 'start_date', + 'label' => 'Start', + 'required' => true, + ) + ); + + $this->add( + array( + 'type' => 'datetime', + 'name' => 'end_date', + 'label' => 'End', + 'required' => true, + 'options' => array( + 'input' => array( + 'validators' => array( + array( + 'name' => 'DateCompare', + 'options' => array( + 'first_date' => 'start_date', + 'format' => 'd/m/Y H:i', + ), + ), + ), + ), + ), + ) + ); + } + + protected function addTab(FieldsetInterface $container, Language $language, $isDefault) + { + $container->add( + array( + 'type' => 'text', + 'name' => 'comment', + 'label' => 'Comment', + 'options' => array( + 'input' => array( + 'filters' => array( + array('name' => 'StringTrim'), + ), + ), + ), + ) + ); + } + + protected function initAfterTabs() + { + $this->addSubmit('Add', 'clock_add'); + } +} diff --git a/module/ShopBundle/Form/Admin/Session/OpeningHour/Edit.php b/module/ShopBundle/Form/Admin/Session/OpeningHour/Edit.php new file mode 100644 index 0000000000..e6ee3c3e6b --- /dev/null +++ b/module/ShopBundle/Form/Admin/Session/OpeningHour/Edit.php @@ -0,0 +1,19 @@ + + */ +class Edit extends \ShopBundle\Form\Admin\Session\OpeningHour\Add +{ + public function init() + { + parent::init(); + + $this->remove('submit') + ->addSubmit('Save', 'clock_edit'); + } +} diff --git a/module/ShopBundle/Form/Admin/Session/OpeningHour/Schedule.php b/module/ShopBundle/Form/Admin/Session/OpeningHour/Schedule.php new file mode 100644 index 0000000000..d7b2c4b2c8 --- /dev/null +++ b/module/ShopBundle/Form/Admin/Session/OpeningHour/Schedule.php @@ -0,0 +1,152 @@ + + */ +class Schedule extends \CommonBundle\Component\Form\Admin\Form +{ + protected $hydrator = 'ShopBundle\Hydrator\Session\OpeningHour'; + + public function init() + { + parent::init(); + + $days = $this->createDaysArray(); + + foreach ($days as $day) { + $this->add( + array( + 'type' => 'checkbox', + 'name' => 'interval_12:30-14:00_' . $day->format('d/m/Y'), + 'label' => $day->format('l') . ' 12:30 - 14:00', + 'required' => true, + 'attributes' => array( + 'id' => 'interval_12:30-14:00_' . $day->format('d/m/Y'), + ), + ) + ); + + $this->add( + array( + 'type' => 'text', + 'name' => 'volunteers_12:30-14:00_' . $day->format('d/m/Y'), + 'label' => 'Volunteers', + 'attributes' => array( + 'value' => '0', + ), + 'options' => array( + 'input' => array( + 'filters' => array( + array('name' => 'StringTrim'), + ), + 'validators' => array( + array('name' => 'Int'), + ), + ), + ), + ) + ); + + $this->add( + array( + 'type' => 'text', + 'name' => 'volunteers-min_12:30-14:00_' . $day->format('d/m/Y'), + 'label' => 'Min. Volunteers', + 'attributes' => array( + 'value' => '0', + ), + 'options' => array( + 'input' => array( + 'filters' => array( + array('name' => 'StringTrim'), + ), + 'validators' => array( + array('name' => 'Int'), + ), + ), + ), + ) + ); + + $this->add( + array( + 'type' => 'checkbox', + 'name' => 'interval_18:00-19:00_' . $day->format('d/m/Y'), + 'label' => '18:00 - 19:00', + 'required' => true, + 'attributes' => array( + 'id' => 'interval_18:00-19:00_' . $day->format('d/m/Y'), + ), + ) + ); + + $this->add( + array( + 'type' => 'text', + 'name' => 'volunteers_18:00-19:00_' . $day->format('d/m/Y'), + 'label' => 'Volunteers', + 'attributes' => array( + 'value' => '0', + ), + 'options' => array( + 'input' => array( + 'filters' => array( + array('name' => 'StringTrim'), + ), + 'validators' => array( + array('name' => 'Int'), + ), + ), + ), + ) + ); + + $this->add( + array( + 'type' => 'text', + 'name' => 'volunteers-min_18:00-19:00_' . $day->format('d/m/Y'), + 'label' => 'Min. Volunteers', + 'attributes' => array( + 'value' => '0', + ), + 'options' => array( + 'input' => array( + 'filters' => array( + array('name' => 'StringTrim'), + ), + 'validators' => array( + array('name' => 'Int'), + ), + ), + ), + ) + ); + } + + $this->addSubmit('Add', 'clock_add'); + } + + /** + * @return array + */ + private function createDaysArray() + { + $dt = new DateTime(); // create DateTime object with current time + $dt->setISODate($dt->format('o'), $dt->format('W') + 1); // set object to Monday on next week + $periods = new DatePeriod($dt, new DateInterval('P1D'), 3); // get all 1day periods from Monday to +6 days + $days = iterator_to_array($periods); // convert DatePeriod object to array + // $days[0] is Monday, ..., $days[3] is Thursday + // to format selected date do: $days[1]->format('Y-m-d'); + + return $days; + } +} + diff --git a/module/ShopBundle/Hydrator/Session/OpeningHour.php b/module/ShopBundle/Hydrator/Session/OpeningHour.php new file mode 100644 index 0000000000..bbacaa6552 --- /dev/null +++ b/module/ShopBundle/Hydrator/Session/OpeningHour.php @@ -0,0 +1,53 @@ + $object->getStartDate()->format('d/m/Y H:i'), + 'end_date' => $object->getEndDate()->format('d/m/Y H:i'), + 'tab_content' => array(), + ); + + foreach ($this->getLanguages() as $language) { + $data['tab_content']['tab_' . $language->getAbbrev()] = array( + 'comment' => $object->getComment($language, false), + ); + } + + return $data; + } + + protected function doHydrate(array $data, $object = null) + { + if ($object === null) { + $object = new OpeningHourEntity($this->getPersonEntity()); + } + $object->setStartDate(self::loadDateTime($data['start_date'])) + ->setEndDate(self::loadDateTime($data['end_date'])); + + foreach ($this->getLanguages() as $language) { + $abbrev = $language->getAbbrev(); + + if (isset($data['tab_content']) + && isset($data['tab_content']['tab_' . $abbrev]) + && isset($data['tab_content']['tab_' . $abbrev]['comment']) + ) { + $object->setComment($language, $data['tab_content']['tab_' . $abbrev]['comment']); + } else { + $object->setComment($language, null); + } + } + + return $object; + } +} diff --git a/module/ShopBundle/Repository/Session/OpeningHour.php b/module/ShopBundle/Repository/Session/OpeningHour.php new file mode 100644 index 0000000000..0a03c7da8a --- /dev/null +++ b/module/ShopBundle/Repository/Session/OpeningHour.php @@ -0,0 +1,173 @@ +getEntityManager()->createQueryBuilder(); + return $query->select('o') + ->from('ShopBundle\Entity\Session\OpeningHour', 'o') + ->where( + $query->expr()->gte('o.endDate', ':now') + ) + ->setParameter('now', new DateTime()) + ->orderBy('o.startDate', 'ASC') + ->getQuery(); + } + + /** + * @return \Doctrine\ORM\Query + */ + public function findAllOldQuery() + { + $query = $this->getEntityManager()->createQueryBuilder(); + return $query->select('o') + ->from('ShopBundle\Entity\Session\OpeningHour', 'o') + ->where( + $query->expr()->lt('o.endDate', ':now') + ) + ->setParameter('now', new DateTime()) + ->orderBy('o.startDate', 'DESC') + ->getQuery(); + } + + /** + * @return \Doctrine\ORM\Query + */ + public function findCurrentWeekQuery() + { + $start = new DateTime(); + $start->setTime(0, 0); + if ($start->format('N') > 5) { + $start->add(new DateInterval('P' . (8 - $start->format('N')) . 'D')); + } else { + $start->sub(new DateInterval('P' . ($start->format('N') - 1) . 'D')); + } + + $end = clone $start; + $end->add(new DateInterval('P7D')); + + $query = $this->getEntityManager()->createQueryBuilder(); + return $query->select('o') + ->from('ShopBundle\Entity\Session\OpeningHour', 'o') + ->where( + $query->expr()->andX( + $query->expr()->gt('o.startDate', ':start'), + $query->expr()->lt('o.endDate', ':end') + ) + ) + ->setParameter('start', $start) + ->setParameter('end', $end) + ->orderBy('o.startDate') + ->getQuery(); + } + + /** + * @param DateInterval $interval + * @return \Doctrine\ORM\Query + */ + public function findCommingIntervalQuery(DateInterval $interval) + { + $start = new DateTime(); + + $end = clone $start; + $end->add($interval); + + $query = $this->getEntityManager()->createQueryBuilder(); + return $query->select('o') + ->from('ShopBundle\Entity\Session\OpeningHour', 'o') + ->where( + $query->expr()->andX( + $query->expr()->gt('o.endDate', ':start'), + $query->expr()->lt('o.startDate', ':end') + ) + ) + ->setParameter('start', $start) + ->setParameter('end', $end) + ->orderBy('o.startDate') + ->getQuery(); + } + + /** + * @param string $interval + * @return \Doctrine\ORM\Query + */ + public function findPeriodFromNowQuery($interval = 'P14D') + { + $start = new DateTime(); + + $end = clone $start; + $end->setTime(0, 0); + $end->add(new DateInterval($interval)); + + $query = $this->getEntityManager()->createQueryBuilder(); + return $query->select('o') + ->from('ShopBundle\Entity\Session\OpeningHour', 'o') + ->where( + $query->expr()->andX( + $query->expr()->gt('o.endDate', ':start'), + $query->expr()->lt('o.endDate', ':end') + ) + ) + ->setParameter('start', $start) + ->setParameter('end', $end) + ->orderBy('o.startDate') + ->getQuery(); + } + + /** + * @return \ShopBundle\Entity\Session\OpeningHour|null + */ + public function findCurrent() + { + $query = $this->getEntityManager()->createQueryBuilder(); + return $query->select('o') + ->from('ShopBundle\Entity\Session\OpeningHour', 'o') + ->where( + $query->expr()->andX( + $query->expr()->lt('o.startDate', ':now'), + $query->expr()->gt('o.endDate', ':now') + ) + ) + ->setParameter('now', new DateTime()) + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(); + } + + /** + * @param $start DateTime + * @param $end DateTime + * @return \Doctrine\ORM\Query + */ + public function findBetweenQuery($start, $end) + { + $query = $this->getEntityManager()->createQueryBuilder(); + return $query->select('o') + ->from('ShopBundle\Entity\Session\OpeningHour', 'o') + ->where( + $query->expr()->andX( + $query->expr()->gt('o.endDate', ':start'), + $query->expr()->lt('o.endDate', ':end') + ) + ) + ->setParameter('start', $start) + ->setParameter('end', $end) + ->orderBy('o.startDate') + ->getQuery(); + } +} diff --git a/module/ShopBundle/Repository/Session/OpeningHour/Translation.php b/module/ShopBundle/Repository/Session/OpeningHour/Translation.php new file mode 100644 index 0000000000..475f9a97d1 --- /dev/null +++ b/module/ShopBundle/Repository/Session/OpeningHour/Translation.php @@ -0,0 +1,13 @@ + 'manage', 'title' => 'Message', ), + 'shop_admin_shop_openinghour' => array( + 'action' => 'manage', + 'title' => 'Opening Hours', + 'help' => 'Manage the opening hours of the Theokot. These opening hours will be shown on the website.', + ), ), 'controllers' => array('shop_admin_shop'), diff --git a/module/ShopBundle/Resources/config/assetic.config.php b/module/ShopBundle/Resources/config/assetic.config.php index 26837d3c86..64f8b90321 100644 --- a/module/ShopBundle/Resources/config/assetic.config.php +++ b/module/ShopBundle/Resources/config/assetic.config.php @@ -65,6 +65,18 @@ '@common_jquery_form', '@common_remote_typeahead', ), + 'shop_admin_shop_openinghour' => array( + '@common_jquery', + '@admin_css', + '@admin_js', + '@bootstrap_js_tab', + '@bootstrap_js_transition', + '@bootstrap_js_modal', + '@common_jqueryui', + '@common_jqueryui_datepicker', + '@common_jqueryui_css', + '@common_jqueryui_datepicker_css', + ), 'shop' => array( '@common_jquery', diff --git a/module/ShopBundle/Resources/config/install/acl.config.php b/module/ShopBundle/Resources/config/install/acl.config.php index d04c92a2e9..be6e2a9050 100644 --- a/module/ShopBundle/Resources/config/install/acl.config.php +++ b/module/ShopBundle/Resources/config/install/acl.config.php @@ -20,5 +20,8 @@ 'shop_admin_shop_message' => array( 'manage', 'delete', 'add', 'edit', ), + 'shop_admin_shop_openinghour' => array( + 'add', 'edit', 'schedule', 'delete', 'manage', 'old', + ), ), ); diff --git a/module/ShopBundle/Resources/config/router.config.php b/module/ShopBundle/Resources/config/router.config.php index f656f63a6e..02a5e92ae2 100644 --- a/module/ShopBundle/Resources/config/router.config.php +++ b/module/ShopBundle/Resources/config/router.config.php @@ -103,6 +103,23 @@ ), ), ), + 'shop_admin_shop_openinghour' => array( + 'type' => 'Laminas\Router\Http\Segment', + 'options' => array( + 'route' => '/admin/shop/openinghours[/:action[/page/:page][/:id]][/]', + 'constraints' => array( + 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', + 'id' => '[0-9]*', + 'page' => '[0-9]*', + 'field' => '[a-zA-Z][a-zA-Z0-9_-]*', + 'string' => '[a-zA-Z][%a-zA-Z0-9:.,_-]*', + ), + 'defaults' => array( + 'controller' => 'shop_admin_shop_openinghour', + 'action' => 'manage', + ), + ), + ), 'shop' => array( 'type' => 'Laminas\Router\Http\Segment', 'options' => array( @@ -126,6 +143,7 @@ 'shop_admin_shop_reservation' => 'ShopBundle\Controller\Admin\ReservationController', 'shop_admin_shop_reservationpermission' => 'ShopBundle\Controller\Admin\ReservationPermissionController', 'shop_admin_shop_message' => 'ShopBundle\Controller\Admin\MessageController', + 'shop_admin_shop_openinghour ' => 'ShopBundle\Controller\Admin\OpeningHourController', 'shop' => 'ShopBundle\Controller\ShopController', ), ); diff --git a/module/ShopBundle/Resources/views/shop/admin/opening-hour/add.twig b/module/ShopBundle/Resources/views/shop/admin/opening-hour/add.twig new file mode 100644 index 0000000000..316ebd499b --- /dev/null +++ b/module/ShopBundle/Resources/views/shop/admin/opening-hour/add.twig @@ -0,0 +1,20 @@ +{% extends 'admin/base.twig' %} + +{% block content %} + {% include 'shop/admin/opening-hour/partials/navigation.twig' %} + + {% include 'admin/partials/flashMessenger.twig' %} + +
+ {% import 'admin/partials/form.twig' as forms %} + {{ forms.renderForm(form) }} +
+{% endblock %} + +{% block content_script %} + +{% endblock %} diff --git a/module/ShopBundle/Resources/views/shop/admin/opening-hour/delete.twig b/module/ShopBundle/Resources/views/shop/admin/opening-hour/delete.twig new file mode 100644 index 0000000000..89e8fe679b --- /dev/null +++ b/module/ShopBundle/Resources/views/shop/admin/opening-hour/delete.twig @@ -0,0 +1,3 @@ +{% autoescape false %} + {{ result|json_encode }} +{% endautoescape %} diff --git a/module/ShopBundle/Resources/views/shop/admin/opening-hour/edit.twig b/module/ShopBundle/Resources/views/shop/admin/opening-hour/edit.twig new file mode 100644 index 0000000000..24d388957c --- /dev/null +++ b/module/ShopBundle/Resources/views/shop/admin/opening-hour/edit.twig @@ -0,0 +1 @@ +{% extends 'shop/admin/opening-hour/add.twig' %} diff --git a/module/ShopBundle/Resources/views/shop/admin/opening-hour/manage.twig b/module/ShopBundle/Resources/views/shop/admin/opening-hour/manage.twig new file mode 100644 index 0000000000..7e60e3c662 --- /dev/null +++ b/module/ShopBundle/Resources/views/shop/admin/opening-hour/manage.twig @@ -0,0 +1,111 @@ +{% extends 'admin/base.twig' %} + +{% block content %} + {% include 'shop/admin/opening-hour/partials/navigation.twig' %} + + {% include 'admin/partials/flashMessenger.twig' %} +
+
Success
+
+

The opening hour was successfully removed!

+
+
+
+
Error
+
+

An error occurred while trying to delete the opening hour.

+
+
+ +
+ + + + + + + + + + + {% for openingHour in paginator %} + + + + + + + + {% endfor %} +
PersonStartEndCommentAction
{{ openingHour.getPerson().getFullName() }}{{ openingHour.getStartDate().format('Y-m-d H:i') }}{{ openingHour.getEndDate().format('Y-m-d H:i') }}{{ openingHour.getComment(language) }} + {% if hasAccess('shop_admin_shop_openinghour', 'edit') %} + Edit + {% endif %} + {% if hasAccess('shop_admin_shop_openinghour', 'delete') %} + Delete + {% endif %} +
+ + {% include 'admin/partials/paginationControl.twig' %} +
+ + +{% endblock %} + +{% block content_script %} + +{% endblock %} diff --git a/module/ShopBundle/Resources/views/shop/admin/opening-hour/old.twig b/module/ShopBundle/Resources/views/shop/admin/opening-hour/old.twig new file mode 100644 index 0000000000..a49cd2b145 --- /dev/null +++ b/module/ShopBundle/Resources/views/shop/admin/opening-hour/old.twig @@ -0,0 +1 @@ +{% extends 'shop/admin/opening-hour/manage.twig' %} diff --git a/module/ShopBundle/Resources/views/shop/admin/opening-hour/partials/navigation.twig b/module/ShopBundle/Resources/views/shop/admin/opening-hour/partials/navigation.twig new file mode 100644 index 0000000000..76659ba82d --- /dev/null +++ b/module/ShopBundle/Resources/views/shop/admin/opening-hour/partials/navigation.twig @@ -0,0 +1,19 @@ +
+
Opening Hours
+ +
diff --git a/module/ShopBundle/Resources/views/shop/admin/opening-hour/schedule.twig b/module/ShopBundle/Resources/views/shop/admin/opening-hour/schedule.twig new file mode 100644 index 0000000000..08c4c92a71 --- /dev/null +++ b/module/ShopBundle/Resources/views/shop/admin/opening-hour/schedule.twig @@ -0,0 +1,12 @@ +{% extends 'admin/base.twig' %} + +{% block content %} + {% include 'shop/admin/opening-hour/partials/navigation.twig' %} + + {% include 'admin/partials/flashMessenger.twig' %} +

Week: {{ nextMonday.format('l d/m') }} - {{ nextMonday.modify('next thursday').format('l d/m') }}

+
+ {% import 'admin/partials/form.twig' as forms %} + {{ forms.renderForm(form) }} +
+{% endblock %} \ No newline at end of file