Mage_Catalog_Block_Product_List_Toolbar Class Reference

Inheritance diagram for Mage_Catalog_Block_Product_List_Toolbar:

Mage_Page_Block_Html_Pager Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 setCollection ($collection)
 getOrderVarName ()
 getDirectionVarName ()
 getModeVarName ()
 getCurrentOrder ()
 getCurrentDirection ()
 setDefaultOrder ($field)
 setDefaultDirection ($dir)
 getAvailableOrders ()
 setAvailableOrders ($orders)
 addOrderToAvailableOrders ($order, $value)
 removeOrderFromAvailableOrders ($order)
 isOrderCurrent ($order)
 getOrderUrl ($order, $direction)
 getCurrentMode ()
 isModeActive ($mode)
 getModes ()
 setModes ($modes)
 getModeUrl ($mode)
 disableViewSwitcher ()
 enableViewSwitcher ()
 isEnabledViewSwitcher ()
 disableExpanded ()
 enableExpanded ()
 isExpanded ()
 getDefaultPerPageValue ()
 addPagerLimit ($mode, $value, $label='')
 getAvailableLimit ()
 getLimit ()
 getLimitUrl ($limit)

Protected Member Functions

 _getConfig ()
 _construct ()

Protected Attributes

 $_orderVarName = 'order'
 $_directionVarName = 'dir'
 $_modeVarName = 'mode'
 $_availableOrder = array()
 $_availableMode = array()
 $_enableViewSwitcher = true
 $_isExpanded = true
 $_orderField = null
 $_direction = 'asc'
 $_viewMode = null


Detailed Description

Definition at line 34 of file Toolbar.php.


Member Function Documentation

_construct (  )  [protected]

Init Toolbar

Reimplemented from Mage_Page_Block_Html_Pager.

Definition at line 120 of file Toolbar.php.

00121     {
00122         parent::_construct();
00123         $this->_orderField  = Mage::getStoreConfig(
00124             Mage_Catalog_Model_Config::XML_PATH_LIST_DEFAULT_SORT_BY
00125         );
00126 
00127         $this->_availableOrder = $this->_getConfig()->getAttributeUsedForSortByArray();
00128 
00129         switch (Mage::getStoreConfig('catalog/frontend/list_mode')) {
00130             case 'grid':
00131                 $this->_availableMode = array('grid' => $this->__('Grid'));
00132                 break;
00133 
00134             case 'list':
00135                 $this->_availableMode = array('list' => $this->__('List'));
00136                 break;
00137 
00138             case 'grid-list':
00139                 $this->_availableMode = array('grid' => $this->__('Grid'), 'list' =>  $this->__('List'));
00140                 break;
00141 
00142             case 'list-grid':
00143                 $this->_availableMode = array('list' => $this->__('List'), 'grid' => $this->__('Grid'));
00144                 break;
00145         }
00146         $this->setTemplate('catalog/product/list/toolbar.phtml');
00147     }

_getConfig (  )  [protected]

Retrieve Catalog Config object

Returns:
Mage_Catalog_Model_Config

Definition at line 111 of file Toolbar.php.

00112     {
00113         return Mage::getSingleton('catalog/config');
00114     }

addOrderToAvailableOrders ( order,
value 
)

Add order to available orders

Parameters:
string $order
string $value
Returns:
Mage_Catalog_Block_Product_List_Toolbar

Definition at line 286 of file Toolbar.php.

00287     {
00288         $this->_availableOrder[$order] = $value;
00289         return $this;
00290     }

addPagerLimit ( mode,
value,
label = '' 
)

Add new limit to pager for mode

Parameters:
string $mode
string $value
string $label
Returns:
Mage_Catalog_Block_Product_List_Toolbar

Definition at line 496 of file Toolbar.php.

00497     {
00498         if (!isset($this->_availableLimit[$mode])) {
00499             $this->_availableLimit[$mode] = array();
00500         }
00501         $this->_availableLimit[$mode][$value] = empty($label) ? $value : $label;
00502         return $this;
00503     }

