Example #1
0
 /**
  * Helper function for the isChildOf function. This function is used for a recursive call.
  *
  * @param $category Category
  * @param $searched Category
  * @return bool
  */
 protected function isChildOfInternal(Category $category, Category $searched)
 {
     if ($category->getParent() && $category->getParent()->getId() === $searched->getId()) {
         return true;
     }
     if ($category->getParent() instanceof Category) {
         return $this->isChildOfInternal($category->getParent(), $searched);
     }
     return false;
 }
 /**
  * Sets the internal path field for given category based on it's parents
  *
  * @param Category $category
  * @return Category
  */
 public function setPathForCategory(Category $category)
 {
     $parent = $category->getParent();
     $parentId = $parent->getId();
     $parents = $this->getCategoryComponent()->getParentCategoryIds($parentId);
     $path = implode('|', $parents);
     if (empty($path)) {
         $path = null;
     } else {
         $path = '|' . $path . '|';
     }
     $category->internalSetPath($path);
     return $category;
 }
 /**
  * {@inheritDoc}
  */
 public function getParent()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getParent', array());
     return parent::getParent();
 }