Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Abstract.php
Go to the documentation of this file.
1 <?php
30 abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Countable, ArrayAccess
31 {
37  protected $_data = array();
38 
44  protected $_table;
45 
53  protected $_connected = true;
54 
60  protected $_tableClass;
61 
67  protected $_rowClass = 'Zend_Db_Table_Row';
68 
74  protected $_pointer = 0;
75 
81  protected $_count;
82 
88  protected $_rows = array();
89 
93  protected $_stored = false;
94 
98  protected $_readOnly = false;
99 
105  public function __construct(array $config)
106  {
107  if (isset($config['table'])) {
108  $this->_table = $config['table'];
109  $this->_tableClass = get_class($this->_table);
110  }
111  if (isset($config['rowClass'])) {
112  $this->_rowClass = $config['rowClass'];
113  }
114  if (!class_exists($this->_rowClass)) {
115  #require_once 'Zend/Loader.php';
116  Zend_Loader::loadClass($this->_rowClass);
117  }
118  if (isset($config['data'])) {
119  $this->_data = $config['data'];
120  }
121  if (isset($config['readOnly'])) {
122  $this->_readOnly = $config['readOnly'];
123  }
124  if (isset($config['stored'])) {
125  $this->_stored = $config['stored'];
126  }
127 
128  // set the count of rows
129  $this->_count = count($this->_data);
130 
131  $this->init();
132  }
133 
139  public function __sleep()
140  {
141  return array('_data', '_tableClass', '_rowClass', '_pointer', '_count', '_rows', '_stored',
142  '_readOnly');
143  }
144 
152  public function __wakeup()
153  {
154  $this->_connected = false;
155  }
156 
164  public function init()
165  {
166  }
167 
173  public function isConnected()
174  {
175  return $this->_connected;
176  }
177 
183  public function getTable()
184  {
185  return $this->_table;
186  }
187 
197  {
198  $this->_table = $table;
199  $this->_connected = false;
200  // @todo This works only if we have iterated through
201  // the result set once to instantiate the rows.
202  foreach ($this as $row) {
203  $connected = $row->setTable($table);
204  if ($connected == true) {
205  $this->_connected = true;
206  }
207  }
208  $this->rewind();
209  return $this->_connected;
210  }
211 
218  public function getTableClass()
219  {
220  return $this->_tableClass;
221  }
222 
230  public function rewind()
231  {
232  $this->_pointer = 0;
233  return $this;
234  }
235 
243  public function current()
244  {
245  if ($this->valid() === false) {
246  return null;
247  }
248 
249  // return the row object
250  return $this->_loadAndReturnRow($this->_pointer);
251  }
252 
260  public function key()
261  {
262  return $this->_pointer;
263  }
264 
272  public function next()
273  {
274  ++$this->_pointer;
275  }
276 
284  public function valid()
285  {
286  return $this->_pointer >= 0 && $this->_pointer < $this->_count;
287  }
288 
296  public function count()
297  {
298  return $this->_count;
299  }
300 
309  public function seek($position)
310  {
311  $position = (int) $position;
312  if ($position < 0 || $position >= $this->_count) {
313  #require_once 'Zend/Db/Table/Rowset/Exception.php';
314  throw new Zend_Db_Table_Rowset_Exception("Illegal index $position");
315  }
316  $this->_pointer = $position;
317  return $this;
318  }
319 
327  public function offsetExists($offset)
328  {
329  return isset($this->_data[(int) $offset]);
330  }
331 
339  public function offsetGet($offset)
340  {
341  $offset = (int) $offset;
342  if ($offset < 0 || $offset >= $this->_count) {
343  #require_once 'Zend/Db/Table/Rowset/Exception.php';
344  throw new Zend_Db_Table_Rowset_Exception("Illegal index $offset");
345  }
346  $this->_pointer = $offset;
347 
348  return $this->current();
349  }
350 
358  public function offsetSet($offset, $value)
359  {
360  }
361 
368  public function offsetUnset($offset)
369  {
370  }
371 
380  public function getRow($position, $seek = false)
381  {
382  try {
383  $row = $this->_loadAndReturnRow($position);
384  } catch (Zend_Db_Table_Rowset_Exception $e) {
385  #require_once 'Zend/Db/Table/Rowset/Exception.php';
386  throw new Zend_Db_Table_Rowset_Exception('No row could be found at position ' . (int) $position, 0, $e);
387  }
388 
389  if ($seek == true) {
390  $this->seek($position);
391  }
392 
393  return $row;
394  }
395 
403  public function toArray()
404  {
405  // @todo This works only if we have iterated through
406  // the result set once to instantiate the rows.
407  foreach ($this->_rows as $i => $row) {
408  $this->_data[$i] = $row->toArray();
409  }
410  return $this->_data;
411  }
412 
413  protected function _loadAndReturnRow($position)
414  {
415  if (!isset($this->_data[$position])) {
416  #require_once 'Zend/Db/Table/Rowset/Exception.php';
417  throw new Zend_Db_Table_Rowset_Exception("Data for provided position does not exist");
418  }
419 
420  // do we already have a row object for this position?
421  if (empty($this->_rows[$position])) {
422  $this->_rows[$position] = new $this->_rowClass(
423  array(
424  'table' => $this->_table,
425  'data' => $this->_data[$position],
426  'stored' => $this->_stored,
427  'readOnly' => $this->_readOnly
428  )
429  );
430 
431  if ( $this->_table instanceof Zend_Db_Table_Abstract ) {
432  $info = $this->_table->info();
433 
434  if ( $this->_rows[$position] instanceof Zend_Db_Table_Row_Abstract ) {
435  if ($info['cols'] == array_keys($this->_data[$position])) {
436  $this->_rows[$position]->setTable($this->getTable());
437  }
438  }
439  } else {
440  $this->_rows[$position]->setTable(null);
441  }
442  }
443 
444  // return the row object
445  return $this->_rows[$position];
446  }
447 
448 }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
getRow($position, $seek=false)
Definition: Abstract.php:380
$config
Definition: fraud_order.php:17
__construct(array $config)
Definition: Abstract.php:105
$value
Definition: gender.phtml:16
setTable(Zend_Db_Table_Abstract $table)
Definition: Abstract.php:196
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
$table
Definition: trigger.php:14
offsetSet($offset, $value)
Definition: Abstract.php:358
$i
Definition: gallery.phtml:31