From d7b3d536b0b650d21e43b2e407cbfa1d6bc65c51 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sun, 6 Oct 2013 15:30:36 +0200 Subject: [PATCH 01/18] update .gitignore file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index be8430509..2219e9c48 100755 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ xhprof/ phpunit.phar .DS_Store phpmyadmin +templates/default-esi +local/modules/TemplateEsiModule From 51a307527cffb51e4d95ac868a06dfd661677ed7 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 7 Oct 2013 10:50:44 +0200 Subject: [PATCH 02/18] create coutry events --- .../Thelia/Config/Resources/routing/admin.xml | 28 +-- .../Controller/Admin/CountryController.php | 176 ++++++++++++++++-- .../Core/Event/Country/CountryCreateEvent.php | 154 +++++++++++++++ .../Core/Event/Country/CountryDeleteEvent.php | 60 ++++++ .../Core/Event/Country/CountryEvent.php | 73 ++++++++ .../Core/Event/Country/CountryUpdateEvent.php | 35 ++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 20 +- core/lib/Thelia/Model/Country.php | 3 + templates/admin/default/countries.html | 12 +- 9 files changed, 529 insertions(+), 32 deletions(-) create mode 100644 core/lib/Thelia/Core/Event/Country/CountryCreateEvent.php create mode 100644 core/lib/Thelia/Core/Event/Country/CountryDeleteEvent.php create mode 100644 core/lib/Thelia/Core/Event/Country/CountryEvent.php create mode 100644 core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 2f85b57bc..2e83bd7fb 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -405,6 +405,21 @@ Thelia\Controller\Admin\FolderController::updatePositionAction + + + + Thelia\Controller\Admin\CountryController::defaultAction + + + + Thelia\Controller\Admin\CountryController::createAction + + + + Thelia\Controller\Admin\CountryController::updateAction + \d+ + + Thelia\Controller\Admin\ContentController::createAction @@ -668,20 +683,7 @@ - - - Thelia\Controller\Admin\CountryController::indexAction - - - - 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 404c062a4..6efe1f898 100644 --- a/core/lib/Thelia/Controller/Admin/CountryController.php +++ b/core/lib/Thelia/Controller/Admin/CountryController.php @@ -22,31 +22,185 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\TheliaEvents; /** * Class CustomerController * @package Thelia\Controller\Admin * @author Manuel Raynaud */ -class CountryController extends BaseAdminController +class CountryController extends AbstractCrudController { - public function indexAction() + + /** + * @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( + 'country', + 'manual', + 'country_order', + + 'admin.country.default', + 'admin.country.create', + 'admin.country.update', + 'admin.country.delete', + + TheliaEvents::COUNTRY_CREATE, + TheliaEvents::COUNTRY_UPDATE, + TheliaEvents::COUNTRY_DELETE + ); + } + + /** + * Return the creation form for this object + */ + protected function getCreationForm() + { + // TODO: Implement getCreationForm() method. + } + + /** + * Return the update form for this object + */ + protected function getUpdateForm() + { + // TODO: Implement getUpdateForm() method. + } + + /** + * Hydrate the update form for this object, before passing it to the update template + * + * @param unknown $object + */ + protected function hydrateObjectForm($object) + { + // TODO: Implement hydrateObjectForm() method. + } + + /** + * Creates the creation event with the provided form data + * + * @param unknown $formData + */ + protected function getCreationEvent($formData) + { + // TODO: Implement getCreationEvent() method. + } + + /** + * Creates the update event with the provided form data + * + * @param unknown $formData + */ + protected function getUpdateEvent($formData) + { + // TODO: Implement getUpdateEvent() method. + } + + /** + * Creates the delete event with the provided form data + */ + protected function getDeleteEvent() + { + // TODO: Implement getDeleteEvent() method. + } + + /** + * Return true if the event contains the object, e.g. the action has updated the object in the event. + * + * @param unknown $event + */ + protected function eventContainsObject($event) + { + // TODO: Implement eventContainsObject() method. + } + + /** + * Get the created object from an event. + * + * @param unknown $createEvent + */ + protected function getObjectFromEvent($event) + { + // TODO: Implement getObjectFromEvent() method. + } + + /** + * Load an existing object from the database + */ + protected function getExistingObject() + { + // TODO: Implement getExistingObject() method. + } + + /** + * Returns the object label form the object event (name, title, etc.) + * + * @param unknown $object + */ + protected function getObjectLabel($object) + { + // TODO: Implement getObjectLabel() method. + } + + /** + * Returns the object ID from the object + * + * @param unknown $object + */ + protected function getObjectId($object) + { + // TODO: Implement getObjectId() method. + } + + /** + * Render the main list template + * + * @param unknown $currentOrder, if any, null otherwise. + */ + protected function renderListTemplate($currentOrder) { - if (null !== $response = $this->checkAuth("admin.country.view")) return $response; return $this->render("countries", array("display_country" => 20)); } /** - * update country action - * - * @param $country_id - * @return mixed|\Symfony\Component\HttpFoundation\Response + * Render the edition template */ - public function updateAction($country_id) + protected function renderEditionTemplate() { - return $this->render("country-edit", array( - "country_id" => $country_id - )); + // TODO: Implement renderEditionTemplate() method. } + /** + * Redirect to the edition template + */ + protected function redirectToEditionTemplate() + { + // TODO: Implement redirectToEditionTemplate() method. + } + + /** + * Redirect to the list template + */ + protected function redirectToListTemplate() + { + // TODO: Implement redirectToListTemplate() method. + } } diff --git a/core/lib/Thelia/Core/Event/Country/CountryCreateEvent.php b/core/lib/Thelia/Core/Event/Country/CountryCreateEvent.php new file mode 100644 index 000000000..48e8469a4 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Country/CountryCreateEvent.php @@ -0,0 +1,154 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Country; + + +/** + * Class CountryCreateEvent + * @package Thelia\Core\Event\Country + * @author Manuel Raynaud + */ +class CountryCreateEvent extends CountryEvent +{ + protected $locale; + protected $title; + protected $isocode; + protected $isoAlpha2; + protected $isoAlpha3; + + /** + * @var int area zone + */ + protected $area; + + /** + * @param mixed $isoAlpha2 + */ + public function setIsoAlpha2($isoAlpha2) + { + $this->isoAlpha2 = $isoAlpha2; + + return $this; + } + + /** + * @return mixed + */ + public function getIsoAlpha2() + { + return $this->isoAlpha2; + } + + /** + * @param mixed $isoAlpha3 + */ + public function setIsoAlpha3($isoAlpha3) + { + $this->isoAlpha3 = $isoAlpha3; + + return $this; + } + + /** + * @return mixed + */ + public function getIsoAlpha3() + { + return $this->isoAlpha3; + } + + /** + * @param mixed $isocode + */ + public function setIsocode($isocode) + { + $this->isocode = $isocode; + + return $this; + } + + /** + * @return mixed + */ + public function getIsocode() + { + return $this->isocode; + } + + /** + * @param mixed $locale + */ + public function setLocale($locale) + { + $this->locale = $locale; + + return $this; + } + + /** + * @return mixed + */ + public function getLocale() + { + return $this->locale; + } + + /** + * @param mixed $title + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return mixed + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param int $area + */ + public function setArea($area) + { + $this->area = $area; + + return $this; + } + + /** + * @return int + */ + public function getArea() + { + return $this->area; + } + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Country/CountryDeleteEvent.php b/core/lib/Thelia/Core/Event/Country/CountryDeleteEvent.php new file mode 100644 index 000000000..4a7d9c400 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Country/CountryDeleteEvent.php @@ -0,0 +1,60 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Country; + + +/** + * Class CountryDeleteEvent + * @package Thelia\Core\Event\Country + * @author Manuel Raynaud + */ +class CountryDeleteEvent extends CountryEvent +{ + /** + * @var int country id + */ + protected $country_id; + + function __construct($country_id) + { + $this->country_id = $country_id; + } + + /** + * @param int $country_id + */ + public function setCountryId($country_id) + { + $this->country_id = $country_id; + } + + /** + * @return int + */ + public function getCountryId() + { + return $this->country_id; + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Country/CountryEvent.php b/core/lib/Thelia/Core/Event/Country/CountryEvent.php new file mode 100644 index 000000000..91f7bafa1 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Country/CountryEvent.php @@ -0,0 +1,73 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Country; +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Country; + + +/** + * Class CountryEvent + * @package Thelia\Core\Event\Country + * @author Manuel Raynaud + */ +class CountryEvent extends ActionEvent +{ + /* + * @var \Thelia\Model\Country + */ + protected $country; + + function __construct(Country $country) + { + $this->country = $country; + } + + /** + * @param mixed $country + */ + public function setCountry(Country $country) + { + $this->country = $country; + + return $this; + } + + /** + * @return null|\Thelia\Model\Country + */ + public function getCountry() + { + return $this->country; + } + + /** + * @return bool + */ + public function hasCountry() + { + return null !== $this->country; + } + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php b/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php new file mode 100644 index 000000000..5c4ad1cf3 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php @@ -0,0 +1,35 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Country; + + +/** + * Class CountryUpdateEvent + * @package Thelia\Core\Event\Country + * @author Manuel Raynaud + */ +class CountryUpdateEvent extends CountryCreateEvent +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index f0dc68702..daf647085 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -183,8 +183,6 @@ final class TheliaEvents const FOLDER_TOGGLE_VISIBILITY = "action.toggleFolderVisibility"; const FOLDER_UPDATE_POSITION = "action.updateFolderPosition"; -// const FOLDER_ADD_CONTENT = "action.categoryAddContent"; -// const FOLDER_REMOVE_CONTENT = "action.categoryRemoveContent"; const BEFORE_CREATEFOLDER = "action.before_createFolder"; const AFTER_CREATEFOLDER = "action.after_createFolder"; @@ -216,6 +214,24 @@ final class TheliaEvents const BEFORE_UPDATECONTENT = "action.before_updateContent"; const AFTER_UPDATECONTENT = "action.after_updateContent"; + // -- country management ----------------------------------------------- + + const COUNTRY_CREATE = "action.createCountry"; + const COUNTRY_UPDATE = "action.updateCountry"; + const COUNTRY_DELETE = "action.deleteCountry"; + const COUNTRY_TOGGLE_VISIBILITY = "action.toggleCountryVisibility"; + //const COUNTRY_UPDATE_POSITION = "action.updateFolderPosition"; + + + const BEFORE_CREATECOUNTRY = "action.before_createCountry"; + const AFTER_CREATECOUNTRY = "action.after_createCountry"; + + const BEFORE_DELETECOUNTRY = "action.before_deleteCountry"; + const AFTER_DELETECOUNTRY = "action.after_deleteCountry"; + + const BEFORE_UPDATECOUNTRY = "action.before_updateCountry"; + const AFTER_UPDATECOUNTRY = "action.after_updateCountry"; + // -- Categories Associated Content ---------------------------------------- const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent"; diff --git a/core/lib/Thelia/Model/Country.php b/core/lib/Thelia/Model/Country.php index a7a6c23b9..56a7667cf 100755 --- a/core/lib/Thelia/Model/Country.php +++ b/core/lib/Thelia/Model/Country.php @@ -6,4 +6,7 @@ use Thelia\Model\Base\Country as BaseCountry; class Country extends BaseCountry { + + + } diff --git a/templates/admin/default/countries.html b/templates/admin/default/countries.html index fe1b614a1..bf68db361 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -35,12 +35,12 @@ - ID - Name - Default - Shop - N° ISO - ISO Code + {intl l="ID"} + {intl l="Name"} + {intl l="Default"} + {intl l="Shop"} + {intl l="N° ISO"} + {intl l="ISO Code"} {module_include location='countries_table_header'} From ea94a54280be069d2cac920650f329ecb489826a Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 7 Oct 2013 10:59:58 +0200 Subject: [PATCH 03/18] add pre/post CRUD method in Country model --- core/lib/Thelia/Model/Country.php | 39 ++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Model/Country.php b/core/lib/Thelia/Model/Country.php index 56a7667cf..9dc409910 100755 --- a/core/lib/Thelia/Model/Country.php +++ b/core/lib/Thelia/Model/Country.php @@ -2,11 +2,48 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; +use Thelia\Core\Event\Country\CountryEvent; +use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Country as BaseCountry; -class Country extends BaseCountry { +class Country extends BaseCountry +{ + use \Thelia\Model\Tools\ModelEventDispatcherTrait; + public function preInsert(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::BEFORE_CREATECOUNTRY, new CountryEvent($this)); + return true; + } + public function postInsert(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_CREATECOUNTRY, new CountryEvent($this)); + } + public function preUpdate(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::BEFORE_UPDATECOUNTRY, new CountryEvent($this)); + + return true; + } + + public function postUpdate(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_UPDATECOUNTRY, new CountryEvent($this)); + } + + public function preDelete(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::BEFORE_DELETECOUNTRY, new CountryEvent($this)); + + return true; + } + + public function postDelete(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_DELETECOUNTRY, new CountryEvent($this)); + } } From 3b20d5baf542c510273bab4b91477ebad6359749 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 7 Oct 2013 11:00:26 +0200 Subject: [PATCH 04/18] create country action class --- core/lib/Thelia/Action/Country.php | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 core/lib/Thelia/Action/Country.php diff --git a/core/lib/Thelia/Action/Country.php b/core/lib/Thelia/Action/Country.php new file mode 100644 index 000000000..41e1f310e --- /dev/null +++ b/core/lib/Thelia/Action/Country.php @@ -0,0 +1,84 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Country\CountryCreateEvent; +use Thelia\Core\Event\Country\CountryDeleteEvent; +use Thelia\Core\Event\Country\CountryUpdateEvent; +use Thelia\Core\Event\TheliaEvents; + + +/** + * Class Country + * @package Thelia\Action + * @author Manuel Raynaud + */ +class Country extends BaseAction implements EventSubscriberInterface +{ + + public function create(CountryCreateEvent $event) + { + + } + + public function update(CountryUpdateEvent $event) + { + + } + + public function delete(CountryDeleteEvent $event) + { + + } + + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::COUNTRY_CREATE => array('create', 128), + TheliaEvents::COUNTRY_UPDATE => array('update', 128), + TheliaEvents::COUNTRY_DELETE => array('delete', 128), + ); + } +} \ No newline at end of file From 0f1dee978c7eaf169de47adfea0794e319ce8cb3 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 7 Oct 2013 11:34:29 +0200 Subject: [PATCH 05/18] implement abstract method from AbstractCrudController in Country Controller --- .../Thelia/Config/Resources/routing/admin.xml | 2 +- .../Controller/Admin/CountryController.php | 63 +++++++++++++----- .../Core/Event/Country/CountryEvent.php | 2 +- .../Thelia/Form/CountryModificationForm.php | 65 +------------------ 4 files changed, 51 insertions(+), 81 deletions(-) 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" - ) - )) ; } From 65d23db8541943dc004acc01b0107b7c8b89eb27 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 7 Oct 2013 12:46:40 +0200 Subject: [PATCH 06/18] validate country creation --- core/lib/Thelia/Action/Country.php | 13 +++++++++++++ core/lib/Thelia/Config/Resources/action.xml | 5 +++++ core/lib/Thelia/Config/Resources/routing/admin.xml | 2 +- .../Thelia/Controller/Admin/CountryController.php | 13 +++++++++++-- core/lib/Thelia/Form/CountryCreationForm.php | 7 +++++-- core/lib/Thelia/Form/CountryModificationForm.php | 5 +++++ core/lib/Thelia/Model/Base/Country.php | 13 ++++++++++++- core/lib/Thelia/Model/Map/CountryTableMap.php | 6 +++++- install/thelia.sql | 2 +- local/config/schema.xml | 2 +- templates/admin/default/countries.html | 10 ++++++++-- templates/admin/default/country-edit.html | 6 +++--- 12 files changed, 70 insertions(+), 14 deletions(-) diff --git a/core/lib/Thelia/Action/Country.php b/core/lib/Thelia/Action/Country.php index 41e1f310e..1fa90b6b9 100644 --- a/core/lib/Thelia/Action/Country.php +++ b/core/lib/Thelia/Action/Country.php @@ -22,11 +22,13 @@ /*************************************************************************************/ namespace Thelia\Action; + use Symfony\Component\EventDispatcher\EventSubscriberInterface; 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\Model\Country as CountryModel; /** @@ -39,6 +41,17 @@ class Country extends BaseAction implements EventSubscriberInterface public function create(CountryCreateEvent $event) { + $country = new CountryModel(); + + $country + ->setIsocode($event->getIsocode()) + ->setIsoalpha2($event->getIsoAlpha2()) + ->setIsoalpha3($event->getIsoAlpha3()) + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->save(); + + $event->setCountry($country); } diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 87575f59b..a9b3e247d 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -116,6 +116,11 @@ + + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index aaebec3f9..47208fdb4 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 d2951d3f2..c63be90b4 100644 --- a/core/lib/Thelia/Controller/Admin/CountryController.php +++ b/core/lib/Thelia/Controller/Admin/CountryController.php @@ -93,11 +93,20 @@ class CountryController extends AbstractCrudController /** * Hydrate the update form for this object, before passing it to the update template * - * @param unknown $object + * @param \Thelia\Model\Country $object */ protected function hydrateObjectForm($object) { - // TODO: Implement hydrateObjectForm() method. + $data = array( + 'id' => $object->getId(), + 'locale' => $object->getLocale(), + 'title' => $object->getTitle(), + 'isocode' => $object->getIsocode(), + 'isoalpha2' => $object->getIsoalpha2(), + 'isoalpha3' => $object->getIsoalpha3(), + ); + + return new CountryModificationForm($this->getRequest(), 'form', $data); } /** diff --git a/core/lib/Thelia/Form/CountryCreationForm.php b/core/lib/Thelia/Form/CountryCreationForm.php index 1b10ebc07..fe7486852 100644 --- a/core/lib/Thelia/Form/CountryCreationForm.php +++ b/core/lib/Thelia/Form/CountryCreationForm.php @@ -39,11 +39,14 @@ class CountryCreationForm extends BaseForm "for" => "title" ) )) - ->add("area", "text", array( + ->add("locale", "text", array( "constraints" => array( new NotBlank() ), - "label" => Translator::getInstance()->trans("Country area *"), + "label_attr" => array("for" => "locale_create") + )) + ->add("area", "text", array( + "label" => Translator::getInstance()->trans("Country area"), "label_attr" => array( "for" => "area" ) diff --git a/core/lib/Thelia/Form/CountryModificationForm.php b/core/lib/Thelia/Form/CountryModificationForm.php index 687642ed1..68570425b 100644 --- a/core/lib/Thelia/Form/CountryModificationForm.php +++ b/core/lib/Thelia/Form/CountryModificationForm.php @@ -28,6 +28,8 @@ use Thelia\Core\Translation\Translator; class CountryModificationForm extends CountryCreationForm { + use StandardDescriptionFieldsTrait; + protected function buildForm() { parent::buildForm(true); @@ -35,6 +37,9 @@ class CountryModificationForm extends CountryCreationForm $this->formBuilder ->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0))))) ; + + // Add standard description fields, excluding title and locale, which a re defined in parent class + $this->addStandardDescFields(array('title', 'locale')); } public function getName() diff --git a/core/lib/Thelia/Model/Base/Country.php b/core/lib/Thelia/Model/Base/Country.php index fd16e148d..eb8312369 100644 --- a/core/lib/Thelia/Model/Base/Country.php +++ b/core/lib/Thelia/Model/Base/Country.php @@ -1071,6 +1071,10 @@ abstract class Country implements ActiveRecordInterface $modifiedColumns = array(); $index = 0; + $this->modifiedColumns[] = CountryTableMap::ID; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . CountryTableMap::ID . ')'); + } // check the columns in natural order for more readable SQL queries if ($this->isColumnModified(CountryTableMap::ID)) { @@ -1140,6 +1144,13 @@ abstract class Country implements ActiveRecordInterface throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); } + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + $this->setNew(false); } @@ -1439,7 +1450,6 @@ abstract class Country implements ActiveRecordInterface */ public function copyInto($copyObj, $deepCopy = false, $makeNew = true) { - $copyObj->setId($this->getId()); $copyObj->setAreaId($this->getAreaId()); $copyObj->setIsocode($this->getIsocode()); $copyObj->setIsoalpha2($this->getIsoalpha2()); @@ -1475,6 +1485,7 @@ abstract class Country implements ActiveRecordInterface if ($makeNew) { $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value } } diff --git a/core/lib/Thelia/Model/Map/CountryTableMap.php b/core/lib/Thelia/Model/Map/CountryTableMap.php index 519af7176..752f2b34a 100644 --- a/core/lib/Thelia/Model/Map/CountryTableMap.php +++ b/core/lib/Thelia/Model/Map/CountryTableMap.php @@ -167,7 +167,7 @@ class CountryTableMap extends TableMap $this->setPhpName('Country'); $this->setClassName('\\Thelia\\Model\\Country'); $this->setPackage('Thelia.Model'); - $this->setUseIdGenerator(false); + $this->setUseIdGenerator(true); // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addForeignKey('AREA_ID', 'AreaId', 'INTEGER', 'area', 'ID', false, null, null); @@ -466,6 +466,10 @@ class CountryTableMap extends TableMap $criteria = $criteria->buildCriteria(); // build Criteria from Country object } + if ($criteria->containsKey(CountryTableMap::ID) && $criteria->keyContainsValue(CountryTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.CountryTableMap::ID.')'); + } + // Set the correct dbName $query = CountryQuery::create()->mergeWith($criteria); diff --git a/install/thelia.sql b/install/thelia.sql index 9b4ea4880..4371aa4f5 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -93,7 +93,7 @@ DROP TABLE IF EXISTS `country`; CREATE TABLE `country` ( - `id` INTEGER NOT NULL, + `id` INTEGER NOT NULL AUTO_INCREMENT, `area_id` INTEGER, `isocode` VARCHAR(4) NOT NULL, `isoalpha2` VARCHAR(2), diff --git a/local/config/schema.xml b/local/config/schema.xml index 9cd2e481a..65928176e 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -75,7 +75,7 @@ - + diff --git a/templates/admin/default/countries.html b/templates/admin/default/countries.html index bf68db361..21d3819e4 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -71,7 +71,7 @@
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.countries.change"} - + {/loop} @@ -121,7 +121,7 @@ {form_field form=$form field='success_url'} {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} - + {/form_field} {form_field form=$form field='title'} @@ -160,6 +160,12 @@
{/form_field} + {loop type="lang" name="default-lang" default_only="1"} + + {form_field form=$form field='locale'} + + {/form_field} + {/loop} {module_include location='country_create_form'} diff --git a/templates/admin/default/country-edit.html b/templates/admin/default/country-edit.html index fe1a0f240..b5d68e46b 100644 --- a/templates/admin/default/country-edit.html +++ b/templates/admin/default/country-edit.html @@ -92,13 +92,13 @@ {form_field form=$form field='title'}
- +
{/form_field} - {form_field form=$form field='short-description'} + {form_field form=$form field='chapo'}
- +
{/form_field} {form_field form=$form field='description'} From ae887f6a67eaa34bcf6cd9566c9e45a07bb67f7e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 7 Oct 2013 13:03:28 +0200 Subject: [PATCH 07/18] validate country removal --- core/lib/Thelia/Action/Country.php | 5 +++++ core/lib/Thelia/Config/Resources/routing/admin.xml | 4 ++++ templates/admin/default/countries.html | 13 ++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Action/Country.php b/core/lib/Thelia/Action/Country.php index 1fa90b6b9..f4f59b2bb 100644 --- a/core/lib/Thelia/Action/Country.php +++ b/core/lib/Thelia/Action/Country.php @@ -29,6 +29,7 @@ use Thelia\Core\Event\Country\CountryDeleteEvent; use Thelia\Core\Event\Country\CountryUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Country as CountryModel; +use Thelia\Model\CountryQuery; /** @@ -62,7 +63,11 @@ class Country extends BaseAction implements EventSubscriberInterface public function delete(CountryDeleteEvent $event) { + if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { + $country->delete(); + $event->setCountry($country); + } } diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 47208fdb4..c69c0659d 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -420,6 +420,10 @@ \d+ + + Thelia\Controller\Admin\CountryController::deleteAction + + Thelia\Controller\Admin\ContentController::createAction diff --git a/templates/admin/default/countries.html b/templates/admin/default/countries.html index 21d3819e4..3207357a1 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -216,10 +216,17 @@ {/javascripts} From 342a1f2486255c5bcd23a9807da82f8c1e173441 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 7 Oct 2013 14:17:18 +0200 Subject: [PATCH 08/18] complete javascript for changing default country --- templates/admin/default/countries.html | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/templates/admin/default/countries.html b/templates/admin/default/countries.html index 3207357a1..ad03857a2 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -54,8 +54,8 @@
{$ID} {$TITLE} -
- +
+
@@ -225,6 +225,17 @@ $('.country-delete').click(function(ev){ $('#country_delete_id').val($(this).data('id')); }); + + $('.change-default-toggle').on('switch-change', function(e, data){ + if(data.value) { + $.ajax({ + url : "{url path='/admin/configuration/country/toggleDefault'}", + data : { + country_id: $(this).data('id') + } + }); + } + }); }); From d45074051eeb176639b9de41afdc21169c5e22e2 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 7 Oct 2013 17:43:43 +0200 Subject: [PATCH 09/18] fiw module generator class name issue --- core/lib/Thelia/Command/Skeleton/Module/Class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/Thelia/Command/Skeleton/Module/Class.php b/core/lib/Thelia/Command/Skeleton/Module/Class.php index c9c7109ac..c4c90aa60 100755 --- a/core/lib/Thelia/Command/Skeleton/Module/Class.php +++ b/core/lib/Thelia/Command/Skeleton/Module/Class.php @@ -25,7 +25,7 @@ namespace %%NAMESPACE%%; use Thelia\Module\BaseModule; -class Class extends BaseModule +class %%CLASSNAME%% extends BaseModule { /** * YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class From 43467681fd5dfcb5a39cc86521070d256ca74c23 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 8 Oct 2013 10:16:18 +0200 Subject: [PATCH 10/18] enabled change default country --- core/lib/Thelia/Action/Country.php | 18 +++++-- .../Thelia/Config/Resources/routing/admin.xml | 4 ++ .../Controller/Admin/CountryController.php | 22 +++++++++ core/lib/Thelia/Controller/BaseController.php | 4 +- .../Country/CountryToggleDefaultEvent.php | 48 +++++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 2 +- .../lib/Thelia/Core/Template/Loop/Country.php | 4 +- core/lib/Thelia/Model/Country.php | 11 +++++ templates/admin/default/countries.html | 2 +- 9 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 core/lib/Thelia/Core/Event/Country/CountryToggleDefaultEvent.php diff --git a/core/lib/Thelia/Action/Country.php b/core/lib/Thelia/Action/Country.php index f4f59b2bb..9bccfcea5 100644 --- a/core/lib/Thelia/Action/Country.php +++ b/core/lib/Thelia/Action/Country.php @@ -26,6 +26,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Country\CountryCreateEvent; use Thelia\Core\Event\Country\CountryDeleteEvent; +use Thelia\Core\Event\Country\CountryToggleDefaultEvent; use Thelia\Core\Event\Country\CountryUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Country as CountryModel; @@ -70,6 +71,16 @@ class Country extends BaseAction implements EventSubscriberInterface } } + public function toggleDefault(CountryToggleDefaultEvent $event) + { + if( null !== $country = CountryQuery::create()->findPk($event->getCountryId())) + { + $country->toggleDefault(); + + $event->setCountry($country); + } + } + /** * Returns an array of event names this subscriber wants to listen to. @@ -94,9 +105,10 @@ class Country extends BaseAction implements EventSubscriberInterface public static function getSubscribedEvents() { return array( - TheliaEvents::COUNTRY_CREATE => array('create', 128), - TheliaEvents::COUNTRY_UPDATE => array('update', 128), - TheliaEvents::COUNTRY_DELETE => array('delete', 128), + TheliaEvents::COUNTRY_CREATE => array('create', 128), + TheliaEvents::COUNTRY_UPDATE => array('update', 128), + TheliaEvents::COUNTRY_DELETE => array('delete', 128), + TheliaEvents::COUNTRY_TOGGLE_DEFAULT => array('toggleDefault', 128) ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index c69c0659d..5df02e5bd 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -424,6 +424,10 @@ Thelia\Controller\Admin\CountryController::deleteAction + + Thelia\Controller\Admin\CountryController::toggleDefaultAction + + Thelia\Controller\Admin\ContentController::createAction diff --git a/core/lib/Thelia/Controller/Admin/CountryController.php b/core/lib/Thelia/Controller/Admin/CountryController.php index c63be90b4..a272f7364 100644 --- a/core/lib/Thelia/Controller/Admin/CountryController.php +++ b/core/lib/Thelia/Controller/Admin/CountryController.php @@ -24,6 +24,7 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Event\Country\CountryCreateEvent; use Thelia\Core\Event\Country\CountryDeleteEvent; +use Thelia\Core\Event\Country\CountryToggleDefaultEvent; use Thelia\Core\Event\Country\CountryUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\CountryCreationForm; @@ -245,4 +246,25 @@ class CountryController extends AbstractCrudController { $this->redirectToRoute('admin.configuration.countries.default'); } + + public function toggleDefaultAction() + { + if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; + $content = null; + if (null !== $country_id = $this->getRequest()->get('country_id')) { + $toogleDefaultEvent = new CountryToggleDefaultEvent($country_id); + try { + $this->dispatch(TheliaEvents::COUNTRY_TOGGLE_DEFAULT, $toogleDefaultEvent); + + if($toogleDefaultEvent->hasCountry()) { + return $this->nullResponse(); + } + } catch (\Exception $ex) { + $content = $ex->getMessage(); + } + + } + + return $this->nullResponse($content, 500); + } } diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 51d2015ea..8c819159b 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -58,9 +58,9 @@ class BaseController extends ContainerAware /** * Return an empty response (after an ajax request, for example) */ - protected function nullResponse() + protected function nullResponse($status = 200) { - return new Response(); + return new Response(null, $status); } /** diff --git a/core/lib/Thelia/Core/Event/Country/CountryToggleDefaultEvent.php b/core/lib/Thelia/Core/Event/Country/CountryToggleDefaultEvent.php new file mode 100644 index 000000000..8f8142d0d --- /dev/null +++ b/core/lib/Thelia/Core/Event/Country/CountryToggleDefaultEvent.php @@ -0,0 +1,48 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Country; + + +/** + * Class CountryToggleDefaultEvent + * @package Thelia\Core\Event\Country + * @author manuel raynaud + */ +class CountryToggleDefaultEvent extends CountryEvent +{ + protected $country_id; + + function __construct($country_id) + { + $this->country_id = $country_id; + } + + /** + * @return mixed + */ + public function getCountryId() + { + return $this->country_id; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index daf647085..4e4f55ba8 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -219,7 +219,7 @@ final class TheliaEvents const COUNTRY_CREATE = "action.createCountry"; const COUNTRY_UPDATE = "action.updateCountry"; const COUNTRY_DELETE = "action.deleteCountry"; - const COUNTRY_TOGGLE_VISIBILITY = "action.toggleCountryVisibility"; + const COUNTRY_TOGGLE_DEFAULT = "action.toggleCountryDefault"; //const COUNTRY_UPDATE_POSITION = "action.updateFolderPosition"; diff --git a/core/lib/Thelia/Core/Template/Loop/Country.php b/core/lib/Thelia/Core/Template/Loop/Country.php index 3a05b684a..c3271a6ac 100755 --- a/core/lib/Thelia/Core/Template/Loop/Country.php +++ b/core/lib/Thelia/Core/Template/Loop/Country.php @@ -115,8 +115,10 @@ class Country extends BaseI18nLoop ->set("POSTSCRIPTUM", $country->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("ISOCODE", $country->getIsocode()) ->set("ISOALPHA2", $country->getIsoalpha2()) - ->set("ISOALPHA3", $country->getIsoalpha3()); + ->set("ISOALPHA3", $country->getIsoalpha3()) + ->set('IS_DEFAULT', $country->getByDefault()) + ; $loopResult->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Model/Country.php b/core/lib/Thelia/Model/Country.php index 9dc409910..e254d4a5e 100755 --- a/core/lib/Thelia/Model/Country.php +++ b/core/lib/Thelia/Model/Country.php @@ -11,6 +11,17 @@ class Country extends BaseCountry { use \Thelia\Model\Tools\ModelEventDispatcherTrait; + public function toggleDefault() + { + CountryQuery::create() + ->filterByByDefault(1) + ->update(array('ByDefault' => 0)); + + $this + ->setByDefault(1) + ->save(); + } + public function preInsert(ConnectionInterface $con = null) { $this->dispatchEvent(TheliaEvents::BEFORE_CREATECOUNTRY, new CountryEvent($this)); diff --git a/templates/admin/default/countries.html b/templates/admin/default/countries.html index ad03857a2..99d46ed17 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -55,7 +55,7 @@ {$TITLE}
- +
From 7b147367161cdca36dfe155098cbdd5feab644eb Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 8 Oct 2013 10:48:51 +0200 Subject: [PATCH 11/18] add modal error id changing default country failed --- templates/admin/default/countries.html | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/templates/admin/default/countries.html b/templates/admin/default/countries.html index 99d46ed17..6de45aa38 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -208,6 +208,23 @@ form_content = {$smarty.capture.delete_dialog nofilter} } + + {/block} {block name="javascript-initialization"} @@ -233,6 +250,8 @@ data : { country_id: $(this).data('id') } + }).fail(function(){ + $('#toggle-default-failed').modal('show'); }); } }); From a7a663ebb82aa4a423f2adcbd4ceff45b6e57f7d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 8 Oct 2013 10:56:22 +0200 Subject: [PATCH 12/18] select default country in front register form --- templates/default/register.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/templates/default/register.html b/templates/default/register.html index ad7945457..fb12e4ad4 100644 --- a/templates/default/register.html +++ b/templates/default/register.html @@ -204,7 +204,14 @@ {if $error } From e2f975923e541af17e65a3ffc92125ee966d866b Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 8 Oct 2013 12:20:43 +0200 Subject: [PATCH 13/18] update smarty version --- composer.json | 2 +- composer.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 0a4fc0629..a3395bcf5 100755 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "symfony/form": "2.2.*", "symfony/validator": "2.3.*", - "smarty/smarty": "v3.1.14", + "smarty/smarty": "v3.1.15", "kriswallsmith/assetic": "1.2.*@dev", "leafo/lessphp": "0.3.*@dev", "ptachoire/cssembed": "dev-master", diff --git a/composer.lock b/composer.lock index f50fb4a4d..0e5c079ad 100755 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "852879ecc2e39e5cf283a3b1c5051a8e", + "hash": "9c5ea1a9fd0f8ba533c41ff3676e0970", "packages": [ { "name": "ensepar/html2pdf", @@ -507,11 +507,11 @@ }, { "name": "smarty/smarty", - "version": "v3.1.14", + "version": "v3.1.15", "source": { "type": "svn", "url": "http://smarty-php.googlecode.com/svn", - "reference": "/tags/v3.1.14/@4752" + "reference": "/tags/v3.1.15/@4782" }, "require": { "php": ">=5.2" @@ -547,7 +547,7 @@ "keywords": [ "templating" ], - "time": "2013-07-02 16:38:47" + "time": "2013-10-01 21:08:54" }, { "name": "swiftmailer/swiftmailer", From e8fd8227951eef8752997c41c3bb0ce4e9062e49 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 8 Oct 2013 13:22:06 +0200 Subject: [PATCH 14/18] add higher priority to module routing --- core/lib/Thelia/Config/Resources/routing.xml | 2 +- .../Core/DependencyInjection/Compiler/RegisterRouterPass.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing.xml b/core/lib/Thelia/Config/Resources/routing.xml index efeea61e8..54159734c 100755 --- a/core/lib/Thelia/Config/Resources/routing.xml +++ b/core/lib/Thelia/Config/Resources/routing.xml @@ -64,7 +64,7 @@ %kernel.debug% - + diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php index 505d7a3fa..7d7ab086f 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php @@ -84,7 +84,7 @@ class RegisterRouterPass implements CompilerPassInterface $container->setDefinition("router.".$moduleCode, $definition); - $chainRouter->addMethodCall("add", array(new Reference("router.".$moduleCode), 1)); + $chainRouter->addMethodCall("add", array(new Reference("router.".$moduleCode), 150)); } } } From d866ffaaf5342cb29dca3fff617dc44c2991c978 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 9 Oct 2013 09:05:48 +0200 Subject: [PATCH 15/18] escape view parameter --- core/lib/Thelia/Core/Template/Smarty/SmartyParser.php | 4 ++-- templates/default/layout.tpl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index 868f1570c..b6c1ed1b7 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -212,14 +212,14 @@ class SmartyParser extends Smarty implements ParserInterface $templateDir = realpath(THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/"); if (strpos($pathFileName, $templateDir) !== 0) { - throw new ResourceNotFoundException(sprintf("'%s' view does not exists", $file)); + throw new ResourceNotFoundException(sprintf("'%s' view does not exists", htmlspecialchars($file))); } if (!file_exists($fileName)) { $fileName .= ".html"; if (!file_exists($fileName)) { - throw new ResourceNotFoundException(sprintf("'%s' file not found in %s template", $file, $this->template)); + throw new ResourceNotFoundException(sprintf("'%s' file not found in %s template", htmlspecialchars($file), $this->template)); } } diff --git a/templates/default/layout.tpl b/templates/default/layout.tpl index 2c8a56d44..0f01dfc78 100644 --- a/templates/default/layout.tpl +++ b/templates/default/layout.tpl @@ -28,7 +28,7 @@ URL: http://www.thelia.net {block name="meta"}{/block} - {stylesheets file='assets/less/styles.less' filters='less,cssembed'} + {stylesheets file='assets/less/styles.less' filters='less,cssembed,cssrewrite'} {/stylesheets} {debugbar_rendercss} From 5d0eb4e61e5d41ad2a2b5a9f6fda9fbd0930aeef Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 9 Oct 2013 10:34:35 +0200 Subject: [PATCH 16/18] do not display some information about template file --- core/lib/Thelia/Core/Template/Smarty/SmartyParser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index b6c1ed1b7..6acbf834b 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -212,14 +212,14 @@ class SmartyParser extends Smarty implements ParserInterface $templateDir = realpath(THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/"); if (strpos($pathFileName, $templateDir) !== 0) { - throw new ResourceNotFoundException(sprintf("'%s' view does not exists", htmlspecialchars($file))); + throw new ResourceNotFoundException(sprintf("this view does not exists")); } if (!file_exists($fileName)) { $fileName .= ".html"; if (!file_exists($fileName)) { - throw new ResourceNotFoundException(sprintf("'%s' file not found in %s template", htmlspecialchars($file), $this->template)); + throw new ResourceNotFoundException(sprintf("file not found in %s template", $this->template)); } } From d8ec745fea39595b949a6ce5dabeb1c8b049f1ab Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 9 Oct 2013 12:44:49 +0200 Subject: [PATCH 17/18] fix issue concerning absoluteUrl --- core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php | 2 +- core/lib/Thelia/Tools/URL.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php index b7bb95b83..93dbb6f86 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php @@ -36,7 +36,7 @@ class Assetic extends AbstractSmartyPlugin { $web_root = THELIA_WEB_DIR; - $asset_dir_from_web_root = ConfigQuery::read('asset_dir_from_web_root', 'assets'); + $asset_dir_from_web_root = ConfigQuery::read('asset_dir_from_web_root', 'assets/'); $this->assetManager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root, $developmentMode == 'dev'); } diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 83469f602..3e137e5e4 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -129,8 +129,9 @@ class URL // If only a path is requested, be sure to remove the script name (index.php or index_dev.php), if any. if ($path_only == self::PATH_TO_FILE) { + // As the base_url always ends with '/', if we don't find / at the end, we have a script. - if (substr($base_url, -1) != '/') $base_url = dirname($base_url); + if (substr($base_url, -3) == 'php') $base_url = dirname($base_url); } // Normalize the given path From 159441a1a94232e515bf6df060f793d4fd47983d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 11 Oct 2013 10:57:31 +0200 Subject: [PATCH 18/18] normalize url generator cache class --- .../Core/DependencyInjection/Compiler/RegisterRouterPass.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php index 7d7ab086f..8fb086403 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php @@ -58,6 +58,7 @@ class RegisterRouterPass implements CompilerPassInterface $priority = isset($attributes[0]["priority"]) ? $attributes[0]["priority"] : 0; $router = $container->getDefinition($id); $router->addMethodCall("setOption", array("matcher_cache_class", $container::camelize("ProjectUrlMatcher".$id))); + $router->addMethodCall("setOption", array("generator_cache_class", $container::camelize("ProjectUrlGenerator".$id))); $chainRouter->addMethodCall("add", array(new Reference($id), $priority)); @@ -76,7 +77,8 @@ class RegisterRouterPass implements CompilerPassInterface array( "cache_dir" => $container->getParameter("kernel.cache_dir"), "debug" => $container->getParameter("kernel.debug"), - "matcher_cache_class" => $container::camelize("ProjectUrlMatcher".$moduleCode) + "matcher_cache_class" => $container::camelize("ProjectUrlMatcher".$moduleCode), + "generator_cache_class" => $container::camelize("ProjectUrlGenerator".$moduleCode), ), new Reference("request.context") )