diff --git a/app/code/community/TM/Core/Model/Resource/Module/Collection/Abstract.php b/app/code/community/TM/Core/Model/Resource/Module/Collection/Abstract.php new file mode 100644 index 0000000..fcc249d --- /dev/null +++ b/app/code/community/TM/Core/Model/Resource/Module/Collection/Abstract.php @@ -0,0 +1,51 @@ +isLoaded()) { + return $this; + } + + $this->_collectedModules = $this->_loadModules(); + + // calculate totals + $this->_totalRecords = count($this->_collectedModules); + $this->_setIsLoaded(); + + // paginate and add items + $from = ($this->getCurPage() - 1) * $this->getPageSize(); + $to = $from + $this->getPageSize() - 1; + $isPaginated = $this->getPageSize() > 0; + + $cnt = 0; + foreach ($this->_collectedModules as $row) { + $cnt++; + if ($isPaginated && ($cnt < $from || $cnt > $to)) { + continue; + } + $item = new $this->_itemObjectClass(); + $this->addItem($item->addData($row)); + if (!$item->hasId()) { + $item->setId($cnt); + } + } + + return $this; + } + + protected function _loadModules() + { + return array(); + } +} diff --git a/app/code/community/TM/Core/Model/Resource/Module/LocalCollection.php b/app/code/community/TM/Core/Model/Resource/Module/LocalCollection.php index a14b4c5..95138bd 100644 --- a/app/code/community/TM/Core/Model/Resource/Module/LocalCollection.php +++ b/app/code/community/TM/Core/Model/Resource/Module/LocalCollection.php @@ -1,22 +1,14 @@ isLoaded()) { - return $this; - } - $modules = array(); $nodes = Mage::getConfig()->getNode('modules')->children(); foreach ($nodes as $code => $info) { @@ -39,30 +31,6 @@ public function loadData($printQuery = false, $logQuery = false) } } - $this->_collectedModules = $modules; - - // calculate totals - $this->_totalRecords = count($this->_collectedModules); - $this->_setIsLoaded(); - - // paginate and add items - $from = ($this->getCurPage() - 1) * $this->getPageSize(); - $to = $from + $this->getPageSize() - 1; - $isPaginated = $this->getPageSize() > 0; - - $cnt = 0; - foreach ($this->_collectedModules as $row) { - $cnt++; - if ($isPaginated && ($cnt < $from || $cnt > $to)) { - continue; - } - $item = new $this->_itemObjectClass(); - $this->addItem($item->addData($row)); - if (!$item->hasId()) { - $item->setId($cnt); - } - } - - return $this; + return $modules; } } diff --git a/app/code/community/TM/Core/Model/Resource/Module/RemoteCollection.php b/app/code/community/TM/Core/Model/Resource/Module/RemoteCollection.php index 4e41c2c..8bff731 100644 --- a/app/code/community/TM/Core/Model/Resource/Module/RemoteCollection.php +++ b/app/code/community/TM/Core/Model/Resource/Module/RemoteCollection.php @@ -1,13 +1,11 @@ isLoaded()) { - return $this; - } - try { if (!$responseBody = Mage::app()->loadCache(self::RESPONSE_CACHE_KEY)) { $responseBody = $this->_fetch($this->_getFeedUri()); @@ -139,33 +131,10 @@ public function loadData($printQuery = false, $logQuery = false) } foreach ($result as $moduleName => $values) { - $values['id'] = $values['code']; - $this->_collectedModules[$values['code']] = $values; - } - - // calculate totals - $this->_totalRecords = count($this->_collectedModules); - $this->_setIsLoaded(); - - // paginate and add items - $from = ($this->getCurPage() - 1) * $this->getPageSize(); - $to = $from + $this->getPageSize() - 1; - $isPaginated = $this->getPageSize() > 0; - - $cnt = 0; - foreach ($this->_collectedModules as $row) { - $cnt++; - if ($isPaginated && ($cnt < $from || $cnt > $to)) { - continue; - } - $item = new $this->_itemObjectClass(); - $this->addItem($item->addData($row)); - if (!$item->hasId()) { - $item->setId($cnt); - } + $result[$moduleName]['id'] = $moduleName; } - return $this; + return $result; } /**