Merge branch 'master' into tax

This commit is contained in:
Etienne Roudeix
2013-10-11 11:13:41 +02:00
32 changed files with 932 additions and 131 deletions

2
.gitignore vendored
View File

@@ -24,3 +24,5 @@ xhprof/
phpunit.phar
.DS_Store
phpmyadmin
templates/default-esi
local/modules/TemplateEsiModule

View File

@@ -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",

8
composer.lock generated
View File

@@ -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",

View File

@@ -0,0 +1,114 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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)
);
}
}

View File

@@ -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

View File

@@ -121,6 +121,11 @@
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.country" class="Thelia\Action\Country">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
</services>
</config>

View File

@@ -64,7 +64,7 @@
<argument key="debug">%kernel.debug%</argument>
</argument>
<argument type="service" id="request.context"/>
<tag name="router.register" priority="254"/>
<tag name="router.register" priority="128"/>
</service>
<service id="router.rewrite" class="Thelia\Core\Routing\RewritingRouter">

View File

@@ -405,6 +405,29 @@
<default key="_controller">Thelia\Controller\Admin\FolderController::updatePositionAction</default>
</route>
<!-- Countries routes management -->
<route id="admin.configuration.countries.default" path="/admin/configuration/countries">
<default key="_controller">Thelia\Controller\Admin\CountryController::defaultAction</default>
</route>
<route id="admin.configuration.countries.create" path="/admin/configuration/countries/create">
<default key="_controller">Thelia\Controller\Admin\CountryController::createAction</default>
</route>
<route id="admin.configuration.countries.update" path="/admin/configuration/country/update/{country_id}">
<default key="_controller">Thelia\Controller\Admin\CountryController::updateAction</default>
<requirement key="country_id">\d+</requirement>
</route>
<route id="admin.configuration.countries.delete" path="/admin/configuration/countries/delete">
<default key="_controller">Thelia\Controller\Admin\CountryController::deleteAction</default>
</route>
<route id="admin.configuration.toggle-default" path="/admin/configuration/country/toggleDefault">
<default key="_controller">Thelia\Controller\Admin\CountryController::toggleDefaultAction</default>
</route>
<!-- content routes management -->
<route id="admin.content.create" path="/admin/content/create">
<default key="_controller">Thelia\Controller\Admin\ContentController::createAction</default>
@@ -668,20 +691,7 @@
<!-- end attribute and feature routes management -->
<!-- Countries routes management -->
<route id="admin.configuration.countries.default" path="/admin/configuration/countries">
<default key="_controller">Thelia\Controller\Admin\CountryController::indexAction</default>
</route>
<route id="admin.configuration.countries.create" path="/admin/configuration/countries/create">
<default key="_controller">Thelia\Controller\Admin\CountryController::createAction</default>
</route>
<route id="admin.configuration.countries.update.view" path="/admin/configuration/countries/update/{country_id}" methods="get">
<default key="_controller">Thelia\Controller\Admin\CountryController::updateAction</default>
<requirement key="country_id">\d+</requirement>
</route>
<!-- end countries routes management -->

View File

@@ -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 <mraynaud@openstudio.fr>
*/
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);
}
}

View File

@@ -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);
}
/**

View File

@@ -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));
}
}
}

View File

@@ -0,0 +1,154 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Country;
/**
* Class CountryCreateEvent
* @package Thelia\Core\Event\Country
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Country;
/**
* Class CountryDeleteEvent
* @package Thelia\Core\Event\Country
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Country;
use Thelia\Core\Event\ActionEvent;
use Thelia\Model\Country;
/**
* Class CountryEvent
* @package Thelia\Core\Event\Country
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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;
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Country;
/**
* Class CountryToggleDefaultEvent
* @package Thelia\Core\Event\Country
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
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;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Country;
/**
* Class CountryUpdateEvent
* @package Thelia\Core\Event\Country
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class CountryUpdateEvent extends CountryCreateEvent
{
}

View File

@@ -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";

View File

@@ -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);
}

View File

@@ -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');
}

View File

@@ -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));
}
}

View File

@@ -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"
)

View File

@@ -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()

View File

@@ -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
}
}

View File

@@ -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));
}
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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),

View File

@@ -75,7 +75,7 @@
<behavior name="timestampable" />
</table>
<table name="country" namespace="Thelia\Model">
<column name="id" primaryKey="true" required="true" type="INTEGER" />
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="area_id" type="INTEGER" />
<column name="isocode" required="true" size="4" type="VARCHAR" />
<column name="isoalpha2" size="2" type="VARCHAR" />

View File

@@ -35,12 +35,12 @@
</caption>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Default</th>
<th>Shop</th>
<th>N° ISO</th>
<th>ISO Code</th>
<th>{intl l="ID"}</th>
<th>{intl l="Name"}</th>
<th>{intl l="Default"}</th>
<th>{intl l="Shop"}</th>
<th>{intl l="N° ISO"}</th>
<th>{intl l="ISO Code"}</th>
{module_include location='countries_table_header'}
@@ -54,8 +54,8 @@
<td>{$ID}</td>
<td>{$TITLE}</td>
<td>
<div class="make-switch switch-small switch-radio" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input class="change-default" type="radio" name="" value="{$ID}" {if $IS_DEFAULT}selected="selected"{/if}/>
<div class="make-switch switch-small switch-radio change-default-toggle" data-id="{$ID}" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input class="change-default-toggle" type="radio" name="by_default" value="{$ID}" {if $IS_DEFAULT}checked="checked"{/if}/>
</div>
</td>
<td>
@@ -71,7 +71,7 @@
<td class="actions">
<div class="btn-group">
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.countries.change"}
<a class="btn btn-default btn-xs country-change" title="{intl l='Change this country'}" href="{url path="/admin/configuration/countries/update/{$ID}"}">
<a class="btn btn-default btn-xs country-change" title="{intl l='Change this country'}" href="{url path="/admin/configuration/country/update/{$ID}"}">
<span class="glyphicon glyphicon-edit"></span>
</a>
{/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 *}
<input type="hidden" name="{$name}" value="{url path='/admin/country/update' country_id='_ID_'}" />
<input type="hidden" name="{$name}" value="{url path='/admin/configuration/country/update/_ID_'}" />
{/form_field}
{form_field form=$form field='title'}
@@ -160,6 +160,12 @@
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Alpha code 3'}">
</div>
{/form_field}
{loop type="lang" name="default-lang" default_only="1"}
<input type="hidden" name="edit_language_id" value="{$ID}" />
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$LOCALE}" />
{/form_field}
{/loop}
{module_include location='country_create_form'}
@@ -202,6 +208,23 @@
form_content = {$smarty.capture.delete_dialog nofilter}
}
<div class="modal fade" id="toggle-default-failed" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content alert alert-block alert-danger ">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h2>{intl l="Error"}</h2>
</div>
<div class="modal-body">
<strong>{intl l="Impossible to change default country. Please contact your administrator or try later"}</strong>
</div>
</div>
</div>
</div>
{/block}
{block name="javascript-initialization"}
@@ -210,10 +233,30 @@
<script src="{$asset_url}"></script>
<script>
// Toogle switch on input radio
$('.switch-radio').on('switch-change', function () {
$('.switch-radio').bootstrapSwitch('toggleRadioState');
$(document).ready(function(){
// Toogle switch on input radio
$('.switch-radio').on('switch-change', function () {
$('.switch-radio').bootstrapSwitch('toggleRadioState');
});
$('.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')
}
}).fail(function(){
$('#toggle-default-failed').modal('show');
});
}
});
});
</script>
{/javascripts}

View File

@@ -92,13 +92,13 @@
{form_field form=$form field='title'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Country title'}">
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$TITLE}" title="{intl l="{$label}"}" placeholder="{intl l='Country title'}">
</div>
{/form_field}
{form_field form=$form field='short-description'}
{form_field form=$form field='chapo'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
<textarea id="{$label_attr.for}" name="{$name}" class="form-control" title="{intl l="{$label}"}" placeholder="{intl l='Country short description'}"></textarea>
<textarea id="{$label_attr.for}" name="{$name}" class="form-control" title="{intl l=""}" placeholder="{intl l='Country short description'}"></textarea>
</div>
{/form_field}
{form_field form=$form field='description'}

View File

@@ -28,7 +28,7 @@ URL: http://www.thelia.net
{block name="meta"}{/block}
<!-- StyleSheet -->
{stylesheets file='assets/less/styles.less' filters='less,cssembed'}
{stylesheets file='assets/less/styles.less' filters='less,cssembed,cssrewrite'}
<link rel="stylesheet" href="{$asset_url}">
{/stylesheets}
{debugbar_rendercss}

View File

@@ -204,7 +204,14 @@
<select name="{$name}" id="{$label_attr.for}" class="form-control" required>
<option value="">-- {intl l="Select Country"} --</option>
{loop type="country" name="country.list"}
<option value="{$ID}" {if $value == $ID}selected{/if} >{$TITLE}</option>
<option value="{$ID}"
{if $value != ""}
{if $value == $ID}selected{/if}
{else}
{if $IS_DEFAULT}selected{/if}
{/if}
>{$TITLE}</option>
{/loop}
</select>
{if $error }