From dd7a6d618ffc09186ce3d0d1fc8f950ad6462ec0 Mon Sep 17 00:00:00 2001 From: TheCoreDev Date: Wed, 3 Mar 2021 13:43:34 +0100 Subject: [PATCH] =?UTF-8?q?PointRetrait=20:=20cr=C3=A9ation=20et=20suppres?= =?UTF-8?q?sion=20OK,=20il=20reste=20un=20peu=20de=20boulot=20sur=20l'enre?= =?UTF-8?q?gistrement.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- local/modules/PointRetrait/Config/config.xml | 1 + local/modules/PointRetrait/Config/routing.xml | 9 +- .../Controller/backOffice/PlaceController.php | 63 +++++++++++ .../modules/PointRetrait/Form/CreateForm.php | 96 +++++++++++++++++ local/modules/PointRetrait/I18n/fr_FR.php | 10 +- local/modules/PointRetrait/PointRetrait.php | 1 + .../backOffice/default/form/place-create.html | 102 ++++++++++++++++++ .../backOffice/default/places-list.html | 56 +++++++++- 8 files changed, 329 insertions(+), 9 deletions(-) create mode 100644 local/modules/PointRetrait/Form/CreateForm.php create mode 100644 local/modules/PointRetrait/templates/backOffice/default/form/place-create.html diff --git a/local/modules/PointRetrait/Config/config.xml b/local/modules/PointRetrait/Config/config.xml index bd969275..6a47c596 100644 --- a/local/modules/PointRetrait/Config/config.xml +++ b/local/modules/PointRetrait/Config/config.xml @@ -24,6 +24,7 @@
+ diff --git a/local/modules/PointRetrait/Config/routing.xml b/local/modules/PointRetrait/Config/routing.xml index 5909739b..0ba3a772 100644 --- a/local/modules/PointRetrait/Config/routing.xml +++ b/local/modules/PointRetrait/Config/routing.xml @@ -4,7 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - + PointRetrait\Controller\backOffice\ListController::viewAction @@ -19,5 +19,12 @@ PointRetrait\Controller\backOffice\PlaceController::editPlace + + PointRetrait\Controller\backOffice\PlaceController::createPlace + + + + PointRetrait\Controller\backOffice\PlaceController::deletePlace + diff --git a/local/modules/PointRetrait/Controller/backOffice/PlaceController.php b/local/modules/PointRetrait/Controller/backOffice/PlaceController.php index 7fcd35c6..b66e3713 100644 --- a/local/modules/PointRetrait/Controller/backOffice/PlaceController.php +++ b/local/modules/PointRetrait/Controller/backOffice/PlaceController.php @@ -2,14 +2,18 @@ namespace PointRetrait\Controller\backOffice; +use PointRetrait\Model\PdrPlaces; use PointRetrait\Model\PdrPlacesQuery; use PointRetrait\PointRetrait; +use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Propel; +use Symfony\Component\HttpFoundation\RedirectResponse; use Thelia\Controller\Admin\BaseAdminController; use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; use Thelia\Form\Exception\FormValidationException; +use Thelia\Tools\URL; /** * Class PlaceController @@ -62,4 +66,63 @@ class PlaceController extends BaseAdminController return $this->render("places-list"); } + + public function createPlace() + { + // Check current user authorization + if (null !== $response = $this->checkAuth(AdminResources::MODULE, PointRetrait::getModuleCode(), AccessManager::VIEW)) + return $response; + + $con = Propel::getConnection(); + $con->beginTransaction(); + + $error_msg = ""; + $createForm = $this->createForm("pointretrait.place.create", "form"); + + try { + $form = $this->validateForm($createForm, "POST"); + $data = $form->getData(); + + $newPlace = new PdrPlaces(); + $newPlace->fromArray($data, TableMap::TYPE_FIELDNAME); + $newPlace->save(); + $con->commit(); + + } catch (FormValidationException $ex) { + $error_msg = $this->createStandardFormValidationErrorMessage($ex); + } + + if ($this->getRequest()->request->get("success_url") == null) { + return new RedirectResponse(URL::getInstance()->absoluteUrl(PointRetrait::MODULE_URL)); + } else { + return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getRequest()->request->get("success_url"))); + } + } + + + public function deletePlace() + { + // Check current user authorization + if (null !== $response = $this->checkAuth(AdminResources::MODULE, PointRetrait::getModuleCode(), AccessManager::VIEW)) + return $response; + + $placeId = $this->getRequest()->get('attr-place-id'); + $query = PdrPlacesQuery::create()->findById($placeId); + if ($query === null) + $error_msg = "Place not found by Id"; + else + { + $con = Propel::getConnection(); + $con->beginTransaction(); + $query->delete($con); + $con->commit(); + } + + if ($this->getRequest()->request->get("success_url") == null) { + return new RedirectResponse(URL::getInstance()->absoluteUrl(PointRetrait::MODULE_URL)); + } else { + return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getRequest()->request->get("success_url"))); + } + } + } \ No newline at end of file diff --git a/local/modules/PointRetrait/Form/CreateForm.php b/local/modules/PointRetrait/Form/CreateForm.php new file mode 100644 index 00000000..fa5686f6 --- /dev/null +++ b/local/modules/PointRetrait/Form/CreateForm.php @@ -0,0 +1,96 @@ +formBuilder + ->add( + "title", + "text", + [ + "required" => true, + "constraints" => [new Constraints\NotBlank()], + "label" => $this->translator->trans('Place name', [], PointRetrait::DOMAIN_NAME), + "label_attr" => ['for' => 'title'] + ]) + ->add( + "price", + "number", + [ + "required" => true, + "constraints" => [new GreaterThanOrEqual(["value" => 0])], + "label" => $this->translator->trans('Withdrawal price', [], PointRetrait::DOMAIN_NAME), + "label_attr" => ['for' => 'price'] + ]) + ->add( + "minimum_amount", + "number", + [ + "required" => true, + "constraints" => [new GreaterThanOrEqual(["value" => 0])], + "label" => $this->translator->trans('Minimum amount', [], PointRetrait::DOMAIN_NAME), + "label_attr" => ['for' => 'minimum_amount'] + ]) + ->add( + "address1","text", + [ + "required" => true, + "constraints" => [new Constraints\NotBlank()], + "label" => $this->translator->trans('Address1', [], PointRetrait::DOMAIN_NAME), + "label_attr" => ['for' => 'address1'] + ]) + ->add( + "address2","text", + [ + "required" => false, + "label" => $this->translator->trans('Address2', [], PointRetrait::DOMAIN_NAME), + "label_attr" => ['for' => 'address2'] + ]) + ->add( + "zipcode","text", + [ + "required" => true, + "constraints" => [new Constraints\NotBlank()], + "label" => $this->translator->trans('Zipcode', [], PointRetrait::DOMAIN_NAME), + "label_attr" => ['for' => 'zipcode'] + ]) + ->add( + "city","text", + [ + "required" => true, + "constraints" => [new Constraints\NotBlank()], + "label" => $this->translator->trans('City', [], PointRetrait::DOMAIN_NAME), + "label_attr" => ['for' => 'city'] + ]) + ->add( + "active", + "number", + [ + "required" => true + ] + ); + } + + /** + * @inheritDoc + */ + public function getName() + { + return "place_create"; + } +} diff --git a/local/modules/PointRetrait/I18n/fr_FR.php b/local/modules/PointRetrait/I18n/fr_FR.php index cc03eca9..b09afdfb 100644 --- a/local/modules/PointRetrait/I18n/fr_FR.php +++ b/local/modules/PointRetrait/I18n/fr_FR.php @@ -6,24 +6,28 @@ return array( 'Address1' => 'Adresse', 'Address2' => 'Complément d\'adresse', 'City' => 'Commune', + 'Create a new place' => 'Créer un nouveau point de retrait', + 'Do you really want to remove this place ?' => 'Voulez-vous réellement supprimer ce point de retrait ?', + 'Delete a place' => 'Supprimer un point de retrait', 'Delivery delay' => 'Délai avant retrait', 'Edit a place' => 'Modifier un lieu de retrait', 'Location set' => 'Coordonnées GPS présentes ?', 'Main' => 'Généralités', - 'Message no location' => 'Ce point de retrait ne possède pas de coordonnées GPS : il est conseillé de localiser l\'adresse, pour les clients', + 'Message no location' => 'Ce point de retrait ne possède pas de coordonnées GPS : pour vos clients, il est conseillé de géolocaliser l\'adresse.', 'Minimum amount' => 'Minimum de commande', 'Module name' => 'Point de Retrait AuxBieauxLegumes', 'My places' => 'Point de retrait AuxBieauxLegumes', 'My withdrawal places' => 'Mes points de retrait AuxBieauxLegumes', 'Order number' => 'N° de commande', - 'Place' => 'Point de retrait', - 'Recenter map' => 'Recentrer la carte sur l\'adresse', + 'Place name' => 'Nom du point de retrait', + 'Recenter map' => 'Géolocaliser l\'adresse', 'Revert origin position' => 'Revenir à la position d\'origine', 'Schedule' => 'Horaires de retrait', 'Scheduled date' => 'Date de retrait prévue', 'Scheduled withdrawals' => 'Commandes à retirer en Point Retrait', 'Title of config view' => 'Point retrait AuxBieauxLegumes - Configuration', 'There is no order to withdraw' => 'Aucune commande à retirer en Point Retrait', + 'There is no schedule for this place' => 'Aucun créneau de retrait sur ce point de retrait', 'Withdrawal days' => 'Jours de retrait', 'Withdrawal price' => 'Coût du retrait', 'Zipcode' => 'Code postal', diff --git a/local/modules/PointRetrait/PointRetrait.php b/local/modules/PointRetrait/PointRetrait.php index b286fa9c..a71cd2fa 100644 --- a/local/modules/PointRetrait/PointRetrait.php +++ b/local/modules/PointRetrait/PointRetrait.php @@ -17,6 +17,7 @@ class PointRetrait extends AbstractDeliveryModule /** @var string */ const DOMAIN_NAME = 'pointretrait'; const MESSAGE_DOMAIN = 'pointretrait'; + const MODULE_URL = '/admin/module/PointRetrait'; /** diff --git a/local/modules/PointRetrait/templates/backOffice/default/form/place-create.html b/local/modules/PointRetrait/templates/backOffice/default/form/place-create.html new file mode 100644 index 00000000..69e6527d --- /dev/null +++ b/local/modules/PointRetrait/templates/backOffice/default/form/place-create.html @@ -0,0 +1,102 @@ +{form name=$form_name} + {form_hidden_fields form=$form} + + {render_form_field form=$form field="success_url" value={$success_url|default:{url path='/admin/module/PointRetrait'}}} + + {form_field form=$form field="title"} +
+ + + {form_error form=$form field="title"}{$message}{/form_error} + +
+ {/form_field} + + {form_field form=$form field="price"} +
+ + +  € +
+ {form_error form=$form field="price"}{$message}{/form_error} + {/form_field} + + {form_field form=$form field="minimum_amount"} +
+ + +  € +
+ {form_error form=$form field="minimum_amount"}{$message}{/form_error} + {/form_field} + + {form_field form=$form field="address1"} +
+ + +
+ +
+
+ {form_error form=$form field="address1"}{$message}{/form_error} + {/form_field} + + {form_field form=$form field="address2"} +
+ + +
+ +
+
+ {form_error form=$form field="address2"}{$message}{/form_error} + {/form_field} + + {form_field form=$form field="zipcode"} +
+ + +
+ +
+
+ {form_error form=$form field="zipcode"}{$message}{/form_error} + {/form_field} + + {form_field form=$form field="city"} +
+ + +
+ +
+
+ {form_error form=$form field="city"}{$message}{/form_error} + {/form_field} + + {form_field form=$form field="active"} + + {/form_field} + +{/form} \ No newline at end of file diff --git a/local/modules/PointRetrait/templates/backOffice/default/places-list.html b/local/modules/PointRetrait/templates/backOffice/default/places-list.html index 3dc21804..49b4bb49 100644 --- a/local/modules/PointRetrait/templates/backOffice/default/places-list.html +++ b/local/modules/PointRetrait/templates/backOffice/default/places-list.html @@ -28,7 +28,7 @@ mais{extends file="admin-layout.tpl"} - {intl l="Place" d='pointretrait'} + {intl l="Place name" d='pointretrait'} {intl l="Active" d='pointretrait'} {intl l="Address" d='pointretrait'} {intl l="Withdrawal days" d='pointretrait'} @@ -38,10 +38,22 @@ mais{extends file="admin-layout.tpl"} + + {loop name="auth-create" type="auth" role="ADMIN" resource="admin.pdr.main" access="CREATE" module="PointRetrait"} +
+ + + +
+ {/loop} + + {loop name="places" type="pdr_places"} - {$TITLE} + {$TITLE} + + {* CREATE Modal *} + {form name="pointretrait.place.create"} + {capture "place_create"} + {include file="form/place-create.html" form_name="pointretrait.place.create"} + {/capture} + + {include file="includes/generic-create-dialog.html" + dialog_id = "place-create-modal" + dialog_title = {intl l="Create a new place" d="pointretrait"} + dialog_body = {$smarty.capture.place_create nofilter} + dialog_ok_label = {intl l="Create"} + dialog_cancel_label = {intl l="Cancel"} + form_action = {$current_url} + form_enctype = {form_enctype form=$form} + } + {/form} + + {* DELETE modal *} + {capture "place_delete"} + {intl l="Do you really want to remove this place ?" d="pointretrait"} + + + {/capture} + + {include file="includes/generic-confirm-dialog.html" + dialog_id = "place-delete" + dialog_title = {intl l="Delete a place" d="pointretrait"} + dialog_message = {$smarty.capture.place_delete nofilter} + dialog_ok_label = {intl l="Delete"} + dialog_cancel_label = {intl l="Cancel"} + form_action = {token_url path='/admin/module/PointRetrait/delete'} + } + {/block} {block name="javascript-initialization"} @@ -78,8 +124,8 @@ mais{extends file="admin-layout.tpl"}