Public Member Functions | |
loadData ($printQuery=false, $logQuery=false) | |
setOrder ($field, $dir) | |
sortPackages ($a, $b) | |
addFieldToFilter ($field, $condition) | |
validateRow ($row) | |
getAllIds () | |
Protected Member Functions | |
_fetchPackages () |
Definition at line 30 of file Abstract.php.
_fetchPackages | ( | ) | [abstract, protected] |
addFieldToFilter | ( | $ | field, | |
$ | condition | |||
) |
getAllIds | ( | ) |
Definition at line 138 of file Abstract.php.
00139 { 00140 $this->load(); 00141 00142 $ids = array(); 00143 foreach ($this->getIterator() as $item) { 00144 $ids[] = $item->getId(); 00145 } 00146 return $ids; 00147 }
loadData | ( | $ | printQuery = false , |
|
$ | logQuery = false | |||
) |
Load data
Reimplemented from Varien_Data_Collection.
Definition at line 33 of file Abstract.php.
00034 { 00035 if ($this->isLoaded()) { 00036 return $this; 00037 } 00038 00039 // fetch packages specific to source 00040 $packages = $this->_fetchPackages(); 00041 00042 // apply filters 00043 if (!empty($this->_filters)) { 00044 foreach ($packages as $i=>$pkg) { 00045 if (!$this->validateRow($pkg)) { 00046 unset($packages[$i]); 00047 } 00048 } 00049 } 00050 00051 // find totals 00052 $this->_totalRecords = sizeof($packages); 00053 $this->_setIsLoaded(); 00054 00055 // sort packages 00056 if (!empty($this->_orders)) { 00057 usort($packages, array($this, 'sortPackages')); 00058 } 00059 00060 // pagination and add to collection 00061 $from = ($this->getCurPage() - 1) * $this->getPageSize(); 00062 $to = $from + $this->getPageSize() - 1; 00063 00064 $cnt = 0; 00065 foreach ($packages as $pkg) { 00066 $cnt++; 00067 if ($cnt<$from || $cnt>$to) { 00068 continue; 00069 } 00070 $item = new $this->_itemObjectClass(); 00071 $item->addData($pkg); 00072 $this->addItem($item); 00073 } 00074 00075 return $this; 00076 }
setOrder | ( | $ | field, | |
$ | direction | |||
) |
Set select order
string | $field | |
string | $direction |
Reimplemented from Varien_Data_Collection.
Definition at line 80 of file Abstract.php.
00081 { 00082 $this->_orders[] = array('field'=>$field, 'dir'=>$dir); 00083 return $this; 00084 }
sortPackages | ( | $ | a, | |
$ | b | |||
) |
Definition at line 86 of file Abstract.php.
00087 { 00088 $field = $this->_orders[0]['field']; 00089 $dir = $this->_orders[0]['dir']; 00090 00091 $cmp = $a[$field] > $b[$field] ? 1 : ($a[$field] < $b[$field] ? -1 : 0); 00092 00093 return ('asc'===$dir) ? $cmp : -$cmp; 00094 }
validateRow | ( | $ | row | ) |
Definition at line 102 of file Abstract.php.
00103 { 00104 if (empty($this->_filters)) { 00105 return true; 00106 } 00107 foreach ($this->_filters as $field=>$filter) { 00108 if (!isset($row[$field])) { 00109 return false; 00110 } 00111 if (isset($filter['eq'])) { 00112 if ($filter['eq']!=$row[$field]) { 00113 return false; 00114 } 00115 } 00116 if (isset($filter['like'])) { 00117 $query = preg_replace('#(^%|%$)#', '', $filter['like']); 00118 if (strpos(strtolower($row[$field]), strtolower($query))===false) { 00119 return false; 00120 } 00121 } 00122 if ('version'===$field) { 00123 if (isset($filter['from'])) { 00124 if (!version_compare($filter['from'], $row[$field], '<=')) { 00125 return false; 00126 } 00127 } 00128 if (isset($filter['to'])) { 00129 if (!version_compare($filter['to'], $row[$field], '>=')) { 00130 return false; 00131 } 00132 } 00133 } 00134 } 00135 return true; 00136 }