This commit is contained in:
franck
2013-07-08 13:25:08 +02:00
parent 6890482101
commit 2b0fdc670b
8 changed files with 141 additions and 69 deletions

View File

@@ -60,7 +60,7 @@ class DatabaseConfiguration implements ConfigurationInterface
->cannotBeEmpty() ->cannotBeEmpty()
->end() ->end()
->scalarNode("classname") ->scalarNode("classname")
->defaultValue("Propel\Runtime\Connection\PropelPDO") ->defaultValue("\Propel\Runtime\Connection\PropelPDO")
->end() ->end()
->end() ->end()
->end() ->end()

View File

@@ -0,0 +1,22 @@
<?php
/**
* Created by JetBrains PhpStorm.
* User: manu
* Date: 08/07/13
* Time: 11:41
* To change this template use File | Settings | File Templates.
*/
namespace Thelia\Core\HttpFoundation;
use Symfony\Component\HttpFoundation\Request as BaseRequest;
class Request extends BaseRequest{
public function getProductId()
{
return $this->get("product_id");
}
}

View File

@@ -21,7 +21,7 @@
/* */ /* */
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Core\Session; namespace Thelia\Core\HttpFoundation\Session;
use Symfony\Component\HttpFoundation\Session\Session as BaseSession; use Symfony\Component\HttpFoundation\Session\Session as BaseSession;

View File

