예제 #1
0
 protected function setInstanceOf(Zend_Db_Table_Rowset $rowset)
 {
     if (!$rowset instanceof Zend_Db_Table_Rowset) {
         throw new Exception("Rowset must be an instance of Zend_Db_Table_Rowset");
     }
     $tableClass = $rowset->getTableClass();
     $tableClass = str_replace('_DbTable_', '_', $tableClass);
     foreach ($rowset as $row) {
         if (!class_exists($tableClass)) {
             throw new Exception("Class {$tableClass} not existis!");
         }
         $this->row[] = new $tableClass($row);
     }
     return $this->row;
 }
예제 #2
0
파일: Sorter.php 프로젝트: laiello/resmania
 public function sort()
 {
     $data = $this->_units->toArray();
     $data = $this->_calculateAllPrices($data);
     usort($data, array('RM_Unit_Sorter', 'cmp'));
     $config = array('table' => $this->_units->getTable(), 'data' => $data, 'rowClass' => 'RM_Unit_Row', 'stored' => true);
     $this->_sortedUnits = new Zend_Db_Table_Rowset($config);
 }
예제 #3
0
파일: Db.php 프로젝트: tormit/Ho_Import
 /**
  * Constructor.
  * @param array $config
  */
 public function __construct(array $config)
 {
     $logHelper = Mage::helper('ho_import/log');
     $model = $config['model'];
     $query = $config['query'];
     unset($config['model']);
     unset($config['query']);
     /** @var Zend_Db_Adapter_Abstract $db */
     $db = new $model($config);
     if (isset($config['limit']) || isset($config['offset'])) {
         $limit = (int) isset($config['limit']) ? $config['limit'] : 0;
         $offset = (int) isset($config['offset']) ? $config['offset'] : 0;
         $logHelper->log($logHelper->__('Setting limit to %s and offset to %s', $limit, $offset), Zend_Log::NOTICE);
         $query = $db->limit($query, $config['limit'], $offset);
         $logHelper->log($query, Zend_Log::DEBUG);
     }
     $logHelper->log('Fetching data...');
     $result = $db->fetchAll($query);
     $logHelper->log('Done');
     $config['data'] =& $result;
     return parent::__construct($config);
 }
예제 #4
0
파일: Rowset.php 프로젝트: bersace/strass
 function __wakeup()
 {
     parent::__wakeup();
     $this->setTable(new $this->_tableClass());
 }
예제 #5
0
 /**
  * Load attributes values with single query
  * 
  * @param Zend_Db_Table_Rowset $rows
  * @param Zend_Db_Table_Rowset $attributes
  * @return array
  */
 public function loadAttributes($rows, $attributes)
 {
     if (!$rows->valid()) {
         return;
     }
     $this->cacheAttributes($attributes);
     $result = array();
     $entities = array();
     foreach ($rows as $row) {
         $entities[$this->getEntityId($row)] = $row;
     }
     $eavModels = $this->getEavModels($attributes);
     $queries = array();
     $entityIds = array_keys($entities);
     foreach ($eavModels as $type => $eavModel) {
         $select = $eavModel->select();
         $select->where('entity_id IN(?)', $entityIds);
         $attributeIds = array();
         foreach ($attributes as $attribute) {
             if ($type == $this->getAttributeType($attribute)) {
                 $attributeIds[] = $this->getAttributeId($attribute);
             }
         }
         $select->where('attribute_id IN(?)', $attributeIds);
         $queries[] = $select->__toString();
     }
     /* build query */
     $query = '(' . implode(') UNION ALL (', $queries) . ')';
     $db = Zend_Db_Table::getDefaultAdapter();
     $rows = $db->fetchAll($query);
     foreach ($rows as $row) {
         $attributeId = $this->getAttributeId($this->getAttribute($row['attribute_id']));
         $entities[$row['entity_id']]->setAttributeValue($attributeId, $row['value']);
     }
     return $rows;
 }
예제 #6
0
 protected function _loadByPrimaryKeys(\Zend_Db_Table_Rowset $results)
 {
     $collection = array();
     foreach ($results->toArray() as $row) {
         $collection[] = $this->load(array_shift($row));
     }
     return $collection;
 }