From d950df435eeb7716b69466e7cdf6dd8ddf251dce Mon Sep 17 00:00:00 2001 From: Dries Vanspauwen Date: Mon, 6 Nov 2023 14:32:12 +0000 Subject: [PATCH] refactor reservationpermission into ban --- .../Controller/Admin/BanController.php | 135 +++++++++++++- .../Admin/ReservationController.php | 1 - .../Admin/ReservationPermissionController.php | 175 ------------------ .../Entity/Reservation/Permission.php | 67 ------- .../Form/Admin/ReservationPermission/Add.php | 50 ----- .../Hydrator/Reservation/Permission.php | 31 ---- .../Repository/Reservation/Permission.php | 46 ----- .../Resources/config/admin.config.php | 2 +- .../Resources/config/assetic.config.php | 2 +- .../Resources/config/install/acl.config.php | 2 +- .../Resources/config/router.config.php | 10 +- .../{reservation-permission => ban}/add.twig | 2 +- .../delete.twig | 0 .../manage.twig | 12 +- .../{reservation-permission => ban}/old.twig | 12 +- .../shop/admin/ban/partials/navigation.twig | 20 ++ .../search.twig | 0 .../togglepermission.twig | 0 .../partials/navigation.twig | 20 -- 19 files changed, 175 insertions(+), 412 deletions(-) delete mode 100644 module/ShopBundle/Controller/Admin/ReservationPermissionController.php delete mode 100644 module/ShopBundle/Entity/Reservation/Permission.php delete mode 100644 module/ShopBundle/Form/Admin/ReservationPermission/Add.php delete mode 100644 module/ShopBundle/Hydrator/Reservation/Permission.php delete mode 100644 module/ShopBundle/Repository/Reservation/Permission.php rename module/ShopBundle/Resources/views/shop/admin/{reservation-permission => ban}/add.twig (92%) rename module/ShopBundle/Resources/views/shop/admin/{reservation-permission => ban}/delete.twig (100%) rename module/ShopBundle/Resources/views/shop/admin/{reservation-permission => ban}/manage.twig (91%) rename module/ShopBundle/Resources/views/shop/admin/{reservation-permission => ban}/old.twig (91%) create mode 100644 module/ShopBundle/Resources/views/shop/admin/ban/partials/navigation.twig rename module/ShopBundle/Resources/views/shop/admin/{reservation-permission => ban}/search.twig (100%) rename module/ShopBundle/Resources/views/shop/admin/{reservation-permission => ban}/togglepermission.twig (100%) delete mode 100644 module/ShopBundle/Resources/views/shop/admin/reservation-permission/partials/navigation.twig diff --git a/module/ShopBundle/Controller/Admin/BanController.php b/module/ShopBundle/Controller/Admin/BanController.php index 2f9ff20cb8..7e1aff91da 100644 --- a/module/ShopBundle/Controller/Admin/BanController.php +++ b/module/ShopBundle/Controller/Admin/BanController.php @@ -3,7 +3,13 @@ namespace ShopBundle\Controller\Admin; use Laminas\View\Model\ViewModel; +use ShopBundle\Repository\Reservation\Ban; +/** + * BanPermissionController + * + * @author Floris Kint + */ class BanController extends \CommonBundle\Component\Controller\ActionController\AdminController { public function manageAction() @@ -39,4 +45,131 @@ public function oldAction() ) ); } -} \ No newline at end of file + +// shop_reservationPermission_add + + public function addAction() + { + $form = $this->getForm('shop_reservation_ban_add'); + + if ($this->getRequest()->isPost()) { + $formData = $this->getRequest()->getPost(); + $form->setData($formData); + + if ($form->isValid()) { + error_log("before hydrate"); + $ban = $form->hydrateObject(); + error_log("before persist"); + $this->getEntityManager()->persist($ban); + error_log("before flush"); + $this->getEntityManager()->flush(); + + $this->flashMessenger()->success( + 'Success', + 'The ban was successfully created!' + ); + + $this->redirect()->toRoute( + 'shop_admin_shop_ban', + array( + 'action' => 'add', + ) + ); + + return new ViewModel(); + } + } + + return new ViewModel( + array( + 'form' => $form, + ) + ); + } + + public function deleteAction() + { + $this->initAjax(); + + $ban = $this->getBanEntity(); + if ($ban === null) { + return new ViewModel(); + } + + $this->getEntityManager()->remove($ban); + $this->getEntityManager()->flush(); + + return new ViewModel( + array( + 'result' => array( + 'status' => 'success', + ), + ) + ); + } + + /** + * @return Ban|null + */ + private function getBanEntity() + { + $ban = $this->getEntityById('ShopBundle\Entity\Reservation\Ban'); + + if (!($ban instanceof Ban)) { + $this->flashMessenger()->error( + 'Error', + 'No ban was found!' + ); + + $this->redirect()->toRoute( + 'shop_admin_shop_ban', + array( + 'action' => 'manage', + ) + ); + return; + } + return $ban; + } + + public function searchAction() + { +// $this->initAjax(); +// +// $numResults = $this->getEntityManager() +// ->getRepository('CommonBundle\Entity\General\Config') +// ->getConfigValue('search_max_results'); +// +// $reservationPermissions = $this->search() +// ->setMaxResults($numResults) +// ->getResult(); +// +// $result = array(); +// foreach ($reservationPermissions as $reservationPermission) { +// $item = (object) array(); +// $item->id = $reservationPermission->getPerson()->getId(); +// $item->name = $reservationPermission->getPerson()->getFullName(); +// $item->reservationsAllowed = $reservationPermission->getReservationsAllowed(); +// $result[] = $item; +// } +// +// return new ViewModel( +// array( +// 'result' => $result, +// ) +// ); + } + + /** + * @return \Doctrine\ORM\Query|null + */ + private function search() + { +// switch ($this->getParam('field')) { +// case 'name': +// return $this->getEntityManager() +// ->getRepository('ShopBundle\Entity\Reservation\Permission') +// ->findByNameQuery($this->getParam('string')); +// } + } +} diff --git a/module/ShopBundle/Controller/Admin/ReservationController.php b/module/ShopBundle/Controller/Admin/ReservationController.php index 595fe677c0..dfc19e2603 100644 --- a/module/ShopBundle/Controller/Admin/ReservationController.php +++ b/module/ShopBundle/Controller/Admin/ReservationController.php @@ -12,7 +12,6 @@ use ShopBundle\Component\NoShow\NoShowConfig; use ShopBundle\Entity\Reservation; use ShopBundle\Entity\Reservation\Ban; -use ShopBundle\Entity\Reservation\Permission as ReservationPermission; use ShopBundle\Entity\Session as SalesSession; /** diff --git a/module/ShopBundle/Controller/Admin/ReservationPermissionController.php b/module/ShopBundle/Controller/Admin/ReservationPermissionController.php deleted file mode 100644 index da3f687f78..0000000000 --- a/module/ShopBundle/Controller/Admin/ReservationPermissionController.php +++ /dev/null @@ -1,175 +0,0 @@ - - */ -class ReservationPermissionController extends \CommonBundle\Component\Controller\ActionController\AdminController -{ - public function manageAction() - { - $paginator = $this->paginator()->createFromQuery( - $this->getEntityManager() - ->getRepository('ShopBundle\Entity\Reservation\Ban') - ->findActiveQuery(), - $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\Reservation\Ban') - ->findOldQuery(), - $this->getParam('page') - ); - - return new ViewModel( - array( - 'paginator' => $paginator, - 'paginationControl' => $this->paginator()->createControl(true), - ) - ); - } - -// shop_reservationPermission_add - - public function addAction() - { - $form = $this->getForm('shop_reservation_ban_add'); - - if ($this->getRequest()->isPost()) { - $formData = $this->getRequest()->getPost(); - $form->setData($formData); - - if ($form->isValid()) { - error_log("before hydrate"); - $ban = $form->hydrateObject(); - error_log("before persist"); - $this->getEntityManager()->persist($ban); - error_log("before flush"); - $this->getEntityManager()->flush(); - - $this->flashMessenger()->success( - 'Success', - 'The ban was successfully created!' - ); - - $this->redirect()->toRoute( - 'shop_admin_shop_reservationpermission', - array( - 'action' => 'add', - ) - ); - - return new ViewModel(); - } - } - - return new ViewModel( - array( - 'form' => $form, - ) - ); - } - - public function deleteAction() - { - $this->initAjax(); - - $ban = $this->getBanEntity(); - if ($ban === null) { - return new ViewModel(); - } - - $this->getEntityManager()->remove($ban); - $this->getEntityManager()->flush(); - - return new ViewModel( - array( - 'result' => array( - 'status' => 'success', - ), - ) - ); - } - - /** - * @return Ban|null - */ - private function getBanEntity() - { - $ban = $this->getEntityById('ShopBundle\Entity\Reservation\Ban'); - - if (!($ban instanceof Ban)) { - $this->flashMessenger()->error( - 'Error', - 'No ban was found!' - ); - - $this->redirect()->toRoute( - 'shop_admin_shop_reservationpermission', - array( - 'action' => 'manage', - ) - ); - return; - } - return $ban; - } - - public function searchAction() - { -// $this->initAjax(); -// -// $numResults = $this->getEntityManager() -// ->getRepository('CommonBundle\Entity\General\Config') -// ->getConfigValue('search_max_results'); -// -// $reservationPermissions = $this->search() -// ->setMaxResults($numResults) -// ->getResult(); -// -// $result = array(); -// foreach ($reservationPermissions as $reservationPermission) { -// $item = (object) array(); -// $item->id = $reservationPermission->getPerson()->getId(); -// $item->name = $reservationPermission->getPerson()->getFullName(); -// $item->reservationsAllowed = $reservationPermission->getReservationsAllowed(); -// $result[] = $item; -// } -// -// return new ViewModel( -// array( -// 'result' => $result, -// ) -// ); - } - - /** - * @return \Doctrine\ORM\Query|null - */ - private function search() - { -// switch ($this->getParam('field')) { -// case 'name': -// return $this->getEntityManager() -// ->getRepository('ShopBundle\Entity\Reservation\Permission') -// ->findByNameQuery($this->getParam('string')); -// } - } -} diff --git a/module/ShopBundle/Entity/Reservation/Permission.php b/module/ShopBundle/Entity/Reservation/Permission.php deleted file mode 100644 index 84225afb58..0000000000 --- a/module/ShopBundle/Entity/Reservation/Permission.php +++ /dev/null @@ -1,67 +0,0 @@ -person; - } - - /** - * @param Person $person - * @return self - */ - public function setPerson($person) - { - $this->person = $person; - - return $this; - } - - /** - * @return boolean - */ - public function getReservationsAllowed() - { - return $this->reservationsAllowed; - } - - /** - * @param boolean $reservationsAllowed - * @return self - */ - public function setReservationsAllowed($reservationsAllowed) - { - $this->reservationsAllowed = $reservationsAllowed; - - return $this; - } -} diff --git a/module/ShopBundle/Form/Admin/ReservationPermission/Add.php b/module/ShopBundle/Form/Admin/ReservationPermission/Add.php deleted file mode 100644 index fa32d31e58..0000000000 --- a/module/ShopBundle/Form/Admin/ReservationPermission/Add.php +++ /dev/null @@ -1,50 +0,0 @@ - - */ -class Add extends \CommonBundle\Component\Form\Admin\Form -{ - protected $hydrator = 'ShopBundle\Hydrator\Reservation\Permission'; - - public function init() - { - parent::init(); - - $this->add( - array( - 'type' => 'typeahead', - 'name' => 'person', - 'label' => 'User', - 'required' => true, - 'options' => array( - 'input' => array( - 'filters' => array( - array('name' => 'StringTrim'), - ), - 'validators' => array( - array('name' => 'TypeaheadPerson'), - ), - ), - ), - ) - ); - - $this->add( - array( - 'type' => 'checkbox', - 'name' => 'reservations_allowed', - 'label' => 'Reservations allowed', - 'attributes' => array( - 'data-help' => 'Enabling this option will allow this client to reserve articles.', - ), - ) - ); - - $this->addSubmit('Add', 'add'); - } -} diff --git a/module/ShopBundle/Hydrator/Reservation/Permission.php b/module/ShopBundle/Hydrator/Reservation/Permission.php deleted file mode 100644 index 26d596a5e0..0000000000 --- a/module/ShopBundle/Hydrator/Reservation/Permission.php +++ /dev/null @@ -1,31 +0,0 @@ -stdHydrate($data, $object, self::$stdKeys); - - $person = $this->getEntityManager() - ->getRepository('CommonBundle\Entity\User\Person') - ->find($data['person']['id']); - $object->setPerson($person); - - return $object; - } -} diff --git a/module/ShopBundle/Repository/Reservation/Permission.php b/module/ShopBundle/Repository/Reservation/Permission.php deleted file mode 100644 index d4d699fcbc..0000000000 --- a/module/ShopBundle/Repository/Reservation/Permission.php +++ /dev/null @@ -1,46 +0,0 @@ -getEntityManager()->createQueryBuilder(); - - return $query->select('rp') - ->from('ShopBundle\Entity\Reservation\Permission', 'rp') - ->join('rp.person', 'p') - ->where( - $query->expr()->orX( - $query->expr()->like($query->expr()->lower($query->expr()->concat('p.firstName', $query->expr()->concat("' '", 'p.lastName'))), ':name'), - $query->expr()->like($query->expr()->lower($query->expr()->concat('p.lastName', $query->expr()->concat("' '", 'p.firstName'))), ':name') - ) - ) - ->orderBy('p.id', 'ASC') - ->setParameter('name', '%' . strtolower($name) . '%') - ->getQuery(); - } - - /** - * @return \Doctrine\ORM\Query - */ - public function findAllQuery() - { - $query = $this->getEntityManager()->createQueryBuilder(); - - return $query->select('rp') - ->from('ShopBundle\Entity\Reservation\Permission', 'rp') - ->getQuery(); - } -} diff --git a/module/ShopBundle/Resources/config/admin.config.php b/module/ShopBundle/Resources/config/admin.config.php index ff9e756be2..54e72177d9 100644 --- a/module/ShopBundle/Resources/config/admin.config.php +++ b/module/ShopBundle/Resources/config/admin.config.php @@ -13,7 +13,7 @@ 'action' => 'manage', 'title' => 'Sales Sessions', ), - 'shop_admin_shop_reservationpermission' => array( + 'shop_admin_shop_ban' => array( 'action' => 'manage', 'title' => 'Bans', ), diff --git a/module/ShopBundle/Resources/config/assetic.config.php b/module/ShopBundle/Resources/config/assetic.config.php index 64f8b90321..58c97cff22 100644 --- a/module/ShopBundle/Resources/config/assetic.config.php +++ b/module/ShopBundle/Resources/config/assetic.config.php @@ -46,7 +46,7 @@ '@common_jqueryui_css', '@common_remote_typeahead', ), - 'shop_admin_shop_reservationpermission' => array( + 'shop_admin_shop_ban' => array( '@common_jquery', '@admin_css', '@admin_js', diff --git a/module/ShopBundle/Resources/config/install/acl.config.php b/module/ShopBundle/Resources/config/install/acl.config.php index 768db1111e..c6f9c718d9 100644 --- a/module/ShopBundle/Resources/config/install/acl.config.php +++ b/module/ShopBundle/Resources/config/install/acl.config.php @@ -14,7 +14,7 @@ 'shop_admin_shop_reservation' => array( 'salessession', 'csv', 'delete', 'noshow', 'search', ), - 'shop_admin_shop_reservationpermission' => array( + 'shop_admin_shop_ban' => array( 'manage', 'old', 'delete', 'add', 'search', ), 'shop_admin_shop_message' => array( diff --git a/module/ShopBundle/Resources/config/router.config.php b/module/ShopBundle/Resources/config/router.config.php index 73a367b669..7aaa8f6bfc 100644 --- a/module/ShopBundle/Resources/config/router.config.php +++ b/module/ShopBundle/Resources/config/router.config.php @@ -68,10 +68,10 @@ ), ), ), - 'shop_admin_shop_reservationpermission' => array( + 'shop_admin_shop_ban' => array( 'type' => 'Laminas\Router\Http\Segment', 'options' => array( - 'route' => '/admin/shop/reservationpermission[/:action[/:id][/type/:type][/page/:page]][/:field/:string][/]', + 'route' => '/admin/shop/ban[/:action[/:id][/type/:type][/page/:page]][/:field/:string][/]', 'constraints' => array( 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[0-9]*', @@ -81,7 +81,7 @@ 'string' => '[a-zA-Z][%a-zA-Z0-9:.,_-]*', ), 'defaults' => array( - 'controller' => 'shop_admin_shop_reservationpermission', + 'controller' => 'shop_admin_shop_ban', 'action' => 'manage', ), ), @@ -141,9 +141,9 @@ 'shop_admin_shop_salessession' => 'ShopBundle\Controller\Admin\SalesSessionController', 'shop_admin_shop_product' => 'ShopBundle\Controller\Admin\ProductController', 'shop_admin_shop_reservation' => 'ShopBundle\Controller\Admin\ReservationController', - 'shop_admin_shop_reservationpermission' => 'ShopBundle\Controller\Admin\ReservationPermissionController', + 'shop_admin_shop_ban' => 'ShopBundle\Controller\Admin\BanController', 'shop_admin_shop_message' => 'ShopBundle\Controller\Admin\MessageController', - 'shop_admin_shop_openinghour' => 'ShopBundle\Controller\Admin\OpeningHourController', + 'shop_admin_shop_openinghour' => 'ShopBundle\Controller\Admin\OpeningHourController', 'shop' => 'ShopBundle\Controller\ShopController', ), ); diff --git a/module/ShopBundle/Resources/views/shop/admin/reservation-permission/add.twig b/module/ShopBundle/Resources/views/shop/admin/ban/add.twig similarity index 92% rename from module/ShopBundle/Resources/views/shop/admin/reservation-permission/add.twig rename to module/ShopBundle/Resources/views/shop/admin/ban/add.twig index 4f8f58c8cd..e47d8e45aa 100644 --- a/module/ShopBundle/Resources/views/shop/admin/reservation-permission/add.twig +++ b/module/ShopBundle/Resources/views/shop/admin/ban/add.twig @@ -1,7 +1,7 @@ {% extends 'admin/base.twig' %} {% block content %} - {% include 'shop/admin/reservation-permission/partials/navigation.twig' %} + {% include 'shop/admin/ban/partials/navigation.twig' %} {% include 'admin/partials/flashMessenger.twig' %} diff --git a/module/ShopBundle/Resources/views/shop/admin/reservation-permission/delete.twig b/module/ShopBundle/Resources/views/shop/admin/ban/delete.twig similarity index 100% rename from module/ShopBundle/Resources/views/shop/admin/reservation-permission/delete.twig rename to module/ShopBundle/Resources/views/shop/admin/ban/delete.twig diff --git a/module/ShopBundle/Resources/views/shop/admin/reservation-permission/manage.twig b/module/ShopBundle/Resources/views/shop/admin/ban/manage.twig similarity index 91% rename from module/ShopBundle/Resources/views/shop/admin/reservation-permission/manage.twig rename to module/ShopBundle/Resources/views/shop/admin/ban/manage.twig index 75049d7521..410eb71fd5 100644 --- a/module/ShopBundle/Resources/views/shop/admin/reservation-permission/manage.twig +++ b/module/ShopBundle/Resources/views/shop/admin/ban/manage.twig @@ -1,7 +1,7 @@ {% extends 'admin/base.twig' %} {% block content %} - {% include 'shop/admin/reservation-permission/partials/navigation.twig' %} + {% include 'shop/admin/ban/partials/navigation.twig' %} {% include 'admin/partials/flashMessenger.twig' %}
@@ -54,7 +54,7 @@ {{ ban.getStartTimestamp().format('d/m/Y H:i') }} {{ ban.getEndTimestamp().format('d/m/Y H:i') }} - {% if hasAccess('shop_admin_shop_reservationpermission', 'delete') %} + {% if hasAccess('shop_admin_shop_ban', 'delete') %} Delete {% endif %} @@ -96,14 +96,14 @@ {% block content_script %}