Mage_Catalog_Block_Navigation Class Reference

Inheritance diagram for Mage_Catalog_Block_Navigation:

Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 getCacheKey ()
 getCurrenCategoryKey ()
 getStoreCategories ()
 getCurrentChildCategories ()
 isCategoryActive ($category)
 getCategoryUrl ($category)
 drawItem ($category, $level=0, $last=false)
 getCurrentCategory ()
 getCurrentCategoryPath ()
 drawOpenCategoryItem ($category)

Protected Member Functions

 _construct ()
 _getCategoryInstance ()

Protected Attributes

 $_categoryInstance = null


Detailed Description

Definition at line 35 of file Navigation.php.


Member Function Documentation

_construct (  )  [protected]

Internal constructor, that is called from real constructor

Please override this one instead of overriding real __construct constructor

Please override this one instead of overriding real __construct constructor

Reimplemented from Mage_Core_Block_Abstract.

Definition at line 39 of file Navigation.php.

00040     {
00041         $this->addData(array(
00042             'cache_lifetime'    => false,
00043             'cache_tags'        => array(Mage_Catalog_Model_Category::CACHE_TAG, Mage_Core_Model_Store_Group::CACHE_TAG),
00044         ));
00045     }

_getCategoryInstance (  )  [protected]

Definition at line 112 of file Navigation.php.

00113     {
00114         if (is_null($this->_categoryInstance)) {
00115             $this->_categoryInstance = Mage::getModel('catalog/category');
00116         }
00117         return $this->_categoryInstance;
00118     }

drawItem ( category,
level = 0,
last = false 
)

Enter description here...

Parameters:
Mage_Catalog_Model_Category $category
int $level
boolean $last
Returns:
string

Definition at line 147 of file Navigation.php.

00148     {
00149         $html = '';
00150         if (!$category->getIsActive()) {
00151             return $html;
00152         }
00153         if (Mage::helper('catalog/category_flat')->isEnabled()) {
00154             $children = $category->getChildrenNodes();
00155             $childrenCount = count($children);
00156         } else {
00157             $children = $category->getChildren();
00158             $childrenCount = $children->count();
00159         }
00160         $hasChildren = $children && $childrenCount;
00161         $html.= '<li';
00162         if ($hasChildren) {
00163              $html.= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"';
00164         }
00165 
00166         $html.= ' class="level'.$level;
00167         $html.= ' nav-'.str_replace('/', '-', Mage::helper('catalog/category')->getCategoryUrlPath($category->getRequestPath()));
00168         if ($this->isCategoryActive($category)) {
00169             $html.= ' active';
00170         }
00171         if ($last) {
00172             $html .= ' last';
00173         }
00174         if ($hasChildren) {
00175             $cnt = 0;
00176             foreach ($children as $child) {
00177                 if ($child->getIsActive()) {
00178                     $cnt++;
00179                 }
00180             }
00181             if ($cnt > 0) {
00182                 $html .= ' parent';
00183             }
00184         }
00185         $html.= '">'."\n";
00186         $html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span></a>'."\n";
00187 
00188         if ($hasChildren){
00189 
00190             $j = 0;
00191             $htmlChildren = '';
00192             foreach ($children as $child) {
00193                 if ($child->getIsActive()) {
00194                     $htmlChildren.= $this->drawItem($child, $level+1, ++$j >= $cnt);
00195                 }
00196             }
00197 
00198             if (!empty($htmlChildren)) {
00199                 $html.= '<ul class="level' . $level . '">'."\n"
00200                         .$htmlChildren
00201                         .'</ul>';
00202             }
00203 
00204         }
00205         $html.= '</li>'."\n";
00206         return $html;
00207     }

drawOpenCategoryItem ( category  ) 

Enter description here...

Parameters:
Mage_Catalog_Model_Category $category
Returns:
string

Definition at line 241 of file Navigation.php.

