diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 58c0c8579..17ed3b332 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -14,6 +14,7 @@ + diff --git a/core/lib/Thelia/Core/Template/Loop/Folder.php b/core/lib/Thelia/Core/Template/Loop/Folder.php new file mode 100755 index 000000000..d6de1f7a7 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Folder.php @@ -0,0 +1,198 @@ +. */ +/* */ +/*************************************************************************************/ + +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; + +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Log\Tlog; + +use Thelia\Model\FolderQuery; +use Thelia\Model\ConfigQuery; +use Thelia\Type\TypeCollection; +use Thelia\Type; + +/** + * + * Folder loop, all params available : + * + * - id : can be an id (eq : 3) or a "string list" (eg: 3, 4, 5) + * - parent : categories having this parent id + * - current : current id is used if you are on a folder page + * - not_empty : if value is 1, folder and subcategories must have at least 1 product + * - visible : default 1, if you want folder not visible put 0 + * - order : all value available : 'alpha', 'alpha_reverse', 'manual' (default), 'manual-reverse', 'random' + * - exclude : all folder id you want to exclude (as for id, an integer or a "string list" can be used) + * + * example : + * + * + * #TITLE : #ID + * + * + * + * Class Folder + * @package Thelia\Core\Template\Loop + * @author Manuel Raynaud + * @author Etienne Roudeix + */ +class Folder extends BaseLoop +{ + /** + * @return ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id'), + Argument::createIntTypeArgument('parent'), + Argument::createBooleanTypeArgument('current'), + Argument::createBooleanTypeArgument('not_empty', 0), + Argument::createBooleanTypeArgument('visible', 1), + new Argument( + 'order', + new TypeCollection( + new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual-reverse', 'random')) + ), + 'manual' + ), + Argument::createIntListTypeArgument('exclude') + ); + } + + /** + * @param $pagination + * + * @return \Thelia\Core\Template\Element\LoopResult + */ + public function exec(&$pagination) + { + $search = FolderQuery::create(); + + $id = $this->getId(); + + if (!is_null($id)) { + $search->filterById($id, Criteria::IN); + } + + $parent = $this->getParent(); + + if (!is_null($parent)) { + $search->filterByParent($parent); + } + + + $current = $this->getCurrent(); + + if ($current === true) { + $search->filterById($this->request->get("folder_id")); + } elseif ($current === false) { + $search->filterById($this->request->get("folder_id"), Criteria::NOT_IN); + } + + + $exclude = $this->getExclude(); + + if (!is_null($exclude)) { + $search->filterById($exclude, Criteria::NOT_IN); + } + + $search->filterByVisible($this->getVisible() ? 1 : 0); + + $orders = $this->getOrder(); + + foreach($orders as $order) { + switch ($order) { + case "alpha": + $search->addAscendingOrderByColumn(\Thelia\Model\Map\FolderI18nTableMap::TITLE); + break; + case "alpha_reverse": + $search->addDescendingOrderByColumn(\Thelia\Model\Map\FolderI18nTableMap::TITLE); + break; + case "manual-reverse": + $search->orderByPosition(Criteria::DESC); + break; + case "manual": + $search->orderByPosition(Criteria::ASC); + break; + case "random": + $search->clearOrderByColumns(); + $search->addAscendingOrderByColumn('RAND()'); + break(2); + break; + } + } + + /** + * \Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation. + * + * @todo : verify here if we want results for row without translations. + */ + + $search->joinWithI18n( + $this->request->getSession()->getLocale(), + (ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN + ); + + $categories = $this->search($search, $pagination); + + $notEmpty = $this->getNot_empty(); + + $loopResult = new LoopResult(); + + foreach ($categories as $folder) { + + if ($notEmpty && $folder->countAllProducts() == 0) continue; + + $loopResultRow = new LoopResultRow(); + + $loopResultRow + ->set("ID", $folder->getId()) + ->set("TITLE",$folder->getTitle()) + ->set("CHAPO", $folder->getChapo()) + ->set("DESCRIPTION", $folder->getDescription()) + ->set("POSTSCRIPTUM", $folder->getPostscriptum()) + ->set("PARENT", $folder->getParent()) + ->set("URL", $folder->getUrl()) + ->set("PRODUCT_COUNT", $folder->countChild()) + ->set("VISIBLE", $folder->getVisible() ? "1" : "0") + ->set("POSITION", $folder->getPosition()) + + ->set("CREATE_DATE", $folder->getCreatedAt()) + ->set("UPDATE_DATE", $folder->getUpdatedAt()) + ->set("VERSION", $folder->getVersion()) + ->set("VERSION_DATE", $folder->getVersionCreatedAt()) + ->set("VERSION_AUTHOR", $folder->getVersionCreatedBy()) + ; + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} \ No newline at end of file diff --git a/templates/default/folder.html b/templates/default/folder.html new file mode 100755 index 000000000..ea50c314b --- /dev/null +++ b/templates/default/folder.html @@ -0,0 +1,20 @@ +{loop name="folder0" type="folder" parent="0"} +

FOLDER : #TITLE

+ {loop name="folder1" type="folder" parent="#ID"} +
+

SUBFOLDER : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

+ {*loop name="content" type="content" folder="#ID"} +

CONTENT : #REF / #TITLE

+ #PRICE € + {/loop*} +
+
+ {/loop} + + {*loop name="content" type="content" folder="#ID"} +

CONTENT : #REF / #TITLE

+ #PRICE € + {/loop*} +
+
+{/loop} \ No newline at end of file