@@ -35,7 +35,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class TheliaLoop implements SmartyPluginInterface class TheliaLoop implements SmartyPluginInterface
{ {
protected $pagination = null; protected static $pagination = null;
protected $loopDefinition = array(); protected $loopDefinition = array();
@@ -43,9 +43,8 @@ class TheliaLoop implements SmartyPluginInterface
protected $dispatcher; protected $dispatcher;
protected $varstack = array();
protected $loopstack = array(); protected $loopstack = array();
protected $varstack = array();
public function __construct(Request $request, EventDispatcherInterface $dispatcher) public function __construct(Request $request, EventDispatcherInterface $dispatcher)
{ {
@@ -58,13 +57,13 @@ class TheliaLoop implements SmartyPluginInterface
* *
* @return \PropelModelPager * @return \PropelModelPager
*/ */
protected function getPagination($loopId) public static function getPagination($loopId)
{ {
if(!empty($this->pagination[$loopId])) { if(!empty(self::$pagination[$loopId])) {
return $this->pagination[$loopId]; return self::$pagination[$loopId];
} else { } else {
return null; return null;
} }
} }
/** /**
@@ -93,12 +92,13 @@ class TheliaLoop implements SmartyPluginInterface
throw new \InvalidArgumentException("A loop named '$name' already exists in the current scope."); throw new \InvalidArgumentException("A loop named '$name' already exists in the current scope.");
} }
$loop = $this->createLoopInstance($params); $loop = $this->createLoopInstance(strtolower($params['type']));
$this->pagination[$name] = null; $this->getLoopArgument($loop, $params);
$loopResults = $loop->exec($this->pagination[$name]); self::$pagination[$name] = null;
$loopResults = $loop->exec(self::$pagination[$name]);
$this->loopstack[$name] = $loopResults; $this->loopstack[$name] = $loopResults;
} else { } else {
@@ -130,13 +130,13 @@ class TheliaLoop implements SmartyPluginInterface
$template->assign($var, $val); $template->assign($var, $val);
} }
// Assign meta information $repeat = true;
$template->assign('LOOP_COUNT', 1 + $loopResults->key());
$template->assign('LOOP_TOTAL', $loopResults->getCount());
$repeat = $loopResults->valid();
} }
// Assign meta information
$template->assign('LOOP_COUNT', 1 + $loopResults->key());
$template->assign('LOOP_TOTAL', $loopResults->getCount());
// Loop is terminated. Cleanup. // Loop is terminated. Cleanup.
if (! $repeat) { if (! $repeat) {
// Restore previous variables values before terminating // Restore previous variables values before terminating
@@ -187,7 +187,6 @@ class TheliaLoop implements SmartyPluginInterface
*/ */
public function theliaIfLoop($params, $content, $template, &$repeat) public function theliaIfLoop($params, $content, $template, &$repeat)
{ {
// When encountering close tag, check if loop has results. // When encountering close tag, check if loop has results.
if ($repeat === false) { if ($repeat === false) {
return $this->checkEmptyLoop($params, $template) ? '' : $content; return $this->checkEmptyLoop($params, $template) ? '' : $content;
@@ -207,43 +206,45 @@ class TheliaLoop implements SmartyPluginInterface
*/ */
public function theliaPageLoop($params, $content, $template, &$repeat) public function theliaPageLoop($params, $content, $template, &$repeat)
{ {
if (empty($params['rel'])) if (empty($params['rel']))
throw new \InvalidArgumentException("Missing 'rel' parameter in page loop"); throw new \InvalidArgumentException("Missing 'rel' parameter in page loop");
$loopName = $params['rel']; $loopName = $params['rel'];
// Find loop results in the current template vars // Find loop results in the current template vars
if (! isset($this->loopstack[$loopName])) { /* $loopResults = $template->getTemplateVars($loopName);
throw new \InvalidArgumentException("Loop $loopName is not defined."); if (empty($loopResults)) {
} throw new \InvalidArgumentException("Loop $loopName is not defined.");
}*/
$loopResults = $this->loopstack[$loopName]; // Find pagination
$pagination = self::getPagination($loopName);
if ($pagination === null) {
throw new \InvalidArgumentException("Loop $loopName is not defined");
}
// Find pagination if($pagination->getNbResults() == 0) {
$pagination = $this->getPagination($loopName); return '';
}
if ($pagination === null) { if ($content === null) {
throw new \InvalidArgumentException("Loop $loopName : no pagination found."); $page = 1;
} } else {
$page = $template->getTemplateVars('PAGE');
$page++;
}
if ($content === null) { if ($page <= $pagination->getLastPage()) {
$page = 1; $template->assign('PAGE', $page);
} else { $template->assign('CURRENT', $pagination->getPage());
$page = $template->getTemplateVars('PAGE'); $template->assign('LAST', $pagination->getLastPage());
$page++;
}
if ($page <= $pagination->getLastPage()) { $repeat = true;
$template->assign('PAGE', $page); }
$template->assign('CURRENT', $pagination->getPage());
$template->assign('LAST', $pagination->getLastPage());
$repeat = true; if ($content !== null) {
} return $content;
}
if ($content !== null) {
return $content;
}
} }
/** /**
@@ -275,32 +276,27 @@ class TheliaLoop implements SmartyPluginInterface
* *
* @param string $name * @param string $name
* @return \Thelia\Core\Template\Element\BaseLoop * @return \Thelia\Core\Template\Element\BaseLoop
* @throws \Thelia\Tpex\Exception\InvalidElementException * @throws InvalidElementException
* @throws \Thelia\Tpex\Exception\ElementNotFoundException * @throws ElementNotFoundException
*/ */
protected function createLoopInstance($smartyParams) protected function createLoopInstance($name)
{ {
$type = strtolower($smartyParams['type']);
if (! isset($this->loopDefinition[$type])) { if (! isset($this->loopDefinition[$name])) {
throw new ElementNotFoundException(sprintf("%s loop does not exists", $type)); throw new ElementNotFoundException(sprintf("%s loop does not exists", $name));
} }
$class = new \ReflectionClass($this->loopDefinition[$type]); $class = new \ReflectionClass($this->loopDefinition[$name]);
if ($class->isSubclassOf("Thelia\Core\Template\Element\BaseLoop") === false) { if ($class->isSubclassOf("Thelia\Core\Template\Element\BaseLoop") === false) {
throw new InvalidElementException(sprintf("%s Loop class have to extends Thelia\Core\Template\Element\BaseLoop", throw new InvalidElementException(sprintf("%s Loop class have to extends Thelia\Core\Template\Element\BaseLoop",
$type)); $name));
} }
$loop = $class->newInstance( return $class->newInstance(
$this->request, $this->request,
$this->dispatcher $this->dispatcher
); );
$loop->initializeArgs($smartyParams);
return $loop;
} }
/** /**
@@ -312,11 +308,10 @@ class TheliaLoop implements SmartyPluginInterface
*/ */
protected function getLoopArgument(BaseLoop $loop, $smartyParam) protected function getLoopArgument(BaseLoop $loop, $smartyParam)
{ {
$faultActor = array(); $faultActor = array();
$faultDetails = array(); $faultDetails = array();
$argumentsCollection = $loop->getArgs(); $argumentsCollection = $loop->getArgs();
foreach( $argumentsCollection as $argument ) { foreach( $argumentsCollection as $argument ) {
$value = isset($smartyParam[$argument->name]) ? (string)$smartyParam[$argument->name] : null; $value = isset($smartyParam[$argument->name]) ? (string)$smartyParam[$argument->name] : null;
@@ -373,7 +368,7 @@ class TheliaLoop implements SmartyPluginInterface
* "myLoop" => "My\Own\Loop" * "myLoop" => "My\Own\Loop"
* ); * );
* *
* @param array $loops * @param array $loopDefinition
* @throws \InvalidArgumentException if loop name already exists * @throws \InvalidArgumentException if loop name already exists
*/ */
public function setLoopList(array $loopDefinition) public function setLoopList(array $loopDefinition)

View File

@@ -196,7 +196,7 @@ class TheliaHttpKernel extends HttpKernel
$storage->setOptions(json_decode(Model\ConfigQuery::read("session_config.config"))); $storage->setOptions(json_decode(Model\ConfigQuery::read("session_config.config")));
} }
$session = new \Thelia\Core\Session\Session($storage); $session = new \Thelia\Core\HttpFoundation\Session\Session($storage);
$session->start(); $session->start();
$request->setSession($session); $request->setSession($session);

View File

@@ -0,0 +1,55 @@
{assign var=category_current_page value={$smarty.get.category_page|default:1}}
<h1>Pagination</h1>
<h2>Categories</h2>
<div style="border: solid 1px; padding: 20px;">
{loop name="cat" type="category" page="{$category_current_page}" limit="2"}
<h2>#LOOP_COUNT - #TITLE</h2>
<h3>Products :</h3>
<div style="border: solid 1px; padding: 20px;">
{assign var=this_product_getter value="product_`$ID`_page"}
{assign var=product_current_page value={$smarty.get.$this_product_getter|default:1}}
<ul>
{loop name="prod" type="product" category="#ID" page="{$product_current_page}" limit="2"}
<li>
#REF
</li>
{/loop}
</ul>
</div>
<p>#TITLE page choice</p>
{pageloop rel="prod"}
{if ${PAGE} != {$product_current_page}}
<a href="index_dev.php?view=pagination&category_page={$category_current_page}&{$this_product_getter}=#PAGE">#PAGE</a>
{else}
{ #PAGE }
{/if}
{if {$PAGE} != {$LAST}}
-
{/if}
{/pageloop}
{/loop}
</div>
<p>categories page choice</p>
{pageloop rel="cat"}
{if ${PAGE} != {$category_current_page}}
<a href="index_dev.php?view=pagination&category_page=#PAGE">#PAGE</a>
{else}
{ #PAGE }
{/if}
{if {$PAGE} != {$LAST}}
-
{/if}
{/pageloop}

View File

@@ -1,6 +1,6 @@
<?php <?php
use Symfony\Component\HttpFoundation\Request;
use Thelia\Core\Thelia; use Thelia\Core\Thelia;
use Thelia\Core\HttpFoundation\Request;
//use Symfony\Component\DependencyInjection; //use Symfony\Component\DependencyInjection;

View File

@@ -1,6 +1,6 @@
<?php <?php
use Symfony\Component\HttpFoundation\Request;
use Thelia\Core\Thelia; use Thelia\Core\Thelia;
use Thelia\Core\HttpFoundation\Request;
//use Symfony\Component\DependencyInjection; //use Symfony\Component\DependencyInjection;