Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Db_Table_Rowset_Abstract Class Reference
Inheritance diagram for Zend_Db_Table_Rowset_Abstract:
Zend_Db_Table_Rowset

Public Member Functions

 __construct (array $config)
 
 __sleep ()
 
 __wakeup ()
 
 init ()
 
 isConnected ()
 
 getTable ()
 
 setTable (Zend_Db_Table_Abstract $table)
 
 getTableClass ()
 
 rewind ()
 
 current ()
 
 key ()
 
 next ()
 
 valid ()
 
 count ()
 
 seek ($position)
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 getRow ($position, $seek=false)
 
 toArray ()
 

Protected Member Functions

 _loadAndReturnRow ($position)
 

Protected Attributes

 $_data = array()
 
 $_table
 
 $_connected = true
 
 $_tableClass
 
 $_rowClass = 'Zend_Db_Table_Row'
 
 $_pointer = 0
 
 $_count
 
 $_rows = array()
 
 $_stored = false
 
 $_readOnly = false
 

Detailed Description

Definition at line 30 of file Abstract.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $config)

Constructor.

Parameters
array$config

Definition at line 105 of file Abstract.php.

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  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
$config
Definition: fraud_order.php:17

Member Function Documentation

◆ __sleep()

__sleep ( )

Store data, class names, and state in serialized object

Returns
array

Definition at line 139 of file Abstract.php.

140  {
141  return array('_data', '_tableClass', '_rowClass', '_pointer', '_count', '_rows', '_stored',
142  '_readOnly');
143  }

◆ __wakeup()

__wakeup ( )

Setup to do on wakeup. A de-serialized Rowset should not be assumed to have access to a live database connection, so set _connected = false.

Returns
void

Definition at line 152 of file Abstract.php.

153  {
154  $this->_connected = false;
155  }

◆ _loadAndReturnRow()

_loadAndReturnRow (   $position)
protected

Definition at line 413 of file Abstract.php.

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  }
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ count()

count ( )

Returns the number of elements in the collection.

Implements Countable::count()

Returns
int

Definition at line 296 of file Abstract.php.

297  {
298  return $this->_count;
299  }

◆ current()

current ( )

Return the current element. Similar to the current() function for arrays in PHP Required by interface Iterator.

Returns
Zend_Db_Table_Row_Abstract current element from the collection

Definition at line 243 of file Abstract.php.

244  {
245  if ($this->valid() === false) {
246  return null;
247  }
248 
249  // return the row object
250  return $this->_loadAndReturnRow($this->_pointer);
251  }

◆ getRow()

getRow (   $position,
  $seek = false 
)

Returns a Zend_Db_Table_Row from a known position into the Iterator

Parameters
int$positionthe position of the row expected
bool$seekwether or not seek the iterator to that position after
Returns
Zend_Db_Table_Row
Exceptions
Zend_Db_Table_Rowset_Exception

Definition at line 380 of file Abstract.php.

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  }

◆ getTable()

getTable ( )

Returns the table object, or null if this is disconnected rowset

Returns
Zend_Db_Table_Abstract

Definition at line 183 of file Abstract.php.

184  {
185  return $this->_table;
186  }

◆ getTableClass()

getTableClass ( )

Query the class name of the Table object for which this Rowset was created.

Returns
string

Definition at line 218 of file Abstract.php.

219  {
220  return $this->_tableClass;
221  }

◆ init()

init ( )

Initialize object

Called from __construct() as final step of object instantiation.

Returns
void

Definition at line 164 of file Abstract.php.

165  {
166  }

◆ isConnected()

isConnected ( )

Return the connected state of the rowset.

Returns
boolean

Definition at line 173 of file Abstract.php.

174  {
175  return $this->_connected;
176  }

◆ key()

key ( )

Return the identifying key of the current element. Similar to the key() function for arrays in PHP. Required by interface Iterator.

Returns
int

