refactor Loop Category

This commit is contained in:
Manuel Raynaud
2013-05-14 11:57:52 +02:00
parent 6a3909c793
commit b1abcc7e58
3 changed files with 19 additions and 17 deletions

View File

@@ -26,6 +26,8 @@ namespace Thelia\Core\Template\Loop;
use Thelia\Tpex\Element\Loop\BaseLoop; use Thelia\Tpex\Element\Loop\BaseLoop;
use Thelia\Tpex\Element\Loop\LoopResult;
use Thelia\Tpex\Element\Loop\LoopResultRow;
use Thelia\Model\CategoryQuery; use Thelia\Model\CategoryQuery;
/** /**
@@ -92,10 +94,9 @@ class Category extends BaseLoop {
/** /**
* *
* *
* @param string $text * @return \Thelia\Tpex\Element\Loop\LoopResult
* @return mixed|string
*/ */
public function exec($text) public function exec()
{ {
$search = CategoryQuery::create(); $search = CategoryQuery::create();
@@ -157,25 +158,27 @@ class Category extends BaseLoop {
$categories = $search->find(); $categories = $search->find();
$res = ""; $loopResult = new LoopResult();
foreach ($categories as $category) { foreach ($categories as $category) {
if ($this->not_empty && $category->countAllProducts() == 0) continue; if ($this->not_empty && $category->countAllProducts() == 0) continue;
$temp = str_replace("#TITLE", $category->getTitle(), $text); $loopResultRow = new LoopResultRow();
$temp = str_replace("#CHAPO", $category->getChapo(), $temp); $loopResultRow->set("TITLE",$category->getTitle());
$temp = str_replace("#DESCRIPTION", $category->getDescription(), $temp); $loopResultRow->set("CHAPO", $category->getChapo());
$temp = str_replace("#POSTSCRIPTUM", $category->getPostscriptum(), $temp); $loopResultRow->set("DESCRIPTION", $category->getDescription());
$temp = str_replace("#PARENT", $category->getParent(), $temp); $loopResultRow->set("POSTSCRIPTUM", $category->getPostscriptum());
$temp = str_replace("#ID", $category->getId(), $temp); $loopResultRow->set("PARENT", $category->getParent());
$temp = str_replace("#URL", $category->getUrl(), $temp); $loopResultRow->set("ID", $category->getId());
$temp = str_replace("#LINK", $category->getLink(), $temp); $loopResultRow->set("URL", $category->getUrl());
$temp = str_replace("#NB_CHILD", $category->countChild(), $temp); $loopResultRow->set("LINK", $category->getLink());
$res .= $temp; $loopResultRow->set("NB_CHILD", $category->countChild());
$loopResult->addRow($loopResultRow);
} }
return $res; return $loopResult;
} }
} }

View File

@@ -6,7 +6,6 @@
</head> </head>
<body> <body>
<div>TODO write content<br /> <div>TODO write content<br />
<THELIA_cat type="category"> <THELIA_cat type="category">
#__COUNT__ - #TITLE <br /> #__COUNT__ - #TITLE <br />
nb child : #NB_CHILD <br /><br /> nb child : #NB_CHILD <br /><br />