Merge branch 'master' into tax
This commit is contained in:
114
core/lib/Thelia/Action/Country.php
Normal file
114
core/lib/Thelia/Action/Country.php
Normal 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
154
core/lib/Thelia/Core/Event/Country/CountryCreateEvent.php
Normal file
154
core/lib/Thelia/Core/Event/Country/CountryCreateEvent.php
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
60
core/lib/Thelia/Core/Event/Country/CountryDeleteEvent.php
Normal file
60
core/lib/Thelia/Core/Event/Country/CountryDeleteEvent.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
73
core/lib/Thelia/Core/Event/Country/CountryEvent.php
Normal file
73
core/lib/Thelia/Core/Event/Country/CountryEvent.php
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
35
core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php
Normal file
35
core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php
Normal 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
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user