Merge branch 'country'
This commit is contained in:
326
core/lib/Thelia/Controller/Admin/AreaController.php
Normal file
326
core/lib/Thelia/Controller/Admin/AreaController.php
Normal file
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\Area\AreaAddCountryEvent;
|
||||
use Thelia\Core\Event\Area\AreaCreateEvent;
|
||||
use Thelia\Core\Event\Area\AreaDeleteEvent;
|
||||
use Thelia\Core\Event\Area\AreaRemoveCountryEvent;
|
||||
use Thelia\Core\Event\Area\AreaUpdateEvent;
|
||||
use Thelia\Core\Event\Area\AreaUpdatePostageEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\Area\AreaCountryForm;
|
||||
use Thelia\Form\Area\AreaCreateForm;
|
||||
use Thelia\Form\Area\AreaModificationForm;
|
||||
use Thelia\Form\Area\AreaPostageForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\AreaQuery;
|
||||
|
||||
/**
|
||||
* Class AreaController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class AreaController extends AbstractCrudController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'area',
|
||||
null,
|
||||
null,
|
||||
|
||||
'admin.area.default',
|
||||
'admin.area.create',
|
||||
'admin.area.update',
|
||||
'admin.area.delete',
|
||||
|
||||
TheliaEvents::AREA_CREATE,
|
||||
TheliaEvents::AREA_UPDATE,
|
||||
TheliaEvents::AREA_DELETE
|
||||
);
|
||||
}
|
||||
|
||||
protected function getAreaId()
|
||||
{
|
||||
return $this->getRequest()->get('area_id', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the creation form for this object
|
||||
*/
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new AreaCreateForm($this->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the update form for this object
|
||||
*/
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new AreaModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the update form for this object, before passing it to the update template
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
$data = array(
|
||||
'name' => $object->getName()
|
||||
);
|
||||
|
||||
return new AreaModificationForm($this->getRequest(), 'form', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the creation event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*
|
||||
* @return \Thelia\Core\Event\Area\AreaCreateEvent
|
||||
*/
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$event = new AreaCreateEvent();
|
||||
|
||||
return $this->hydrateEvent($event, $formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the update event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$event = new AreaUpdateEvent();
|
||||
|
||||
return $this->hydrateEvent($event, $formData);
|
||||
}
|
||||
|
||||
private function hydrateEvent($event, $formData)
|
||||
{
|
||||
$event->setAreaName($formData['name']);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the delete event with the provided form data
|
||||
*/
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new AreaDeleteEvent($this->getAreaId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the event contains the object, e.g. the action has updated the object in the event.
|
||||
*
|
||||
* @param \Thelia\Core\Event\Area\AreaEvent $event
|
||||
*/
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasArea();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the created object from an event.
|
||||
*
|
||||
* @param \Thelia\Core\Event\Area\AreaEvent $event
|
||||
*/
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->getArea();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an existing object from the database
|
||||
*/
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return AreaQuery::create()->findPk($this->getAreaId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object label form the object event (name, title, etc.)
|
||||
*
|
||||
* @param \Thelia\Model\Area $object
|
||||
*/
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object ID from the object
|
||||
*
|
||||
* @param \Thelia\Model\Area $object
|
||||
*/
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the main list template
|
||||
*
|
||||
* @param unknown $currentOrder, if any, null otherwise.
|
||||
*/
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
return $this->render("shipping-configuration");
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the edition template
|
||||
*/
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render('shipping-configuration-edit',array(
|
||||
'area_id' => $this->getAreaId()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the edition template
|
||||
*/
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirectToRoute('admin.configuration.shipping-configuration.update.view', array(), array(
|
||||
"area_id" => $this->getAreaId()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the list template
|
||||
*/
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute('admin.configuration.shipping-configuration.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* add a country to a define area
|
||||
*/
|
||||
public function addCountry()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
$areaCountryForm = new AreaCountryForm($this->getRequest());
|
||||
$error_msg = null;
|
||||
try {
|
||||
|
||||
$form = $this->validateForm($areaCountryForm);
|
||||
|
||||
$event = new AreaAddCountryEvent($form->get('area_id')->getData(), $form->get('country_id')->getData());
|
||||
|
||||
$this->dispatch(TheliaEvents::AREA_ADD_COUNTRY, $event);
|
||||
|
||||
if (! $this->eventContainsObject($event))
|
||||
throw new \LogicException(
|
||||
$this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName)));
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($event)) {
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified, new country added", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($areaCountryForm->getSuccessUrl());
|
||||
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $areaCountryForm);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->renderEditionTemplate();
|
||||
}
|
||||
|
||||
public function removeCountry()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
$request = $this->getRequest();
|
||||
$removeCountryEvent = new AreaRemoveCountryEvent($request->request->get('areai_id', 0), $request->request->get('country_id', 0));
|
||||
|
||||
$this->dispatch(TheliaEvents::AREA_REMOVE_COUNTRY, $removeCountryEvent);
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function updatePostageAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
$areaUpdateForm = new AreaPostageForm($this->getRequest());
|
||||
$error_msg = null;
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($areaUpdateForm);
|
||||
|
||||
$event = new AreaUpdatePostageEvent($form->get('area_id')->getData());
|
||||
$event->setPostage($form->get('postage')->getData());
|
||||
|
||||
$this->dispatch(TheliaEvents::AREA_POSTAGE_UPDATE, $event);
|
||||
|
||||
if (! $this->eventContainsObject($event))
|
||||
throw new \LogicException(
|
||||
$this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName)));
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($event)) {
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified, country remove", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($areaUpdateForm->getSuccessUrl());
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $areaUpdateForm);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->renderEditionTemplate();
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,7 @@ class BaseAdminController extends BaseController
|
||||
* @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml
|
||||
* @param unknown $urlParameters the URL parametrs, as a var/value pair array
|
||||
*/
|
||||
public function redirectToRoute($routeId, $urlParameters = array(), $routeParameters = array())
|
||||
public function redirectToRoute($routeId, array $urlParameters = array(), array $routeParameters = array())
|
||||
{
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, $routeParameters), $urlParameters));
|
||||
}
|
||||
|
||||
@@ -39,24 +39,6 @@ use Thelia\Model\CountryQuery;
|
||||
class CountryController extends AbstractCrudController
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $objectName the lower case object name. Example. "message"
|
||||
*
|
||||
* @param string $defaultListOrder the default object list order, or null if list is not sortable. Example: manual
|
||||
* @param string $orderRequestParameterName Name of the request parameter that set the list order (null if list is not sortable)
|
||||
*
|
||||
* @param string $viewPermissionIdentifier the 'view' permission identifier. Example: "admin.configuration.message.view"
|
||||
* @param string $createPermissionIdentifier the 'create' permission identifier. Example: "admin.configuration.message.create"
|
||||
* @param string $updatePermissionIdentifier the 'update' permission identifier. Example: "admin.configuration.message.update"
|
||||
* @param string $deletePermissionIdentifier the 'delete' permission identifier. Example: "admin.configuration.message.delete"
|
||||
*
|
||||
* @param string $createEventIdentifier the dispatched create TheliaEvent identifier. Example: TheliaEvents::MESSAGE_CREATE
|
||||
* @param string $updateEventIdentifier the dispatched update TheliaEvent identifier. Example: TheliaEvents::MESSAGE_UPDATE
|
||||
* @param string $deleteEventIdentifier the dispatched delete TheliaEvent identifier. Example: TheliaEvents::MESSAGE_DELETE
|
||||
*
|
||||
* @param string $visibilityToggleEventIdentifier the dispatched visibility toggle TheliaEvent identifier, or null if the object has no visible options. Example: TheliaEvents::MESSAGE_TOGGLE_VISIBILITY
|
||||
* @param string $changePositionEventIdentifier the dispatched position change TheliaEvent identifier, or null if the object has no position. Example: TheliaEvents::MESSAGE_UPDATE_POSITION
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
@@ -129,7 +111,7 @@ class CountryController extends AbstractCrudController
|
||||
*/
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$event = new CountryUpdateEvent();
|
||||
$event = new CountryUpdateEvent($formData['id']);
|
||||
|
||||
return $this->hydrateEvent($event, $formData);
|
||||
}
|
||||
@@ -139,6 +121,8 @@ class CountryController extends AbstractCrudController
|
||||
$event
|
||||
->setLocale($formData['locale'])
|
||||
->setTitle($formData['title'])
|
||||
->setChapo($formData['chapo'])
|
||||
->setDescription($formData['description'])
|
||||
->setIsocode($formData['isocode'])
|
||||
->setIsoAlpha2($formData['isoalpha2'])
|
||||
->setIsoAlpha3($formData['isoalpha3'])
|
||||
@@ -236,7 +220,10 @@ class CountryController extends AbstractCrudController
|
||||
*/
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirectToRoute('admin.configuration.countries.update', array(), $this->getRequest()->get('country_id', 0));
|
||||
$this->redirectToRoute('admin.configuration.countries.update', array(), array(
|
||||
"country_id" => $this->getRequest()->get('country_id', 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
/**
|
||||
* Class ShippingConfigurationController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ShippingConfigurationController extends BaseAdminController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-configuration.view")) return $response;
|
||||
return $this->render("shipping-configuration", array("display_shipping_configuration" => 20));
|
||||
}
|
||||
|
||||
public function updateAction($shipping_configuration_id)
|
||||
{
|
||||
return $this->render("shipping-configuration-edit", array(
|
||||
"shipping_configuration_id" => $shipping_configuration_id
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,12 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\ShippingZone\ShippingZoneAddAreaEvent;
|
||||
use Thelia\Core\Event\ShippingZone\ShippingZoneRemoveAreaEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Form\ShippingZone\ShippingZoneAddArea;
|
||||
use Thelia\Form\ShippingZone\ShippingZoneRemoveArea;
|
||||
|
||||
/**
|
||||
* Class ShippingZoneController
|
||||
@@ -30,6 +36,8 @@ namespace Thelia\Controller\Admin;
|
||||
*/
|
||||
class ShippingZoneController extends BaseAdminController
|
||||
{
|
||||
public $objectName = 'areaDeliveryModule';
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-zones.view")) return $response;
|
||||
@@ -38,8 +46,99 @@ class ShippingZoneController extends BaseAdminController
|
||||
|
||||
public function updateAction($shipping_zones_id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-zones.view")) return $response;
|
||||
return $this->render("shipping-zones-edit", array(
|
||||
"shipping_zones_id" => $shipping_zones_id
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function addArea()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-zones.update")) return $response;
|
||||
|
||||
$shippingAreaForm = new ShippingZoneAddArea($this->getRequest());
|
||||
$error_msg = null;
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($shippingAreaForm);
|
||||
|
||||
$event = new ShippingZoneAddAreaEvent(
|
||||
$form->get('area_id')->getData(),
|
||||
$form->get('shipping_zone_id')->getData()
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::SHIPPING_ZONE_ADD_AREA, $event);
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($shippingAreaForm->getSuccessUrl());
|
||||
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $shippingAreaForm);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->renderEditionTemplate();
|
||||
}
|
||||
|
||||
public function removeArea()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.shipping-zones.update")) return $response;
|
||||
|
||||
$shippingAreaForm = new ShippingZoneRemoveArea($this->getRequest());
|
||||
$error_msg = null;
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($shippingAreaForm);
|
||||
|
||||
$event = new ShippingZoneRemoveAreaEvent(
|
||||
$form->get('area_id')->getData(),
|
||||
$form->get('shipping_zone_id')->getData()
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::SHIPPING_ZONE_REMOVE_AREA, $event);
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($shippingAreaForm->getSuccessUrl());
|
||||
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $shippingAreaForm);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->renderEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the edition template
|
||||
*/
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render("shipping-zones-edit", array(
|
||||
"shipping_zones_id" => $this->getShippingZoneId()
|
||||
));
|
||||
}
|
||||
|
||||
protected function getShippingZoneId()
|
||||
{
|
||||
return $this->getRequest()->get('shipping_zone_id', 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user