Merge pull request #499 from mespeche/mespeche

Add $ROOT substitution variable
This commit is contained in:
Manuel Raynaud
2014-06-26 11:30:14 +02:00
5 changed files with 47 additions and 1 deletions

View File

@@ -536,4 +536,4 @@ abstract class BaseLoop
*/
abstract protected function getArgDefinitions();
}
}

View File

@@ -214,6 +214,7 @@ class Category extends BaseI18nLoop implements PropelSearchLoopInterface, Search
->set("DESCRIPTION" , $category->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM" , $category->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("PARENT" , $category->getParent())
->set("ROOT" , $category->getRoot($category->getId()))
->set("URL" , $category->getUrl($this->locale))
->set("META_TITLE" , $category->getVirtualColumn('i18n_META_TITLE'))
->set("META_DESCRIPTION" , $category->getVirtualColumn('i18n_META_DESCRIPTION'))

View File

@@ -175,6 +175,7 @@ class Folder extends BaseI18nLoop implements PropelSearchLoopInterface, SearchLo
->set("DESCRIPTION" , $folder->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM" , $folder->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("PARENT" , $folder->getParent())
->set("ROOT" , $folder->getRoot($folder->getId()))
->set("URL" , $folder->getUrl($this->locale))
->set("META_TITLE" , $folder->getVirtualColumn('i18n_META_TITLE'))
->set("META_DESCRIPTION" , $folder->getVirtualColumn('i18n_META_DESCRIPTION'))

View File

@@ -56,6 +56,28 @@ class Category extends BaseCategory
return $countProduct;
}
/**
* Get the root category
* @param int $categoryId
* @return mixed
*/
public function getRoot($categoryId)
{
$category = CategoryQuery::create()->findPk($categoryId);
if(0 !== $category->getParent()) {
$parentCategory = CategoryQuery::create()->findPk($category->getParent());
if (null !== $parentCategory) {
$categoryId = $this->getRoot($parentCategory->getId());
}
}
return $categoryId;
}
/**
* Calculate next position relative to our parent
*/

View File

@@ -55,6 +55,28 @@ class Folder extends BaseFolder
}
/**
* Get the root folder
* @param int $folderId
* @return mixed
*/
public function getRoot($folderId)
{
$folder = FolderQuery::create()->findPk($folderId);
if(0 !== $folder->getParent()) {
$parentFolder = FolderQuery::create()->findPk($folder->getParent());
if (null !== $parentFolder) {
$folderId = $this->getRoot($parentFolder->getId());
}
}
return $folderId;
}
/**
* Calculate next position relative to our parent
*/