Merge branch 'master' into loops

Conflicts:
	core/lib/Thelia/Admin/Controller/BaseAdminController.php
	core/lib/Thelia/Core/Template/Loop/Category.php
	core/lib/Thelia/Model/Admin.php
	core/lib/Thelia/Model/Customer.php
	templates/smarty-sample/index.html
This commit is contained in:
Etienne Roudeix
2013-07-05 11:16:55 +02:00
670 changed files with 153101 additions and 187341 deletions

View File

@@ -47,6 +47,8 @@ abstract class ActionEvent extends Event
*/
protected $action;
protected $form;
/**
*
* @param \Symfony\Component\HttpFoundation\Request $request
@@ -75,4 +77,21 @@ abstract class ActionEvent extends Event
{
return $this->request;
}
public function setFormError($form)
{
$this->form = $form;
$this->stopPropagation();
}
public function getForm()
{
return $this->form;
}
public function hasFormError()
{
return $this->form !== null;
}
}

View File

@@ -0,0 +1,53 @@
<?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\Customer;
class CustomRefEvent extends Event {
protected $ref;
public $customer;
public function __construct(Customer $customer)
{
$this->customer = $customer;
}
public function hasRef()
{
return null !== $this->ref;
}
public function getRef()
{
return $this->ref;
}
public function setRef($ref)
{
$this->ref = $ref;
}
}

View File

@@ -47,4 +47,10 @@ final class TheliaEvents
* Send before starting thelia inclusion
*/
const INCLUSION = "thelia.include";
const BEFORE_CREATECUSTOMER = "action.before_createcustomer";
const AFTER_CREATECUSTOMER = "action.after_createcustomer";
const CREATECUSTOMER_CUSTOMREF = "customer.creation.customref";
}

View File

@@ -46,7 +46,14 @@ class ControllerListener implements EventSubscriberInterface
if (false !== $action = $request->get("action")) {
//search corresponding action
$event = new ActionEventFactory($request, $action, $event->getKernel()->getContainer()->getParameter("thelia.actionEvent"));
$dispatcher->dispatch("action.".$action, $event->createActionEvent());
$actionEvent = $event->createActionEvent();
$dispatcher->dispatch("action.".$action, $actionEvent);
if ($actionEvent->hasFormError()) {
$request->getSession()->set("form_error", true);
$request->getSession()->set("form_name", $actionEvent->getForm()->createView()
->vars["attr"]["thelia_name"]);
}
}
}

View File

