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 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", diff --git a/core/lib/Thelia/Action/Country.php b/core/lib/Thelia/Action/Country.php new file mode 100644 index 000000000..9bccfcea5 --- /dev/null +++ b/core/lib/Thelia/Action/Country.php @@ -0,0 +1,114 @@ +. */ +/* */ +/*************************************************************************************/ + +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; +use Thelia\Model\CountryQuery; + + +/** + * Class Country + * @package Thelia\Action + * @author Manuel Raynaud + */ +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); + + } + + public function update(CountryUpdateEvent $event) + { + + } + + public function delete(CountryDeleteEvent $event) + { + if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { + $country->delete(); + + $event->setCountry($country); + } + } + + 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. + * + * 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), + TheliaEvents::COUNTRY_TOGGLE_DEFAULT => array('toggleDefault', 128) + ); + } +} \ No newline at end of file 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 diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 67c14bce5..939cc9d88 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -121,6 +121,11 @@ + + + + + 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/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index ff829f67f..62049d285 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -405,6 +405,29 @@ Thelia\Controller\Admin\FolderController::updatePositionAction + + + + Thelia\Controller\Admin\CountryController::defaultAction + + + + Thelia\Controller\Admin\CountryController::createAction + + + + Thelia\Controller\Admin\CountryController::updateAction + \d+ + + + + Thelia\Controller\Admin\CountryController::deleteAction + + + + Thelia\Controller\Admin\CountryController::toggleDefaultAction + + Thelia\Controller\Admin\ContentController::createAction @@ -668,20 +691,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..a272f7364 100644 --- a/core/lib/Thelia/Controller/Admin/CountryController.php +++ b/core/lib/Thelia/Controller/Admin/CountryController.php @@ -22,31 +22,249 @@ /*************************************************************************************/ 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; +use Thelia\Form\CountryModificationForm; +use Thelia\Model\CountryQuery; /** * 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() + { + return new CountryCreationForm($this->getRequest()); + } + + /** + * Return the update form for this object + */ + protected function getUpdateForm() + { + return new CountryModificationForm($this->getRequest()); + } + + /** + * Hydrate the update form for this object, before passing it to the update template + * + * @param \Thelia\Model\Country $object + */ + protected function hydrateObjectForm($object) + { + $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); + } + + /** + * Creates the creation event with the provided form data + * + * @param unknown $formData + */ + protected function getCreationEvent($formData) + { + $event = new CountryCreateEvent(); + + return $this->hydrateEvent($event, $formData); + } + + /** + * Creates the update event with the provided form data + * + * @param unknown $formData + */ + protected function getUpdateEvent($formData) + { + $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; + } + + /** + * Creates the delete event with the provided form data + */ + protected function getDeleteEvent() + { + return new CountryDeleteEvent($this->getRequest()->get('country_id')); + } + + /** + * 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) + { + return $event->hasCountry(); + } + + /** + * Get the created object from an event. + * + * @param unknown $createEvent + */ + protected function getObjectFromEvent($event) + { + return $event->getCountry(); + } + + /** + * Load an existing object from the database + */ + protected function getExistingObject() + { + 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 \Thelia\Model\Country $object + */ + protected function getObjectLabel($object) + { + return $object->getTitle(); + } + + /** + * Returns the object ID from the object + * + * @param \Thelia\Model\Country $object + */ + protected function getObjectId($object) + { + return $object->getId(); + } + + /** + * 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 - )); + return $this->render('country-edit', $this->getEditionArgument()); } + protected function getEditionArgument() + { + return array( + 'country_id' => $this->getRequest()->get('country_id', 0) + ); + } + + /** + * Redirect to the edition template + */ + protected function redirectToEditionTemplate() + { + $this->redirectToRoute('admin.configuration.countries.update', array(), $this->getRequest()->get('country_id', 0)); + } + + /** + * Redirect to the list template + */ + protected function redirectToListTemplate() + { + $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/DependencyInjection/Compiler/RegisterRouterPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php index 505d7a3fa..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") ) @@ -84,7 +86,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)); } } } 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..962d880fa --- /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 = null) + { + $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/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/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 e2e0d128c..a21e0a9c9 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_DEFAULT = "action.toggleCountryDefault"; + //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/Core/Template/Loop/Country.php b/core/lib/Thelia/Core/Template/Loop/Country.php index f41173a33..a44e49277 100755 --- a/core/lib/Thelia/Core/Template/Loop/Country.php +++ b/core/lib/Thelia/Core/Template/Loop/Country.php @@ -116,8 +116,10 @@ class Country extends BaseI18nLoop ->set("IS_DEFAULT", $country->getByDefault() === 1 ? "1" : "0") ->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/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/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index 868f1570c..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", $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", $file, $this->template)); + throw new ResourceNotFoundException(sprintf("file not found in %s template", $this->template)); } } 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 757db19d0..68570425b 100644 --- a/core/lib/Thelia/Form/CountryModificationForm.php +++ b/core/lib/Thelia/Form/CountryModificationForm.php @@ -26,78 +26,20 @@ 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 { + use StandardDescriptionFieldsTrait; + protected function buildForm() { parent::buildForm(true); $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" - ) - )) ; + + // 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/Country.php b/core/lib/Thelia/Model/Country.php index a7a6c23b9..e254d4a5e 100755 --- a/core/lib/Thelia/Model/Country.php +++ b/core/lib/Thelia/Model/Country.php @@ -2,8 +2,59 @@ 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 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)); + 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)); + } } 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/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 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 fe1b614a1..6de45aa38 100644 --- a/templates/admin/default/countries.html +++ b/templates/admin/default/countries.html @@ -35,12 +35,12 @@ - - - - - - + + + + + + {module_include location='countries_table_header'} @@ -54,8 +54,8 @@
IDNameDefaultShopN° ISOISO Code{intl l="ID"}{intl l="Name"}{intl l="Default"}{intl l="Shop"}{intl l="N° ISO"}{intl l="ISO Code"}{$ID} {$TITLE} -
- +
+
@@ -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'} @@ -202,6 +208,23 @@ form_content = {$smarty.capture.delete_dialog nofilter} } + + {/block} {block name="javascript-initialization"} @@ -210,10 +233,30 @@ {/javascripts} 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'} 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} 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 }