disableExpanded (  ) 

Disable Expanded

Returns:
Mage_Catalog_Block_Product_List_Toolbar

Definition at line 439 of file Toolbar.php.

00440     {
00441         $this->_isExpanded = false;
00442         return $this;
00443     }

disableViewSwitcher (  ) 

Disable view switcher

Returns:
Mage_Catalog_Block_Product_List_Toolbar

Definition at line 407 of file Toolbar.php.

00408     {
00409         $this->_enableViewSwitcher = false;
00410         return $this;
00411     }

enableExpanded (  ) 

Enable Expanded

Returns:
Mage_Catalog_Block_Product_List_Toolbar

Definition at line 450 of file Toolbar.php.

00451     {
00452         $this->_isExpanded = true;
00453         return $this;
00454     }

enableViewSwitcher (  ) 

Enable view switcher

Returns:
Mage_Catalog_Block_Product_List_Toolbar

Definition at line 418 of file Toolbar.php.

00419     {
00420         $this->_enableViewSwitcher = true;
00421         return $this;
00422     }

getAvailableLimit (  ) 

Retrieve available limits for current view mode

Returns:
array

Reimplemented from Mage_Page_Block_Html_Pager.

Definition at line 510 of file Toolbar.php.

00511     {
00512         if ($this->getCurrentMode() == 'list') {
00513             if (isset($this->_availableLimit['list'])) {
00514                 return $this->_availableLimit['list'];
00515             }
00516             $perPageValues = (string)Mage::getStoreConfig('catalog/frontend/list_per_page_values');
00517             $perPageValues = explode(',', $perPageValues);
00518             $perPageValues = array_combine($perPageValues, $perPageValues);
00519             return ($perPageValues + array('all'=>$this->__('All')));
00520         }
00521         elseif ($this->getCurrentMode() == 'grid') {
00522             if (isset($this->_availableLimit['grid'])) {
00523                 return $this->_availableLimit['grid'];
00524             }
00525             $perPageValues = (string)Mage::getStoreConfig('catalog/frontend/grid_per_page_values');
00526             $perPageValues = explode(',', $perPageValues);
00527             $perPageValues = array_combine($perPageValues, $perPageValues);
00528             return ($perPageValues + array('all'=>$this->__('All')));
00529         }
00530         return parent::getAvailableLimit();
00531     }

getAvailableOrders (  ) 

Retrieve available Order fields list

Returns:
array

Definition at line 262 of file Toolbar.php.

00263     {
00264         return $this->_availableOrder;
00265     }

getCurrentDirection (  ) 

Retrieve current direction

Returns:
string

Definition at line 218 of file Toolbar.php.

00219     {
00220         if ($dir = (string) $this->getRequest()->getParam($this->getDirectionVarName())) {
00221             $dir = strtolower($dir);
00222             if (in_array($dir, array('asc', 'desc'))) {
00223                 return $dir;
00224             }
00225         }
00226         return $this->_direction;
00227     }

getCurrentMode (  ) 

Retrieve current View mode

Returns:
string

Definition at line 340 of file Toolbar.php.

00341     {
00342         $mode = $this->getRequest()->getParam($this->getModeVarName());
00343         if ($mode) {
00344             Mage::getSingleton('catalog/session')->setDisplayMode($mode);
00345         }
00346         else {
00347             $mode = Mage::getSingleton('catalog/session')->getDisplayMode();
00348         }
00349 
00350         if ($mode && isset($this->_availableMode[$mode])) {
00351             return $mode;
00352         }
00353         return current(array_keys($this->_availableMode));
00354     }

getCurrentOrder (  ) 

Retrieve current order field

Returns:
string

Definition at line 199 of file Toolbar.php.