@@ -26,6 +26,7 @@ namespace Thelia\Core\Template\Element;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Propel\Runtime\ActiveQuery\ModelCriteria;
/**
*
@@ -81,7 +82,7 @@ abstract class BaseLoop
*
* @return array|mixed|\PropelModelPager|\PropelObjectCollection
*/
public function search(\ModelCriteria $search, &$pagination = null)
public function search(ModelCriteria $search, &$pagination = null)
{
if($this->page !== null) {
return $this->searchWithPagination($search, $pagination);
@@ -95,7 +96,7 @@ abstract class BaseLoop
*
* @return array|mixed|\PropelObjectCollection
*/
public function searchWithOffset(\ModelCriteria $search)
public function searchWithOffset(ModelCriteria $search)
{
if($this->limit >= 0) {
$search->limit($this->limit);
@@ -111,7 +112,7 @@ abstract class BaseLoop
*
* @return array|\PropelModelPager
*/
public function searchWithPagination(\ModelCriteria $search, &$pagination)
public function searchWithPagination(ModelCriteria $search, &$pagination)
{
$pagination = $search->paginate($this->page, $this->limit);

View File

@@ -23,6 +23,7 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
@@ -32,6 +33,7 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\CategoryQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
@@ -109,7 +111,7 @@ class Category extends BaseLoop
$search = CategoryQuery::create();
if (!is_null($this->id)) {
$search->filterById($this->id, \Criteria::IN);
$search->filterById($this->id, Criteria::IN);
}
if (!is_null($this->parent)) {
@@ -119,11 +121,11 @@ class Category extends BaseLoop
if ($this->current === true) {
$search->filterById($this->request->get("category_id"));
} elseif ($this->current === false) {
$search->filterById($this->request->get("category_id"), \Criteria::NOT_IN);
$search->filterById($this->request->get("category_id"), Criteria::NOT_IN);
}
if (!is_null($this->exclude)) {
$search->filterById($this->exclude, \Criteria::NOT_IN);
$search->filterById($this->exclude, Criteria::NOT_IN);
}
if (!is_null($this->link)) {
@@ -157,7 +159,11 @@ class Category extends BaseLoop
*
* @todo : verify here if we want results for row without translations.
*/
$search->joinWithI18n($this->request->getSession()->get('locale', 'en_US'), \Criteria::INNER_JOIN);
$search->joinWithI18n(
$this->request->getSession()->get('locale', 'en_US'),
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
);
$categories = $this->search($search, $pagination);

View File

@@ -88,8 +88,17 @@ class Form implements SmartyPluginInterface
}
$instance = $this->getInstance($params['name']);
$form = $instance->getForm();
$template->assign("form", $instance->getForm()->createView());
if (
true === $this->request->getSession()->get("form_error", false) &&
$this->request->getSession()->get("form_name") == $instance->getName())
{
$form->bind($this->request);
$this->request->getSession()->set("form_error", false);
}
$template->assign("form", $form->createView());
} else {
return $content;
}
@@ -202,7 +211,10 @@ class Form implements SmartyPluginInterface
$class = new \ReflectionClass($this->formDefinition[$name]);
return $class->newInstance($this->request);
return $class->newInstance(
$this->request,
"form"
);
}
/**

View File

@@ -46,8 +46,8 @@ use Thelia\Core\TheliaContainerBuilder;
use Thelia\Core\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
use Propel;
use PropelConfiguration;
use Propel\Runtime\Propel;
use Propel\Runtime\Connection\ConnectionManagerSingle;
class Thelia extends Kernel
{
@@ -71,7 +71,7 @@ class Thelia extends Kernel
return ;
}
if (! Propel::isInit()) {
/* if (! Propel::isInit()) {
$definePropel = new DefinePropel(new DatabaseConfiguration(),
Yaml::parse(THELIA_ROOT . '/local/config/database.yml'));
@@ -97,6 +97,22 @@ class Thelia extends Kernel
}
Propel::initialize();
}*/
$definePropel = new DefinePropel(new DatabaseConfiguration(),
Yaml::parse(THELIA_ROOT . '/local/config/database.yml'));
$propelConfig = $definePropel->getConfig();
$serviceContainer = Propel::getServiceContainer();
$serviceContainer->setAdapterClass('thelia', 'mysql');
$manager = new ConnectionManagerSingle();
$manager->setConfiguration($definePropel->getConfig());
$serviceContainer->setConnectionManager('thelia', $manager);
if ($this->isDebug()) {
$serviceContainer->setLogger('defaultLogger', Tlog::getInstance());
$con = Propel::getConnection("thelia");
$con->useDebug(true);
}
}

View File

@@ -22,6 +22,7 @@
/*************************************************************************************/
namespace Thelia\Core;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -76,6 +77,7 @@ class TheliaHttpKernel extends HttpKernel
{
//$request->headers->set('X-Php-Ob-Level', ob_get_level());
$request = $this->initSession($request);
$this->initParam($request);
$this->container->enterScope('request');
$this->container->set('request', $request, 'request');
@@ -119,6 +121,59 @@ class TheliaHttpKernel extends HttpKernel
*/
protected function initParam(Request $request)
{
$lang = $this->detectLang($request);
if ($lang) {
$request->getSession()->set("lang", $lang->getCode());
$request->getSession()->set("locale", $lang->getLocale());
}
}
/**
* @param Request $request
* @return null|\Thelia\Model\Lang
*/
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"));
if(is_null($lang)) {
return;
}
//if each lang had is own domain, we redirect the user to the good one.
if (Model\ConfigQuery::read("one_domain_foreach_lang", false) == 1) {
//if lang domain is different from actuel domain, redirect to the good one
if (rtrim($lang->getUrl(), "/") != $request->getSchemeAndHttpHost()) {
// TODO : search if http status 302 is the good one.
$redirect = new RedirectResponse($lang->getUrl(), 302);
$redirect->send();
exit;
} else {
//the user is actually on the good domain, nothing to change
return null;
}
} else {
//one domain for all languages, the lang is set into session
return $lang;
}
}
//check if lang is not defined. If not we have to search the good one.
if (null === $request->getSession()->get("lang")) {
if (Model\ConfigQuery::read("one_domain_foreach_lang", false) == 1) {
//find lang with domain
return Model\LangQuery::create()->filterByUrl($request->getSchemeAndHttpHost(), ModelCriteria::LIKE)->findOne();
}
//find default lang
return Model\LangQuery::create()->findOneByByDefault(1);
}
}