From 6bfca2c6b4a7f1119e87a563cfe5bf2766e28299 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 10 Oct 2013 14:20:53 +0200 Subject: [PATCH] allow country update --- core/lib/Thelia/Action/Country.php | 12 +++ .../Thelia/Config/Resources/routing/admin.xml | 7 +- .../Controller/Admin/BaseAdminController.php | 2 +- .../Controller/Admin/CountryController.php | 9 +- .../Core/Event/Country/CountryUpdateEvent.php | 85 +++++++++++++++++++ .../Form/Image/DocumentModification.php | 12 +-- .../Thelia/Form/Image/ImageModification.php | 12 +-- templates/admin/default/countries.html | 4 +- templates/admin/default/country-edit.html | 71 ++++++---------- 9 files changed, 140 insertions(+), 74 deletions(-) diff --git a/core/lib/Thelia/Action/Country.php b/core/lib/Thelia/Action/Country.php index 9bccfcea5..69bf3c568 100644 --- a/core/lib/Thelia/Action/Country.php +++ b/core/lib/Thelia/Action/Country.php @@ -59,7 +59,19 @@ class Country extends BaseAction implements EventSubscriberInterface public function update(CountryUpdateEvent $event) { + if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { + $country + ->setIsocode($event->getIsocode()) + ->setIsoalpha2($event->getIsoAlpha2()) + ->setIsoalpha3($event->getIsoAlpha3()) + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->setChapo($event->getChapo()) + ->setDescription($event->getDescription()) + ->save(); + $event->setCountry($country); + } } public function delete(CountryDeleteEvent $event) diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 5df02e5bd..b2292b334 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -420,11 +420,16 @@ \d+ + + Thelia\Controller\Admin\CountryController::processUpdateAction + \d+ + + Thelia\Controller\Admin\CountryController::deleteAction - + Thelia\Controller\Admin\CountryController::toggleDefaultAction diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 5d99a877b..9adb7a19a 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -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)); } diff --git a/core/lib/Thelia/Controller/Admin/CountryController.php b/core/lib/Thelia/Controller/Admin/CountryController.php index a272f7364..c97a4c5ee 100644 --- a/core/lib/Thelia/Controller/Admin/CountryController.php +++ b/core/lib/Thelia/Controller/Admin/CountryController.php @@ -129,7 +129,7 @@ class CountryController extends AbstractCrudController */ protected function getUpdateEvent($formData) { - $event = new CountryUpdateEvent(); + $event = new CountryUpdateEvent($formData['id']); return $this->hydrateEvent($event, $formData); } @@ -139,6 +139,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 +238,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) + ) + ); } /** diff --git a/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php b/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php index 5c4ad1cf3..496904172 100644 --- a/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php @@ -31,5 +31,90 @@ namespace Thelia\Core\Event\Country; */ class CountryUpdateEvent extends CountryCreateEvent { + protected $country_id; + + protected $chapo; + protected $description; + protected $postscriptum; + + function __construct($country_id) + { + $this->country_id = $country_id; + } + + /** + * @param mixed $chapo + */ + public function setChapo($chapo) + { + $this->chapo = $chapo; + + return $this; + } + + /** + * @return mixed + */ + public function getChapo() + { + return $this->chapo; + } + + /** + * @param mixed $description + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * @return mixed + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param mixed $postscriptum + */ + public function setPostscriptum($postscriptum) + { + $this->postscriptum = $postscriptum; + + return $this; + } + + /** + * @return mixed + */ + public function getPostscriptum() + { + return $this->postscriptum; + } + + /** + * @param mixed $country_id + */ + public function setCountryId($country_id) + { + $this->country_id = $country_id; + + return $this; + } + + /** + * @return mixed + */ + public function getCountryId() + { + return $this->country_id; + } + + + } \ No newline at end of file diff --git a/core/lib/Thelia/Form/Image/DocumentModification.php b/core/lib/Thelia/Form/Image/DocumentModification.php index 31de5af98..dbb85f5b3 100644 --- a/core/lib/Thelia/Form/Image/DocumentModification.php +++ b/core/lib/Thelia/Form/Image/DocumentModification.php @@ -122,16 +122,6 @@ abstract class DocumentModification extends BaseForm ) ) ) - ->add( - 'postscriptum', - 'text', - array( - 'constraints' => array(), - 'label' => Translator::getInstance()->trans('Post Scriptum'), - 'label_attr' => array( - 'for' => 'postscriptum' - ) - ) - ); + ; } } diff --git a/core/lib/Thelia/Form/Image/ImageModification.php b/core/lib/Thelia/Form/Image/ImageModification.php index e95a39c37..368f82410 100644 --- a/core/lib/Thelia/Form/Image/ImageModification.php +++ b/core/lib/Thelia/Form/Image/ImageModification.php @@ -130,16 +130,6 @@ abstract class ImageModification extends BaseForm ) ) ) - ->add( - 'postscriptum', - 'text', - array( - 'constraints' => array(), - 'label' => Translator::getInstance()->trans('Post Scriptum'), - 'label_attr' => array( - 'for' => 'postscriptum' - ) - ) - ); + ; } } diff --git a/templates/admin/default/countries.html b/templates/admin/default/countries.html index 6de45aa38..48dda2c4d 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -58,11 +58,11 @@ - +{*
- + *} {$ISOCODE} {$ISOALPHA3} diff --git a/templates/admin/default/country-edit.html b/templates/admin/default/country-edit.html index b5d68e46b..447a6b355 100644 --- a/templates/admin/default/country-edit.html +++ b/templates/admin/default/country-edit.html @@ -30,8 +30,8 @@
{form name="thelia.admin.country.modification"} -
- + + {include file = "includes/inner-form-toolbar.html"}
{* Be sure to get the country ID, even if the form could not be validated *} @@ -40,8 +40,12 @@ {form_hidden_fields form=$form} {form_field form=$form field='success_url'} - - {/form_field} + + {/form_field} + + {form_field form=$form field='locale'} + + {/form_field} {if $form_error}
{$form_error_message}
{/if} @@ -74,51 +78,26 @@
{/form_field} -
- -
- {intl l="Translations"} -
- {loop type="lang" name="lang"} -
-
-
-

- {intl l=$TITLE} {$TITLE} -

-
-
- {form_field form=$form field='title'} -
- - -
- {/form_field} - {form_field form=$form field='chapo'} -
- - -
- {/form_field} - {form_field form=$form field='description'} -
- - -
- {/form_field} -
+ {form_field form=$form field='title'} +
+ +
-
- {/loop} - -
- + {/form_field} + {form_field form=$form field='chapo'} +
+ + +
+ {/form_field} + {form_field form=$form field='description'} +
+ + +
+ {/form_field}
-
{/form}