start to create first loop

This commit is contained in:
Manuel Raynaud
2013-05-03 17:06:43 +02:00
parent 7d766c68ff
commit 046f0e0f94
10 changed files with 176 additions and 24 deletions

View File

@@ -59,6 +59,9 @@ class DatabaseConfiguration implements ConfigurationInterface
->scalarNode("dsn") ->scalarNode("dsn")
->cannotBeEmpty() ->cannotBeEmpty()
->end() ->end()
->scalarNode("classname")
->defaultValue("PropelPDO")
->end()
->end() ->end()
->end() ->end()
->end() ->end()

View File

@@ -50,7 +50,8 @@ class DefinePropel {
array( array(
"dsn" => $connection["dsn"], "dsn" => $connection["dsn"],
"user" => $connection["user"], "user" => $connection["user"],
"password" => $connection["password"] "password" => $connection["password"],
"classname" => $connection["classname"]
) )
) )
) )

View File

@@ -11,6 +11,7 @@
<loops> <loops>
<loop name="foo" class="Foo\Bar"/> <loop name="foo" class="Foo\Bar"/>
<loop name="fooz" class="Foo\Barz"/> <loop name="fooz" class="Foo\Barz"/>
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
</loops> </loops>
<services> <services>

View File

@@ -0,0 +1,131 @@
<?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\Template\Loop;
use Thelia\Log\Tlog;
use Thelia\Tpex\Element\Loop\BaseLoop;
use Thelia\Model\CategoryQuery;
class Category extends BaseLoop {
public $id;
public $parent;
public $current;
public $not_empty;
public $visible;
public $link;
public $order;
public $random;
public $exclude;
public $start;
public $offset;
public function defineArgs()
{
return array(
"id" => "optional",
"parent" => "optional",
"current" => "optional",
"not_empty" => 0,
"visible" => 1,
"link" => "optional",
"order" => "optional",
"random" => 0,
"exclude" => "optional",
"limit" => 10,
"offset" => 0,
);
}
public function exec($text)
{
$search = CategoryQuery::create();
if (!is_null($this->id)) {
$search->filterById($this->id);
}
if(!is_null($this->parent)) {
$search->filterByParent($this->parent);
}
if($this->current == 1) {
$search->filterById($this->request->get("category_id"));
} else if ($this->current == 0) {
$search->filterById($this->request->get("category_id"), \Criteria::NOT_IN);
}
if (!is_null($this->exclude)) {
$search->filterById(explode(",", $this->exclude), \Criteria::NOT_IN);
}
if (!is_null($this->link)) {
$search->filterByLink($this->link);
}
if($this->limit > -1) {
$search->limit($this->limit);
}
$search->offset($this->offset);
switch($this->order) {
case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break;
case "alpha_reverse":
$search->addDescendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break;
case "reverse":
$search->orderByPosition(\Criteria::DESC);
break;
default:
$search->orderByPosition();
break;
}
if($this->random == 1) {
$search->clearOrderByColumns();
$search->addAscendingOrderByColumn('RAND()');
}
$search->joinWithI18n('en_US');
$categories = $search->find();
$res = "";
foreach ($categories as $category) {
$temp = str_replace("#TITLE", $category->getTitle(), $text);
$temp = str_replace("#CHAPO", $category->getChapo(), $temp);
$temp = str_replace("#ID", $category->getId(), $temp);
$res .= $temp;
}
return $res;
}
}

View File

@@ -84,10 +84,17 @@ class Thelia extends Kernel
if ($this->isDebug()) { if ($this->isDebug()) {
Propel::setLogger(Tlog::getInstance()); Propel::setLogger(Tlog::getInstance());
$config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
$config->setParameter('debugpdo.logging.details.method.enabled', true); $config->setParameter('debugpdo.logging.methods', array(
$config->setParameter('debugpdo.logging.details.time.enabled', true); 'PropelPDO::exec',
$config->setParameter('debugpdo.logging.details.mem.enabled', true); 'PropelPDO::query',
'PropelPDO::prepare',
'DebugPDOStatement::execute',
), false);
$config->setParameter('debugpdo.logging.details', array(
'time' => array('enabled' => true),
'mem' => array('enabled' => true),
'connection' => array('enabled' => true),
));
$con = Propel::getConnection("thelia"); $con = Propel::getConnection("thelia");
$con->useDebug(true); $con->useDebug(true);
} }

View File

@@ -68,7 +68,7 @@ try {
$con->commit(); $con->commit();
} catch (Exception $e) { } catch (Exception $e) {
echo "error : ".$e->getMessage(); echo "error : ".$e->getMessage()."\n";
$con->rollBack(); $con->rollBack();
} }

View File

@@ -15,13 +15,19 @@ use Thelia\Model\ProductQuery;
class Doobitch extends BaseLoop { class Doobitch extends BaseLoop {
public function exec($text, $args) public function defineArgs()
{
return array(
"param1",
"param2" => array("default" => "foo")
);
}
public function exec($text)
{ {
$param1 = Tools::extractValueParam("param1", $args);
$res = ""; $res = "";
if($param1 == 2 || $param1 == 3) { if($this->param1 == 2 || $this->param1 == 3) {
for($i = 0; $i < 4; $i++) { for($i = 0; $i < 4; $i++) {
$tmp = str_replace("#ALFRED", "foo".$i, $text); $tmp = str_replace("#ALFRED", "foo".$i, $text);
if($i%2){ if($i%2){
@@ -35,6 +41,8 @@ class Doobitch extends BaseLoop {
} }
} }
echo $this->param2;
return $res; return $res;
} }
} }

View File

@@ -13,7 +13,12 @@ use Thelia\Tpex\Element\Loop\BaseLoop;
class Foo extends BaseLoop { class Foo extends BaseLoop {
public function exec($text, $args) public function defineArgs()
{
return array();
}
public function exec($text)
{ {
$res = ""; $res = "";
for($i = 0; $i < 4; $i++) { for($i = 0; $i < 4; $i++) {

View File

@@ -5,21 +5,17 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head> </head>
<body> <body>
<div>TODO write content #SET{toto, 4} toto vaut #GET{toto} zeafazefaze azef azef azef azef <br /> <div>TODO write content<br />
<THELIA_FOO type="foo" id="loop1" param1="#GET{toto}">
toto : #TOTO <br />
count : #__COUNT__ <br /><br />
<THELIA_FU type="doobitch" param1="#__COUNT__" param2="#TUTU">
#ALFRED azd azd azed azd <br />
<T:CHAPO>#CHAPO n'est pas vide</T:CHAPO>le chapo est vide<//T:CHAPO> <br />
</THELIA_FU>
</THELIA_FOO>
<TEST_equel test="equal" variable="3" value="1"> <THELIA_cat type="category" order="alpha_reverse">
#__COUNT__ - #TITLE <br />
</THELIA_cat>
<TEST_equal test="equal" variable="3" value="1">
test vrai test vrai
</TEST_equel> </TEST_equal>
test faux test faux
<//TEST_equel> <//TEST_equal>
<br /> <br />
<REPEAT_loopy start="6" end="12" increment="1"> <REPEAT_loopy start="6" end="12" increment="1">
Compteur = #INDEX<br /> Compteur = #INDEX<br />