diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index 2e83bd7fb..aaebec3f9 100755
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -415,7 +415,7 @@
Thelia\Controller\Admin\CountryController::createAction
-
+
Thelia\Controller\Admin\CountryController::updateAction
\d+
diff --git a/core/lib/Thelia/Controller/Admin/CountryController.php b/core/lib/Thelia/Controller/Admin/CountryController.php
index 6efe1f898..d2951d3f2 100644
--- a/core/lib/Thelia/Controller/Admin/CountryController.php
+++ b/core/lib/Thelia/Controller/Admin/CountryController.php
@@ -22,7 +22,13 @@
/*************************************************************************************/
namespace Thelia\Controller\Admin;
+use Thelia\Core\Event\Country\CountryCreateEvent;
+use Thelia\Core\Event\Country\CountryDeleteEvent;
+use Thelia\Core\Event\Country\CountryUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
+use Thelia\Form\CountryCreationForm;
+use Thelia\Form\CountryModificationForm;
+use Thelia\Model\CountryQuery;
/**
* Class CustomerController
@@ -73,7 +79,7 @@ class CountryController extends AbstractCrudController
*/
protected function getCreationForm()
{
- // TODO: Implement getCreationForm() method.
+ return new CountryCreationForm($this->getRequest());
}
/**
@@ -81,7 +87,7 @@ class CountryController extends AbstractCrudController
*/
protected function getUpdateForm()
{
- // TODO: Implement getUpdateForm() method.
+ return new CountryModificationForm($this->getRequest());
}
/**
@@ -101,7 +107,9 @@ class CountryController extends AbstractCrudController
*/
protected function getCreationEvent($formData)
{
- // TODO: Implement getCreationEvent() method.
+ $event = new CountryCreateEvent();
+
+ return $this->hydrateEvent($event, $formData);
}
/**
@@ -111,7 +119,23 @@ class CountryController extends AbstractCrudController
*/
protected function getUpdateEvent($formData)
{
- // TODO: Implement getUpdateEvent() method.
+ $event = new CountryUpdateEvent();
+
+ return $this->hydrateEvent($event, $formData);
+ }
+
+ protected function hydrateEvent($event, $formData)
+ {
+ $event
+ ->setLocale($formData['locale'])
+ ->setTitle($formData['title'])
+ ->setIsocode($formData['isocode'])
+ ->setIsoAlpha2($formData['isoalpha2'])
+ ->setIsoAlpha3($formData['isoalpha3'])
+ ->setArea($formData['area'])
+ ;
+
+ return $event;
}
/**
@@ -119,7 +143,7 @@ class CountryController extends AbstractCrudController
*/
protected function getDeleteEvent()
{
- // TODO: Implement getDeleteEvent() method.
+ return new CountryDeleteEvent($this->getRequest()->get('country_id'));
}
/**
@@ -129,7 +153,7 @@ class CountryController extends AbstractCrudController
*/
protected function eventContainsObject($event)
{
- // TODO: Implement eventContainsObject() method.
+ return $event->hasCountry();
}
/**
@@ -139,7 +163,7 @@ class CountryController extends AbstractCrudController
*/
protected function getObjectFromEvent($event)
{
- // TODO: Implement getObjectFromEvent() method.
+ return $event->getCountry();
}
/**
@@ -147,27 +171,29 @@ class CountryController extends AbstractCrudController
*/
protected function getExistingObject()
{
- // TODO: Implement getExistingObject() method.
+ return CountryQuery::create()
+ ->joinWithI18n($this->getCurrentEditionLocale())
+ ->findPk($this->getRequest()->get('country_id', 0));
}
/**
* Returns the object label form the object event (name, title, etc.)
*
- * @param unknown $object
+ * @param \Thelia\Model\Country $object
*/
protected function getObjectLabel($object)
{
- // TODO: Implement getObjectLabel() method.
+ return $object->getTitle();
}
/**
* Returns the object ID from the object
*
- * @param unknown $object
+ * @param \Thelia\Model\Country $object
*/
protected function getObjectId($object)
{
- // TODO: Implement getObjectId() method.
+ return $object->getId();
}
/**
@@ -185,7 +211,14 @@ class CountryController extends AbstractCrudController
*/
protected function renderEditionTemplate()
{
- // TODO: Implement renderEditionTemplate() method.
+ return $this->render('country-edit', $this->getEditionArgument());
+ }
+
+ protected function getEditionArgument()
+ {
+ return array(
+ 'country_id' => $this->getRequest()->get('country_id', 0)
+ );
}
/**
@@ -193,7 +226,7 @@ class CountryController extends AbstractCrudController
*/
protected function redirectToEditionTemplate()
{
- // TODO: Implement redirectToEditionTemplate() method.
+ $this->redirectToRoute('admin.configuration.countries.update', array(), $this->getRequest()->get('country_id', 0));
}
/**
@@ -201,6 +234,6 @@ class CountryController extends AbstractCrudController
*/
protected function redirectToListTemplate()
{
- // TODO: Implement redirectToListTemplate() method.
+ $this->redirectToRoute('admin.configuration.countries.default');
}
}
diff --git a/core/lib/Thelia/Core/Event/Country/CountryEvent.php b/core/lib/Thelia/Core/Event/Country/CountryEvent.php
index 91f7bafa1..962d880fa 100644
--- a/core/lib/Thelia/Core/Event/Country/CountryEvent.php
+++ b/core/lib/Thelia/Core/Event/Country/CountryEvent.php
@@ -38,7 +38,7 @@ class CountryEvent extends ActionEvent
*/
protected $country;
- function __construct(Country $country)
+ function __construct(Country $country = null)
{
$this->country = $country;
}
diff --git a/core/lib/Thelia/Form/CountryModificationForm.php b/core/lib/Thelia/Form/CountryModificationForm.php
index 757db19d0..687642ed1 100644
--- a/core/lib/Thelia/Form/CountryModificationForm.php
+++ b/core/lib/Thelia/Form/CountryModificationForm.php
@@ -26,7 +26,7 @@ use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
-class CountryModificationForm extends CurrencyCreationForm
+class CountryModificationForm extends CountryCreationForm
{
protected function buildForm()
{
@@ -34,69 +34,6 @@ class CountryModificationForm extends CurrencyCreationForm
$this->formBuilder
->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))
- ->add("title", "text", array(
- "constraints" => array(
- new NotBlank()
- ),
- "label" => Translator::getInstance()->trans("Country title *"),
- "label_attr" => array(
- "for" => "title"
- )
- ))
- ->add("short-description", "text", array(
- "constraints" => array(
- new NotBlank()
- ),
- "label" => Translator::getInstance()->trans("Country short description *"),
- "label_attr" => array(
- "for" => "short-description"
- )
- ))
- ->add("description", "text", array(
- "constraints" => array(
- new NotBlank()
- ),
- "label" => Translator::getInstance()->trans("Country description *"),
- "label_attr" => array(
- "for" => "description"
- )
- ))
- ->add("area", "text", array(
- "constraints" => array(
- new NotBlank()
- ),
- "label" => Translator::getInstance()->trans("Country area *"),
- "label_attr" => array(
- "for" => "area"
- )
- ))
- ->add("isocode", "text", array(
- "constraints" => array(
- new NotBlank()
- ),
- "label" => Translator::getInstance()->trans("ISO Code *"),
- "label_attr" => array(
- "for" => "isocode"
- )
- ))
- ->add("isoalpha2", "text", array(
- "constraints" => array(
- new NotBlank()
- ),
- "label" => Translator::getInstance()->trans("Alpha code 2 *"),
- "label_attr" => array(
- "for" => "isoalpha2"
- )
- ))
- ->add("isoalpha3", "text", array(
- "constraints" => array(
- new NotBlank()
- ),
- "label" => Translator::getInstance()->trans("Alpha code 3 *"),
- "label_attr" => array(
- "for" => "isoalpha3"
- )
- ))
;
}