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()
->end()
->scalarNode("classname")
->defaultValue("Propel\Runtime\Connection\PropelPDO")
->defaultValue("\Propel\Runtime\Connection\PropelPDO")
->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;

View File

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

View File

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