Definition at line 260 of file Abstract.php.

261  {
262  return $this->_pointer;
263  }

◆ next()

next ( )

Move forward to next element. Similar to the next() function for arrays in PHP. Required by interface Iterator.

Returns
void

Definition at line 272 of file Abstract.php.

273  {
274  ++$this->_pointer;
275  }

◆ offsetExists()

offsetExists (   $offset)

Check if an offset exists Required by the ArrayAccess implementation

Parameters
string$offset
Returns
boolean

Definition at line 327 of file Abstract.php.

328  {
329  return isset($this->_data[(int) $offset]);
330  }

◆ offsetGet()

offsetGet (   $offset)

Get the row for the given offset Required by the ArrayAccess implementation

Parameters
string$offset
Returns
Zend_Db_Table_Row_Abstract

Definition at line 339 of file Abstract.php.

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  }

◆ offsetSet()

offsetSet (   $offset,
  $value 
)

Does nothing Required by the ArrayAccess implementation

Parameters
string$offset
mixed$value

Definition at line 358 of file Abstract.php.

359  {
360  }

◆ offsetUnset()

offsetUnset (   $offset)

Does nothing Required by the ArrayAccess implementation

Parameters
string$offset

Definition at line 368 of file Abstract.php.

369  {
370  }

◆ rewind()

rewind ( )

Rewind the Iterator to the first element. Similar to the reset() function for arrays in PHP. Required by interface Iterator.

Returns
Zend_Db_Table_Rowset_Abstract Fluent interface.

Definition at line 230 of file Abstract.php.

231  {
232  $this->_pointer = 0;
233  return $this;
234  }

◆ seek()

seek (   $position)

Take the Iterator to position $position Required by interface SeekableIterator.

Parameters
int$positionthe position to seek to
Returns
Zend_Db_Table_Rowset_Abstract
Exceptions
Zend_Db_Table_Rowset_Exception

Definition at line 309 of file Abstract.php.

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  }

◆ setTable()

setTable ( Zend_Db_Table_Abstract  $table)

Set the table object, to re-establish a live connection to the database for a Rowset that has been de-serialized.

Parameters
Zend_Db_Table_Abstract$table
Returns
boolean
Exceptions
Zend_Db_Table_Row_Exception

Definition at line 196 of file Abstract.php.

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  }
$table
Definition: trigger.php:14

◆ toArray()

toArray ( )

Returns all data as an array.

Updates the $_data property with current row object values.

Returns
array

Definition at line 403 of file Abstract.php.

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  }
$i
Definition: gallery.phtml:31

◆ valid()

valid ( )

Check if there is a current element after calls to rewind() or next(). Used to check if we've iterated to the end of the collection. Required by interface Iterator.

Returns
bool False if there's nothing more to iterate over

Definition at line 284 of file Abstract.php.

285  {
286  return $this->_pointer >= 0 && $this->_pointer < $this->_count;
287  }

Field Documentation

◆ $_connected

$_connected = true
protected

Definition at line 53 of file Abstract.php.

◆ $_count

$_count
protected

Definition at line 81 of file Abstract.php.

◆ $_data

$_data = array()
protected

Definition at line 37 of file Abstract.php.

◆ $_pointer

$_pointer = 0
protected

Definition at line 74 of file Abstract.php.

◆ $_readOnly

$_readOnly = false
protected

Definition at line 98 of file Abstract.php.

◆ $_rowClass

$_rowClass = 'Zend_Db_Table_Row'
protected

Definition at line 67 of file Abstract.php.

◆ $_rows

$_rows = array()
protected

Definition at line 88 of file Abstract.php.

◆ $_stored

$_stored = false
protected

Definition at line 93 of file Abstract.php.

◆ $_table

$_table
protected

Definition at line 44 of file Abstract.php.

◆ $_tableClass

$_tableClass
protected

Definition at line 60 of file Abstract.php.


The documentation for this class was generated from the following file: