implement abstract method from AbstractCrudController in Country

Controller
This commit is contained in:
Manuel Raynaud
2013-10-07 11:34:29 +02:00
parent 3b20d5baf5
commit 0f1dee978c
4 changed files with 51 additions and 81 deletions

View File

@@ -415,7 +415,7 @@
<default key="_controller">Thelia\Controller\Admin\CountryController::createAction</default> <default key="_controller">Thelia\Controller\Admin\CountryController::createAction</default>
</route> </route>
<route id="admin.configuration.countries.update.view" path="/admin/configuration/countries/update/{country_id}" methods="get"> <route id="admin.configuration.countries.update" path="/admin/configuration/countries/update/{country_id}" methods="get">
<default key="_controller">Thelia\Controller\Admin\CountryController::updateAction</default> <default key="_controller">Thelia\Controller\Admin\CountryController::updateAction</default>
<requirement key="country_id">\d+</requirement> <requirement key="country_id">\d+</requirement>
</route> </route>

View File

@@ -22,7 +22,13 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Controller\Admin; 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\Core\Event\TheliaEvents;
use Thelia\Form\CountryCreationForm;
use Thelia\Form\CountryModificationForm;
use Thelia\Model\CountryQuery;
/** /**
* Class CustomerController * Class CustomerController
@@ -73,7 +79,7 @@ class CountryController extends AbstractCrudController
*/ */
protected function getCreationForm() protected function getCreationForm()
{ {
// TODO: Implement getCreationForm() method. return new CountryCreationForm($this->getRequest());
} }
/** /**
@@ -81,7 +87,7 @@ class CountryController extends AbstractCrudController
*/ */
protected function getUpdateForm() protected function getUpdateForm()
{ {
// TODO: Implement getUpdateForm() method. return new CountryModificationForm($this->getRequest());
} }
/** /**
@@ -101,7 +107,9 @@ class CountryController extends AbstractCrudController
*/ */
protected function getCreationEvent($formData) 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) 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() 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) protected function eventContainsObject($event)
{ {
// TODO: Implement eventContainsObject() method. return $event->hasCountry();
} }
/** /**
@@ -139,7 +163,7 @@ class CountryController extends AbstractCrudController
*/ */
protected function getObjectFromEvent($event) protected function getObjectFromEvent($event)
{ {
// TODO: Implement getObjectFromEvent() method. return $event->getCountry();
} }
/** /**
@@ -147,27 +171,29 @@ class CountryController extends AbstractCrudController
*/ */
protected function getExistingObject() 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.) * Returns the object label form the object event (name, title, etc.)
* *
* @param unknown $object * @param \Thelia\Model\Country $object
*/ */
protected function getObjectLabel($object) protected function getObjectLabel($object)
{ {
// TODO: Implement getObjectLabel() method. return $object->getTitle();
} }
/** /**
* Returns the object ID from the object * Returns the object ID from the object
* *
* @param unknown $object * @param \Thelia\Model\Country $object
*/ */
protected function getObjectId($object) protected function getObjectId($object)
{ {
// TODO: Implement getObjectId() method. return $object->getId();
} }
/** /**
@@ -185,7 +211,14 @@ class CountryController extends AbstractCrudController
*/ */
protected function renderEditionTemplate() 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() 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() protected function redirectToListTemplate()
{ {
// TODO: Implement redirectToListTemplate() method. $this->redirectToRoute('admin.configuration.countries.default');
} }
} }

View File

@@ -38,7 +38,7 @@ class CountryEvent extends ActionEvent
*/ */
protected $country; protected $country;
function __construct(Country $country) function __construct(Country $country = null)
{ {
$this->country = $country; $this->country = $country;
} }

View File

@@ -26,7 +26,7 @@ use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator; use Thelia\Core\Translation\Translator;
class CountryModificationForm extends CurrencyCreationForm class CountryModificationForm extends CountryCreationForm
{ {
protected function buildForm() protected function buildForm()
{ {
@@ -34,69 +34,6 @@ class CountryModificationForm extends CurrencyCreationForm
$this->formBuilder $this->formBuilder
->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0))))) ->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"
)
))
; ;
} }