diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 43f07fc50..d4d63ac77 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -21,6 +21,7 @@ + diff --git a/core/lib/Thelia/Core/Template/Loop/FolderPath.php b/core/lib/Thelia/Core/Template/Loop/FolderPath.php new file mode 100644 index 000000000..895d8e08c --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/FolderPath.php @@ -0,0 +1,160 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Loop; +use Thelia\Core\Template\Element\BaseI18nLoop; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\LoopResultRow; +use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Model\FolderQuery; +use Thelia\Type\BooleanOrBothType; + + +/** + * Class FolderPath + * @package Thelia\Core\Template\Loop + * @author Manuel Raynaud + */ +class FolderPath extends BaseI18nLoop +{ + + /** + * + * define all args used in your loop + * + * + * example : + * + * public function getArgDefinitions() + * { + * return new ArgumentCollection( + * Argument::createIntListTypeArgument('id'), + * new Argument( + * 'ref', + * new TypeCollection( + * new Type\AlphaNumStringListType() + * ) + * ), + * Argument::createIntListTypeArgument('category'), + * Argument::createBooleanTypeArgument('new'), + * Argument::createBooleanTypeArgument('promo'), + * Argument::createFloatTypeArgument('min_price'), + * Argument::createFloatTypeArgument('max_price'), + * Argument::createIntTypeArgument('min_stock'), + * Argument::createFloatTypeArgument('min_weight'), + * Argument::createFloatTypeArgument('max_weight'), + * Argument::createBooleanTypeArgument('current'), + * + * ); + * } + * + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntTypeArgument('folder', null, true), + Argument::createIntTypeArgument('depth'), + Argument::createIntTypeArgument('level'), + Argument::createBooleanOrBothTypeArgument('visible', true, false) + ); + } + + /** + * + * this function have to be implement in your own loop class. + * + * All loops parameters can be accessible via getter. + * + * for example, ref parameter is accessible through getRef method + * + * @param $pagination + * + * @return mixed + */ + public function exec(&$pagination) + { + $id = $this->getFolder(); + $visible = $this->getVisible(); + + $search = FolderQuery::create(); + + $locale = $this->configureI18nProcessing($search, array('TITLE')); + + $search->filterById($id); + if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible); + + $results = array(); + + $ids = array(); + + do { + $folder = $search->findOne(); + + if ($folder != null) { + + $loopResultRow = new LoopResultRow(); + + $loopResultRow + ->set("TITLE",$folder->getVirtualColumn('i18n_TITLE')) + ->set("URL", $folder->getUrl($locale)) + ->set("ID", $folder->getId()) + ->set("LOCALE",$locale) + ; + + $results[] = $loopResultRow; + + $parent = $folder->getParent(); + + if ($parent > 0) { + + // Prevent circular refererences + if (in_array($parent, $ids)) { + throw new \LogicException(sprintf("Circular reference detected in category ID=%d hierarchy (category ID=%d appears more than one times in path)", $id, $parent)); + } + + $ids[] = $parent; + + $search = FolderQuery::create(); + + $this->configureI18nProcessing($search, array('TITLE')); + + $search->filterById($parent); + if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible); + } + } + } while ($folder != null && $parent > 0); + + // Reverse list and build the final result + $results = array_reverse($results); + + $loopResult = new LoopResult(); + + foreach($results as $result) $loopResult->addRow($result); + + return $loopResult; + } + + +} \ No newline at end of file diff --git a/templates/admin/default/folders.html b/templates/admin/default/folders.html index 654a9d3f9..95f696c95 100644 --- a/templates/admin/default/folders.html +++ b/templates/admin/default/folders.html @@ -9,7 +9,7 @@
- {* include file="includes/folder-breadcrumb.html" *} + {include file="includes/folder-breadcrumb.html" } {module_include location='folders_top'} diff --git a/templates/admin/default/includes/folder-breadcrumb.html b/templates/admin/default/includes/folder-breadcrumb.html index 4319ba5ff..acb78663e 100644 --- a/templates/admin/default/includes/folder-breadcrumb.html +++ b/templates/admin/default/includes/folder-breadcrumb.html @@ -5,17 +5,17 @@
  • Folders {ifloop rel="folder_path"}
  • - {loop name="folder_path" type="folder-path" visible="*" folder=$folder_id} - {if $ID == $folder_id} + {loop name="folder_path" type="folder-path" visible="*" folder=$parent} + {if $ID == $parent}
  • {if $editing_folder == true} {intl l='Editing %fold' fold="{$TITLE}"} {else} - {$TITLE} {intl l="(edit)"} + {$TITLE} {intl l="(edit)"} {/if}
  • {else} -
  • {$TITLE}
  • +
  • {$TITLE}
  • {/if} {/loop} {/ifloop}