00200     {
00201         $order = $this->getRequest()->getParam($this->getOrderVarName());
00202         $orders = $this->getAvailableOrders();
00203         if ($order && isset($orders[$order])) {
00204             return $order;
00205         }
00206         if ($this->_orderField && isset($orders[$this->_orderField])) {
00207             return $this->_orderField;
00208         }
00209         $keys = array_keys($orders);
00210         return $keys[0];
00211     }

getDefaultPerPageValue (  ) 

Retrieve default per page values

Returns:
string (comma separated)

Definition at line 471 of file Toolbar.php.

00472     {
00473         if ($this->getCurrentMode() == 'list') {
00474             if ($default = $this->getDefaultListPerPage()) {
00475                 return $default;
00476             }
00477             return Mage::getStoreConfig('catalog/frontend/list_per_page');
00478         }
00479         elseif ($this->getCurrentMode() == 'grid') {
00480             if ($default = $this->getDefaultGridPerPage()) {
00481                 return $default;
00482             }
00483             return Mage::getStoreConfig('catalog/frontend/grid_per_page');
00484         }
00485         return 0;
00486     }

getDirectionVarName (  ) 

Retrieve sort direction GET var name

Returns:
string

Definition at line 179 of file Toolbar.php.

00180     {
00181         return $this->_directionVarName;
00182     }

getLimit (  ) 

Retrieve current limit per page

Returns:
string

Reimplemented from Mage_Page_Block_Html_Pager.

Definition at line 538 of file Toolbar.php.

00539     {
00540         $limits = $this->getAvailableLimit();
00541         $limit = $this->getRequest()->getParam($this->getLimitVarName());
00542 
00543         if ($limit && isset($limits[$limit])) {
00544             Mage::getSingleton('catalog/session')->setLimitPage($limit);
00545         } else {
00546             $limit = Mage::getSingleton('catalog/session')->getLimitPage();
00547         }
00548         if (isset($limits[$limit])) {
00549             return $limit;
00550         }
00551         if ($limit = $this->getDefaultPerPageValue()) {
00552             if (isset($limits[$limit])) {
00553                 return $limit;
00554             }
00555         }
00556 
00557         $limits = array_keys($limits);
00558         return $limits[0];
00559     }

getLimitUrl ( limit  ) 

Retrieve Limit Pager URL

Parameters:
int $limit
Returns:
string

Reimplemented from Mage_Page_Block_Html_Pager.

Definition at line 567 of file Toolbar.php.

00568     {
00569         return $this->getPagerUrl(array(
00570             $this->getLimitVarName() => $limit,
00571             $this->getPageVarName() => null
00572         ));
00573     }

getModes (  ) 

Retrieve availables view modes

Returns:
array

Definition at line 372 of file Toolbar.php.

00373     {
00374         return $this->_availableMode;
00375     }

getModeUrl ( mode  ) 

Retrive URL for view mode

Parameters:
string $mode
Returns:
string

Definition at line 397 of file Toolbar.php.

00398     {
00399         return $this->getPagerUrl( array($this->getModeVarName()=>$mode, $this->getPageVarName() => null) );
00400     }

getModeVarName (  ) 

Retrieve view mode GET var name

Returns:
string

Definition at line 189 of file Toolbar.php.

00190     {
00191         return $this->_modeVarName;
00192     }

getOrderUrl ( order,
direction 
)

Retrieve Pager URL

Parameters:
string $order
string $direction
Returns:
string

Definition at line 323 of file Toolbar.php.

00324     {
00325         if (is_null($order)) {
00326             $order = $this->getCurrentOrder() ? $this->getCurrentOrder() : $this->_availableOrder[0];
00327         }
00328         return $this->getPagerUrl(array(
00329             $this->getOrderVarName()=>$order,
00330             $this->getDirectionVarName()=>$direction,
00331             $this->getPageVarName() => null
00332         ));
00333     }

getOrderVarName (  ) 

Retrieve order field GET var name

Returns:
string

Definition at line 169 of file Toolbar.php.

00170     {
00171         return $this->_orderVarName;
00172     }

isEnabledViewSwitcher (  ) 

Is a enabled view switcher

