Public Member Functions | |
__construct () | |
addFilter ($field, $value, $type= 'and') | |
isLoaded () | |
getCurPage ($displacement=0) | |
getLastPageNumber () | |
getPageSize () | |
getSize () | |
getFirstItem () | |
getLastItem () | |
getItems () | |
getColumnValues ($colName) | |
getItemsByColumnValue ($column, $value) | |
getItemByColumnValue ($column, $value) | |
addItem (Varien_Object $item) | |
removeItemByKey ($key) | |
clear () | |
walk ($callback, array $args=array()) | |
each ($obj_method, $args=array()) | |
setDataToAll ($key, $value=null) | |
setCurPage ($page) | |
setPageSize ($size) | |
setOrder ($field, $direction= 'desc') | |
setItemObjectClass ($className) | |
getNewEmptyItem () | |
distinct ($flag) | |
loadData ($printQuery=false, $logQuery=false) | |
load ($printQuery=false, $logQuery=false) | |
toXml () | |
toArray ($arrRequiredFields=array()) | |
toOptionArray () | |
toOptionHash () | |
getItemById ($idValue) | |
getIterator () | |
count () | |
setCacheKey ($key) | |
getCacheKey () | |
setCacheTags ($tags) | |
getCacheTags () | |
getCacheLifetime () | |
getFlag ($flag) | |
setFlag ($flag, $value=null) | |
hasFlag ($flag) | |
Public Attributes | |
const | SORT_ORDER_ASC = 'ASC' |
const | SORT_ORDER_DESC = 'DESC' |
Protected Member Functions | |
_setIsLoaded ($flag=true) | |
_getItemId (Varien_Object $item) | |
_renderFilters () | |
_renderOrders () | |
_renderLimit () | |
_toOptionArray ($valueField='id', $labelField='name', $additional=array()) | |
_toOptionHash ($valueField='id', $labelField='name') | |
Protected Attributes | |
$_items = array() | |
$_itemObjectClass = 'Varien_Object' | |
$_orders = array() | |
$_filters = array() | |
$_isFiltersRendered = false | |
$_curPage = 1 | |
$_pageSize = false | |
$_totalRecords | |
$_isCollectionLoaded | |
$_cacheKey | |
$_cacheTags = array() | |
$_cacheLifetime = 86400 | |
$_flags = array() |
Definition at line 34 of file Collection.php.
__construct | ( | ) |
Reimplemented in Mage_Admin_Model_Mysql4_Acl_Role_Collection, Mage_Backup_Model_Fs_Collection, Mage_Core_Model_Mysql4_Email_Template_Collection, Mage_Directory_Model_Mysql4_Country_Collection, Mage_Directory_Model_Mysql4_Currency_Collection, Mage_Directory_Model_Mysql4_Region_Collection, Mage_Eav_Model_Entity_Collection, Mage_Log_Model_Mysql4_Visitor_Collection, Mage_Newsletter_Model_Mysql4_Subscriber_Collection, Mage_Newsletter_Model_Mysql4_Template_Collection, Mage_Rating_Model_Mysql4_Rating_Option_Collection, Mage_Reports_Model_Mysql4_Product_Collection, Mage_Review_Model_Mysql4_Review_Collection, Mage_Review_Model_Mysql4_Review_Status_Collection, Mage_Review_Model_Mysql4_Review_Summary_Collection, Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection, and Mage_Tag_Model_Entity_Customer_Collection.
Definition at line 117 of file Collection.php.
_getItemId | ( | Varien_Object $ | item | ) | [protected] |
_renderFilters | ( | ) | [protected] |
Render sql select conditions
Reimplemented in Varien_Data_Collection_Db, and Varien_Directory_Collection.
Definition at line 498 of file Collection.php.
_renderLimit | ( | ) | [protected] |
Render sql select limit
Reimplemented in Varien_Data_Collection_Db.
Definition at line 518 of file Collection.php.
_renderOrders | ( | ) | [protected] |
Render sql select orders
Reimplemented in Varien_Data_Collection_Db.
Definition at line 508 of file Collection.php.
_setIsLoaded | ( | $ | flag = true |
) | [protected] |
Set collection loading status flag
unknown_type | $flag |
Definition at line 157 of file Collection.php.
_toOptionArray | ( | $ | valueField = 'id' , |
|
$ | labelField = 'name' , |
|||
$ | additional = array() | |||
) | [protected] |
Convert items array to array for select options
return items array array( $index => array( 'value' => mixed 'label' => mixed ) )
string | $valueField | |
string | $labelField |
Definition at line 605 of file Collection.php.
00606 { 00607 $res = array(); 00608 $additional['value'] = $valueField; 00609 $additional['label'] = $labelField; 00610 00611 foreach ($this as $item) { 00612 foreach ($additional as $code => $field) { 00613 $data[$code] = $item->getData($field); 00614 } 00615 $res[] = $data; 00616 } 00617 return $res; 00618 }
_toOptionHash | ( | $ | valueField = 'id' , |
|
$ | labelField = 'name' | |||
) | [protected] |
Convert items array to hash for select options
return items hash array($value => $label)
string | $valueField | |
string | $labelField |
Definition at line 640 of file Collection.php.
00641 { 00642 $res = array(); 00643 foreach ($this as $item) { 00644 $res[$item->getData($valueField)] = $item->getData($labelField); 00645 } 00646 return $res; 00647 }
addFilter | ( | $ | field, | |
$ | value, | |||
$ | type = 'and' | |||
) |
Add collection filter
string | $field | |
string | $value | |
string | $type and|or|string |
Definition at line 129 of file Collection.php.
00130 { 00131 $filter = array(); 00132 $filter['field'] = $field; 00133 $filter['value'] = $value; 00134 $filter['type'] = strtolower($type); 00135 00136 $this->_filters[] = $filter; 00137 $this->_isFiltersRendered = false; 00138 return $this; 00139 }
addItem | ( | Varien_Object $ | item | ) |
Adding item to item array
Varien_Object | $item |
Reimplemented in Mage_Eav_Model_Entity_Collection_Abstract, and Mage_Rule_Model_Mysql4_Rule_Collection.
Definition at line 327 of file Collection.php.
00328 { 00329 $itemId = $this->_getItemId($item); 00330 if (!is_null($itemId)) { 00331 if (isset($this->_items[$itemId])) { 00332 throw new Exception('Item ('.get_class($item).') with the same id "'.$item->getId().'" already exist'); 00333 } 00334 $this->_items[$itemId] = $item; 00335 } 00336 else { 00337 $this->_items[] = $item; 00338 } 00339 return $this; 00340 }
clear | ( | ) |
Clear collection
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection.
Definition at line 366 of file Collection.php.
00367 { 00368 $this->_setIsLoaded(false); 00369 $this->_items = array(); 00370 return $this; 00371 }
count | ( | ) |
Retireve count of collection loaded items
Definition at line 678 of file Collection.php.
distinct | ( | $ | flag | ) |
Set select distinct
bool | $flag |
Reimplemented in Varien_Data_Collection_Db.
Definition at line 528 of file Collection.php.
each | ( | $ | obj_method, | |
$ | args = array() | |||
) |
Definition at line 399 of file Collection.php.
00400 { 00401 foreach ($args->_items as $k => $item) { 00402 $args->_items[$k] = call_user_func($obj_method, $item); 00403 } 00404 }
getCacheKey | ( | ) |
getCacheLifetime | ( | ) |
getCacheTags | ( | ) |
getColumnValues | ( | $ | colName | ) |
Retrieve field values from all items
string | $colName |
Reimplemented in Mage_Review_Model_Mysql4_Review_Product_Collection.
Definition at line 271 of file Collection.php.
00272 { 00273 $this->load(); 00274 00275 $col = array(); 00276 foreach ($this->getItems() as $item) { 00277 $col[] = $item->getData($colName); 00278 } 00279 return $col; 00280 }
getCurPage | ( | $ | displacement = 0 |
) |
Get current collection page
int | $displacement |
Definition at line 169 of file Collection.php.
00170 { 00171 if ($this->_curPage + $displacement < 1) { 00172 return 1; 00173 } 00174 elseif ($this->_curPage + $displacement > $this->getLastPageNumber()) { 00175 return $this->getLastPageNumber(); 00176 } else { 00177 return $this->_curPage + $displacement; 00178 } 00179 }
getFirstItem | ( | ) |
Retrieve collection first item
Definition at line 226 of file Collection.php.
00227 { 00228 $this->load(); 00229 00230 if (count($this->_items)) { 00231 reset($this->_items); 00232 return current($this->_items); 00233 } 00234 00235 return new $this->_itemObjectClass(); 00236 }
getFlag | ( | $ | flag | ) |
getItemByColumnValue | ( | $ | column, | |
$ | value | |||
) |
Search first item by field value
string | $column | |
mixed | $value |
Definition at line 309 of file Collection.php.
00310 { 00311 $this->load(); 00312 00313 foreach ($this as $item) { 00314 if ($item->getData($column)==$value) { 00315 return $item; 00316 } 00317 } 00318 return null; 00319 }
getItemById | ( | $ | idValue | ) |
Retrieve item by id
mixed | $idValue |
Reimplemented in Mage_Directory_Model_Mysql4_Country_Collection.
Definition at line 655 of file Collection.php.
00656 { 00657 $this->load(); 00658 if (isset($this->_items[$idValue])) { 00659 return $this->_items[$idValue]; 00660 } 00661 return null; 00662 }
getItems | ( | ) |
Retrieve collection items
Definition at line 259 of file Collection.php.
00260 { 00261 $this->load(); 00262 return $this->_items; 00263 }
getItemsByColumnValue | ( | $ | column, | |
$ | value | |||
) |
Search all items by field value
string | $column | |
mixed | $value |
Definition at line 289 of file Collection.php.
00290 { 00291 $this->load(); 00292 00293 $res = array(); 00294 foreach ($this as $item) { 00295 if ($item->getData($column)==$value) { 00296 $res[] = $item; 00297 } 00298 } 00299 return $res; 00300 }
getIterator | ( | ) |
Implementation of IteratorAggregate.getIterator()
Definition at line 667 of file Collection.php.
00668 { 00669 $this->load(); 00670 return new ArrayIterator($this->_items); 00671 }
getLastItem | ( | ) |
Retrieve collection last item
Definition at line 243 of file Collection.php.
00244 { 00245 $this->load(); 00246 00247 if (count($this->_items)) { 00248 return end($this->_items); 00249 } 00250 00251 return new $this->_itemObjectClass(); 00252 }
getLastPageNumber | ( | ) |
Retrieve collection last page number
Definition at line 186 of file Collection.php.
00187 { 00188 $collectionSize = (int) $this->getSize(); 00189 if (0 === $collectionSize) { 00190 return 1; 00191 } 00192 elseif($this->_pageSize) { 00193 return ceil($collectionSize/$this->_pageSize); 00194 } 00195 else{ 00196 return 1; 00197 } 00198 }
getNewEmptyItem | ( | ) |
Retrieve collection empty item
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.
Definition at line 488 of file Collection.php.
getPageSize | ( | ) |
getSize | ( | ) |
Retrieve collection all items count
Reimplemented in Mage_Backup_Model_Fs_Collection, and Varien_Data_Collection_Db.
Definition at line 215 of file Collection.php.
00216 { 00217 $this->load(); 00218 return $this->_totalRecords; 00219 }
hasFlag | ( | $ | flag | ) |
isLoaded | ( | ) |
load | ( | $ | printQuery = false , |
|
$ | logQuery = false | |||
) |
Load data
Reimplemented in Mage_Backup_Model_Fs_Collection, Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection, Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection, Mage_Core_Model_Mysql4_Collection_Abstract, Mage_Core_Model_Mysql4_Store_Collection, Mage_Core_Model_Mysql4_Store_Group_Collection, Mage_Core_Model_Mysql4_Website_Collection, Mage_Eav_Model_Entity_Collection_Abstract, Mage_GoogleBase_Model_Mysql4_Attribute_Collection, Mage_Log_Model_Mysql4_Visitor_Collection, Mage_Newsletter_Model_Mysql4_Problem_Collection, Mage_Newsletter_Model_Mysql4_Queue_Collection, Mage_Newsletter_Model_Mysql4_Subscriber_Collection, Mage_Review_Model_Mysql4_Review_Collection, Mage_Tag_Model_Entity_Customer_Collection, Mage_Tag_Model_Mysql4_Popular_Collection, Mage_Tag_Model_Mysql4_Tag_Collection, Mage_Wishlist_Model_Mysql4_Item_Collection, and Varien_Data_Collection_Db.
Definition at line 548 of file Collection.php.
00549 { 00550 return $this->loadData($printQuery, $logQuery); 00551 }
loadData | ( | $ | printQuery = false , |
|
$ | logQuery = false | |||
) |
Load data
Reimplemented in Mage_Adminhtml_Model_Extension_Collection_Abstract, and Varien_Data_Collection_Db.
Definition at line 538 of file Collection.php.
removeItemByKey | ( | $ | key | ) |
Remove item from collection by item key
mixed | $key |
Definition at line 353 of file Collection.php.
00354 { 00355 if (isset($this->_items[$key])) { 00356 unset($this->_items[$key]); 00357 } 00358 return $this; 00359 }
setCacheKey | ( | $ | key | ) |
setCacheTags | ( | $ | tags | ) |
setCurPage | ( | $ | page | ) |
Set current page
int | $page |
Definition at line 433 of file Collection.php.
setDataToAll | ( | $ | key, | |
$ | value = null | |||
) |
Setting data for all collection items
mixed | $key | |
mixed | $value |
Definition at line 413 of file Collection.php.
00414 { 00415 if (is_array($key)) { 00416 foreach ($key as $k=>$v) { 00417 $this->setDataToAll($k, $v); 00418 } 00419 return $this; 00420 } 00421 foreach ($this->getItems() as $item) { 00422 $item->setData($key, $value); 00423 } 00424 return $this; 00425 }
setFlag | ( | $ | flag, | |
$ | value = null | |||
) |
Set Flag
string | $flag | |
mixed | $value |
Definition at line 729 of file Collection.php.
setItemObjectClass | ( | $ | className | ) |
Set collection item class name
string | $className |
is_subclass_of($className, 'Varien_Object') - Segmentation fault in php 5.2.3
Definition at line 470 of file Collection.php.
00471 { 00472 $className = Mage::getConfig()->getModelClassName($className); 00473 /** 00474 * is_subclass_of($className, 'Varien_Object') - Segmentation fault in php 5.2.3 00475 */ 00476 /*if (!is_subclass_of($className, 'Varien_Object')) { 00477 throw new Exception($className.' does not extends from Varien_Object'); 00478 }*/ 00479 $this->_itemObjectClass = $className; 00480 return $this; 00481 }
setOrder | ( | $ | field, | |
$ | direction = 'desc' | |||
) |
Set select order
string | $field | |
string | $direction |
Reimplemented in Mage_Adminhtml_Model_Extension_Collection_Abstract, Mage_Backup_Model_Fs_Collection, Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection, Mage_Eav_Model_Entity_Collection_Abstract, Mage_Reports_Model_Mysql4_Product_Collection, Mage_Reports_Model_Mysql4_Product_Downloads_Collection, Mage_Reports_Model_Mysql4_Review_Collection, Mage_Reports_Model_Mysql4_Tag_Customer_Collection, Mage_Reports_Model_Mysql4_Tag_Product_Collection, Mage_Reports_Model_Mysql4_Wishlist_Product_Collection, Mage_Review_Model_Mysql4_Review_Product_Collection, Mage_Tag_Model_Mysql4_Customer_Collection, Mage_Tag_Model_Mysql4_Product_Collection, and Varien_Data_Collection_Db.
Definition at line 458 of file Collection.php.
setPageSize | ( | $ | size | ) |
Set collection page size
int | $size |
Definition at line 445 of file Collection.php.
toArray | ( | $ | arrRequiredFields = array() |
) |
Convert collection to array
Reimplemented in Mage_Eav_Model_Entity_Collection_Abstract.
Definition at line 578 of file Collection.php.
00579 { 00580 $arrItems = array(); 00581 $arrItems['totalRecords'] = $this->getSize(); 00582 00583 $arrItems['items'] = array(); 00584 foreach ($this as $item) { 00585 $arrItems['items'][] = $item->toArray($arrRequiredFields); 00586 } 00587 return $arrItems; 00588 }
toOptionArray | ( | ) |
Reimplemented in Mage_Admin_Model_Mysql4_Roles_Collection, Mage_Api_Model_Mysql4_Roles_Collection, Mage_Cms_Model_Mysql4_Block_Collection, Mage_Cms_Model_Mysql4_Page_Collection, Mage_Core_Model_Mysql4_Design_Theme, Mage_Core_Model_Mysql4_Email_Template_Collection, Mage_Core_Model_Mysql4_Language_Collection, Mage_Core_Model_Mysql4_Store_Collection, Mage_Core_Model_Mysql4_Store_Group_Collection, Mage_Core_Model_Mysql4_Website_Collection, Mage_Customer_Model_Entity_Group_Collection, Mage_Directory_Model_Mysql4_Currency_Collection, Mage_Directory_Model_Mysql4_Region_Collection, Mage_Eav_Model_Mysql4_Entity_Attribute_Set_Collection, Mage_Newsletter_Model_Mysql4_Queue_Collection, Mage_Newsletter_Model_Mysql4_Template_Collection, Mage_Reports_Model_Mysql4_Event_Type_Collection, Mage_Review_Model_Mysql4_Review_Status_Collection, Mage_Tax_Model_Mysql4_Calculation_Rate_Collection, and Mage_Tax_Model_Mysql4_Class_Collection.
Definition at line 620 of file Collection.php.
00621 { 00622 return $this->_toOptionArray(); 00623 }
toOptionHash | ( | ) |
Reimplemented in Mage_Core_Model_Mysql4_Language_Collection, Mage_Core_Model_Mysql4_Store_Collection, Mage_Core_Model_Mysql4_Website_Collection, Mage_Customer_Model_Entity_Group_Collection, Mage_Eav_Model_Mysql4_Entity_Attribute_Set_Collection, Mage_Tax_Model_Mysql4_Calculation_Rate_Collection, and Mage_Tax_Model_Mysql4_Class_Collection.
Definition at line 625 of file Collection.php.
00626 { 00627 return $this->_toOptionHash(); 00628 }
toXml | ( | ) |
Convert collection to XML
Definition at line 558 of file Collection.php.
00559 { 00560 $xml = '<?xml version="1.0" encoding="UTF-8"?> 00561 <collection> 00562 <totalRecords>'.$this->_totalRecords.'</totalRecords> 00563 <items>'; 00564 00565 foreach ($this as $item) { 00566 $xml.=$item->toXml(); 00567 } 00568 $xml.= '</items> 00569 </collection>'; 00570 return $xml; 00571 }
Walk through the collection and run model method or external callback with optional arguments
Returns array with results of callback for each item
string | $method | |
array | $args |
Definition at line 383 of file Collection.php.
00384 { 00385 $results = array(); 00386 $useItemCallback = is_string($callback) && strpos($callback, '::')===false; 00387 foreach ($this->getItems() as $id=>$item) { 00388 if ($useItemCallback) { 00389 $cb = array($item, $callback); 00390 } else { 00391 $cb = $callback; 00392 array_unshift($args, $item); 00393 } 00394 $results[$id] = call_user_func_array($cb, $args); 00395 } 00396 return $results; 00397 }
$_cacheKey [protected] |
Definition at line 104 of file Collection.php.
$_cacheLifetime = 86400 [protected] |
Definition at line 108 of file Collection.php.
$_cacheTags = array() [protected] |
Definition at line 106 of file Collection.php.
$_curPage = 1 [protected] |
Definition at line 79 of file Collection.php.
$_filters = array() [protected] |
$_flags = array() [protected] |
Definition at line 115 of file Collection.php.
$_isCollectionLoaded [protected] |
Definition at line 102 of file Collection.php.
$_isFiltersRendered = false [protected] |
Definition at line 72 of file Collection.php.
$_itemObjectClass = 'Varien_Object' [protected] |
Definition at line 51 of file Collection.php.
$_items = array() [protected] |
Definition at line 44 of file Collection.php.
$_orders = array() [protected] |
Definition at line 58 of file Collection.php.
$_pageSize = false [protected] |
Definition at line 88 of file Collection.php.
$_totalRecords [protected] |
Definition at line 95 of file Collection.php.
const SORT_ORDER_ASC = 'ASC' |
Definition at line 36 of file Collection.php.
const SORT_ORDER_DESC = 'DESC' |
Definition at line 37 of file Collection.php.