Merge branch 'master' of https://github.com/thelia/thelia into coupon
# By Manuel Raynaud (18) and others # Via franck (9) and others * 'master' of https://github.com/thelia/thelia: (39 commits) Working : Working : Working : Working : Fixed minor visual glitches Working : Resize countries flag + Add bootstrap-switch fix test suite clear asset cache in cache:cler command Added a 'development mode' to assetic smarty plugin rewriting router use good Request object Added Tools\URL test case, and a test case superclass for initializing Tools\URL remove unused UrlWritin controller create router for rewriting matching customer substitutions fix typo in front id Working : For attributes on labels Working : For attributes on labels add label_attr attribute to form smarty plugin start refactorin rewriting routing ... Conflicts: core/lib/Thelia/Config/Resources/routing/front.xml templates/admin/default/assets/less/thelia/bootstrap-editable.less templates/admin/default/categories.html
This commit is contained in:
@@ -143,7 +143,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
||||
return array(
|
||||
"action.addArticle" => array("addItem", 128),
|
||||
"action.deleteArticle" => array("deleteItem", 128),
|
||||
"action.changeArticle" => array("changeItem", 128),
|
||||
"action.updateArticle" => array("changeItem", 128),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -248,9 +248,9 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::CATEGORY_TOGGLE_VISIBILITY => array("toggleVisibility", 128),
|
||||
TheliaEvents::CATEGORY_CHANGE_POSITION => array("changePosition", 128),
|
||||
|
||||
"action.changeCategoryPositionU" => array("changePositionUp", 128),
|
||||
"action.changeCategoryPositionDown" => array("changePositionDown", 128),
|
||||
"action.changeCategoryPosition" => array("changePosition", 128),
|
||||
"action.updateCategoryPositionU" => array("changePositionUp", 128),
|
||||
"action.updateCategoryPositionDown" => array("changePositionDown", 128),
|
||||
"action.updateCategoryPosition" => array("changePosition", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ use Thelia\Model\Config as ConfigModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\ConfigChangeEvent;
|
||||
use Thelia\Core\Event\ConfigUpdateEvent;
|
||||
use Thelia\Core\Event\ConfigCreateEvent;
|
||||
use Thelia\Core\Event\ConfigDeleteEvent;
|
||||
|
||||
@@ -65,9 +65,9 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a configuration entry value
|
||||
*
|
||||
* @param ConfigChangeEvent $event
|
||||
* @param ConfigUpdateEvent $event
|
||||
*/
|
||||
public function setValue(ConfigChangeEvent $event)
|
||||
public function setValue(ConfigUpdateEvent $event)
|
||||
{
|
||||
$search = ConfigQuery::create();
|
||||
|
||||
@@ -90,9 +90,9 @@ class Config extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a configuration entry
|
||||
*
|
||||
* @param ConfigChangeEvent $event
|
||||
* @param ConfigUpdateEvent $event
|
||||
*/
|
||||
public function modify(ConfigChangeEvent $event)
|
||||
public function modify(ConfigUpdateEvent $event)
|
||||
{
|
||||
$search = ConfigQuery::create();
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ use Thelia\Model\Currency as CurrencyModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\CurrencyChangeEvent;
|
||||
use Thelia\Core\Event\CurrencyUpdateEvent;
|
||||
use Thelia\Core\Event\CurrencyCreateEvent;
|
||||
use Thelia\Core\Event\CurrencyDeleteEvent;
|
||||
use Thelia\Model\Map\CurrencyTableMap;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Event\CurrencyUpdatePositionEvent;
|
||||
|
||||
class Currency extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
@@ -67,9 +67,9 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a currency
|
||||
*
|
||||
* @param CurrencyChangeEvent $event
|
||||
* @param CurrencyUpdateEvent $event
|
||||
*/
|
||||
public function update(CurrencyChangeEvent $event)
|
||||
public function update(CurrencyUpdateEvent $event)
|
||||
{
|
||||
$search = CurrencyQuery::create();
|
||||
|
||||
@@ -93,9 +93,9 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Set the default currency
|
||||
*
|
||||
* @param CurrencyChangeEvent $event
|
||||
* @param CurrencyUpdateEvent $event
|
||||
*/
|
||||
public function setDefault(CurrencyChangeEvent $event)
|
||||
public function setDefault(CurrencyUpdateEvent $event)
|
||||
{
|
||||
$search = CurrencyQuery::create();
|
||||
|
||||
@@ -107,6 +107,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
CurrencyQuery::create()->filterByByDefault(true)->update(array('ByDefault' => false));
|
||||
|
||||
$currency
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->setByDefault($event->getIsDefault())
|
||||
->save()
|
||||
;
|
||||
@@ -139,7 +140,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
$rates_url = ConfigQuery::read('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml');
|
||||
|
||||
$rate_data = file_get_contents($rates_url);
|
||||
$rate_data = @file_get_contents($rates_url);
|
||||
|
||||
if ($rate_data && $sxe = new \SimpleXMLElement($rate_data)) {
|
||||
|
||||
@@ -149,12 +150,38 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
$rate = floatval($last['rate']);
|
||||
|
||||
if (null !== $currency = CurrencyQuery::create()->findOneByCode($code)) {
|
||||
$currency->setRate($rate)->save();
|
||||
$currency
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->setRate($rate)
|
||||
->save()
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new \RuntimeException(sprintf("Failed to get currency rates data from URL %s", $url));
|
||||
throw new \RuntimeException(sprintf("Failed to get currency rates data from URL %s", $rates_url));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes position, selecting absolute ou relative change.
|
||||
*
|
||||
* @param CategoryChangePositionEvent $event
|
||||
*/
|
||||
public function updatePosition(CurrencyUpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $currency = CurrencyQuery::create()->findOneById($event->getObjectId())) {
|
||||
|
||||
$currency->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
|
||||
if ($mode == CurrencyUpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
return $currency->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == CurrencyUpdatePositionEvent::POSITION_UP)
|
||||
return $currency->movePositionUp();
|
||||
else if ($mode == CurrencyUpdatePositionEvent::POSITION_DOWN)
|
||||
return $currency->movePositionDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,12 +191,12 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::CURRENCY_CREATE => array("create", 128),
|
||||
TheliaEvents::CURRENCY_UPDATE => array("update", 128),
|
||||
TheliaEvents::CURRENCY_DELETE => array("delete", 128),
|
||||
TheliaEvents::CURRENCY_SET_DEFAULT => array("setDefault", 128),
|
||||
TheliaEvents::CURRENCY_UPDATE_RATES => array("updateRates", 128),
|
||||
|
||||
TheliaEvents::CURRENCY_CREATE => array("create", 128),
|
||||
TheliaEvents::CURRENCY_UPDATE => array("update", 128),
|
||||
TheliaEvents::CURRENCY_DELETE => array("delete", 128),
|
||||
TheliaEvents::CURRENCY_SET_DEFAULT => array("setDefault", 128),
|
||||
TheliaEvents::CURRENCY_UPDATE_RATES => array("updateRates", 128),
|
||||
TheliaEvents::CURRENCY_UPDATE_POSITION => array("updatePosition", 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,8 +269,8 @@ class Image extends BaseAction implements EventSubscriberInterface
|
||||
$event->setCacheFilepath($cacheFilePath);
|
||||
$event->setCacheOriginalFilepath($originalImagePathInCache);
|
||||
|
||||
$event->setFileUrl(URL::absoluteUrl($processed_image_url, null, URL::PATH_TO_FILE));
|
||||
$event->setOriginalFileUrl(URL::absoluteUrl($original_image_url, null, URL::PATH_TO_FILE));
|
||||
$event->setFileUrl(URL::getInstance()->absoluteUrl($processed_image_url, null, URL::PATH_TO_FILE));
|
||||
$event->setOriginalFileUrl(URL::getInstance()->absoluteUrl($original_image_url, null, URL::PATH_TO_FILE));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,7 +382,7 @@ class Image extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
$path = $this->getCachePathFromWebRoot($subdir);
|
||||
|
||||
return URL::absoluteUrl(sprintf("%s/%s", $path, $safe_filename), null, URL::PATH_TO_FILE);
|
||||
return URL::getInstance()->absoluteUrl(sprintf("%s/%s", $path, $safe_filename), null, URL::PATH_TO_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -494,4 +494,4 @@ class Image extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::IMAGE_CLEAR_CACHE => array("clearCache", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ use Thelia\Model\Message as MessageModel;
|
||||
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
use Thelia\Core\Event\MessageChangeEvent;
|
||||
use Thelia\Core\Event\MessageUpdateEvent;
|
||||
use Thelia\Core\Event\MessageCreateEvent;
|
||||
use Thelia\Core\Event\MessageDeleteEvent;
|
||||
|
||||
@@ -65,9 +65,9 @@ class Message extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change a message
|
||||
*
|
||||
* @param MessageChangeEvent $event
|
||||
* @param MessageUpdateEvent $event
|
||||
*/
|
||||
public function modify(MessageChangeEvent $event)
|
||||
public function modify(MessageUpdateEvent $event)
|
||||
{
|
||||
$search = MessageQuery::create();
|
||||
|
||||
|
||||
157
core/lib/Thelia/Action/PositionManagementTrait.php
Normal file
157
core/lib/Thelia/Action/PositionManagementTrait.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?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 Thelia\Core\Event\BaseChangePositionEvent;
|
||||
|
||||
trait PositionManagementTrait {
|
||||
|
||||
const POSITION_UP
|
||||
/**
|
||||
* Changes object position, selecting absolute ou relative change.
|
||||
*
|
||||
* @param BaseChangePositionEvent $event
|
||||
*/
|
||||
public function changePosition(BaseChangePositionEvent $event)
|
||||
{
|
||||
if ($event->getMode() == BaseChangePositionEvent::POSITION_ABSOLUTE)
|
||||
return $this->changeAbsolutePosition($event);
|
||||
else
|
||||
return $this->exchangePosition($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move up or down a object
|
||||
*
|
||||
* @param BaseChangePositionEvent $event
|
||||
*/
|
||||
protected function exchangePosition(BaseChangePositionEvent $event)
|
||||
{
|
||||
$object = CategoryQuery::create()->findPk($event->getCategoryId());
|
||||
|
||||
if ($object !== null) {
|
||||
|
||||
// The current position of the object
|
||||
$my_position = $object->getPosition();
|
||||
|
||||
// Find object to exchange position with
|
||||
$search = CategoryQuery::create()
|
||||
->filterByParent($object->getParent());
|
||||
|
||||
// Up or down ?
|
||||
if ($event->getMode() == BaseChangePositionEvent::POSITION_UP) {
|
||||
// Find the object immediately before me
|
||||
$search->filterByPosition(array('max' => $my_position-1))->orderByPosition(Criteria::DESC);
|
||||
} elseif ($event->getMode() == BaseChangePositionEvent::POSITION_DOWN) {
|
||||
// Find the object immediately after me
|
||||
$search->filterByPosition(array('min' => $my_position+1))->orderByPosition(Criteria::ASC);
|
||||
} else
|
||||
|
||||
return;
|
||||
|
||||
$result = $search->findOne();
|
||||
|
||||
// If we found the proper object, exchange their positions
|
||||
if ($result) {
|
||||
|
||||
$cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
|
||||
|
||||
$cnx->beginTransaction();
|
||||
|
||||
try {
|
||||
$object
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->setPosition($result->getPosition())
|
||||
->save()
|
||||
;
|
||||
|
||||
$result->setPosition($my_position)->save();
|
||||
|
||||
$cnx->commit();
|
||||
} catch (Exception $e) {
|
||||
$cnx->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes object position
|
||||
*
|
||||
* @param BaseChangePositionEvent $event
|
||||
*/
|
||||
protected function changeAbsolutePosition(BaseChangePositionEvent $event)
|
||||
{
|
||||
$object = CategoryQuery::create()->findPk($event->getCategoryId());
|
||||
|
||||
if ($object !== null) {
|
||||
|
||||
// The required position
|
||||
$new_position = $event->getPosition();
|
||||
|
||||
// The current position
|
||||
$current_position = $object->getPosition();
|
||||
|
||||
if ($new_position != null && $new_position > 0 && $new_position != $current_position) {
|
||||
|
||||
// Find categories to offset
|
||||
$search = CategoryQuery::create()->filterByParent($object->getParent());
|
||||
|
||||
if ($new_position > $current_position) {
|
||||
// The new position is after the current position -> we will offset + 1 all categories located between us and the new position
|
||||
$search->filterByPosition(array('min' => 1+$current_position, 'max' => $new_position));
|
||||
|
||||
$delta = -1;
|
||||
} else {
|
||||
// The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position
|
||||
$search->filterByPosition(array('min' => $new_position, 'max' => $current_position - 1));
|
||||
|
||||
$delta = 1;
|
||||
}
|
||||
|
||||
$results = $search->find();
|
||||
|
||||
$cnx = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
|
||||
|
||||
$cnx->beginTransaction();
|
||||
|
||||
try {
|
||||
foreach ($results as $result) {
|
||||
$result->setPosition($result->getPosition() + $delta)->save($cnx);
|
||||
}
|
||||
|
||||
$object
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->setPosition($new_position)
|
||||
->save($cnx)
|
||||
;
|
||||
|
||||
$cnx->commit();
|
||||
} catch (Exception $e) {
|
||||
$cnx->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
namespace Thelia\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
@@ -44,7 +45,14 @@ class CacheClear extends ContainerAwareCommand
|
||||
{
|
||||
$this
|
||||
->setName("cache:clear")
|
||||
->setDescription("Invalidate all caches");
|
||||
->setDescription("Invalidate all caches")
|
||||
->addOption(
|
||||
"without-assets",
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
"remove cache assets"
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
@@ -52,20 +60,28 @@ class CacheClear extends ContainerAwareCommand
|
||||
|
||||
$cacheDir = $this->getContainer()->getParameter("kernel.cache_dir");
|
||||
|
||||
if (!is_writable($cacheDir)) {
|
||||
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $cacheDir));
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("Clearing cache in <info>%s</info> directory", $cacheDir));
|
||||
|
||||
$fs = new Filesystem();
|
||||
try {
|
||||
$fs->remove($cacheDir);
|
||||
|
||||
$output->writeln("<info>cache cleared successfully</info>");
|
||||
} catch (IOException $e) {
|
||||
$output->writeln(sprintf("error during clearing cache : %s", $e->getMessage()));
|
||||
$this->clearCache($cacheDir, $output);
|
||||
if(!$input->getOption("without-assets")) {
|
||||
$this->clearCache(THELIA_WEB_DIR . "/assets", $output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function clearCache($dir, OutputInterface $output)
|
||||
{
|
||||
if (!is_writable($dir)) {
|
||||
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $dir));
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("Clearing cache in <info>%s</info> directory", $dir));
|
||||
|
||||
$fs = new Filesystem();
|
||||
try {
|
||||
$fs->remove($dir);
|
||||
|
||||
$output->writeln(sprintf("<info>%s cache dir cleared successfully</info>", $dir));
|
||||
} catch (IOException $e) {
|
||||
$output->writeln(sprintf("error during clearing cache : %s", $e->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.address" class="Thelia\Action\Address">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.image" class="Thelia\Action\Image">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
|
||||
@@ -44,6 +44,9 @@
|
||||
<form name="thelia.customer.login" class="Thelia\Form\CustomerLogin"/>
|
||||
<form name="thelia.admin.login" class="Thelia\Form\AdminLogin"/>
|
||||
|
||||
<form name="thelia.address.create" class="Thelia\Form\AddressCreateForm" />
|
||||
<form name="thelia.address.update" class="Thelia\Form\AddressUpdateForm" />
|
||||
|
||||
<form name="thelia.admin.category.creation" class="Thelia\Form\CategoryCreationForm"/>
|
||||
<form name="thelia.admin.category.deletion" class="Thelia\Form\CategoryDeletionForm"/>
|
||||
|
||||
@@ -75,6 +78,13 @@
|
||||
|
||||
<services>
|
||||
|
||||
<!-- URL maganement -->
|
||||
|
||||
<service id="thelia.url.manager" class="Thelia\Tools\URL">
|
||||
<argument type="service" id="service_container" />
|
||||
<argument >%kernel.environment%</argument>
|
||||
</service>
|
||||
|
||||
<service id="event_dispatcher" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
@@ -122,6 +132,7 @@
|
||||
|
||||
<service id="smarty.plugin.assetic" class="Thelia\Core\Template\Smarty\Plugins\Assetic" >
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
<argument>%kernel.environment%</argument>
|
||||
</service>
|
||||
|
||||
<service id="smarty.plugin.theliasyntax" class="Thelia\Core\Template\Smarty\Plugins\TheliaSyntax" >
|
||||
|
||||
@@ -75,6 +75,10 @@
|
||||
<argument key="debug">%kernel.debug%</argument>
|
||||
</argument>
|
||||
<argument type="service" id="request.context"/>
|
||||
<tag name="router.register" priority="254"/>
|
||||
</service>
|
||||
|
||||
<service id="router.rewrite" class="Thelia\Core\Routing\RewritingRouter">
|
||||
<tag name="router.register" priority="255"/>
|
||||
</service>
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\ConfigController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.variables.change-values" path="/admin/configuration/variables/change-values">
|
||||
<route id="admin.configuration.variables.update-values" path="/admin/configuration/variables/update-values">
|
||||
<default key="_controller">Thelia\Controller\Admin\ConfigController::changeValuesAction</default>
|
||||
</route>
|
||||
|
||||
@@ -78,11 +78,11 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\ConfigController::createAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.variables.change" path="/admin/configuration/variables/change">
|
||||
<route id="admin.configuration.variables.update" path="/admin/configuration/variables/update">
|
||||
<default key="_controller">Thelia\Controller\Admin\ConfigController::changeAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.variables.save-change" path="/admin/configuration/variables/save-change">
|
||||
<route id="admin.configuration.variables.save" path="/admin/configuration/variables/save">
|
||||
<default key="_controller">Thelia\Controller\Admin\ConfigController::saveChangeAction</default>
|
||||
</route>
|
||||
|
||||
@@ -100,11 +100,11 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\MessageController::createAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.messages.change" path="/admin/configuration/messages/change">
|
||||
<route id="admin.configuration.messages.update" path="/admin/configuration/messages/update">
|
||||
<default key="_controller">Thelia\Controller\Admin\MessageController::changeAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.messages.save-change" path="/admin/configuration/messages/save-change">
|
||||
<route id="admin.configuration.messages.save" path="/admin/configuration/messages/save">
|
||||
<default key="_controller">Thelia\Controller\Admin\MessageController::saveChangeAction</default>
|
||||
</route>
|
||||
|
||||
@@ -122,11 +122,11 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::createAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.currencies.change" path="/admin/configuration/currencies/change">
|
||||
<route id="admin.configuration.currencies.update" path="/admin/configuration/currencies/update">
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::changeAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.currencies.save-change" path="/admin/configuration/currencies/save-change">
|
||||
<route id="admin.configuration.currencies.save" path="/admin/configuration/currencies/save">
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::saveChangeAction</default>
|
||||
</route>
|
||||
|
||||
@@ -142,6 +142,10 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.currencies.update-position" path="/admin/configuration/currencies/update-position">
|
||||
<default key="_controller">Thelia\Controller\Admin\CurrencyController::updatePositionAction</default>
|
||||
</route>
|
||||
|
||||
<!-- The default route, to display a template -->
|
||||
|
||||
<route id="admin.processTemplate" path="/admin/{template}">
|
||||
|
||||
@@ -29,8 +29,18 @@
|
||||
<!-- end customer routes -->
|
||||
|
||||
<!-- customer address routes -->
|
||||
<route id="customer.adress.create" path="/customer/address/create" >
|
||||
<default key="_controller">Thelia\Controller\Front\CustomerAddressController::createAction</default>
|
||||
<route id="address.create" path="/address/create" >
|
||||
<default key="_controller">Thelia\Controller\Front\AddressController::createAction</default>
|
||||
<default key="_view">address</default>
|
||||
</route>
|
||||
|
||||
<route id="address.edit" path="/address/edit/{address_id}">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">address_edit</default>
|
||||
</route>
|
||||
|
||||
<route id="address.update" path="/address/update" >
|
||||
<default key="_controller">Thelia\Controller\Front\AddressController::updateAction</default>
|
||||
</route>
|
||||
<!-- end customer address routes -->
|
||||
|
||||
@@ -40,7 +50,7 @@
|
||||
<default key="_view">cart</default>
|
||||
</route>
|
||||
|
||||
<route id="cart.change.process" path="/cart/delete/{cart_item}">
|
||||
<route id="cart.delete.process" path="/cart/delete/{cart_item}">
|
||||
<default key="_controller">Thelia\Controller\Front\CartController::deleteItem</default>
|
||||
<default key="_view">cart</default>
|
||||
</route>
|
||||
@@ -50,9 +60,4 @@
|
||||
<default key="_view">cart</default>
|
||||
</route>
|
||||
|
||||
<!--<route id="url-rewriting.check" path="/{rewritten_url}" methods="GET">-->
|
||||
<!--<default key="_controller">Thelia\Controller\Front\UrlRewritingController::check</default>-->
|
||||
<!--<requirement key="rewritten_url">.*</requirement>-->
|
||||
<!--</route>-->
|
||||
|
||||
</routes>
|
||||
|
||||
@@ -85,10 +85,16 @@ class BaseAdminController extends BaseController
|
||||
/**
|
||||
* Return a general error page
|
||||
*
|
||||
* @param mixed $message a message string, or an exception instance
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function errorPage($message)
|
||||
{
|
||||
if ($message instanceof \Exception) {
|
||||
$message = sprintf("Sorry, an error occured: %s", $message->getMessage());
|
||||
}
|
||||
|
||||
return $this->render('general_error', array(
|
||||
"error_message" => $message)
|
||||
);
|
||||
@@ -168,24 +174,31 @@ class BaseAdminController extends BaseController
|
||||
* @param unknown $urlParameters the URL parametrs, as a var/value pair array
|
||||
*/
|
||||
public function redirectToRoute($routeId, $urlParameters = array()) {
|
||||
$this->redirect(URL::absoluteUrl($this->getRoute($routeId), $urlParameters));
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId), $urlParameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current edition lang ID, checking if a change was requested in the current request
|
||||
* Get the current edition lang ID, checking if a change was requested in the current request.
|
||||
*/
|
||||
protected function getCurrentEditionLangId() {
|
||||
return $this->getRequest()->get(
|
||||
'edit_language_id',
|
||||
$this->getSession()->getAdminEditionLangId()
|
||||
);
|
||||
protected function getCurrentEditionLang() {
|
||||
|
||||
// Return the new language if a change is required.
|
||||
if (null !== $edit_language_id = $this->getRequest()->get('edit_language_id', null)) {
|
||||
|
||||
if (null !== $edit_language = LangQuery::create()->findOneById($edit_language_id)) {
|
||||
return $edit_language;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise return the lang stored in session.
|
||||
return $this->getSession()->getAdminEditionLang();
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple helper to get the current edition locale, from the session edition language ID
|
||||
* A simple helper to get the current edition locale.
|
||||
*/
|
||||
protected function getCurrentEditionLocale() {
|
||||
return LangQuery::create()->findOneById($this->getCurrentEditionLangId())->getLocale();
|
||||
return $this->getCurrentEditionLang()->getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,23 +230,14 @@ class BaseAdminController extends BaseController
|
||||
|
||||
$session = $this->getSession();
|
||||
|
||||
$edition_language = $this->getCurrentEditionLangId();
|
||||
|
||||
// Current back-office (not edition) language
|
||||
$current_lang = LangQuery::create()->findOneById($session->getLangId());
|
||||
|
||||
// Find the current edit language ID
|
||||
$edition_language = LangQuery::create()->findOneById($this->getCurrentEditionLangId());
|
||||
$edition_language = $this->getCurrentEditionLang();
|
||||
|
||||
// Prepare common template variables
|
||||
$args = array_merge($args, array(
|
||||
'locale' => $session->getLocale(),
|
||||
'lang_code' => $session->getLang(),
|
||||
'lang_id' => $session->getLangId(),
|
||||
|
||||
'datetime_format' => $current_lang->getDateTimeFormat(),
|
||||
'date_format' => $current_lang->getDateFormat(),
|
||||
'time_format' => $current_lang->getTimeFormat(),
|
||||
'locale' => $session->getLang()->getLocale(),
|
||||
'lang_code' => $session->getLang()->getCode(),
|
||||
'lang_id' => $session->getLang()->getId(),
|
||||
|
||||
'edit_language_id' => $edition_language->getId(),
|
||||
'edit_language_locale' => $edition_language->getLocale(),
|
||||
@@ -242,7 +246,7 @@ class BaseAdminController extends BaseController
|
||||
));
|
||||
|
||||
// Update the current edition language in session
|
||||
$this->getSession()->setAdminEditionLangId($edition_language->getId());
|
||||
$this->getSession()->setAdminEditionLang($edition_language);
|
||||
|
||||
// Render the template.
|
||||
try {
|
||||
@@ -253,7 +257,7 @@ class BaseAdminController extends BaseController
|
||||
catch (AuthenticationException $ex) {
|
||||
// User is not authenticated, and templates requires authentication -> redirect to login page
|
||||
// We user login_tpl as a path, not a template.
|
||||
Redirect::exec(URL::absoluteUrl($ex->getLoginTemplate()));
|
||||
Redirect::exec(URL::getInstance()->absoluteUrl($ex->getLoginTemplate()));
|
||||
}
|
||||
catch (AuthorizationException $ex) {
|
||||
// User is not allowed to perform the required action. Return the error page instead of the requested page.
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\ConfigDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Core\Event\ConfigChangeEvent;
|
||||
use Thelia\Core\Event\ConfigUpdateEvent;
|
||||
use Thelia\Core\Event\ConfigCreateEvent;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
@@ -154,7 +154,7 @@ class ConfigController extends BaseAdminController
|
||||
public function changeAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.variables.change")) return $response;
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response;
|
||||
|
||||
// Load the config object
|
||||
$config = ConfigQuery::create()
|
||||
@@ -196,7 +196,7 @@ class ConfigController extends BaseAdminController
|
||||
public function saveChangeAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.variables.change")) return $response;
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response;
|
||||
|
||||
$message = false;
|
||||
|
||||
@@ -214,7 +214,7 @@ class ConfigController extends BaseAdminController
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
$changeEvent = new ConfigChangeEvent($data['id']);
|
||||
$changeEvent = new ConfigUpdateEvent($data['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
@@ -284,13 +284,13 @@ class ConfigController extends BaseAdminController
|
||||
public function changeValuesAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.variables.change")) return $response;
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response;
|
||||
|
||||
$variables = $this->getRequest()->get('variable', array());
|
||||
|
||||
// Process all changed variables
|
||||
foreach($variables as $id => $value) {
|
||||
$event = new ConfigChangeEvent($id);
|
||||
$event = new ConfigUpdateEvent($id);
|
||||
$event->setValue($value);
|
||||
|
||||
$this->dispatch(TheliaEvents::CONFIG_SETVALUE, $event);
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\CurrencyDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Core\Event\CurrencyChangeEvent;
|
||||
use Thelia\Core\Event\CurrencyUpdateEvent;
|
||||
use Thelia\Core\Event\CurrencyCreateEvent;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
@@ -34,6 +34,7 @@ use Thelia\Core\Security\Exception\AuthorizationException;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Form\CurrencyModificationForm;
|
||||
use Thelia\Form\CurrencyCreationForm;
|
||||
use Thelia\Core\Event\CurrencyUpdatePositionEvent;
|
||||
|
||||
/**
|
||||
* Manages currencies sent by mail
|
||||
@@ -124,7 +125,7 @@ class CurrencyController extends BaseAdminController
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage());
|
||||
$error_msg = $ex;
|
||||
}
|
||||
|
||||
if ($error_msg !== false) {
|
||||
@@ -153,7 +154,7 @@ class CurrencyController extends BaseAdminController
|
||||
public function changeAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
|
||||
|
||||
// Load the currency object
|
||||
$currency = CurrencyQuery::create()
|
||||
@@ -191,7 +192,7 @@ class CurrencyController extends BaseAdminController
|
||||
public function saveChangeAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
|
||||
|
||||
$error_msg = false;
|
||||
|
||||
@@ -209,7 +210,7 @@ class CurrencyController extends BaseAdminController
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
$changeEvent = new CurrencyChangeEvent($data['id']);
|
||||
$changeEvent = new CurrencyUpdateEvent($data['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
@@ -231,7 +232,7 @@ class CurrencyController extends BaseAdminController
|
||||
// just redirect to the edit page again.
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.currencies.change",
|
||||
"admin.configuration.currencies.update",
|
||||
array('currency_id' => $currency_id)
|
||||
);
|
||||
}
|
||||
@@ -245,7 +246,7 @@ class CurrencyController extends BaseAdminController
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage());
|
||||
$error_msg = $ex;
|
||||
}
|
||||
|
||||
if ($error_msg !== false) {
|
||||
@@ -271,9 +272,9 @@ class CurrencyController extends BaseAdminController
|
||||
*/
|
||||
public function setDefaultAction() {
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
|
||||
|
||||
$changeEvent = new CurrencyChangeEvent($this->getRequest()->get('currency_id', 0));
|
||||
$changeEvent = new CurrencyUpdateEvent($this->getRequest()->get('currency_id', 0));
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent->setIsDefault(true);
|
||||
@@ -283,7 +284,7 @@ class CurrencyController extends BaseAdminController
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage(sprintf("Sorry, an error occured: %s", $ex->getMessage()));
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.configuration.currencies.default');
|
||||
@@ -294,19 +295,55 @@ class CurrencyController extends BaseAdminController
|
||||
*/
|
||||
public function updateRatesAction() {
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage(sprintf("Sorry, an error occured: %s", $ex->getMessage()));
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.configuration.currencies.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update currencyposition
|
||||
*/
|
||||
public function updatePositionAction() {
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
|
||||
|
||||
try {
|
||||
$mode = $this->getRequest()->get('mode', null);
|
||||
|
||||
if ($mode == 'up')
|
||||
$mode = CurrencyUpdatePositionEvent::POSITION_UP;
|
||||
else if ($mode == 'down')
|
||||
$mode = CurrencyUpdatePositionEvent::POSITION_DOWN;
|
||||
else
|
||||
$mode = CurrencyUpdatePositionEvent::POSITION_ABSOLUTE;
|
||||
|
||||
$position = $this->getRequest()->get('position', null);
|
||||
|
||||
$event = new CurrencyUpdatePositionEvent(
|
||||
$this->getRequest()->get('currency_id', null),
|
||||
$mode,
|
||||
$this->getRequest()->get('position', null)
|
||||
);
|
||||
|
||||
$this->dispatch(TheliaEvents::CURRENCY_UPDATE_POSITION, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.configuration.currencies.default');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a currency object
|
||||
*
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\MessageDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Core\Event\MessageChangeEvent;
|
||||
use Thelia\Core\Event\MessageUpdateEvent;
|
||||
use Thelia\Core\Event\MessageCreateEvent;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
@@ -133,7 +133,7 @@ class MessageController extends BaseAdminController
|
||||
public function changeAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.messages.change")) return $response;
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.messages.update")) return $response;
|
||||
|
||||
// Load the message object
|
||||
$message = MessageQuery::create()
|
||||
@@ -173,7 +173,7 @@ class MessageController extends BaseAdminController
|
||||
public function saveChangeAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.messages.change")) return $response;
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.messages.update")) return $response;
|
||||
|
||||
$message = false;
|
||||
|
||||
@@ -191,7 +191,7 @@ class MessageController extends BaseAdminController
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
$changeEvent = new MessageChangeEvent($data['id']);
|
||||
$changeEvent = new MessageUpdateEvent($data['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
@@ -215,7 +215,7 @@ class MessageController extends BaseAdminController
|
||||
// just redirect to the edit page again.
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.messages.change",
|
||||
"admin.configuration.messages.update",
|
||||
array('message_id' => $message_id)
|
||||
);
|
||||
}
|
||||
@@ -265,6 +265,6 @@ class MessageController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::MESSAGE_DELETE, $event);
|
||||
|
||||
$this->redirect(URL::adminViewUrl('messages'));
|
||||
$this->redirect(URL::getInstance()->adminViewUrl('messages'));
|
||||
}
|
||||
}
|
||||
@@ -24,33 +24,42 @@
|
||||
namespace Thelia\Controller\Front;
|
||||
use Thelia\Core\Event\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\AddressForm;
|
||||
use Thelia\Form\AddressCreateForm;
|
||||
use Thelia\Form\AddressUpdateForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\Base\AddressQuery;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
|
||||
/**
|
||||
* Class CustomerAddressController
|
||||
* Class AddressController
|
||||
* @package Thelia\Controller\Front
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class CustomerAddressController extends BaseFrontController
|
||||
class AddressController extends BaseFrontController
|
||||
{
|
||||
|
||||
/**
|
||||
* Create controller.
|
||||
* Check if customer is logged in
|
||||
*
|
||||
* Dispatch TheliaEvents::ADDRESS_CREATE event
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
if ($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
$this->redirect(URL::getIndexPage());
|
||||
$this->redirect(URL::getInstance()->getIndexPage());
|
||||
}
|
||||
|
||||
$addressCreate = new AddressForm($this->getRequest());
|
||||
$addressCreate = new AddressCreateForm($this->getRequest());
|
||||
|
||||
try {
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
|
||||
$form = $this->validateForm($addressCreate, "post");
|
||||
$event = $this->createAddressEvent($form->getData(), $customer);
|
||||
$event = $this->createAddressEvent($form);
|
||||
$event->setCustomer($customer);
|
||||
|
||||
$this->dispatch(TheliaEvents::ADDRESS_CREATE, $event);
|
||||
$this->redirectSuccess($addressCreate);
|
||||
@@ -74,23 +83,76 @@ class CustomerAddressController extends BaseFrontController
|
||||
}
|
||||
}
|
||||
|
||||
protected function createAddressEvent($data, Customer $customer)
|
||||
public function updateAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
$this->redirectToRoute("home");
|
||||
}
|
||||
|
||||
if(null === $address_id = $request->get("address_id")) {
|
||||
$this->redirectToRoute("home");
|
||||
}
|
||||
|
||||
$addressUpdate = new AddressUpdateForm($request);
|
||||
|
||||
try {
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
|
||||
$form = $this->validateForm($addressUpdate);
|
||||
|
||||
$address = AddressQuery::create()->findPk($address_id);
|
||||
|
||||
if (null === $address) {
|
||||
$this->redirectToRoute("home");
|
||||
}
|
||||
|
||||
if($address->getCustomer()->getId() != $customer->getId()) {
|
||||
$this->redirectToRoute("home");
|
||||
}
|
||||
|
||||
$event = $this->createAddressEvent($form);
|
||||
$event->setAddress($address);
|
||||
|
||||
$this->dispatch(TheliaEvents::ADDRESS_UPDATE, $event);
|
||||
|
||||
$this->redirectSuccess($addressUpdate);
|
||||
}catch (FormValidationException $e) {
|
||||
$message = sprintf("Please check your input: %s", $e->getMessage());
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$message = sprintf("Sorry, an error occured: %s", $e->getMessage());
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));
|
||||
|
||||
$addressUpdate->setErrorMessage($message);
|
||||
|
||||
$this->getParserContext()
|
||||
->addForm($addressUpdate)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
protected function createAddressEvent($form)
|
||||
{
|
||||
return new AddressCreateOrUpdateEvent(
|
||||
$data["label"],
|
||||
$data["title"],
|
||||
$data["firstname"],
|
||||
$data["lastname"],
|
||||
$data["address1"],
|
||||
$data["address2"],
|
||||
$data["address3"],
|
||||
$data["zipcode"],
|
||||
$data["city"],
|
||||
$data["country"],
|
||||
$data["cellpone"],
|
||||
$data["phone"],
|
||||
$data["company"],
|
||||
$customer
|
||||
$form->get("label")->getData(),
|
||||
$form->get("title")->getData(),
|
||||
$form->get("firstname")->getData(),
|
||||
$form->get("lastname")->getData(),
|
||||
$form->get("address1")->getData(),
|
||||
$form->get("address2")->getData(),
|
||||
$form->get("address3")->getData(),
|
||||
$form->get("zipcode")->getData(),
|
||||
$form->get("city")->getData(),
|
||||
$form->get("country")->getData(),
|
||||
$form->get("cellphone")->getData(),
|
||||
$form->get("phone")->getData(),
|
||||
$form->get("company")->getData()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
use Thelia\Controller\BaseController;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
class BaseFrontController extends BaseController
|
||||
{
|
||||
@@ -44,6 +45,6 @@ class BaseFrontController extends BaseController
|
||||
* @param unknown $urlParameters the URL parametrs, as a var/value pair array
|
||||
*/
|
||||
public function redirectToRoute($routeId, $urlParameters = array()) {
|
||||
$this->redirect(URL::absoluteUrl($this->getRoute($routeId), $urlParameters));
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId), $urlParameters));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ class CustomerController extends BaseFrontController
|
||||
}
|
||||
|
||||
// Redirect to home page
|
||||
$this->redirect(URL::getIndexPage());
|
||||
$this->redirect(URL::getInstance()->getIndexPage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,23 +46,30 @@ class DefaultController extends BaseFrontController
|
||||
*/
|
||||
public function noAction(Request $request)
|
||||
{
|
||||
if(ConfigQuery::isRewritingEnable()) {
|
||||
|
||||
/* Does the query GET parameters match a rewritten URL ? */
|
||||
$rewrittenUrl = URL::init()->retrieveCurrent($request);
|
||||
if($rewrittenUrl->rewrittenUrl !== null) {
|
||||
/* 301 redirection to rewritten URL */
|
||||
$this->redirect($rewrittenUrl->rewrittenUrl, 301);
|
||||
}
|
||||
}
|
||||
$view = null;
|
||||
|
||||
if (! $view = $request->query->get('view')) {
|
||||
$view = "index";
|
||||
if ($request->request->has('view')) {
|
||||
$view = $request->request->get('view');
|
||||
}
|
||||
}
|
||||
if(null !== $view) {
|
||||
$request->attributes->set('_view', $view);
|
||||
}
|
||||
|
||||
$request->attributes->set('_view', $view);
|
||||
if (null === $view && null === $request->attributes->get("_view")) {
|
||||
$request->attributes->set("_view", "index");
|
||||
}
|
||||
|
||||
if(ConfigQuery::isRewritingEnable()) {
|
||||
if($request->attributes->get('_rewritten', false) === false) {
|
||||
/* Does the query GET parameters match a rewritten URL ? */
|
||||
$rewrittenUrl = URL::getInstance()->retrieveCurrent($request);
|
||||
if($rewrittenUrl->rewrittenUrl !== null) {
|
||||
/* 301 redirection to rewritten URL */
|
||||
$this->redirect($rewrittenUrl->rewrittenUrl, 301);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
<?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\Controller\Front;
|
||||
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Exception\UrlRewritingException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
class UrlRewritingController extends BaseFrontController
|
||||
{
|
||||
public function check(Request $request, $rewritten_url)
|
||||
{
|
||||
if(ConfigQuery::isRewritingEnable()) {
|
||||
try {
|
||||
$rewrittenUrlData = URL::init()->resolve($rewritten_url);
|
||||
} catch(UrlRewritingException $e) {
|
||||
switch($e->getCode()) {
|
||||
case UrlRewritingException::URL_NOT_FOUND :
|
||||
return $this->pageNotFound();
|
||||
break;
|
||||
default:
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/* is the URL redirected ? */
|
||||
|
||||
if(null !== $rewrittenUrlData->redirectedToUrl) {
|
||||
$this->redirect($rewrittenUrlData->redirectedToUrl, 301);
|
||||
}
|
||||
|
||||
/* define GET arguments in request */
|
||||
|
||||
if(null !== $rewrittenUrlData->view) {
|
||||
$request->query->set('view', $rewrittenUrlData->view);
|
||||
if(null !== $rewrittenUrlData->viewId) {
|
||||
$request->query->set($rewrittenUrlData->view . '_id', $rewrittenUrlData->viewId);
|
||||
}
|
||||
}
|
||||
if(null !== $rewrittenUrlData->locale) {
|
||||
$request->query->set('locale', $rewrittenUrlData->locale);
|
||||
}
|
||||
|
||||
foreach($rewrittenUrlData->otherParameters as $parameter => $value) {
|
||||
$request->query->set($parameter, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if (! $view = $request->query->get('view')) {
|
||||
$view = "index";
|
||||
if ($request->request->has('view')) {
|
||||
$view = $request->request->get('view');
|
||||
}
|
||||
}
|
||||
|
||||
$request->attributes->set('_view', $view);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,7 @@ use Thelia\Model\Customer;
|
||||
* @package Thelia\Core\Event
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class AddressCreateOrUpdateEvent extends Event
|
||||
class AddressCreateOrUpdateEvent extends ActionEvent
|
||||
{
|
||||
/**
|
||||
* @var string address label
|
||||
|
||||
54
core/lib/Thelia/Core/Event/AddressEvent.php
Normal file
54
core/lib/Thelia/Core/Event/AddressEvent.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Thelia\Model\Address;
|
||||
|
||||
|
||||
/**
|
||||
* Class AddressEvent
|
||||
* @package Thelia\Core\Event
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class AddressEvent extends ActionEvent
|
||||
{
|
||||
/**
|
||||
* @var \Thelia\Model\Address
|
||||
*/
|
||||
protected $address;
|
||||
|
||||
function __construct(Address $address)
|
||||
{
|
||||
$this->address = $address;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Address
|
||||
*/
|
||||
public function getAddress()
|
||||
{
|
||||
return $this->address;
|
||||
}
|
||||
}
|
||||
77
core/lib/Thelia/Core/Event/BaseUpdatePositionEvent.php
Normal file
77
core/lib/Thelia/Core/Event/BaseUpdatePositionEvent.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?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;
|
||||
|
||||
class BaseUpdatePositionEvent extends ActionEvent
|
||||
{
|
||||
const POSITION_UP = 1;
|
||||
const POSITION_DOWN = 2;
|
||||
const POSITION_ABSOLUTE = 3;
|
||||
|
||||
protected $object_id;
|
||||
protected $mode;
|
||||
protected $position;
|
||||
|
||||
protected $object;
|
||||
|
||||
public function __construct($object_id, $mode, $position = null)
|
||||
{
|
||||
$this->object_id = $object_id;
|
||||
$this->mode = $mode;
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
public function getMode()
|
||||
{
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
public function setMode($mode)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPosition()
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function setPosition($position)
|
||||
{
|
||||
$this->position = $position;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getObjectId()
|
||||
{
|
||||
return $this->object_id;
|
||||
}
|
||||
|
||||
public function setObjectId($object_id)
|
||||
{
|
||||
$this->object_id = $object_id;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ namespace Thelia\Core\Event;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Thelia\Model\Cart;
|
||||
|
||||
class CartEvent extends Event
|
||||
class CartEvent extends ActionEvent
|
||||
{
|
||||
protected $cart;
|
||||
protected $quantity;
|
||||
|
||||
@@ -22,64 +22,7 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
use Thelia\Model\Category;
|
||||
|
||||
class CategoryChangePositionEvent extends ActionEvent
|
||||
class CurrencyUpdatePositionEvent extends BaseUpdatePositionEvent
|
||||
{
|
||||
const POSITION_UP = 1;
|
||||
const POSITION_DOWN = 2;
|
||||
const POSITION_ABSOLUTE = 3;
|
||||
|
||||
protected $category_id;
|
||||
protected $mode;
|
||||
protected $position;
|
||||
protected $category;
|
||||
|
||||
public function __construct($category_id, $mode, $position = null)
|
||||
{
|
||||
$this->category_id = $category_id;
|
||||
$this->mode = $mode;
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
public function getMode()
|
||||
{
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
public function setMode($mode)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
public function getPosition()
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function setPosition($position)
|
||||
{
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function setCategory($category)
|
||||
{
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
public function getCategoryId()
|
||||
{
|
||||
return $this->category_id;
|
||||
}
|
||||
|
||||
public function setCategoryId($category_id)
|
||||
{
|
||||
$this->category_id = $category_id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace Thelia\Core\Event;
|
||||
|
||||
use Thelia\Model\Category;
|
||||
|
||||
class CategoryCreateEvent extends ActionEvent
|
||||
class CategoryUpdateEvent extends ActionEvent
|
||||
{
|
||||
protected $category_id;
|
||||
protected $locale;
|
||||
@@ -25,7 +25,7 @@ namespace Thelia\Core\Event;
|
||||
|
||||
use Thelia\Model\Config;
|
||||
|
||||
class ConfigChangeEvent extends ConfigCreateEvent
|
||||
class ConfigUpdateEvent extends ConfigCreateEvent
|
||||
{
|
||||
protected $config_id;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Core\Event;
|
||||
use Thelia\Model\Currency;
|
||||
|
||||
class CurrencyChangeEvent extends CurrencyCreateEvent
|
||||
class CurrencyUpdateEvent extends CurrencyCreateEvent
|
||||
{
|
||||
protected $currency_id;
|
||||
protected $is_default;
|
||||
28
core/lib/Thelia/Core/Event/CurrencyUpdatePositionEvent.php
Normal file
28
core/lib/Thelia/Core/Event/CurrencyUpdatePositionEvent.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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;
|
||||
|
||||
class CurrencyUpdatePositionEvent extends BaseUpdatePositionEvent
|
||||
{
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace Thelia\Core\Event;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Thelia\Model\Customer;
|
||||
|
||||
class CustomerCreateOrUpdateEvent extends Event {
|
||||
class CustomerCreateOrUpdateEvent extends ActionEvent {
|
||||
|
||||
//base parameters for creating new customer
|
||||
protected $title;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Thelia\Core\Event;
|
||||
|
||||
use Thelia\Model\Message;
|
||||
|
||||
class MessageChangeEvent extends MessageCreateEvent
|
||||
class MessageUpdateEvent extends MessageCreateEvent
|
||||
{
|
||||
protected $message_id;
|
||||
|
||||
@@ -88,12 +88,13 @@ final class TheliaEvents
|
||||
/**
|
||||
* Sent once the customer change form has been successfully validated, and before customer update in the database.
|
||||
*/
|
||||
const BEFORE_CHANGECUSTOMER = "action.before_updateCustomer";
|
||||
const BEFORE_UPDATECUSTOMER = "action.before_updateCustomer";
|
||||
/**
|
||||
* Sent just after a successful update of a customer in the database.
|
||||
*/
|
||||
const AFTER_CHANGECUSTOMER = "action.after_updateCustomer";
|
||||
const AFTER_UPDATECUSTOMER = "action.after_updateCustomer";
|
||||
|
||||
// -- ADDRESS MANAGEMENT ---------------------------------------------------------
|
||||
/**
|
||||
* sent for address creation
|
||||
*/
|
||||
@@ -104,6 +105,17 @@ final class TheliaEvents
|
||||
*/
|
||||
const ADDRESS_UPDATE = "action.updateAddress";
|
||||
|
||||
const BEFORE_CREATEADDRESS = "action.before_createAddress";
|
||||
const AFTER_CREATEADDRESS = "action.after_createAddress";
|
||||
|
||||
const BEFORE_UPDATEADDRESS = "action.before_updateAddress";
|
||||
const AFTER_UPDATEADDRESS = "action.after_updateAddress";
|
||||
|
||||
const BEFORE_DELETEADDRESS = "action.before_deleteAddress";
|
||||
const AFTER_DELETEADDRESS = "action.after_deleteAddress";
|
||||
|
||||
// -- END ADDRESS MANAGEMENT ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sent once the category creation form has been successfully validated, and before category insertion in the database.
|
||||
*/
|
||||
@@ -124,7 +136,7 @@ final class TheliaEvents
|
||||
/**
|
||||
* Change category position
|
||||
*/
|
||||
const CATEGORY_CHANGE_POSITION = "action.changeCategoryPosition";
|
||||
const CATEGORY_CHANGE_POSITION = "action.updateCategoryPosition";
|
||||
|
||||
/**
|
||||
* Sent just after a successful insert of a new category in the database.
|
||||
@@ -344,12 +356,12 @@ final class TheliaEvents
|
||||
|
||||
// -- Currencies management ---------------------------------------------
|
||||
|
||||
const CURRENCY_CREATE = "action.createCurrency";
|
||||
const CURRENCY_UPDATE = "action.updateCurrency";
|
||||
const CURRENCY_DELETE = "action.deleteCurrency";
|
||||
const CURRENCY_SET_DEFAULT = "action.setDefaultCurrency";
|
||||
const CURRENCY_UPDATE_RATES = "action.updateCurrencyRates";
|
||||
|
||||
const CURRENCY_CREATE = "action.createCurrency";
|
||||
const CURRENCY_UPDATE = "action.updateCurrency";
|
||||
const CURRENCY_DELETE = "action.deleteCurrency";
|
||||
const CURRENCY_SET_DEFAULT = "action.setDefaultCurrency";
|
||||
const CURRENCY_UPDATE_RATES = "action.updateCurrencyRates";
|
||||
const CURRENCY_UPDATE_POSITION = "action.updateCurrencyPosition";
|
||||
|
||||
const BEFORE_CREATECURRENCY = "action.before_createCurrency";
|
||||
const AFTER_CREATECURRENCY = "action.after_createCurrency";
|
||||
|
||||
@@ -86,7 +86,7 @@ class ViewListener implements EventSubscriberInterface
|
||||
} catch (AuthenticationException $ex) {
|
||||
|
||||
// Redirect to the login template
|
||||
Redirect::exec(URL::viewUrl($ex->getLoginTemplate()));
|
||||
Redirect::exec($this->container->get('thelia.url.manager')->viewUrl($ex->getLoginTemplate()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,55 +41,29 @@ use Thelia\Model\Lang;
|
||||
*/
|
||||
class Session extends BaseSession
|
||||
{
|
||||
// -- Language ------------------------------------------------------------
|
||||
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->get("locale", "en_US");
|
||||
}
|
||||
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->set("locale", $locale);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Lang|null
|
||||
*/
|
||||
public function getLang()
|
||||
{
|
||||
return $this->get("lang");
|
||||
return $this->get("thelia.current.lang", Lang::getDefaultLanguage());
|
||||
}
|
||||
|
||||
public function setLang(Lang $lang)
|
||||
{
|
||||
$this->set("lang", $lang);
|
||||
$this->set("thelia.current.lang", $lang);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLangId()
|
||||
public function getAdminEditionLang()
|
||||
{
|
||||
return $this->get("lang_id", Lang::getDefaultLanguage()->getId());
|
||||
return $this->get('thelia.admin.edition.lang', Lang::getDefaultLanguage());
|
||||
}
|
||||
|
||||
public function setLangId($langId)
|
||||
public function setAdminEditionLang($langId)
|
||||
{
|
||||
$this->set("lang_id", $langId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAdminEditionLangId()
|
||||
{
|
||||
return $this->get('admin.edition_language', Lang::getDefaultLanguage()->getId());
|
||||
}
|
||||
|
||||
public function setAdminEditionLangId($langId)
|
||||
{
|
||||
$this->set('admin.edition_language', $langId);
|
||||
$this->set('thelia.admin.edition.lang', $langId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -98,43 +72,43 @@ class Session extends BaseSession
|
||||
|
||||
public function setCustomerUser(UserInterface $user)
|
||||
{
|
||||
$this->set('customer_user', $user);
|
||||
$this->set('thelia.customer_user', $user);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCustomerUser()
|
||||
{
|
||||
return $this->get('customer_user');
|
||||
return $this->get('thelia.customer_user');
|
||||
}
|
||||
|
||||
public function clearCustomerUser()
|
||||
{
|
||||
return $this->remove('customer_user');
|
||||
return $this->remove('thelia.customer_user');
|
||||
}
|
||||
|
||||
// -- Admin user -----------------------------------------------------------
|
||||
|
||||
public function setAdminUser(UserInterface $user)
|
||||
{
|
||||
$this->set('admin_user', $user);
|
||||
$this->set('thelia.admin_user', $user);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAdminUser()
|
||||
{
|
||||
return $this->get('admin_user');
|
||||
return $this->get('thelia.admin_user');
|
||||
}
|
||||
|
||||
public function clearAdminUser()
|
||||
{
|
||||
return $this->remove('admin_user');
|
||||
return $this->remove('thelia.admin_user');
|
||||
}
|
||||
|
||||
// -- Return page ----------------------------------------------------------
|
||||
|
||||
public function setReturnToUrl($url)
|
||||
{
|
||||
$this->set('return_to_url', $url);
|
||||
$this->set('thelia.return_to_url', $url);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -144,7 +118,7 @@ class Session extends BaseSession
|
||||
*/
|
||||
public function getReturnToUrl()
|
||||
{
|
||||
return $this->get('return_to_url', URL::getIndexPage());
|
||||
return $this->get('thelia.return_to_url', URL::getInstance()->getIndexPage());
|
||||
}
|
||||
|
||||
// -- Cart ------------------------------------------------------------------
|
||||
@@ -156,7 +130,7 @@ class Session extends BaseSession
|
||||
*/
|
||||
public function getCart()
|
||||
{
|
||||
$cart_id = $this->get("cart_id");
|
||||
$cart_id = $this->get("thelia.cart_id");
|
||||
$cart = null;
|
||||
if ($cart_id) {
|
||||
$cart = CartQuery::create()->findPk($cart_id);
|
||||
@@ -193,7 +167,7 @@ class Session extends BaseSession
|
||||
*/
|
||||
public function setCart($cart_id)
|
||||
{
|
||||
$this->set("cart_id", $cart_id);
|
||||
$this->set("thelia.cart_id", $cart_id);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
219
core/lib/Thelia/Core/Routing/RewritingRouter.php
Normal file
219
core/lib/Thelia/Core/Routing/RewritingRouter.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?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\Routing;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Exception\InvalidParameterException;
|
||||
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
|
||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
use Thelia\Exception\RedirectException;
|
||||
use Thelia\Exception\UrlRewritingException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\Redirect;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
|
||||
/**
|
||||
* Class RewritingRouter
|
||||
* @package Thelia\Core\Routing
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class RewritingRouter implements RouterInterface, RequestMatcherInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var RequestContext The context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @var options, don't use for now but mandatory
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Sets the request context.
|
||||
*
|
||||
* @param RequestContext $context The context
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setContext(RequestContext $context)
|
||||
{
|
||||
// TODO: Implement setContext() method.
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the request context.
|
||||
*
|
||||
* @return RequestContext The context
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getContext()
|
||||
{
|
||||
// TODO: Implement getContext() method.
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
public function setOption($key, $value)
|
||||
{
|
||||
//NOTHING TO DO FOR NOW
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RouteCollection instance associated with this Router.
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*/
|
||||
public function getRouteCollection()
|
||||
{
|
||||
return new RouteCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a URL or path for a specific route based on the given parameters.
|
||||
*
|
||||
* Parameters that reference placeholders in the route pattern will substitute them in the
|
||||
* path or host. Extra params are added as query string to the URL.
|
||||
*
|
||||
* When the passed reference type cannot be generated for the route because it requires a different
|
||||
* host or scheme than the current one, the method will return a more comprehensive reference
|
||||
* that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH
|
||||
* but the route requires the https scheme whereas the current scheme is http, it will instead return an
|
||||
* ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches
|
||||
* the route in any case.
|
||||
*
|
||||
* If there is no route with the given name, the generator must throw the RouteNotFoundException.
|
||||
*
|
||||
* @param string $name The name of the route
|
||||
* @param mixed $parameters An array of parameters
|
||||
* @param Boolean|string $referenceType The type of reference to be generated (one of the constants)
|
||||
*
|
||||
* @return string The generated URL
|
||||
*
|
||||
* @throws RouteNotFoundException If the named route doesn't exist
|
||||
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
|
||||
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
||||
* it does not match the requirement
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
|
||||
{
|
||||
// TODO: Implement generate() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to match a URL path with a set of routes.
|
||||
*
|
||||
* If the matcher can not find information, it must throw one of the exceptions documented
|
||||
* below.
|
||||
*
|
||||
* @param string $pathinfo The path info to be parsed (raw format, i.e. not urldecoded)
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*
|
||||
* @throws ResourceNotFoundException If the resource could not be found
|
||||
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function match($pathinfo)
|
||||
{
|
||||
throw new ResourceNotFoundException("impossible to find route with this method, please use matchRequest method");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to match a request with a set of routes.
|
||||
*
|
||||
* If the matcher can not find information, it must throw one of the exceptions documented
|
||||
* below.
|
||||
*
|
||||
* @param Request $request The request to match
|
||||
*
|
||||
* @throws \Exception|\Thelia\Exception\UrlRewritingException
|
||||
* @throws \Symfony\Component\Routing\Exception\ResourceNotFoundException
|
||||
* @throws \Thelia\Exception\RedirectException
|
||||
* @return array An array of parameters
|
||||
*
|
||||
*/
|
||||
public function matchRequest(Request $request)
|
||||
{
|
||||
if(ConfigQuery::isRewritingEnable()) {
|
||||
try {
|
||||
$rewrittenUrlData = URL::getInstance()->resolve($request->getPathInfo());
|
||||
} catch(UrlRewritingException $e) {
|
||||
switch($e->getCode()) {
|
||||
case UrlRewritingException::URL_NOT_FOUND :
|
||||
throw new ResourceNotFoundException();
|
||||
break;
|
||||
default:
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/* is the URL redirected ? */
|
||||
|
||||
if(null !== $rewrittenUrlData->redirectedToUrl) {
|
||||
$this->redirect($rewrittenUrlData->redirectedToUrl, 301);
|
||||
}
|
||||
|
||||
/* define GET arguments in request */
|
||||
|
||||
if(null !== $rewrittenUrlData->view) {
|
||||
$request->attributes->set('_view', $rewrittenUrlData->view);
|
||||
if(null !== $rewrittenUrlData->viewId) {
|
||||
$request->query->set($rewrittenUrlData->view . '_id', $rewrittenUrlData->viewId);
|
||||
}
|
||||
}
|
||||
if(null !== $rewrittenUrlData->locale) {
|
||||
$request->query->set('locale', $rewrittenUrlData->locale);
|
||||
}
|
||||
|
||||
foreach($rewrittenUrlData->otherParameters as $parameter => $value) {
|
||||
$request->query->set($parameter, $value);
|
||||
}
|
||||
|
||||
return array (
|
||||
'_controller' => 'Thelia\\Controller\\Front\\DefaultController::noAction',
|
||||
'_route' => 'rewrite',
|
||||
'_rewritten' => true,
|
||||
);
|
||||
}
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
protected function redirect($url, $status = 302)
|
||||
{
|
||||
Redirect::exec($url, $status);
|
||||
}
|
||||
}
|
||||
@@ -43,15 +43,16 @@ class AsseticHelper
|
||||
* Generates assets from $asset_path in $output_path, using $filters.
|
||||
*
|
||||
* @param string $asset_path the full path to the asset file (or file collection)
|
||||
* @param unknown $output_path the full disk path to the output directory (shoud be visible to web server)
|
||||
* @param unknown $output_url the URL to the generated asset directory
|
||||
* @param unknown $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
||||
* @param unknown $filters a list of filters, as defined below (see switch($filter_name) ...)
|
||||
* @param unknown $debug true / false
|
||||
* @param string $output_path the full disk path to the output directory (shoud be visible to web server)
|
||||
* @param string $output_url the URL to the generated asset directory
|
||||
* @param string $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
|
||||
* @param array $filters a list of filters, as defined below (see switch($filter_name) ...)
|
||||
* @param boolean $debug true / false
|
||||
* @param boolean $dev_mode true / false. If true, assets are not cached and always compiled.
|
||||
* @throws \InvalidArgumentException if an invalid filter name is found
|
||||
* @return string The URL to the generated asset file.
|
||||
*/
|
||||
public function asseticize($asset_path, $output_path, $output_url, $asset_type, $filters, $debug)
|
||||
public function asseticize($asset_path, $output_path, $output_url, $asset_type, $filters, $debug, $dev_mode = false)
|
||||
{
|
||||
$asset_name = basename($asset_path);
|
||||
$asset_dir = dirname($asset_path);
|
||||
@@ -106,17 +107,49 @@ class AsseticHelper
|
||||
|
||||
$factory->setDebug($debug);
|
||||
|
||||
$factory->addWorker(new CacheBustingWorker());
|
||||
$factory->addWorker(new CacheBustingWorker('-'));
|
||||
|
||||
// Prepare the assets writer
|
||||
$writer = new AssetWriter($output_path);
|
||||
// We do not pass the filter list here, juste to get the asset file name
|
||||
$asset = $factory->createAsset($asset_name);
|
||||
|
||||
$asset = $factory->createAsset($asset_name, $filter_list);
|
||||
$asset_target_path = $asset->getTargetPath();
|
||||
|
||||
$cache = new AssetCache($asset, new FilesystemCache($output_path));
|
||||
$target_file = sprintf("%s/%s", $output_path, $asset_target_path);
|
||||
|
||||
$writer->writeAsset($cache);
|
||||
// As it seems that assetic cannot handle a real file cache, let's do the job ourselves.
|
||||
// It works only if the CacheBustingWorker is used, as a new file name is generated for each version.
|
||||
//
|
||||
// the previous version of the file is deleted, by getting the first part of the ouput file name
|
||||
// (the one before '-'), and delete aby file beginning with the same string. Example:
|
||||
// old name: 3bc974a-dfacc1f.css
|
||||
// new name: 3bc974a-ad3ef47.css
|
||||
//
|
||||
// before generating 3bc974a-ad3ef47.css, delete 3bc974a-* files.
|
||||
//
|
||||
if ($dev_mode == true || ! file_exists($target_file)) {
|
||||
|
||||
return rtrim($output_url, '/').'/'.$asset->getTargetPath();
|
||||
// Delete previous version of the file
|
||||
list($commonPart, $dummy) = explode('-', $asset_target_path);
|
||||
|
||||
foreach (glob("$output_path/$commonPart-*") as $filename) {
|
||||
@unlink($filename);
|
||||
}
|
||||
|
||||
// Apply filters now
|
||||
foreach ($filter_list as $filter) {
|
||||
if ('?' != $filter[0]) {
|
||||
$asset->ensureFilter($fm->get($filter));
|
||||
}
|
||||
elseif (!$debug) {
|
||||
$asset->ensureFilter($fm->get(substr($filter, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
$writer = new AssetWriter($output_path);
|
||||
|
||||
$writer->writeAsset($asset);
|
||||
}
|
||||
|
||||
return rtrim($output_url, '/').'/'.$asset_target_path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ abstract class BaseI18nLoop extends BaseLoop
|
||||
$this->getBackend_context(),
|
||||
$this->getLang(),
|
||||
$search,
|
||||
$this->request->getSession()->getLocale(),
|
||||
$this->request->getSession()->getLang()->getLocale(),
|
||||
$columns,
|
||||
$foreignTable,
|
||||
$foreignKey,
|
||||
|
||||
@@ -239,31 +239,6 @@ abstract class BaseLoop
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup ModelCriteria for proper i18n processing
|
||||
*
|
||||
* @param ModelCriteria $search the Propel Criteria to configure
|
||||
* @param array $columns the i18n columns
|
||||
* @param string $foreignTable the specified table (default to criteria table)
|
||||
* @param string $foreignKey the foreign key in this table (default to criteria table)
|
||||
*
|
||||
* @return mixed the locale
|
||||
*/
|
||||
protected function configureI18nProcessing(ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID', $forceReturn = false) {
|
||||
|
||||
/* manage translations */
|
||||
return ModelCriteriaTools::getI18n(
|
||||
$this->getBackend_context(),
|
||||
$this->getLang(),
|
||||
$search,
|
||||
$this->request->getSession()->getLocale(),
|
||||
$columns,
|
||||
$foreignTable,
|
||||
$foreignKey,
|
||||
$forceReturn
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* this function have to be implement in your own loop class.
|
||||
|
||||
@@ -64,7 +64,7 @@ class Address extends BaseLoop
|
||||
),
|
||||
'current'
|
||||
),
|
||||
Argument::createBooleanTypeArgument('default'),
|
||||
Argument::createBooleanTypeArgument('default', false),
|
||||
Argument::createIntListTypeArgument('exclude')
|
||||
);
|
||||
}
|
||||
@@ -99,10 +99,9 @@ class Address extends BaseLoop
|
||||
|
||||
$default = $this->getDefault();
|
||||
|
||||
|
||||
if ($default === true) {
|
||||
$search->filterByIsDefault(1, Criteria::EQUAL);
|
||||
} elseif ($default === false) {
|
||||
$search->filterByIsDefault(1, Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
$exclude = $this->getExclude();
|
||||
@@ -119,7 +118,7 @@ class Address extends BaseLoop
|
||||
$loopResultRow = new LoopResultRow($loopResult, $address, $this->versionable, $this->timestampable, $this->countable);
|
||||
$loopResultRow
|
||||
->set("ID", $address->getId())
|
||||
->set("NAME", $address->getName())
|
||||
->set("LABEL", $address->getLabel())
|
||||
->set("CUSTOMER", $address->getCustomerId())
|
||||
->set("TITLE", $address->getTitleId())
|
||||
->set("COMPANY", $address->getCompany())
|
||||
|
||||
@@ -71,10 +71,12 @@ class Cart extends BaseLoop
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$cartItems = $cart->getCartItems();
|
||||
|
||||
$result = new LoopResult($cartItems);
|
||||
|
||||
|
||||
$cart = $this->getCart($this->request);
|
||||
$cartItems = $cart->getCartItems();
|
||||
$result = new LoopResult($cartItems);
|
||||
|
||||
if ($cart === null) {
|
||||
return $result;
|
||||
|
||||
@@ -166,7 +166,7 @@ class Config extends BaseI18nLoop
|
||||
->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("HIDDEN" , $result->getHidden())
|
||||
->set("SECURED" , $result->getSecured())
|
||||
;
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
@@ -34,18 +34,22 @@ class SmartyAssetsManager
|
||||
|
||||
private $web_root;
|
||||
private $path_relative_to_web_root;
|
||||
private $developmentMode;
|
||||
|
||||
/**
|
||||
* Creates a new SmartyAssetsManager instance
|
||||
*
|
||||
* @param string $web_root the disk path to the web root
|
||||
* @param string $path_relative_to_web_root the path (relative to web root) where the assets will be generated
|
||||
* @param string $web_root the disk path to the web root
|
||||
* @param string $path_relative_to_web_root the path (relative to web root) where the assets will be generated
|
||||
* @param boolean $developmentMode true / false. If true, assets are not cached, and always generated.
|
||||
*/
|
||||
public function __construct($web_root, $path_relative_to_web_root)
|
||||
public function __construct($web_root, $path_relative_to_web_root, $developmentMode)
|
||||
{
|
||||
$this->web_root = $web_root;
|
||||
$this->path_relative_to_web_root = $path_relative_to_web_root;
|
||||
|
||||
$this->developmentMode = $developmentMode;
|
||||
|
||||
$this->assetic_manager = new AsseticHelper();
|
||||
}
|
||||
|
||||
@@ -70,10 +74,11 @@ class SmartyAssetsManager
|
||||
$url = $this->assetic_manager->asseticize(
|
||||
$asset_dir.'/'.$asset_file,
|
||||
$this->web_root."/".$this->path_relative_to_web_root,
|
||||
URL::absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */),
|
||||
URL::getInstance()->absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */),
|
||||
$assetType,
|
||||
$filters,
|
||||
$debug
|
||||
$debug,
|
||||
$this->developmentMode
|
||||
);
|
||||
|
||||
return $url;
|
||||
|
||||
@@ -70,12 +70,12 @@ class AdminUtilities extends AbstractSmartyPlugin
|
||||
|
||||
if ($permissions == null || $this->securityContext->isGranted("ADMIN", array($permission))) {
|
||||
return sprintf(
|
||||
'<a href="%s"><i class="icon-arrow-up"></i></a><span class="%s" data-id="%s">%s</span><a href="%s"><i class="icon-arrow-down"></i></a>',
|
||||
URL::absoluteUrl("$path/positionUp", array($url_parameter => $id)),
|
||||
'<a href="%s"><i class="glyphicon glyphicon-arrow-up"></i></a><span class="%s" data-id="%s">%s</span><a href="%s"><i class="glyphicon glyphicon-arrow-down"></i></a>',
|
||||
URL::getInstance()->absoluteUrl($path, array('mode' => 'up', $url_parameter => $id)),
|
||||
$in_place_edit_class,
|
||||
$id,
|
||||
$position,
|
||||
URL::absoluteUrl("$path/positionDown", array($url_parameter => $id))
|
||||
URL::getInstance()->absoluteUrl($path, array('mode' => 'down', $url_parameter => $id))
|
||||
);
|
||||
}
|
||||
else {
|
||||
@@ -121,11 +121,11 @@ class AdminUtilities extends AbstractSmartyPlugin
|
||||
}
|
||||
|
||||
if (! empty($icon))
|
||||
$output = sprintf('<i class="icon icon-chevron-%s"></i> ', $icon);
|
||||
$output = sprintf('<i class="glyphicon glyphicon-chevron-%s"></i> ', $icon);
|
||||
else
|
||||
$output = '';
|
||||
|
||||
return sprintf('%s<a href="%s">%s</a>', $output, URL::absoluteUrl($path, array('order' => $order_change)), $label);
|
||||
return sprintf('%s<a href="%s">%s</a>', $output, URL::getInstance()->absoluteUrl($path, array('order' => $order_change)), $label);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,13 +32,13 @@ class Assetic extends AbstractSmartyPlugin
|
||||
{
|
||||
public $assetManager;
|
||||
|
||||
public function __construct()
|
||||
public function __construct($developmentMode)
|
||||
{
|
||||
$web_root = THELIA_WEB_DIR;
|
||||
|
||||
$asset_dir_from_web_root = ConfigQuery::read('asset_dir_from_web_root', 'assets');
|
||||
|
||||
$this->assetManager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root);
|
||||
$this->assetManager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root, $developmentMode == 'dev');
|
||||
}
|
||||
|
||||
public function blockJavascripts($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
|
||||
@@ -68,14 +68,14 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to user attributes using the accessors.
|
||||
* @param $objectLabel
|
||||
* @param $user
|
||||
* @param $params
|
||||
*
|
||||
* @param array $params
|
||||
* @param unknown $smarty
|
||||
* @return string the value of the requested attribute
|
||||
* @throws InvalidArgumentException if the object does not have the requested attribute.
|
||||
* @return string
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function userDataAccess($objectLabel, $user, $params)
|
||||
protected function userDataAccess($objectLabel, $user, $params)
|
||||
{
|
||||
$attribute = $this->getNormalizedParam($params, array('attribute', 'attrib', 'attr'));
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ class Form extends AbstractSmartyPlugin
|
||||
}
|
||||
|
||||
$template->assign("label", $formFieldView->vars["label"]);
|
||||
$template->assign("label_attr", $formFieldView->vars["label_attr"]);
|
||||
|
||||
$errors = $formFieldView->vars["errors"];
|
||||
|
||||
|
||||
@@ -136,8 +136,23 @@ class TheliaLoop extends AbstractSmartyPlugin
|
||||
}
|
||||
|
||||
if ($loopResults->valid()) {
|
||||
|
||||
$loopResultRow = $loopResults->current();
|
||||
|
||||
// On first iteration, save variables that may be overwritten by this loop
|
||||
if (! isset($this->varstack[$name])) {
|
||||
|
||||
$saved_vars = array();
|
||||
|
||||
$varlist = $loopResultRow->getVars();
|
||||
|
||||
foreach ($varlist as $var) {
|
||||
$saved_vars[$var] = $template->getTemplateVars($var);
|
||||
}
|
||||
|
||||
$this->varstack[$name] = $saved_vars;
|
||||
}
|
||||
|
||||
foreach ($loopResultRow->getVarVal() as $var => $val) {
|
||||
$template->assign($var, $val);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class UrlGenerator extends AbstractSmartyPlugin
|
||||
|
||||
$target = $this->getParam($params, 'target', null);
|
||||
|
||||
$url = URL::absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target')));
|
||||
$url = URL::getInstance()->absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target')));
|
||||
|
||||
if ($target != null) $url .= '#'.$target;
|
||||
|
||||
@@ -102,7 +102,7 @@ class UrlGenerator extends AbstractSmartyPlugin
|
||||
$args = $this->getArgsFromParam($params, array('view', 'action', 'target'));
|
||||
|
||||
if (! empty($action)) $args['action'] = $action;
|
||||
return $forAdmin ? URL::adminViewUrl($view, $args) : URL::viewUrl($view, $args);
|
||||
return $forAdmin ? URL::getInstance()->adminViewUrl($view, $args) : URL::getInstance()->viewUrl($view, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,16 +169,16 @@ class UrlGenerator extends AbstractSmartyPlugin
|
||||
|
||||
protected function getCurrentUrl()
|
||||
{
|
||||
return URL::init()->retrieveCurrent($this->request)->toString();
|
||||
return URL::getInstance()->retrieveCurrent($this->request)->toString();
|
||||
}
|
||||
|
||||
protected function getReturnToUrl()
|
||||
{
|
||||
return URL::absoluteUrl($this->request->getSession()->getReturnToUrl());
|
||||
return URL::getInstance()->absoluteUrl($this->request->getSession()->getReturnToUrl());
|
||||
}
|
||||
|
||||
protected function getIndexUrl()
|
||||
{
|
||||
return Url::getIndexPage();
|
||||
return URL::getInstance()->getIndexPage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,8 @@ class SmartyParser extends Smarty implements ParserInterface
|
||||
|
||||
$this->debugging = $debug;
|
||||
|
||||
$this->escape_html = true;
|
||||
|
||||
// Prevent smarty ErrorException: Notice: Undefined index bla bla bla...
|
||||
$this->error_reporting = E_ALL ^ E_NOTICE;
|
||||
|
||||
|
||||
@@ -122,6 +122,11 @@ class TheliaHttpKernel extends HttpKernel
|
||||
*/
|
||||
protected function initParam(Request $request)
|
||||
{
|
||||
// Ensure an instaciation of URL service, which is accessed as a pseudo-singleton
|
||||
// in the rest of the application.
|
||||
// See Thelia\Tools\URL class.
|
||||
$this->container->get('thelia.url.manager');
|
||||
|
||||
$lang = $this->detectLang($request);
|
||||
|
||||
if ($lang) {
|
||||
@@ -139,6 +144,7 @@ class TheliaHttpKernel extends HttpKernel
|
||||
protected function detectLang(Request $request)
|
||||
{
|
||||
$lang = null;
|
||||
|
||||
//first priority => lang parameter present in request (get or post)
|
||||
if ($request->query->has("lang")) {
|
||||
$lang = Model\LangQuery::create()->findOneByCode($request->query->get("lang"));
|
||||
|
||||
@@ -26,11 +26,11 @@ use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
|
||||
/**
|
||||
* Class AddressForm
|
||||
* Class AddressCreateForm
|
||||
* @package Thelia\Form
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class AddressForm extends BaseForm
|
||||
class AddressCreateForm extends BaseForm
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,8 @@ class AddressForm extends BaseForm
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => "address name"
|
||||
"label" => "address name",
|
||||
"required" => true
|
||||
))
|
||||
->add("title", "text", array(
|
||||
"constraints" => array(
|
||||
69
core/lib/Thelia/Form/AddressUpdateForm.php
Normal file
69
core/lib/Thelia/Form/AddressUpdateForm.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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\Form;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
|
||||
/**
|
||||
* Class AddressUpdateForm
|
||||
* @package Thelia\Form
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class AddressUpdateForm extends AddressCreateForm {
|
||||
|
||||
/**
|
||||
*
|
||||
* in this function you add all the fields you need for your Form.
|
||||
* Form this you have to call add method on $this->formBuilder attribute :
|
||||
*
|
||||
* $this->formBuilder->add("name", "text")
|
||||
* ->add("email", "email", array(
|
||||
* "attr" => array(
|
||||
* "class" => "field"
|
||||
* ),
|
||||
* "label" => "email",
|
||||
* "constraints" => array(
|
||||
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* ->add('age', 'integer');
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
parent::buildForm();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_address_update";
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ abstract class BaseForm
|
||||
$successUrl = $default;
|
||||
}
|
||||
|
||||
return URL::absoluteUrl($successUrl);
|
||||
return URL::getInstance()->absoluteUrl($successUrl);
|
||||
}
|
||||
|
||||
public function createView()
|
||||
|
||||
@@ -67,6 +67,10 @@ class CartAdd extends BaseForm
|
||||
new Constraints\Callback(array("methods" => array(
|
||||
array($this, "checkProduct")
|
||||
)))
|
||||
),
|
||||
"label" => "product",
|
||||
"label_attr" => array(
|
||||
"for" => "cart_product"
|
||||
)
|
||||
))
|
||||
->add("product_sale_elements_id", "text", array(
|
||||
|
||||
@@ -32,6 +32,10 @@ class CategoryCreationForm extends BaseForm
|
||||
->add("title", "text", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => "Category title *",
|
||||
"label_attr" => array(
|
||||
"for" => "title"
|
||||
)
|
||||
))
|
||||
->add("parent", "integer", array(
|
||||
|
||||
@@ -40,11 +40,47 @@ class CurrencyCreationForm extends BaseForm
|
||||
}
|
||||
|
||||
$this->formBuilder
|
||||
->add("name" , "text" , array("constraints" => array(new NotBlank())))
|
||||
->add("locale" , "text" , array("constraints" => array(new NotBlank())))
|
||||
->add("symbol" , "text" , array("constraints" => array(new NotBlank())))
|
||||
->add("rate" , "text" , array("constraints" => array(new NotBlank())))
|
||||
->add("code" , "text" , array("constraints" => $code_constraints))
|
||||
->add("name" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => "Name *",
|
||||
"label_attr" => array(
|
||||
"for" => "name"
|
||||
))
|
||||
)
|
||||
->add("locale" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
))
|
||||
)
|
||||
->add("symbol" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => "Symbol *",
|
||||
"label_attr" => array(
|
||||
"for" => "symbol"
|
||||
))
|
||||
)
|
||||
->add("rate" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => "Rate from € *",
|
||||
"label_attr" => array(
|
||||
"for" => "rate"
|
||||
))
|
||||
)
|
||||
->add("code" , "text" , array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => "ISO 4217 code *",
|
||||
"label_attr" => array(
|
||||
"for" => "iso_4217_code"
|
||||
))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,21 +2,73 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Event\AddressEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Base\Address as BaseAddress;
|
||||
|
||||
class Address extends BaseAddress {
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
protected $dispatcher;
|
||||
|
||||
public function setDispatcher(EventDispatcherInterface $dispatcher)
|
||||
/**
|
||||
* Code to be run before inserting to database
|
||||
* @param ConnectionInterface $con
|
||||
* @return boolean
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEADDRESS, new AddressEvent($this));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDispatcher()
|
||||
/**
|
||||
* Code to be run after inserting to database
|
||||
* @param ConnectionInterface $con
|
||||
*/
|
||||
public function postInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
return $this->dispatcher;
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_CREATEADDRESS, new AddressEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to be run before updating the object in database
|
||||
* @param ConnectionInterface $con
|
||||
* @return boolean
|
||||
*/
|
||||
public function preUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATEADDRESS, new AddressEvent($this));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to be run after updating the object in database
|
||||
* @param ConnectionInterface $con
|
||||
*/
|
||||
public function postUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_UPDATEADDRESS, new AddressEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to be run before deleting the object in database
|
||||
* @param ConnectionInterface $con
|
||||
* @return boolean
|
||||
*/
|
||||
public function preDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_DELETEADDRESS, new AddressEvent($this));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to be run after deleting the object in database
|
||||
* @param ConnectionInterface $con
|
||||
*/
|
||||
public function postDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_DELETEADDRESS, new AddressEvent($this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -85,10 +85,40 @@ abstract class Lang implements ActiveRecordInterface
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* The value for the position field.
|
||||
* @var int
|
||||
* The value for the date_format field.
|
||||
* @var string
|
||||
*/
|
||||
protected $position;
|
||||
protected $date_format;
|
||||
|
||||
/**
|
||||
* The value for the time_format field.
|
||||
* @var string
|
||||
*/
|
||||
protected $time_format;
|
||||
|
||||
/**
|
||||
* The value for the datetime_format field.
|
||||
* @var string
|
||||
*/
|
||||
protected $datetime_format;
|
||||
|
||||
/**
|
||||
* The value for the decimal_separator field.
|
||||
* @var string
|
||||
*/
|
||||
protected $decimal_separator;
|
||||
|
||||
/**
|
||||
* The value for the thousands_separator field.
|
||||
* @var string
|
||||
*/
|
||||
protected $thousands_separator;
|
||||
|
||||
/**
|
||||
* The value for the decimals field.
|
||||
* @var string
|
||||
*/
|
||||
protected $decimals;
|
||||
|
||||
/**
|
||||
* The value for the by_default field.
|
||||
@@ -96,6 +126,12 @@ abstract class Lang implements ActiveRecordInterface
|
||||
*/
|
||||
protected $by_default;
|
||||
|
||||
/**
|
||||
* The value for the position field.
|
||||
* @var int
|
||||
*/
|
||||
protected $position;
|
||||
|
||||
/**
|
||||
* The value for the created_at field.
|
||||
* @var string
|
||||
@@ -426,14 +462,69 @@ abstract class Lang implements ActiveRecordInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [position] column value.
|
||||
* Get the [date_format] column value.
|
||||
*
|
||||
* @return int
|
||||
* @return string
|
||||
*/
|
||||
public function getPosition()
|
||||
public function getDateFormat()
|
||||
{
|
||||
|
||||
return $this->position;
|
||||
return $this->date_format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [time_format] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTimeFormat()
|
||||
{
|
||||
|
||||
return $this->time_format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [datetime_format] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDatetimeFormat()
|
||||
{
|
||||
|
||||
return $this->datetime_format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [decimal_separator] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDecimalSeparator()
|
||||
{
|
||||
|
||||
return $this->decimal_separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [thousands_separator] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getThousandsSeparator()
|
||||
{
|
||||
|
||||
return $this->thousands_separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [decimals] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDecimals()
|
||||
{
|
||||
|
||||
return $this->decimals;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,6 +538,17 @@ abstract class Lang implements ActiveRecordInterface
|
||||
return $this->by_default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [position] column value.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [optionally formatted] temporal [created_at] column value.
|
||||
*
|
||||
@@ -593,25 +695,130 @@ abstract class Lang implements ActiveRecordInterface
|
||||
} // setUrl()
|
||||
|
||||
/**
|
||||
* Set the value of [position] column.
|
||||
* Set the value of [date_format] column.
|
||||
*
|
||||
* @param int $v new value
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setPosition($v)
|
||||
public function setDateFormat($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (int) $v;
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->position !== $v) {
|
||||
$this->position = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::POSITION;
|
||||
if ($this->date_format !== $v) {
|
||||
$this->date_format = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::DATE_FORMAT;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setPosition()
|
||||
} // setDateFormat()
|
||||
|
||||
/**
|
||||
* Set the value of [time_format] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setTimeFormat($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->time_format !== $v) {
|
||||
$this->time_format = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::TIME_FORMAT;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setTimeFormat()
|
||||
|
||||
/**
|
||||
* Set the value of [datetime_format] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setDatetimeFormat($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->datetime_format !== $v) {
|
||||
$this->datetime_format = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::DATETIME_FORMAT;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setDatetimeFormat()
|
||||
|
||||
/**
|
||||
* Set the value of [decimal_separator] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setDecimalSeparator($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->decimal_separator !== $v) {
|
||||
$this->decimal_separator = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::DECIMAL_SEPARATOR;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setDecimalSeparator()
|
||||
|
||||
/**
|
||||
* Set the value of [thousands_separator] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setThousandsSeparator($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->thousands_separator !== $v) {
|
||||
$this->thousands_separator = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::THOUSANDS_SEPARATOR;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setThousandsSeparator()
|
||||
|
||||
/**
|
||||
* Set the value of [decimals] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setDecimals($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->decimals !== $v) {
|
||||
$this->decimals = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::DECIMALS;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setDecimals()
|
||||
|
||||
/**
|
||||
* Set the value of [by_default] column.
|
||||
@@ -634,6 +841,27 @@ abstract class Lang implements ActiveRecordInterface
|
||||
return $this;
|
||||
} // setByDefault()
|
||||
|
||||
/**
|
||||
* Set the value of [position] column.
|
||||
*
|
||||
* @param int $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setPosition($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (int) $v;
|
||||
}
|
||||
|
||||
if ($this->position !== $v) {
|
||||
$this->position = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::POSITION;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setPosition()
|
||||
|
||||
/**
|
||||
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
|
||||
*
|
||||
@@ -728,19 +956,37 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : LangTableMap::translateFieldName('Url', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->url = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : LangTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->position = (null !== $col) ? (int) $col : null;
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : LangTableMap::translateFieldName('DateFormat', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->date_format = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : LangTableMap::translateFieldName('ByDefault', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : LangTableMap::translateFieldName('TimeFormat', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->time_format = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : LangTableMap::translateFieldName('DatetimeFormat', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->datetime_format = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : LangTableMap::translateFieldName('DecimalSeparator', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->decimal_separator = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : LangTableMap::translateFieldName('ThousandsSeparator', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->thousands_separator = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : LangTableMap::translateFieldName('Decimals', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->decimals = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : LangTableMap::translateFieldName('ByDefault', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->by_default = (null !== $col) ? (int) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : LangTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : LangTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->position = (null !== $col) ? (int) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : LangTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
if ($col === '0000-00-00 00:00:00') {
|
||||
$col = null;
|
||||
}
|
||||
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : LangTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : LangTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
if ($col === '0000-00-00 00:00:00') {
|
||||
$col = null;
|
||||
}
|
||||
@@ -753,7 +999,7 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$this->ensureConsistency();
|
||||
}
|
||||
|
||||
return $startcol + 9; // 9 = LangTableMap::NUM_HYDRATE_COLUMNS.
|
||||
return $startcol + 15; // 15 = LangTableMap::NUM_HYDRATE_COLUMNS.
|
||||
|
||||
} catch (Exception $e) {
|
||||
throw new PropelException("Error populating \Thelia\Model\Lang object", 0, $e);
|
||||
@@ -988,12 +1234,30 @@ abstract class Lang implements ActiveRecordInterface
|
||||
if ($this->isColumnModified(LangTableMap::URL)) {
|
||||
$modifiedColumns[':p' . $index++] = 'URL';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::POSITION)) {
|
||||
$modifiedColumns[':p' . $index++] = 'POSITION';
|
||||
if ($this->isColumnModified(LangTableMap::DATE_FORMAT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'DATE_FORMAT';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::TIME_FORMAT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'TIME_FORMAT';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::DATETIME_FORMAT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'DATETIME_FORMAT';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::DECIMAL_SEPARATOR)) {
|
||||
$modifiedColumns[':p' . $index++] = 'DECIMAL_SEPARATOR';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::THOUSANDS_SEPARATOR)) {
|
||||
$modifiedColumns[':p' . $index++] = 'THOUSANDS_SEPARATOR';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::DECIMALS)) {
|
||||
$modifiedColumns[':p' . $index++] = 'DECIMALS';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::BY_DEFAULT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'BY_DEFAULT';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::POSITION)) {
|
||||
$modifiedColumns[':p' . $index++] = 'POSITION';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::CREATED_AT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
|
||||
}
|
||||
@@ -1026,12 +1290,30 @@ abstract class Lang implements ActiveRecordInterface
|
||||
case 'URL':
|
||||
$stmt->bindValue($identifier, $this->url, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'POSITION':
|
||||
$stmt->bindValue($identifier, $this->position, PDO::PARAM_INT);
|
||||
case 'DATE_FORMAT':
|
||||
$stmt->bindValue($identifier, $this->date_format, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'TIME_FORMAT':
|
||||
$stmt->bindValue($identifier, $this->time_format, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'DATETIME_FORMAT':
|
||||
$stmt->bindValue($identifier, $this->datetime_format, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'DECIMAL_SEPARATOR':
|
||||
$stmt->bindValue($identifier, $this->decimal_separator, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'THOUSANDS_SEPARATOR':
|
||||
$stmt->bindValue($identifier, $this->thousands_separator, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'DECIMALS':
|
||||
$stmt->bindValue($identifier, $this->decimals, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'BY_DEFAULT':
|
||||
$stmt->bindValue($identifier, $this->by_default, PDO::PARAM_INT);
|
||||
break;
|
||||
case 'POSITION':
|
||||
$stmt->bindValue($identifier, $this->position, PDO::PARAM_INT);
|
||||
break;
|
||||
case 'CREATED_AT':
|
||||
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
|
||||
break;
|
||||
@@ -1116,15 +1398,33 @@ abstract class Lang implements ActiveRecordInterface
|
||||
return $this->getUrl();
|
||||
break;
|
||||
case 5:
|
||||
return $this->getPosition();
|
||||
return $this->getDateFormat();
|
||||
break;
|
||||
case 6:
|
||||
return $this->getByDefault();
|
||||
return $this->getTimeFormat();
|
||||
break;
|
||||
case 7:
|
||||
return $this->getCreatedAt();
|
||||
return $this->getDatetimeFormat();
|
||||
break;
|
||||
case 8:
|
||||
return $this->getDecimalSeparator();
|
||||
break;
|
||||
case 9:
|
||||
return $this->getThousandsSeparator();
|
||||
break;
|
||||
case 10:
|
||||
return $this->getDecimals();
|
||||
break;
|
||||
case 11:
|
||||
return $this->getByDefault();
|
||||
break;
|
||||
case 12:
|
||||
return $this->getPosition();
|
||||
break;
|
||||
case 13:
|
||||
return $this->getCreatedAt();
|
||||
break;
|
||||
case 14:
|
||||
return $this->getUpdatedAt();
|
||||
break;
|
||||
default:
|
||||
@@ -1160,10 +1460,16 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$keys[2] => $this->getCode(),
|
||||
$keys[3] => $this->getLocale(),
|
||||
$keys[4] => $this->getUrl(),
|
||||
$keys[5] => $this->getPosition(),
|
||||
$keys[6] => $this->getByDefault(),
|
||||
$keys[7] => $this->getCreatedAt(),
|
||||
$keys[8] => $this->getUpdatedAt(),
|
||||
$keys[5] => $this->getDateFormat(),
|
||||
$keys[6] => $this->getTimeFormat(),
|
||||
$keys[7] => $this->getDatetimeFormat(),
|
||||
$keys[8] => $this->getDecimalSeparator(),
|
||||
$keys[9] => $this->getThousandsSeparator(),
|
||||
$keys[10] => $this->getDecimals(),
|
||||
$keys[11] => $this->getByDefault(),
|
||||
$keys[12] => $this->getPosition(),
|
||||
$keys[13] => $this->getCreatedAt(),
|
||||
$keys[14] => $this->getUpdatedAt(),
|
||||
);
|
||||
$virtualColumns = $this->virtualColumns;
|
||||
foreach($virtualColumns as $key => $virtualColumn)
|
||||
@@ -1220,15 +1526,33 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$this->setUrl($value);
|
||||
break;
|
||||
case 5:
|
||||
$this->setPosition($value);
|
||||
$this->setDateFormat($value);
|
||||
break;
|
||||
case 6:
|
||||
$this->setByDefault($value);
|
||||
$this->setTimeFormat($value);
|
||||
break;
|
||||
case 7:
|
||||
$this->setCreatedAt($value);
|
||||
$this->setDatetimeFormat($value);
|
||||
break;
|
||||
case 8:
|
||||
$this->setDecimalSeparator($value);
|
||||
break;
|
||||
case 9:
|
||||
$this->setThousandsSeparator($value);
|
||||
break;
|
||||
case 10:
|
||||
$this->setDecimals($value);
|
||||
break;
|
||||
case 11:
|
||||
$this->setByDefault($value);
|
||||
break;
|
||||
case 12:
|
||||
$this->setPosition($value);
|
||||
break;
|
||||
case 13:
|
||||
$this->setCreatedAt($value);
|
||||
break;
|
||||
case 14:
|
||||
$this->setUpdatedAt($value);
|
||||
break;
|
||||
} // switch()
|
||||
@@ -1260,10 +1584,16 @@ abstract class Lang implements ActiveRecordInterface
|
||||
if (array_key_exists($keys[2], $arr)) $this->setCode($arr[$keys[2]]);
|
||||
if (array_key_exists($keys[3], $arr)) $this->setLocale($arr[$keys[3]]);
|
||||
if (array_key_exists($keys[4], $arr)) $this->setUrl($arr[$keys[4]]);
|
||||
if (array_key_exists($keys[5], $arr)) $this->setPosition($arr[$keys[5]]);
|
||||
if (array_key_exists($keys[6], $arr)) $this->setByDefault($arr[$keys[6]]);
|
||||
if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]);
|
||||
if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]);
|
||||
if (array_key_exists($keys[5], $arr)) $this->setDateFormat($arr[$keys[5]]);
|
||||
if (array_key_exists($keys[6], $arr)) $this->setTimeFormat($arr[$keys[6]]);
|
||||
if (array_key_exists($keys[7], $arr)) $this->setDatetimeFormat($arr[$keys[7]]);
|
||||
if (array_key_exists($keys[8], $arr)) $this->setDecimalSeparator($arr[$keys[8]]);
|
||||
if (array_key_exists($keys[9], $arr)) $this->setThousandsSeparator($arr[$keys[9]]);
|
||||
if (array_key_exists($keys[10], $arr)) $this->setDecimals($arr[$keys[10]]);
|
||||
if (array_key_exists($keys[11], $arr)) $this->setByDefault($arr[$keys[11]]);
|
||||
if (array_key_exists($keys[12], $arr)) $this->setPosition($arr[$keys[12]]);
|
||||
if (array_key_exists($keys[13], $arr)) $this->setCreatedAt($arr[$keys[13]]);
|
||||
if (array_key_exists($keys[14], $arr)) $this->setUpdatedAt($arr[$keys[14]]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1280,8 +1610,14 @@ abstract class Lang implements ActiveRecordInterface
|
||||
if ($this->isColumnModified(LangTableMap::CODE)) $criteria->add(LangTableMap::CODE, $this->code);
|
||||
if ($this->isColumnModified(LangTableMap::LOCALE)) $criteria->add(LangTableMap::LOCALE, $this->locale);
|
||||
if ($this->isColumnModified(LangTableMap::URL)) $criteria->add(LangTableMap::URL, $this->url);
|
||||
if ($this->isColumnModified(LangTableMap::POSITION)) $criteria->add(LangTableMap::POSITION, $this->position);
|
||||
if ($this->isColumnModified(LangTableMap::DATE_FORMAT)) $criteria->add(LangTableMap::DATE_FORMAT, $this->date_format);
|
||||
if ($this->isColumnModified(LangTableMap::TIME_FORMAT)) $criteria->add(LangTableMap::TIME_FORMAT, $this->time_format);
|
||||
if ($this->isColumnModified(LangTableMap::DATETIME_FORMAT)) $criteria->add(LangTableMap::DATETIME_FORMAT, $this->datetime_format);
|
||||
if ($this->isColumnModified(LangTableMap::DECIMAL_SEPARATOR)) $criteria->add(LangTableMap::DECIMAL_SEPARATOR, $this->decimal_separator);
|
||||
if ($this->isColumnModified(LangTableMap::THOUSANDS_SEPARATOR)) $criteria->add(LangTableMap::THOUSANDS_SEPARATOR, $this->thousands_separator);
|
||||
if ($this->isColumnModified(LangTableMap::DECIMALS)) $criteria->add(LangTableMap::DECIMALS, $this->decimals);
|
||||
if ($this->isColumnModified(LangTableMap::BY_DEFAULT)) $criteria->add(LangTableMap::BY_DEFAULT, $this->by_default);
|
||||
if ($this->isColumnModified(LangTableMap::POSITION)) $criteria->add(LangTableMap::POSITION, $this->position);
|
||||
if ($this->isColumnModified(LangTableMap::CREATED_AT)) $criteria->add(LangTableMap::CREATED_AT, $this->created_at);
|
||||
if ($this->isColumnModified(LangTableMap::UPDATED_AT)) $criteria->add(LangTableMap::UPDATED_AT, $this->updated_at);
|
||||
|
||||
@@ -1351,8 +1687,14 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$copyObj->setCode($this->getCode());
|
||||
$copyObj->setLocale($this->getLocale());
|
||||
$copyObj->setUrl($this->getUrl());
|
||||
$copyObj->setPosition($this->getPosition());
|
||||
$copyObj->setDateFormat($this->getDateFormat());
|
||||
$copyObj->setTimeFormat($this->getTimeFormat());
|
||||
$copyObj->setDatetimeFormat($this->getDatetimeFormat());
|
||||
$copyObj->setDecimalSeparator($this->getDecimalSeparator());
|
||||
$copyObj->setThousandsSeparator($this->getThousandsSeparator());
|
||||
$copyObj->setDecimals($this->getDecimals());
|
||||
$copyObj->setByDefault($this->getByDefault());
|
||||
$copyObj->setPosition($this->getPosition());
|
||||
$copyObj->setCreatedAt($this->getCreatedAt());
|
||||
$copyObj->setUpdatedAt($this->getUpdatedAt());
|
||||
if ($makeNew) {
|
||||
@@ -1393,8 +1735,14 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$this->code = null;
|
||||
$this->locale = null;
|
||||
$this->url = null;
|
||||
$this->position = null;
|
||||
$this->date_format = null;
|
||||
$this->time_format = null;
|
||||
$this->datetime_format = null;
|
||||
$this->decimal_separator = null;
|
||||
$this->thousands_separator = null;
|
||||
$this->decimals = null;
|
||||
$this->by_default = null;
|
||||
$this->position = null;
|
||||
$this->created_at = null;
|
||||
$this->updated_at = null;
|
||||
$this->alreadyInSave = false;
|
||||
|
||||
@@ -23,8 +23,14 @@ use Thelia\Model\Map\LangTableMap;
|
||||
* @method ChildLangQuery orderByCode($order = Criteria::ASC) Order by the code column
|
||||
* @method ChildLangQuery orderByLocale($order = Criteria::ASC) Order by the locale column
|
||||
* @method ChildLangQuery orderByUrl($order = Criteria::ASC) Order by the url column
|
||||
* @method ChildLangQuery orderByPosition($order = Criteria::ASC) Order by the position column
|
||||
* @method ChildLangQuery orderByDateFormat($order = Criteria::ASC) Order by the date_format column
|
||||
* @method ChildLangQuery orderByTimeFormat($order = Criteria::ASC) Order by the time_format column
|
||||
* @method ChildLangQuery orderByDatetimeFormat($order = Criteria::ASC) Order by the datetime_format column
|
||||
* @method ChildLangQuery orderByDecimalSeparator($order = Criteria::ASC) Order by the decimal_separator column
|
||||
* @method ChildLangQuery orderByThousandsSeparator($order = Criteria::ASC) Order by the thousands_separator column
|
||||
* @method ChildLangQuery orderByDecimals($order = Criteria::ASC) Order by the decimals column
|
||||
* @method ChildLangQuery orderByByDefault($order = Criteria::ASC) Order by the by_default column
|
||||
* @method ChildLangQuery orderByPosition($order = Criteria::ASC) Order by the position column
|
||||
* @method ChildLangQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
|
||||
* @method ChildLangQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
|
||||
*
|
||||
@@ -33,8 +39,14 @@ use Thelia\Model\Map\LangTableMap;
|
||||
* @method ChildLangQuery groupByCode() Group by the code column
|
||||
* @method ChildLangQuery groupByLocale() Group by the locale column
|
||||
* @method ChildLangQuery groupByUrl() Group by the url column
|
||||
* @method ChildLangQuery groupByPosition() Group by the position column
|
||||
* @method ChildLangQuery groupByDateFormat() Group by the date_format column
|
||||
* @method ChildLangQuery groupByTimeFormat() Group by the time_format column
|
||||
* @method ChildLangQuery groupByDatetimeFormat() Group by the datetime_format column
|
||||
* @method ChildLangQuery groupByDecimalSeparator() Group by the decimal_separator column
|
||||
* @method ChildLangQuery groupByThousandsSeparator() Group by the thousands_separator column
|
||||
* @method ChildLangQuery groupByDecimals() Group by the decimals column
|
||||
* @method ChildLangQuery groupByByDefault() Group by the by_default column
|
||||
* @method ChildLangQuery groupByPosition() Group by the position column
|
||||
* @method ChildLangQuery groupByCreatedAt() Group by the created_at column
|
||||
* @method ChildLangQuery groupByUpdatedAt() Group by the updated_at column
|
||||
*
|
||||
@@ -50,8 +62,14 @@ use Thelia\Model\Map\LangTableMap;
|
||||
* @method ChildLang findOneByCode(string $code) Return the first ChildLang filtered by the code column
|
||||
* @method ChildLang findOneByLocale(string $locale) Return the first ChildLang filtered by the locale column
|
||||
* @method ChildLang findOneByUrl(string $url) Return the first ChildLang filtered by the url column
|
||||
* @method ChildLang findOneByPosition(int $position) Return the first ChildLang filtered by the position column
|
||||
* @method ChildLang findOneByDateFormat(string $date_format) Return the first ChildLang filtered by the date_format column
|
||||
* @method ChildLang findOneByTimeFormat(string $time_format) Return the first ChildLang filtered by the time_format column
|
||||
* @method ChildLang findOneByDatetimeFormat(string $datetime_format) Return the first ChildLang filtered by the datetime_format column
|
||||
* @method ChildLang findOneByDecimalSeparator(string $decimal_separator) Return the first ChildLang filtered by the decimal_separator column
|
||||
* @method ChildLang findOneByThousandsSeparator(string $thousands_separator) Return the first ChildLang filtered by the thousands_separator column
|
||||
* @method ChildLang findOneByDecimals(string $decimals) Return the first ChildLang filtered by the decimals column
|
||||
* @method ChildLang findOneByByDefault(int $by_default) Return the first ChildLang filtered by the by_default column
|
||||
* @method ChildLang findOneByPosition(int $position) Return the first ChildLang filtered by the position column
|
||||
* @method ChildLang findOneByCreatedAt(string $created_at) Return the first ChildLang filtered by the created_at column
|
||||
* @method ChildLang findOneByUpdatedAt(string $updated_at) Return the first ChildLang filtered by the updated_at column
|
||||
*
|
||||
@@ -60,8 +78,14 @@ use Thelia\Model\Map\LangTableMap;
|
||||
* @method array findByCode(string $code) Return ChildLang objects filtered by the code column
|
||||
* @method array findByLocale(string $locale) Return ChildLang objects filtered by the locale column
|
||||
* @method array findByUrl(string $url) Return ChildLang objects filtered by the url column
|
||||
* @method array findByPosition(int $position) Return ChildLang objects filtered by the position column
|
||||
* @method array findByDateFormat(string $date_format) Return ChildLang objects filtered by the date_format column
|
||||
* @method array findByTimeFormat(string $time_format) Return ChildLang objects filtered by the time_format column
|
||||
* @method array findByDatetimeFormat(string $datetime_format) Return ChildLang objects filtered by the datetime_format column
|
||||
* @method array findByDecimalSeparator(string $decimal_separator) Return ChildLang objects filtered by the decimal_separator column
|
||||
* @method array findByThousandsSeparator(string $thousands_separator) Return ChildLang objects filtered by the thousands_separator column
|
||||
* @method array findByDecimals(string $decimals) Return ChildLang objects filtered by the decimals column
|
||||
* @method array findByByDefault(int $by_default) Return ChildLang objects filtered by the by_default column
|
||||
* @method array findByPosition(int $position) Return ChildLang objects filtered by the position column
|
||||
* @method array findByCreatedAt(string $created_at) Return ChildLang objects filtered by the created_at column
|
||||
* @method array findByUpdatedAt(string $updated_at) Return ChildLang objects filtered by the updated_at column
|
||||
*
|
||||
@@ -152,7 +176,7 @@ abstract class LangQuery extends ModelCriteria
|
||||
*/
|
||||
protected function findPkSimple($key, $con)
|
||||
{
|
||||
$sql = 'SELECT ID, TITLE, CODE, LOCALE, URL, POSITION, BY_DEFAULT, CREATED_AT, UPDATED_AT FROM lang WHERE ID = :p0';
|
||||
$sql = 'SELECT ID, TITLE, CODE, LOCALE, URL, DATE_FORMAT, TIME_FORMAT, DATETIME_FORMAT, DECIMAL_SEPARATOR, THOUSANDS_SEPARATOR, DECIMALS, BY_DEFAULT, POSITION, CREATED_AT, UPDATED_AT FROM lang WHERE ID = :p0';
|
||||
try {
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
|
||||
@@ -399,44 +423,177 @@ abstract class LangQuery extends ModelCriteria
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the position column
|
||||
* Filter the query on the date_format column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByPosition(1234); // WHERE position = 1234
|
||||
* $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34)
|
||||
* $query->filterByPosition(array('min' => 12)); // WHERE position > 12
|
||||
* $query->filterByDateFormat('fooValue'); // WHERE date_format = 'fooValue'
|
||||
* $query->filterByDateFormat('%fooValue%'); // WHERE date_format LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param mixed $position The value to use as filter.
|
||||
* Use scalar values for equality.
|
||||
* Use array values for in_array() equivalent.
|
||||
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
|
||||
* @param string $dateFormat The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByPosition($position = null, $comparison = null)
|
||||
public function filterByDateFormat($dateFormat = null, $comparison = null)
|
||||
{
|
||||
if (is_array($position)) {
|
||||
$useMinMax = false;
|
||||
if (isset($position['min'])) {
|
||||
$this->addUsingAlias(LangTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL);
|
||||
$useMinMax = true;
|
||||
}
|
||||
if (isset($position['max'])) {
|
||||
$this->addUsingAlias(LangTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL);
|
||||
$useMinMax = true;
|
||||
}
|
||||
if ($useMinMax) {
|
||||
return $this;
|
||||
}
|
||||
if (null === $comparison) {
|
||||
if (null === $comparison) {
|
||||
if (is_array($dateFormat)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $dateFormat)) {
|
||||
$dateFormat = str_replace('*', '%', $dateFormat);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::POSITION, $position, $comparison);
|
||||
return $this->addUsingAlias(LangTableMap::DATE_FORMAT, $dateFormat, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the time_format column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByTimeFormat('fooValue'); // WHERE time_format = 'fooValue'
|
||||
* $query->filterByTimeFormat('%fooValue%'); // WHERE time_format LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $timeFormat The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByTimeFormat($timeFormat = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($timeFormat)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $timeFormat)) {
|
||||
$timeFormat = str_replace('*', '%', $timeFormat);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::TIME_FORMAT, $timeFormat, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the datetime_format column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByDatetimeFormat('fooValue'); // WHERE datetime_format = 'fooValue'
|
||||
* $query->filterByDatetimeFormat('%fooValue%'); // WHERE datetime_format LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $datetimeFormat The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByDatetimeFormat($datetimeFormat = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($datetimeFormat)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $datetimeFormat)) {
|
||||
$datetimeFormat = str_replace('*', '%', $datetimeFormat);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::DATETIME_FORMAT, $datetimeFormat, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the decimal_separator column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByDecimalSeparator('fooValue'); // WHERE decimal_separator = 'fooValue'
|
||||
* $query->filterByDecimalSeparator('%fooValue%'); // WHERE decimal_separator LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $decimalSeparator The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByDecimalSeparator($decimalSeparator = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($decimalSeparator)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $decimalSeparator)) {
|
||||
$decimalSeparator = str_replace('*', '%', $decimalSeparator);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::DECIMAL_SEPARATOR, $decimalSeparator, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the thousands_separator column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByThousandsSeparator('fooValue'); // WHERE thousands_separator = 'fooValue'
|
||||
* $query->filterByThousandsSeparator('%fooValue%'); // WHERE thousands_separator LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $thousandsSeparator The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByThousandsSeparator($thousandsSeparator = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($thousandsSeparator)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $thousandsSeparator)) {
|
||||
$thousandsSeparator = str_replace('*', '%', $thousandsSeparator);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::THOUSANDS_SEPARATOR, $thousandsSeparator, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the decimals column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByDecimals('fooValue'); // WHERE decimals = 'fooValue'
|
||||
* $query->filterByDecimals('%fooValue%'); // WHERE decimals LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $decimals The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByDecimals($decimals = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($decimals)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $decimals)) {
|
||||
$decimals = str_replace('*', '%', $decimals);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::DECIMALS, $decimals, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,6 +637,47 @@ abstract class LangQuery extends ModelCriteria
|
||||
return $this->addUsingAlias(LangTableMap::BY_DEFAULT, $byDefault, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the position column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByPosition(1234); // WHERE position = 1234
|
||||
* $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34)
|
||||
* $query->filterByPosition(array('min' => 12)); // WHERE position > 12
|
||||
* </code>
|
||||
*
|
||||
* @param mixed $position The value to use as filter.
|
||||
* Use scalar values for equality.
|
||||
* Use array values for in_array() equivalent.
|
||||
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByPosition($position = null, $comparison = null)
|
||||
{
|
||||
if (is_array($position)) {
|
||||
$useMinMax = false;
|
||||
if (isset($position['min'])) {
|
||||
$this->addUsingAlias(LangTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL);
|
||||
$useMinMax = true;
|
||||
}
|
||||
if (isset($position['max'])) {
|
||||
$this->addUsingAlias(LangTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL);
|
||||
$useMinMax = true;
|
||||
}
|
||||
if ($useMinMax) {
|
||||
return $this;
|
||||
}
|
||||
if (null === $comparison) {
|
||||
$comparison = Criteria::IN;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::POSITION, $position, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the created_at column
|
||||
*
|
||||
|
||||
@@ -13,6 +13,8 @@ class Category extends BaseCategory
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* @return int number of child for the current category
|
||||
*/
|
||||
@@ -23,7 +25,7 @@ class Category extends BaseCategory
|
||||
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::init()->retrieve('category', $this->getId(), $locale)->toString();
|
||||
return URL::getInstance()->retrieve('category', $this->getId(), $locale)->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,18 +48,6 @@ class Category extends BaseCategory
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getNextPosition($parent) {
|
||||
|
||||
$last = CategoryQuery::create()
|
||||
->filterByParent($parent)
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->limit(1)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
return $last != null ? $last->getPosition() + 1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* count all products for current category and sub categories
|
||||
|
||||
@@ -9,6 +9,6 @@ class Content extends BaseContent
|
||||
{
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::init()->retrieve('content', $this->getId(), $locale)->toString();
|
||||
return URL::getInstance()->retrieve('content', $this->getId(), $locale)->toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ class Currency extends BaseCurrency {
|
||||
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -18,6 +20,9 @@ class Currency extends BaseCurrency {
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATECURRENCY, new CurrencyEvent($this));
|
||||
|
||||
// Set the current position for the new object
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\Base\Customer as BaseCustomer;
|
||||
|
||||
@@ -115,7 +115,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
|
||||
$con->commit();
|
||||
|
||||
} catch(Exception $e) {
|
||||
} catch(PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
@@ -225,7 +225,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
*/
|
||||
public function preUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CHANGECUSTOMER, new CustomerEvent($this));
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATECUSTOMER, new CustomerEvent($this));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
*/
|
||||
public function postUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_CHANGECUSTOMER, new CustomerEvent($this));
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_UPDATECUSTOMER, new CustomerEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,7 @@ class Folder extends BaseFolder
|
||||
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::init()->retrieve('folder', $this->getId(), $locale)->toString();
|
||||
return URL::getInstance()->retrieve('folder', $this->getId(), $locale)->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,48 +9,15 @@ class Lang extends BaseLang {
|
||||
/**
|
||||
* Return the default language object, using a local variable to cache it.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
private static $default_lang = null;
|
||||
|
||||
public static function getDefaultLanguage() {
|
||||
|
||||
if (self::$default_lang == null) {
|
||||
$default_lang = LangQuery::create()->findOneByByDefault(true);
|
||||
|
||||
if ($default_lang == null) throw new RuntimeException("No default language is defined. Please define one.");
|
||||
}
|
||||
$default_lang = LangQuery::create()->findOneByByDefault(1);
|
||||
|
||||
if ($default_lang == null) throw new \RuntimeException("No default language is defined. Please define one.");
|
||||
|
||||
return $default_lang;
|
||||
}
|
||||
|
||||
public function getDateFormat()
|
||||
{
|
||||
return "d/m/Y";
|
||||
}
|
||||
|
||||
public function getTimeFormat()
|
||||
{
|
||||
return "H:i:s";
|
||||
}
|
||||
|
||||
public function getDateTimeFormat()
|
||||
{
|
||||
return "d/m/Y H:i:s";
|
||||
}
|
||||
|
||||
public function getDecimalSeparator()
|
||||
{
|
||||
return ".";
|
||||
}
|
||||
|
||||
public function getThousandsSeparator()
|
||||
{
|
||||
return " ";
|
||||
}
|
||||
|
||||
public function getDecimals()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class LangTableMap extends TableMap
|
||||
/**
|
||||
* The total number of columns
|
||||
*/
|
||||
const NUM_COLUMNS = 9;
|
||||
const NUM_COLUMNS = 15;
|
||||
|
||||
/**
|
||||
* The number of lazy-loaded columns
|
||||
@@ -67,7 +67,7 @@ class LangTableMap extends TableMap
|
||||
/**
|
||||
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
|
||||
*/
|
||||
const NUM_HYDRATE_COLUMNS = 9;
|
||||
const NUM_HYDRATE_COLUMNS = 15;
|
||||
|
||||
/**
|
||||
* the column name for the ID field
|
||||
@@ -95,15 +95,45 @@ class LangTableMap extends TableMap
|
||||
const URL = 'lang.URL';
|
||||
|
||||
/**
|
||||
* the column name for the POSITION field
|
||||
* the column name for the DATE_FORMAT field
|
||||
*/
|
||||
const POSITION = 'lang.POSITION';
|
||||
const DATE_FORMAT = 'lang.DATE_FORMAT';
|
||||
|
||||
/**
|
||||
* the column name for the TIME_FORMAT field
|
||||
*/
|
||||
const TIME_FORMAT = 'lang.TIME_FORMAT';
|
||||
|
||||
/**
|
||||
* the column name for the DATETIME_FORMAT field
|
||||
*/
|
||||
const DATETIME_FORMAT = 'lang.DATETIME_FORMAT';
|
||||
|
||||
/**
|
||||
* the column name for the DECIMAL_SEPARATOR field
|
||||
*/
|
||||
const DECIMAL_SEPARATOR = 'lang.DECIMAL_SEPARATOR';
|
||||
|
||||
/**
|
||||
* the column name for the THOUSANDS_SEPARATOR field
|
||||
*/
|
||||
const THOUSANDS_SEPARATOR = 'lang.THOUSANDS_SEPARATOR';
|
||||
|
||||
/**
|
||||
* the column name for the DECIMALS field
|
||||
*/
|
||||
const DECIMALS = 'lang.DECIMALS';
|
||||
|
||||
/**
|
||||
* the column name for the BY_DEFAULT field
|
||||
*/
|
||||
const BY_DEFAULT = 'lang.BY_DEFAULT';
|
||||
|
||||
/**
|
||||
* the column name for the POSITION field
|
||||
*/
|
||||
const POSITION = 'lang.POSITION';
|
||||
|
||||
/**
|
||||
* the column name for the CREATED_AT field
|
||||
*/
|
||||
@@ -126,12 +156,12 @@ class LangTableMap extends TableMap
|
||||
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
|
||||
*/
|
||||
protected static $fieldNames = array (
|
||||
self::TYPE_PHPNAME => array('Id', 'Title', 'Code', 'Locale', 'Url', 'Position', 'ByDefault', 'CreatedAt', 'UpdatedAt', ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id', 'title', 'code', 'locale', 'url', 'position', 'byDefault', 'createdAt', 'updatedAt', ),
|
||||
self::TYPE_COLNAME => array(LangTableMap::ID, LangTableMap::TITLE, LangTableMap::CODE, LangTableMap::LOCALE, LangTableMap::URL, LangTableMap::POSITION, LangTableMap::BY_DEFAULT, LangTableMap::CREATED_AT, LangTableMap::UPDATED_AT, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID', 'TITLE', 'CODE', 'LOCALE', 'URL', 'POSITION', 'BY_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ),
|
||||
self::TYPE_FIELDNAME => array('id', 'title', 'code', 'locale', 'url', 'position', 'by_default', 'created_at', 'updated_at', ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, )
|
||||
self::TYPE_PHPNAME => array('Id', 'Title', 'Code', 'Locale', 'Url', 'DateFormat', 'TimeFormat', 'DatetimeFormat', 'DecimalSeparator', 'ThousandsSeparator', 'Decimals', 'ByDefault', 'Position', 'CreatedAt', 'UpdatedAt', ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id', 'title', 'code', 'locale', 'url', 'dateFormat', 'timeFormat', 'datetimeFormat', 'decimalSeparator', 'thousandsSeparator', 'decimals', 'byDefault', 'position', 'createdAt', 'updatedAt', ),
|
||||
self::TYPE_COLNAME => array(LangTableMap::ID, LangTableMap::TITLE, LangTableMap::CODE, LangTableMap::LOCALE, LangTableMap::URL, LangTableMap::DATE_FORMAT, LangTableMap::TIME_FORMAT, LangTableMap::DATETIME_FORMAT, LangTableMap::DECIMAL_SEPARATOR, LangTableMap::THOUSANDS_SEPARATOR, LangTableMap::DECIMALS, LangTableMap::BY_DEFAULT, LangTableMap::POSITION, LangTableMap::CREATED_AT, LangTableMap::UPDATED_AT, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID', 'TITLE', 'CODE', 'LOCALE', 'URL', 'DATE_FORMAT', 'TIME_FORMAT', 'DATETIME_FORMAT', 'DECIMAL_SEPARATOR', 'THOUSANDS_SEPARATOR', 'DECIMALS', 'BY_DEFAULT', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ),
|
||||
self::TYPE_FIELDNAME => array('id', 'title', 'code', 'locale', 'url', 'date_format', 'time_format', 'datetime_format', 'decimal_separator', 'thousands_separator', 'decimals', 'by_default', 'position', 'created_at', 'updated_at', ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -141,12 +171,12 @@ class LangTableMap extends TableMap
|
||||
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
|
||||
*/
|
||||
protected static $fieldKeys = array (
|
||||
self::TYPE_PHPNAME => array('Id' => 0, 'Title' => 1, 'Code' => 2, 'Locale' => 3, 'Url' => 4, 'Position' => 5, 'ByDefault' => 6, 'CreatedAt' => 7, 'UpdatedAt' => 8, ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'title' => 1, 'code' => 2, 'locale' => 3, 'url' => 4, 'position' => 5, 'byDefault' => 6, 'createdAt' => 7, 'updatedAt' => 8, ),
|
||||
self::TYPE_COLNAME => array(LangTableMap::ID => 0, LangTableMap::TITLE => 1, LangTableMap::CODE => 2, LangTableMap::LOCALE => 3, LangTableMap::URL => 4, LangTableMap::POSITION => 5, LangTableMap::BY_DEFAULT => 6, LangTableMap::CREATED_AT => 7, LangTableMap::UPDATED_AT => 8, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID' => 0, 'TITLE' => 1, 'CODE' => 2, 'LOCALE' => 3, 'URL' => 4, 'POSITION' => 5, 'BY_DEFAULT' => 6, 'CREATED_AT' => 7, 'UPDATED_AT' => 8, ),
|
||||
self::TYPE_FIELDNAME => array('id' => 0, 'title' => 1, 'code' => 2, 'locale' => 3, 'url' => 4, 'position' => 5, 'by_default' => 6, 'created_at' => 7, 'updated_at' => 8, ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, )
|
||||
self::TYPE_PHPNAME => array('Id' => 0, 'Title' => 1, 'Code' => 2, 'Locale' => 3, 'Url' => 4, 'DateFormat' => 5, 'TimeFormat' => 6, 'DatetimeFormat' => 7, 'DecimalSeparator' => 8, 'ThousandsSeparator' => 9, 'Decimals' => 10, 'ByDefault' => 11, 'Position' => 12, 'CreatedAt' => 13, 'UpdatedAt' => 14, ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'title' => 1, 'code' => 2, 'locale' => 3, 'url' => 4, 'dateFormat' => 5, 'timeFormat' => 6, 'datetimeFormat' => 7, 'decimalSeparator' => 8, 'thousandsSeparator' => 9, 'decimals' => 10, 'byDefault' => 11, 'position' => 12, 'createdAt' => 13, 'updatedAt' => 14, ),
|
||||
self::TYPE_COLNAME => array(LangTableMap::ID => 0, LangTableMap::TITLE => 1, LangTableMap::CODE => 2, LangTableMap::LOCALE => 3, LangTableMap::URL => 4, LangTableMap::DATE_FORMAT => 5, LangTableMap::TIME_FORMAT => 6, LangTableMap::DATETIME_FORMAT => 7, LangTableMap::DECIMAL_SEPARATOR => 8, LangTableMap::THOUSANDS_SEPARATOR => 9, LangTableMap::DECIMALS => 10, LangTableMap::BY_DEFAULT => 11, LangTableMap::POSITION => 12, LangTableMap::CREATED_AT => 13, LangTableMap::UPDATED_AT => 14, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID' => 0, 'TITLE' => 1, 'CODE' => 2, 'LOCALE' => 3, 'URL' => 4, 'DATE_FORMAT' => 5, 'TIME_FORMAT' => 6, 'DATETIME_FORMAT' => 7, 'DECIMAL_SEPARATOR' => 8, 'THOUSANDS_SEPARATOR' => 9, 'DECIMALS' => 10, 'BY_DEFAULT' => 11, 'POSITION' => 12, 'CREATED_AT' => 13, 'UPDATED_AT' => 14, ),
|
||||
self::TYPE_FIELDNAME => array('id' => 0, 'title' => 1, 'code' => 2, 'locale' => 3, 'url' => 4, 'date_format' => 5, 'time_format' => 6, 'datetime_format' => 7, 'decimal_separator' => 8, 'thousands_separator' => 9, 'decimals' => 10, 'by_default' => 11, 'position' => 12, 'created_at' => 13, 'updated_at' => 14, ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -170,8 +200,14 @@ class LangTableMap extends TableMap
|
||||
$this->addColumn('CODE', 'Code', 'VARCHAR', false, 10, null);
|
||||
$this->addColumn('LOCALE', 'Locale', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('URL', 'Url', 'VARCHAR', false, 255, null);
|
||||
$this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null);
|
||||
$this->addColumn('DATE_FORMAT', 'DateFormat', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('TIME_FORMAT', 'TimeFormat', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('DATETIME_FORMAT', 'DatetimeFormat', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('DECIMAL_SEPARATOR', 'DecimalSeparator', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('THOUSANDS_SEPARATOR', 'ThousandsSeparator', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('DECIMALS', 'Decimals', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('BY_DEFAULT', 'ByDefault', 'TINYINT', false, null, null);
|
||||
$this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null);
|
||||
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
|
||||
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
|
||||
} // initialize()
|
||||
@@ -339,8 +375,14 @@ class LangTableMap extends TableMap
|
||||
$criteria->addSelectColumn(LangTableMap::CODE);
|
||||
$criteria->addSelectColumn(LangTableMap::LOCALE);
|
||||
$criteria->addSelectColumn(LangTableMap::URL);
|
||||
$criteria->addSelectColumn(LangTableMap::POSITION);
|
||||
$criteria->addSelectColumn(LangTableMap::DATE_FORMAT);
|
||||
$criteria->addSelectColumn(LangTableMap::TIME_FORMAT);
|
||||
$criteria->addSelectColumn(LangTableMap::DATETIME_FORMAT);
|
||||
$criteria->addSelectColumn(LangTableMap::DECIMAL_SEPARATOR);
|
||||
$criteria->addSelectColumn(LangTableMap::THOUSANDS_SEPARATOR);
|
||||
$criteria->addSelectColumn(LangTableMap::DECIMALS);
|
||||
$criteria->addSelectColumn(LangTableMap::BY_DEFAULT);
|
||||
$criteria->addSelectColumn(LangTableMap::POSITION);
|
||||
$criteria->addSelectColumn(LangTableMap::CREATED_AT);
|
||||
$criteria->addSelectColumn(LangTableMap::UPDATED_AT);
|
||||
} else {
|
||||
@@ -349,8 +391,14 @@ class LangTableMap extends TableMap
|
||||
$criteria->addSelectColumn($alias . '.CODE');
|
||||
$criteria->addSelectColumn($alias . '.LOCALE');
|
||||
$criteria->addSelectColumn($alias . '.URL');
|
||||
$criteria->addSelectColumn($alias . '.POSITION');
|
||||
$criteria->addSelectColumn($alias . '.DATE_FORMAT');
|
||||
$criteria->addSelectColumn($alias . '.TIME_FORMAT');
|
||||
$criteria->addSelectColumn($alias . '.DATETIME_FORMAT');
|
||||
$criteria->addSelectColumn($alias . '.DECIMAL_SEPARATOR');
|
||||
$criteria->addSelectColumn($alias . '.THOUSANDS_SEPARATOR');
|
||||
$criteria->addSelectColumn($alias . '.DECIMALS');
|
||||
$criteria->addSelectColumn($alias . '.BY_DEFAULT');
|
||||
$criteria->addSelectColumn($alias . '.POSITION');
|
||||
$criteria->addSelectColumn($alias . '.CREATED_AT');
|
||||
$criteria->addSelectColumn($alias . '.UPDATED_AT');
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ class Product extends BaseProduct
|
||||
{
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::init()->retrieve('product', $this->getId(), $locale)->toString();
|
||||
return URL::getInstance()->retrieve('product', $this->getId(), $locale)->toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ trait ModelEventDispatcherTrait {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDispatcher()
|
||||
{
|
||||
return $this->dispatcher;
|
||||
}
|
||||
|
||||
protected function dispatchEvent($eventName, ActionEvent $event)
|
||||
{
|
||||
if (!is_null($this->dispatcher)) {
|
||||
|
||||
190
core/lib/Thelia/Model/Tools/PositionManagementTrait.php
Normal file
190
core/lib/Thelia/Model/Tools/PositionManagementTrait.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?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\Model\Tools;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\PropelQuery;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\Propel;
|
||||
|
||||
trait PositionManagementTrait {
|
||||
|
||||
/**
|
||||
* Create an instancer of this object query
|
||||
*/
|
||||
private function createQuery() {
|
||||
return PropelQuery::from(__CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the database name from this object's table map.
|
||||
*/
|
||||
private function getDatabaseNameFromMap() {
|
||||
$class = new \ReflectionClass(self::TABLE_MAP);
|
||||
|
||||
return $class->getConstant('DATABASE_NAME');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the position of the next inserted object
|
||||
*/
|
||||
public function getNextPosition($parent = null) {
|
||||
|
||||
$query = $this->createQuery()
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->limit(1);
|
||||
|
||||
if ($parent !== null) $last->filterByParent($parent);
|
||||
|
||||
$last = $query->findOne()
|
||||
;
|
||||
|
||||
return $last != null ? $last->getPosition() + 1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move up a object
|
||||
*/
|
||||
public function movePositionUp() {
|
||||
$this->movePositionUpOrDown(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move down a object
|
||||
*/
|
||||
public function movePositionDown() {
|
||||
$this->movePositionUpOrDown(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move up or down a object
|
||||
*
|
||||
* @param the exchange mode: go up (POSITION_UP) or go down (POSITION_DOWN)
|
||||
*/
|
||||
protected function movePositionUpOrDown($up = true)
|
||||
{
|
||||
// The current position of the object
|
||||
$my_position = $this->getPosition();
|
||||
|
||||
// Find object to exchange position with
|
||||
$search = $this->createQuery();
|
||||
|
||||
if (method_exists($this, 'getParent')) $search->filterByParent($this->getParent());
|
||||
|
||||
// Up or down ?
|
||||
if ($up === true) {
|
||||
// Find the object immediately before me
|
||||
$search->filterByPosition(array('max' => $my_position-1))->orderByPosition(Criteria::DESC);
|
||||
}
|
||||
else {
|
||||
// Find the object immediately after me
|
||||
$search->filterByPosition(array('min' => $my_position+1))->orderByPosition(Criteria::ASC);
|
||||
}
|
||||
|
||||
$result = $search->findOne();
|
||||
|
||||
// If we found the proper object, exchange their positions
|
||||
if ($result) {
|
||||
|
||||
$cnx = Propel::getWriteConnection($this->getDatabaseName());
|
||||
|
||||
$cnx->beginTransaction();
|
||||
|
||||
try {
|
||||
$this
|
||||
->setPosition($result->getPosition())
|
||||
->save()
|
||||
;
|
||||
|
||||
$result->setDispatcher($this->getDispatcher())->setPosition($my_position)->save();
|
||||
|
||||
$cnx->commit();
|
||||
} catch (Exception $e) {
|
||||
$cnx->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply return the database name, from the constant in the MAP class.
|
||||
*/
|
||||
protected function getDatabaseName() {
|
||||
// Find DATABASE_NAME constant
|
||||
$mapClassName = self::TABLE_MAP;
|
||||
|
||||
return $mapClassName::DATABASE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes object position
|
||||
*
|
||||
* @param newPosition
|
||||
*/
|
||||
public function changeAbsolutePosition($newPosition)
|
||||
{
|
||||
// The current position
|
||||
$current_position = $this->getPosition();
|
||||
|
||||
if ($newPosition != null && $newPosition > 0 && $newPosition != $current_position) {
|
||||
|
||||
// Find categories to offset
|
||||
$search = $this->createQuery();
|
||||
|
||||
if (method_exists($this, 'getParent')) $search->filterByParent($this->getParent());
|
||||
|
||||
if ($newPosition > $current_position) {
|
||||
// The new position is after the current position -> we will offset + 1 all categories located between us and the new position
|
||||
$search->filterByPosition(array('min' => 1+$current_position, 'max' => $newPosition));
|
||||
|
||||
$delta = -1;
|
||||
} else {
|
||||
// The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position
|
||||
$search->filterByPosition(array('min' => $newPosition, 'max' => $current_position - 1));
|
||||
|
||||
$delta = 1;
|
||||
}
|
||||
|
||||
$results = $search->find();
|
||||
|
||||
$cnx = Propel::getWriteConnection($this->getDatabaseName());
|
||||
|
||||
$cnx->beginTransaction();
|
||||
|
||||
try {
|
||||
foreach ($results as $result) {
|
||||
$result->setDispatcher($this->getDispatcher())->setPosition($result->getPosition() + $delta)->save($cnx);
|
||||
}
|
||||
|
||||
$this
|
||||
->setPosition($newPosition)
|
||||
->save($cnx)
|
||||
;
|
||||
|
||||
$cnx->commit();
|
||||
} catch (Exception $e) {
|
||||
$cnx->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,8 @@ class RewritingResolver
|
||||
|
||||
public function load($rewrittenUrl)
|
||||
{
|
||||
$rewrittenUrl = ltrim($rewrittenUrl, '/');
|
||||
|
||||
$this->search = $this->rewritingUrlQuery->getResolverSearch($rewrittenUrl);
|
||||
|
||||
if($this->search->count() == 0) {
|
||||
|
||||
@@ -66,7 +66,8 @@ class RewritingRetriever
|
||||
$allParametersWithoutView[$view . '_id'] = $viewId;
|
||||
}
|
||||
|
||||
$this->url = URL::viewUrl($view, $allParametersWithoutView);
|
||||
$this->rewrittenUrl = null;
|
||||
$this->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView);
|
||||
if($this->search !== null) {
|
||||
$this->rewrittenUrl = $this->search->getUrl();
|
||||
}
|
||||
@@ -93,7 +94,8 @@ class RewritingRetriever
|
||||
$allParametersWithoutView[$view . '_id'] = $viewId;
|
||||
}
|
||||
|
||||
$this->url = URL::viewUrl($view, $allParametersWithoutView);
|
||||
$this->rewrittenUrl = null;
|
||||
$this->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView);
|
||||
if($this->search !== null) {
|
||||
$this->rewrittenUrl = $this->search->getUrl();
|
||||
}
|
||||
|
||||
@@ -30,13 +30,14 @@ use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Action\Image;
|
||||
use Thelia\Core\Event\ImageEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Class ImageTest
|
||||
*
|
||||
* @package Thelia\Tests\Action\ImageTest
|
||||
*/
|
||||
class ImageTest extends \PHPUnit_Framework_TestCase
|
||||
class ImageTest extends \Thelia\Tests\TestCaseWithURLToolSetup
|
||||
{
|
||||
protected $request;
|
||||
|
||||
@@ -50,6 +51,11 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$container->set("event_dispatcher", $dispatcher);
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($this->session);
|
||||
|
||||
$container->set("request", $request);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ class CacheClearTest extends \PHPUnit_Framework_TestCase
|
||||
$fs = new Filesystem();
|
||||
|
||||
$fs->mkdir($this->cache_dir);
|
||||
$fs->mkdir(THELIA_WEB_DIR . "/assets");
|
||||
}
|
||||
|
||||
public function testCacheClear()
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace Thelia\Tests\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Controller\Front\DefaultController;
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ class DefaultControllerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($request->attributes->get('_view'), "index");
|
||||
}
|
||||
|
||||
public function testNoActionWithQuery()
|
||||
public function testNoActionWithGetParam()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(array(
|
||||
@@ -55,15 +55,59 @@ class DefaultControllerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
public function testNoActionWithRequest()
|
||||
public function testNoActionWithPostParam()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(array(), array(
|
||||
"view" => "foo"
|
||||
));
|
||||
$request = new Request(
|
||||
array(),
|
||||
array("view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
|
||||
public function testNoActionWithAttribute()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array(),
|
||||
array(),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
public function testNoActionWithAttributeAndQuery()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array("view" => "bar"),
|
||||
array(),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'bar');
|
||||
}
|
||||
|
||||
public function testNoActionWithAttributeAndRequest()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array(),
|
||||
array("view" => "bar"),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'bar');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ use Thelia\Core\HttpFoundation\Session\Session;
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
|
||||
abstract class BaseLoopTestor extends \Thelia\Tests\TestCaseWithURLToolSetup
|
||||
{
|
||||
protected $request;
|
||||
protected $dispatcher;
|
||||
|
||||
@@ -71,7 +71,7 @@ class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
|
||||
$retriever->loadViewUrl('view', 'fr_FR', 1);
|
||||
|
||||
$this->assertEquals('foo.html', $retriever->rewrittenUrl);
|
||||
$this->assertEquals(URL::viewUrl('view', array('locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
|
||||
$this->assertEquals(URL::getInstance()->viewUrl('view', array('locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
|
||||
}
|
||||
|
||||
public function testLoadSpecificUrl()
|
||||
@@ -93,6 +93,6 @@ class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
|
||||
$retriever->loadSpecificUrl('view', 'fr_FR', 1, array('foo0' => 'bar0', 'foo1' => 'bar1'));
|
||||
|
||||
$this->assertEquals('foo.html', $retriever->rewrittenUrl);
|
||||
$this->assertEquals(URL::viewUrl('view', array('foo0' => 'bar0', 'foo1' => 'bar1', 'locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
|
||||
$this->assertEquals(URL::getInstance()->viewUrl('view', array('foo0' => 'bar0', 'foo1' => 'bar1', 'locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
|
||||
}
|
||||
}
|
||||
|
||||
64
core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php
Normal file
64
core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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\Tests;
|
||||
|
||||
/**
|
||||
* This class provides URL Tool class initialisation
|
||||
*
|
||||
* @package Thelia\Tests\TestCaseWithURLSetup
|
||||
*/
|
||||
class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->setupURLTool();
|
||||
}
|
||||
|
||||
protected function setupURLTool() {
|
||||
|
||||
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
|
||||
|
||||
$context = new \Symfony\Component\Routing\RequestContext(
|
||||
'/thelia/index.php',
|
||||
'GET',
|
||||
'localhost',
|
||||
'http',
|
||||
80,
|
||||
443,
|
||||
'/path/to/action'
|
||||
);
|
||||
|
||||
$router = $this->getMockBuilder("Symfony\Component\Routing\Router")
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$router->expects($this->any())
|
||||
->method('getContext')
|
||||
->will($this->returnValue($context));
|
||||
|
||||
$container->set("router.admin", $router);
|
||||
|
||||
new \Thelia\Tools\URL($container);
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,208 @@ use Thelia\Tools\URL;
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
* @author Franck Allimant <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class URLTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $context;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
|
||||
|
||||
$router = $this->getMockBuilder("Symfony\Component\Routing\Router")
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->context = new \Symfony\Component\Routing\RequestContext(
|
||||
'/thelia/index.php',
|
||||
'GET',
|
||||
'localhost',
|
||||
'http',
|
||||
80,
|
||||
443,
|
||||
'/path/to/action'
|
||||
);
|
||||
|
||||
$router->expects($this->any())
|
||||
->method('getContext')
|
||||
->will($this->returnValue($this->context));
|
||||
|
||||
$container->set("router.admin", $router);
|
||||
|
||||
new \Thelia\Tools\URL($container);
|
||||
}
|
||||
|
||||
public function testGetIndexPage() {
|
||||
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getIndexPage();
|
||||
$this->assertEquals('http://localhost/thelia/index.php', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getIndexPage();
|
||||
$this->assertEquals('http://localhost/thelia/', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getIndexPage();
|
||||
$this->assertEquals('http://localhost/thelia', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getIndexPage();
|
||||
$this->assertEquals('http://localhost/', $url);
|
||||
}
|
||||
|
||||
public function testGetBaseUrl() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getBaseUrl();
|
||||
$this->assertEquals('http://localhost/thelia/index.php', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getBaseUrl();
|
||||
$this->assertEquals('http://localhost/thelia/', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->getBaseUrl();
|
||||
$this->assertEquals('http://localhost/', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrl() {
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action');
|
||||
$this->assertEquals('http://localhost/path/to/action', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action');
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action');
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action');
|
||||
$this->assertEquals('http://localhost/thelia/index.php/path/to/action', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlOnAbsolutePath() {
|
||||
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action');
|
||||
$this->assertEquals('http://myhost/path/to/action', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action');
|
||||
$this->assertEquals('http://myhost/path/to/action', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action');
|
||||
$this->assertEquals('http://myhost/path/to/action', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlOnAbsolutePathWithParameters() {
|
||||
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p1=v1&p2=v2', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlOnAbsolutePathWithParametersAddParameters() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action?p0=v0', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p0=v0&p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action?p0=v0', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p0=v0&p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('http://myhost/path/to/action?p0=v0', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://myhost/path/to/action?p0=v0&p1=v1&p2=v2', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlWithParameters() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/index.php/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/path/to/action?p1=v1&p2=v2', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlPathOnly() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array(), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlPathOnlyWithParameters() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/thelia/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/path/to/action', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/path/to/action?p1=v1&p2=v2', $url);
|
||||
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlFromIndexWithParameters() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/index.php/?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/thelia/?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"));
|
||||
$this->assertEquals('http://localhost/?p1=v1&p2=v2', $url);
|
||||
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlPathOnlyFromIndexWithParameters() {
|
||||
$this->context->setBaseUrl('/thelia/index.php');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/thelia/?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/thelia/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/thelia/?p1=v1&p2=v2', $url);
|
||||
|
||||
$this->context->setBaseUrl('/');
|
||||
$url = \Thelia\Tools\URL::getInstance()->absoluteUrl('/', array("p1" => "v1", "p2" => "v2"), URL::PATH_TO_FILE);
|
||||
$this->assertEquals('http://localhost/?p1=v1&p2=v2', $url);
|
||||
|
||||
}
|
||||
|
||||
public function testRetrieve()
|
||||
{
|
||||
|
||||
|
||||
@@ -23,38 +23,89 @@
|
||||
|
||||
namespace Thelia\Tools;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Rewriting\RewritingResolver;
|
||||
use Thelia\Rewriting\RewritingRetriever;
|
||||
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
class URL
|
||||
{
|
||||
protected $resolver = null;
|
||||
protected $retriever = null;
|
||||
|
||||
protected $requestContext;
|
||||
|
||||
const PATH_TO_FILE = true;
|
||||
const WITH_INDEX_PAGE = false;
|
||||
|
||||
public function __construct()
|
||||
protected static $instance = null;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
// Allow singleton style calls once intanciated.
|
||||
// For this to work, the URL service has to be instanciated very early. This is done manually
|
||||
// in TheliaHttpKernel, by calling $this->container->get('thelia.url.manager');
|
||||
self::$instance = $this;
|
||||
|
||||
$this->requestContext = $container->get('router.admin')->getContext();
|
||||
|
||||
$this->retriever = new RewritingRetriever();
|
||||
$this->resolver = new RewritingResolver();
|
||||
}
|
||||
|
||||
public static function getIndexPage()
|
||||
{
|
||||
return ConfigQuery::read('base_url', '/') . "index_dev.php"; // FIXME !
|
||||
/**
|
||||
* Return this class instance, only once instanciated.
|
||||
*
|
||||
* @throws \RuntimeException if the class has not been instanciated.
|
||||
* @return \Thelia\Tools\URL the instance.
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (self::$instance == null) throw new \RuntimeException("URL instance is not initialized.");
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public static function init()
|
||||
/**
|
||||
* Return the base URL, either the base_url defined in Config, or the URL
|
||||
* of the current language, if 'one_domain_foreach_lang' is enabled.
|
||||
*
|
||||
* @return string the base URL, with a trailing '/'
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
return new URL();
|
||||
if ($host = $this->requestContext->getHost()) {
|
||||
|
||||
$scheme = $this->requestContext->getScheme();
|
||||
|
||||
$port = '';
|
||||
|
||||
if ('http' === $scheme && 80 != $this->requestContext->getHttpPort()) {
|
||||
$port = ':'.$this->requestContext->getHttpPort();
|
||||
} elseif ('https' === $scheme && 443 != $this->requestContext->getHttpsPort()) {
|
||||
$port = ':'.$this->requestContext->getHttpsPort();
|
||||
}
|
||||
|
||||
$schemeAuthority = "$scheme://$host"."$port";
|
||||
}
|
||||
|
||||
return $schemeAuthority.$this->requestContext->getBaseUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the index page, which is in fact the base URL.
|
||||
*/
|
||||
public function getIndexPage()
|
||||
{
|
||||
// The index page is the base URL :)
|
||||
return $this->getBaseUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Absolute URL for a given path relative to web root. By default,
|
||||
* the index.php (or index_dev.php) script name is added to the URL, use
|
||||
* the script name (index_dev.php) is added to the URL in dev_environment, use
|
||||
* $path_only = true to get a path without the index script.
|
||||
*
|
||||
* @param string $path the relative path
|
||||
@@ -63,19 +114,21 @@ class URL
|
||||
*
|
||||
* @return string The generated URL
|
||||
*/
|
||||
public static function absoluteUrl($path, array $parameters = null, $path_only = self::WITH_INDEX_PAGE)
|
||||
public function absoluteUrl($path, array $parameters = null, $path_only = self::WITH_INDEX_PAGE)
|
||||
{
|
||||
// Already absolute ?
|
||||
if (substr($path, 0, 4) != 'http') {
|
||||
|
||||
/**
|
||||
* @etienne : can't be done here for it's already done in ::viewUrl / ::adminViewUrl
|
||||
* @franck : should be done, as absoluteUrl() is sometimes called directly (see UrlGenerator::generateUrlFunction())
|
||||
*/
|
||||
$root = $path_only == self::PATH_TO_FILE ? ConfigQuery::read('base_url', '/') : self::getIndexPage();
|
||||
//$root = $path_only == self::PATH_TO_FILE ? ConfigQuery::read('base_url', '/') : '';
|
||||
$base_url = $this->getBaseUrl();
|
||||
|
||||
$base = rtrim($root, '/') . '/' . ltrim($path, '/');
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Normalize the given path
|
||||
$base = rtrim($base_url, '/') . '/' . ltrim($path, '/');
|
||||
} else
|
||||
$base = $path;
|
||||
|
||||
@@ -90,6 +143,7 @@ class URL
|
||||
$sepChar = strstr($base, '?') === false ? '?' : '&';
|
||||
|
||||
if ('' !== $queryString = rtrim($queryString, "&")) $queryString = $sepChar . $queryString;
|
||||
|
||||
return $base . $queryString;
|
||||
}
|
||||
|
||||
@@ -101,11 +155,11 @@ class URL
|
||||
*
|
||||
* @return string The generated URL
|
||||
*/
|
||||
public static function adminViewUrl($viewName, array $parameters = array())
|
||||
public function adminViewUrl($viewName, array $parameters = array())
|
||||
{
|
||||
$path = sprintf("%s/admin/%s", self::getIndexPage(), $viewName); // FIXME ! view= should not be required, check routing parameters
|
||||
$path = sprintf("%s/admin/%s", $this->getIndexPage(), $viewName);
|
||||
|
||||
return self::absoluteUrl($path, $parameters);
|
||||
return $this->absoluteUrl($path, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,72 +170,71 @@ class URL
|
||||
*
|
||||
* @return string The generated URL
|
||||
*/
|
||||
public static function viewUrl($viewName, array $parameters = array())
|
||||
public function viewUrl($viewName, array $parameters = array())
|
||||
{
|
||||
$path = sprintf("?view=%s", $viewName);
|
||||
|
||||
return self::absoluteUrl($path, $parameters);
|
||||
return $this->absoluteUrl($path, $parameters);
|
||||
}
|
||||
/**
|
||||
* Retrieve a rewritten URL from a view, a view id and a locale
|
||||
*
|
||||
* @param $view
|
||||
* @param $viewId
|
||||
* @param $viewLocale
|
||||
*
|
||||
* @return RewritingRetriever You can access $url and $rewrittenUrl properties
|
||||
*/
|
||||
public function retrieve($view, $viewId, $viewLocale)
|
||||
{
|
||||
if(ConfigQuery::isRewritingEnable()) {
|
||||
$this->retriever->loadViewUrl($view, $viewLocale, $viewId);
|
||||
}
|
||||
|
||||
return $this->retriever;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a rewritten URL from a view, a view id and a locale
|
||||
*
|
||||
* @param $view
|
||||
* @param $viewId
|
||||
* @param $viewLocale
|
||||
*
|
||||
* @return RewritingRetriever You can access $url and $rewrittenUrl properties
|
||||
*/
|
||||
public function retrieve($view, $viewId, $viewLocale)
|
||||
{
|
||||
if(ConfigQuery::isRewritingEnable()) {
|
||||
$this->retriever->loadViewUrl($view, $viewLocale, $viewId);
|
||||
}
|
||||
/**
|
||||
* Retrieve a rewritten URL from the current GET parameters
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return RewritingRetriever You can access $url and $rewrittenUrl properties or use toString method
|
||||
*/
|
||||
public function retrieveCurrent(Request $request)
|
||||
{
|
||||
if(ConfigQuery::isRewritingEnable()) {
|
||||
$view = $request->attributes->get('_view', null);
|
||||
$viewLocale = $request->query->get('locale', null);
|
||||
$viewId = $view === null ? null : $request->query->get($view . '_id', null);
|
||||
|
||||
return $this->retriever;
|
||||
}
|
||||
$allOtherParameters = $request->query->all();
|
||||
if($view !== null) {
|
||||
unset($allOtherParameters['view']);
|
||||
if($viewId !== null) {
|
||||
unset($allOtherParameters[$view . '_id']);
|
||||
}
|
||||
}
|
||||
if($viewLocale !== null) {
|
||||
unset($allOtherParameters['locale']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a rewritten URL from the current GET parameters
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return RewritingRetriever You can access $url and $rewrittenUrl properties or use toString method
|
||||
*/
|
||||
public function retrieveCurrent(Request $request)
|
||||
{
|
||||
if(ConfigQuery::isRewritingEnable()) {
|
||||
$view = $request->query->get('view', null);
|
||||
$viewLocale = $request->query->get('locale', null);
|
||||
$viewId = $view === null ? null : $request->query->get($view . '_id', null);
|
||||
$this->retriever->loadSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters);
|
||||
}
|
||||
|
||||
$allOtherParameters = $request->query->all();
|
||||
if($view !== null) {
|
||||
unset($allOtherParameters['view']);
|
||||
}
|
||||
if($viewLocale !== null) {
|
||||
unset($allOtherParameters['locale']);
|
||||
}
|
||||
if($viewId !== null) {
|
||||
unset($allOtherParameters[$view . '_id']);
|
||||
}
|
||||
return $this->retriever;
|
||||
}
|
||||
|
||||
$this->retriever->loadSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters);
|
||||
}
|
||||
|
||||
return $this->retriever;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a rewritten URL from the current GET parameters or use toString method
|
||||
*
|
||||
* @param $url
|
||||
*
|
||||
* @return RewritingResolver
|
||||
*/
|
||||
public function resolve($url)
|
||||
{
|
||||
$this->resolver->load($url);
|
||||
return $this->resolver;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Retrieve a rewritten URL from the current GET parameters or use toString method
|
||||
*
|
||||
* @param $url
|
||||
*
|
||||
* @return RewritingResolver
|
||||
*/
|
||||
public function resolve($url)
|
||||
{
|
||||
$this->resolver->load($url);
|
||||
return $this->resolver;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user