Returns:
bool

Definition at line 429 of file Toolbar.php.

00430     {
00431         return $this->_enableViewSwitcher;
00432     }

isExpanded (  ) 

Check is Expanded

Returns:
bool

Definition at line 461 of file Toolbar.php.

00462     {
00463         return $this->_isExpanded;
00464     }

isModeActive ( mode  ) 

Compare defined view mode with current active mode

Parameters:
string $mode
Returns:
bool

Definition at line 362 of file Toolbar.php.

00363     {
00364         return $this->getCurrentMode() == $mode;
00365     }

isOrderCurrent ( order  ) 

Compare defined order field vith current order field

Parameters:
string $order
Returns:
bool

Definition at line 311 of file Toolbar.php.

00312     {
00313         return ($order == $this->getCurrentOrder());
00314     }

removeOrderFromAvailableOrders ( order  ) 

Remove order from available orders if exists

Parameters:
string $order
Mage_Catalog_Block_Product_List_Toolbar 

Definition at line 297 of file Toolbar.php.

00298     {
00299         if (isset($this->_availableOrder[$order])) {
00300             unset($this->_availableOrder[$order]);
00301         }
00302         return $this;
00303     }

setAvailableOrders ( orders  ) 

Set Available order fields list

Parameters:
array $orders
Returns:
Mage_Catalog_Block_Product_List_Toolbar

Definition at line 273 of file Toolbar.php.

00274     {
00275         $this->_availableOrder = $orders;
00276         return $this;
00277     }

setCollection ( collection  ) 

Set collection to pager

Parameters:
Varien_Data_Collection $collection
Returns:
Mage_Catalog_Block_Product_List_Toolbar

Reimplemented from Mage_Page_Block_Html_Pager.

Definition at line 155 of file Toolbar.php.

00156     {
00157         parent::setCollection($collection);
00158         if ($this->getCurrentOrder()) {
00159             $this->getCollection()->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
00160         }
00161         return $this;
00162     }

setDefaultDirection ( dir  ) 

Set default sort direction

Parameters:
string $dir
Returns:
Mage_Catalog_Block_Product_List_Toolbar

Definition at line 249 of file Toolbar.php.

00250     {
00251         if (in_array(strtolower($dir), array('asc', 'desc'))) {
00252             $this->_direction = strtolower($dir);
00253         }
00254         return $this;
00255     }

setDefaultOrder ( field  ) 

Set default Order field

Parameters:
string $field
Returns:
Mage_Catalog_Block_Product_List_Toolbar

Definition at line 235 of file Toolbar.php.

00236     {
00237         if (isset($this->_availableOrder[$field])) {
00238             $this->_orderField = $field;
00239         }
00240         return $this;
00241     }

setModes ( modes  ) 

Set available view modes list

Parameters:
array $modes
Returns:
Mage_Catalog_Block_Product_List_Toolbar

Definition at line 383 of file Toolbar.php.

00384     {
00385         if(!isset($this->_availableMode)){
00386             $this->_availableMode = $modes;
00387         }
00388         return $this;
00389     }


Member Data Documentation

$_availableMode = array() [protected]

Definition at line 69 of file Toolbar.php.

$_availableOrder = array() [protected]

Definition at line 62 of file Toolbar.php.

$_direction = 'asc' [protected]

Definition at line 97 of file Toolbar.php.

$_directionVarName = 'dir' [protected]

Definition at line 48 of file Toolbar.php.

$_enableViewSwitcher = true [protected]

Definition at line 76 of file Toolbar.php.

$_isExpanded = true [protected]

Definition at line 83 of file Toolbar.php.

$_modeVarName = 'mode' [protected]

Definition at line 55 of file Toolbar.php.

$_orderField = null [protected]

Definition at line 90 of file Toolbar.php.

$_orderVarName = 'order' [protected]

Definition at line 41 of file Toolbar.php.

$_viewMode = null [protected]

Definition at line 104 of file Toolbar.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