00241                                                     {
00242         $html = '';
00243         if (!$category->getIsActive()) {
00244             return $html;
00245         }
00246 
00247         $html.= '<li';
00248 
00249         if ($this->isCategoryActive($category)) {
00250             $html.= ' class="active"';
00251         }
00252 
00253         $html.= '>'."\n";
00254         $html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span></a>'."\n";
00255 
00256         if (in_array($category->getId(), $this->getCurrentCategoryPath())){
00257             $children = $category->getChildren();
00258             $hasChildren = $children && $children->count();
00259 
00260             if ($hasChildren) {
00261                 $htmlChildren = '';
00262                 foreach ($children as $child) {
00263                     $htmlChildren.= $this->drawOpenCategoryItem($child);
00264                 }
00265 
00266                 if (!empty($htmlChildren)) {
00267                     $html.= '<ul>'."\n"
00268                             .$htmlChildren
00269                             .'</ul>';
00270                 }
00271             }
00272         }
00273         $html.= '</li>'."\n";
00274         return $html;
00275     }

getCacheKey (  ) 

Retrieve Key for caching block content

Returns:
string

Reimplemented from Mage_Core_Block_Abstract.

Definition at line 52 of file Navigation.php.

00053     {
00054         return 'CATALOG_NAVIGATION_' . Mage::app()->getStore()->getId()
00055             . '_' . Mage::getDesign()->getPackageName()
00056             . '_' . Mage::getDesign()->getTheme('template')
00057             . '_' . Mage::getSingleton('customer/session')->getCustomerGroupId()
00058             . '_' . md5($this->getTemplate() . $this->getCurrenCategoryKey());
00059     }

getCategoryUrl ( category  ) 

Get url for category data

Parameters:
Mage_Catalog_Model_Category $category
Returns:
string

Definition at line 126 of file Navigation.php.

00127     {
00128         if ($category instanceof Mage_Catalog_Model_Category) {
00129             $url = $category->getUrl();
00130         } else {
00131             $url = $this->_getCategoryInstance()
00132                 ->setData($category->getData())
00133                 ->getUrl();
00134         }
00135 
00136         return $url;
00137     }

getCurrenCategoryKey (  ) 

Definition at line 61 of file Navigation.php.

00062     {
00063         if ($category = Mage::registry('current_category')) {
00064             return $category->getPath();
00065         } else {
00066             return Mage::app()->getStore()->getRootCategoryId();
00067         }
00068     }

getCurrentCategory (  ) 

Enter description here...

Returns:
Mage_Catalog_Model_Category

Definition at line 214 of file Navigation.php.

00215     {
00216         if (Mage::getSingleton('catalog/layer')) {
00217             return Mage::getSingleton('catalog/layer')->getCurrentCategory();
00218         }
00219         return false;
00220     }

getCurrentCategoryPath (  ) 

Enter description here...

Returns:
string

Definition at line 227 of file Navigation.php.

00228     {
00229         if ($this->getCurrentCategory()) {
00230             return explode(',', $this->getCurrentCategory()->getPathInStore());
00231         }
00232         return array();
00233     }

getCurrentChildCategories (  ) 

Retrieve child categories of current category

Returns:
Varien_Data_Tree_Node_Collection

Definition at line 86 of file Navigation.php.

00087     {
00088         $layer = Mage::getSingleton('catalog/layer');
00089         $category   = $layer->getCurrentCategory();
00090         /* @var $category Mage_Catalog_Model_Category */
00091         $categories = $category->getChildrenCategories();
00092         $productCollection = Mage::getResourceModel('catalog/product_collection');
00093         $layer->prepareProductCollection($productCollection);
00094         $productCollection->addCountToCategories($categories);
00095         return $categories;
00096     }

getStoreCategories (  ) 

Get catagories of current store

Returns:
Varien_Data_Tree_Node_Collection

Definition at line 75 of file Navigation.php.

00076     {
00077         $helper = Mage::helper('catalog/category');
00078         return $helper->getStoreCategories();
00079     }

isCategoryActive ( category  ) 

Checkin activity of category

Parameters:
Varien_Object $category
Returns:
bool

Definition at line 104 of file Navigation.php.

00105     {
00106         if ($this->getCurrentCategory()) {
00107             return in_array($category->getId(), $this->getCurrentCategory()->getPathIds());
00108         }
00109         return false;
00110     }


Member Data Documentation

$_categoryInstance = null [protected]

Definition at line 37 of file Navigation.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:36 2009 for Magento by  doxygen 1.5.8