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_Row_Abstract Class Reference
Inheritance diagram for Zend_Db_Table_Row_Abstract:
Zend_Db_Table_Row

Public Member Functions

 __construct (array $config=array())
 
 __get ($columnName)
 
 __set ($columnName, $value)
 
 __unset ($columnName)
 
 __isset ($columnName)
 
 __sleep ()
 
 __wakeup ()
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 init ()
 
 getTable ()
 
 setTable (Zend_Db_Table_Abstract $table=null)
 
 getTableClass ()
 
 isConnected ()
 
 isReadOnly ()
 
 setReadOnly ($flag)
 
 select ()
 
 save ()
 
 delete ()
 
 getIterator ()
 
 toArray ()
 
 setFromArray (array $data)
 
 refresh ()
 
 getPrimaryKey ($useDirty=true)
 
 findDependentRowset ($dependentTable, $ruleKey=null, Zend_Db_Table_Select $select=null)
 
 findParentRow ($parentTable, $ruleKey=null, Zend_Db_Table_Select $select=null)
 
 findManyToManyRowset ($matchTable, $intersectionTable, $callerRefRule=null, $matchRefRule=null, Zend_Db_Table_Select $select=null)
 
 __call ($method, array $args)
 

Protected Member Functions

 _transformColumn ($columnName)
 
 _doInsert ()
 
 _doUpdate ()
 
 _getTable ()
 
 _getPrimaryKey ($useDirty=true)
 
 _getWhereQuery ($useDirty=true)
 
 _refresh ()
 
 _insert ()
 
 _postInsert ()
 
 _update ()
 
 _postUpdate ()
 
 _delete ()
 
 _postDelete ()
 
 _prepareReference (Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
 
 _getTableFromString ($tableName)
 

Protected Attributes

 $_data = array()
 
 $_cleanData = array()
 
 $_modifiedFields = array()
 
 $_table = null
 
 $_connected = true
 
 $_readOnly = false
 
 $_tableClass = null
 
 $_primary
 

Detailed Description

Definition at line 35 of file Abstract.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $config = array())

Constructor.

Supported params for $config are:-

Parameters
array$configOPTIONAL Array of user-specified config options.
Returns
void
Exceptions
Zend_Db_Table_Row_Exception

Definition at line 114 of file Abstract.php.

115  {
116  if (isset($config['table']) && $config['table'] instanceof Zend_Db_Table_Abstract) {
117  $this->_table = $config['table'];
118  $this->_tableClass = get_class($this->_table);
119  } elseif ($this->_tableClass !== null) {
120  $this->_table = $this->_getTableFromString($this->_tableClass);
121  }
122 
123  if (isset($config['data'])) {
124  if (!is_array($config['data'])) {
125  #require_once 'Zend/Db/Table/Row/Exception.php';
126  throw new Zend_Db_Table_Row_Exception('Data must be an array');
127  }
128  $this->_data = $config['data'];
129  }
130  if (isset($config['stored']) && $config['stored'] === true) {
131  $this->_cleanData = $this->_data;
132  }
133 
134  if (isset($config['readOnly']) && $config['readOnly'] === true) {
135  $this->setReadOnly(true);
136  }
137 
138  // Retrieve primary keys from table schema
139  if (($table = $this->_getTable())) {
140  $info = $table->info();
141  $this->_primary = (array) $info['primary'];
142  }
143 
144  $this->init();
145  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$config
Definition: fraud_order.php:17
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
$table
Definition: trigger.php:14
_getTableFromString($tableName)
Definition: Abstract.php:1179

Member Function Documentation

◆ __call()

__call (   $method,
array  $args 
)

Turn magic function calls into non-magic function calls to the above methods.

Parameters
string$method
array$argsOPTIONAL Zend_Db_Table_Select query modifier
Returns
Zend_Db_Table_Row_Abstract|Zend_Db_Table_Rowset_Abstract
Exceptions
Zend_Db_Table_Row_ExceptionIf an invalid method is called.

Recognize methods for Has-Many cases: findParent<Class>() findParent<Class>By<Rule>() Use the non-greedy pattern repeat modifier e.g. \w+?

Recognize methods for Many-to-Many cases: find<Class1>Via<Class2>() find<Class1>Via<Class2>By<Rule>() find<Class1>Via<Class2>By<Rule1>And<Rule2>() Use the non-greedy pattern repeat modifier e.g. \w+?

Recognize methods for Belongs-To cases: find<Class>() find<Class>By<Rule>() Use the non-greedy pattern repeat modifier e.g. \w+?

Definition at line 1119 of file Abstract.php.

1120  {
1121  $matches = array();
1122 
1123  if (count($args) && $args[0] instanceof Zend_Db_Table_Select) {
1124  $select = $args[0];
1125  } else {
1126  $select = null;
1127  }
1128 
1135  if (preg_match('/^findParent(\w+?)(?:By(\w+))?$/', $method, $matches)) {
1136  $class = $matches[1];
1137  $ruleKey1 = isset($matches[2]) ? $matches[2] : null;
1138  return $this->findParentRow($class, $ruleKey1, $select);
1139  }
1140 
1148  if (preg_match('/^find(\w+?)Via(\w+?)(?:By(\w+?)(?:And(\w+))?)?$/', $method, $matches)) {
1149  $class = $matches[1];
1150  $viaClass = $matches[2];
1151  $ruleKey1 = isset($matches[3]) ? $matches[3] : null;
1152  $ruleKey2 = isset($matches[4]) ? $matches[4] : null;
1153  return $this->findManyToManyRowset($class, $viaClass, $ruleKey1, $ruleKey2, $select);
1154  }
1155 
1162  if (preg_match('/^find(\w+?)(?:By(\w+))?$/', $method, $matches)) {
1163  $class = $matches[1];
1164  $ruleKey1 = isset($matches[2]) ? $matches[2] : null;
1165  return $this->findDependentRowset($class, $ruleKey1, $select);
1166  }
1167 
1168  #require_once 'Zend/Db/Table/Row/Exception.php';
1169  throw new Zend_Db_Table_Row_Exception("Unrecognized method '$method()'");
1170  }
findDependentRowset($dependentTable, $ruleKey=null, Zend_Db_Table_Select $select=null)
Definition: Abstract.php:878
findParentRow($parentTable, $ruleKey=null, Zend_Db_Table_Select $select=null)
Definition: Abstract.php:934
$_option $_optionId $class
Definition: date.phtml:13
$method
Definition: info.phtml:13
findManyToManyRowset($matchTable, $intersectionTable, $callerRefRule=null, $matchRefRule=null, Zend_Db_Table_Select $select=null)
Definition: Abstract.php:1001

◆ __get()

__get (   $columnName)

Retrieve row field value

Parameters
string$columnNameThe user-specified column name.
Returns
string The corresponding column value.
Exceptions
Zend_Db_Table_Row_Exceptionif the $columnName is not a column in the row.

Definition at line 174 of file Abstract.php.

175  {
176  $columnName = $this->_transformColumn($columnName);
177  if (!array_key_exists($columnName, $this->_data)) {
178  #require_once 'Zend/Db/Table/Row/Exception.php';
179  throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
180  }
181  return $this->_data[$columnName];
182  }
_transformColumn($columnName)
Definition: Abstract.php:157

◆ __isset()

__isset (   $columnName)

Test existence of row field

Parameters
string$columnNameThe column key.
Returns
boolean

Definition at line 231 of file Abstract.php.

232  {
233  $columnName = $this->_transformColumn($columnName);
234  return array_key_exists($columnName, $this->_data);
235  }
_transformColumn($columnName)
Definition: Abstract.php:157

◆ __set()

__set (   $columnName,
  $value 
)

Set row field value

Parameters
string$columnNameThe column key.
mixed$valueThe value for the property.
Returns
void
Exceptions
Zend_Db_Table_Row_Exception

Definition at line 192 of file Abstract.php.

193  {
194  $columnName = $this->_transformColumn($columnName);
195  if (!array_key_exists($columnName, $this->_data)) {
196  #require_once 'Zend/Db/Table/Row/Exception.php';
197  throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
198  }
199  $this->_data[$columnName] = $value;
200  $this->_modifiedFields[$columnName] = true;
201  }
_transformColumn($columnName)
Definition: Abstract.php:157
$value
Definition: gender.phtml:16

◆ __sleep()

__sleep ( )

Store table, primary key and data in serialized object

Returns
array

Definition at line 242 of file Abstract.php.

243  {
244  return array('_tableClass', '_primary', '_data', '_cleanData', '_readOnly' ,'_modifiedFields');
245  }

◆ __unset()

__unset (   $columnName)

Unset row field value

Parameters
string$columnNameThe column key.
Returns
Zend_Db_Table_Row_Abstract
Exceptions
Zend_Db_Table_Row_Exception

Definition at line 210 of file Abstract.php.

211  {
212  $columnName = $this->_transformColumn($columnName);
213  if (!array_key_exists($columnName, $this->_data)) {
214  #require_once 'Zend/Db/Table/Row/Exception.php';
215  throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
216  }
217  if ($this->isConnected() && in_array($columnName, $this->_table->info('primary'))) {
218  #require_once 'Zend/Db/Table/Row/Exception.php';
219  throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is a primary key and should not be unset");
220  }
221  unset($this->_data[$columnName]);
222  return $this;
223  }
_transformColumn($columnName)
Definition: Abstract.php:157

◆ __wakeup()

__wakeup ( )

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

Returns
void

Definition at line 254 of file Abstract.php.

255  {
256  $this->_connected = false;
257  }

◆ _delete()

_delete ( )
protected

Allows pre-delete logic to be applied to row. Subclasses may override this method.

Returns
void

Definition at line 829 of file Abstract.php.

830  {
831  }

◆ _doInsert()

_doInsert ( )
protected
Returns
mixed The primary key value(s), as an associative array if the key is compound, or a scalar if the key is single-column.

A read-only row cannot be saved.

Run pre-INSERT logic

Execute the INSERT (this may throw an exception)

Normalize the result to an array indexed by primary key column(s). The table insert() method may return a scalar.

Save the new primary key value in _data. The primary key may have been generated by a sequence or auto-increment mechanism, and this merge should be done before the _postInsert() method is run, so the new values are available for logging, etc.

Run post-INSERT logic

Update the _cleanData to reflect that the data has been inserted.

Definition at line 448 of file Abstract.php.

449  {
453  if ($this->_readOnly === true) {
454  #require_once 'Zend/Db/Table/Row/Exception.php';
455  throw new Zend_Db_Table_Row_Exception('This row has been marked read-only');
456  }
457 
461  $this->_insert();
462 
466  $data = array_intersect_key($this->_data, $this->_modifiedFields);
467  $primaryKey = $this->_getTable()->insert($data);
468 
473  if (is_array($primaryKey)) {
474  $newPrimaryKey = $primaryKey;
475  } else {
476  //ZF-6167 Use tempPrimaryKey temporary to avoid that zend encoding fails.
477  $tempPrimaryKey = (array) $this->_primary;
478  $newPrimaryKey = array(current($tempPrimaryKey) => $primaryKey);
479  }
480 
487  $this->_data = array_merge($this->_data, $newPrimaryKey);
488 
492  $this->_postInsert();
493 
497  $this->_refresh();
498 
499  return $primaryKey;
500  }

◆ _doUpdate()

_doUpdate ( )
protected
Returns
mixed The primary key value(s), as an associative array if the key is compound, or a scalar if the key is single-column.

A read-only row cannot be saved.

Get expressions for a WHERE clause based on the primary key value(s).

Run pre-UPDATE logic

Compare the data to the modified fields array to discover which columns have been changed.

Were any of the changed columns part of the primary key?

Execute cascading updates against dependent tables. Do this only if primary key value(s) were changed.

Execute the UPDATE (this may throw an exception) Do this only if data values were changed. Use the $diffData variable, so the UPDATE statement includes SET terms only for data values that changed.

Run post-UPDATE logic. Do this before the _refresh() so the _postUpdate() function can tell the difference between changed data and clean (pre-changed) data.

Refresh the data just in case triggers in the RDBMS changed any columns. Also this resets the _cleanData.

Return the primary key value(s) as an array if the key is compound or a scalar if the key is a scalar.

Definition at line 506 of file Abstract.php.

507  {
511  if ($this->_readOnly === true) {
512  #require_once 'Zend/Db/Table/Row/Exception.php';
513  throw new Zend_Db_Table_Row_Exception('This row has been marked read-only');
514  }
515 
520  $where = $this->_getWhereQuery(false);
521 
525  $this->_update();
526 
531  $diffData = array_intersect_key($this->_data, $this->_modifiedFields);
532 
536  $pkDiffData = array_intersect_key($diffData, array_flip((array)$this->_primary));
537 
542  if (count($pkDiffData) > 0) {
543  $depTables = $this->_getTable()->getDependentTables();
544  if (!empty($depTables)) {
545  $pkNew = $this->_getPrimaryKey(true);
546  $pkOld = $this->_getPrimaryKey(false);
547  foreach ($depTables as $tableClass) {
548  $t = $this->_getTableFromString($tableClass);
549  $t->_cascadeUpdate($this->getTableClass(), $pkOld, $pkNew);
550  }
551  }
552  }
553 
560  if (count($diffData) > 0) {
561  $this->_getTable()->update($diffData, $where);
562  }
563 
569  $this->_postUpdate();
570 
575  $this->_refresh();
576 
582  $primaryKey = $this->_getPrimaryKey(true);
583  if (count($primaryKey) == 1) {
584  return current($primaryKey);
585  }
586 
587  return $primaryKey;
588  }
_getPrimaryKey($useDirty=true)
Definition: Abstract.php:707
_getWhereQuery($useDirty=true)
Definition: Abstract.php:744
_getTableFromString($tableName)
Definition: Abstract.php:1179

◆ _getPrimaryKey()

_getPrimaryKey (   $useDirty = true)
protected

Retrieves an associative array of primary keys.

Parameters
bool$useDirty
Returns
array

Definition at line 707 of file Abstract.php.

708  {
709  if (!is_array($this->_primary)) {
710  #require_once 'Zend/Db/Table/Row/Exception.php';
711  throw new Zend_Db_Table_Row_Exception("The primary key must be set as an array");
712  }
713 
714  $primary = array_flip($this->_primary);
715  if ($useDirty) {
716  $array = array_intersect_key($this->_data, $primary);
717  } else {
718  $array = array_intersect_key($this->_cleanData, $primary);
719  }
720  if (count($primary) != count($array)) {
721  #require_once 'Zend/Db/Table/Row/Exception.php';
722  throw new Zend_Db_Table_Row_Exception("The specified Table '$this->_tableClass' does not have the same primary key as the Row");
723  }
724  return $array;
725  }

◆ _getTable()

_getTable ( )
protected

Retrieves an instance of the parent table.

Returns
Zend_Db_Table_Abstract

Definition at line 692 of file Abstract.php.

693  {
694  if (!$this->_connected) {
695  #require_once 'Zend/Db/Table/Row/Exception.php';
696  throw new Zend_Db_Table_Row_Exception('Cannot save a Row unless it is connected');
697  }
698  return $this->_table;
699  }

◆ _getTableFromString()

_getTableFromString (   $tableName)
protected

_getTableFromString

Parameters
string$tableName
Returns
Zend_Db_Table_Abstract

Definition at line 1179 of file Abstract.php.

1180  {
1182  }
$tableName
Definition: trigger.php:13
static getTableFromString($tableName, Zend_Db_Table_Abstract $referenceTable=null)
Definition: Abstract.php:1606

◆ _getWhereQuery()

_getWhereQuery (   $useDirty = true)
protected

Constructs where statement for retrieving row(s).

Parameters
bool$useDirty
Returns
array

Definition at line 744 of file Abstract.php.

745  {
746  $where = array();
747  $db = $this->_getTable()->getAdapter();
748  $primaryKey = $this->_getPrimaryKey($useDirty);
749  $info = $this->_getTable()->info();
751 
752  // retrieve recently updated row using primary keys
753  $where = array();
754  foreach ($primaryKey as $column => $value) {
755  $tableName = $db->quoteIdentifier($info[Zend_Db_Table_Abstract::NAME], true);
756  $type = $metadata[$column]['DATA_TYPE'];
757  $columnName = $db->quoteIdentifier($column, true);
758  $where[] = $db->quoteInto("{$tableName}.{$columnName} = ?", $value, $type);
759  }
760  return $where;
761  }
$tableName
Definition: trigger.php:13
_getPrimaryKey($useDirty=true)
Definition: Abstract.php:707
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ _insert()

_insert ( )
protected

Allows pre-insert logic to be applied to row. Subclasses may override this method.

Returns
void

Definition at line 789 of file Abstract.php.

790  {
791  }

◆ _postDelete()

_postDelete ( )
protected

Allows post-delete logic to be applied to row. Subclasses may override this method.

Returns
void

Definition at line 839 of file Abstract.php.

840  {
841  }

◆ _postInsert()

_postInsert ( )
protected

Allows post-insert logic to be applied to row. Subclasses may override this method.

Returns
void

Definition at line 799 of file Abstract.php.

800  {
801  }

◆ _postUpdate()

_postUpdate ( )
protected

Allows post-update logic to be applied to row. Subclasses may override this method.

Returns
void

Definition at line 819 of file Abstract.php.

820  {
821  }

◆ _prepareReference()

_prepareReference ( Zend_Db_Table_Abstract  $dependentTable,
Zend_Db_Table_Abstract  $parentTable,
  $ruleKey 
)
protected

Prepares a table reference for lookup.

Ensures all reference keys are set and properly formatted.

Parameters
Zend_Db_Table_Abstract$dependentTable
Zend_Db_Table_Abstract$parentTable
string$ruleKey
Returns
array

Definition at line 853 of file Abstract.php.

854  {
855  $parentTableName = (get_class($parentTable) === 'Zend_Db_Table') ? $parentTable->getDefinitionConfigName() : get_class($parentTable);
856  $map = $dependentTable->getReference($parentTableName, $ruleKey);
857 
859  $parentInfo = $parentTable->info();
860  $map[Zend_Db_Table_Abstract::REF_COLUMNS] = array_values((array) $parentInfo['primary']);
861  }
862 
865 
866  return $map;
867  }
getReference($tableClassname, $ruleKey=null)
Definition: Abstract.php:461

◆ _refresh()

_refresh ( )
protected

Refreshes properties from the database.

Returns
void

Definition at line 768 of file Abstract.php.

769  {
770  $where = $this->_getWhereQuery();
771  $row = $this->_getTable()->fetchRow($where);
772 
773  if (null === $row) {
774  #require_once 'Zend/Db/Table/Row/Exception.php';
775  throw new Zend_Db_Table_Row_Exception('Cannot refresh row as parent is missing');
776  }
777 
778  $this->_data = $row->toArray();
779  $this->_cleanData = $this->_data;
780  $this->_modifiedFields = array();
781  }
_getWhereQuery($useDirty=true)
Definition: Abstract.php:744

◆ _transformColumn()

_transformColumn (   $columnName)
protected

Transform a column name from the user-specified form to the physical form used in the database. You can override this method in a custom Row class to implement column name mappings, for example inflection.

Parameters
string$columnNameColumn name given.
Returns
string The column name after transformation applied (none by default).
Exceptions
Zend_Db_Table_Row_Exceptionif the $columnName is not a string.

Definition at line 157 of file Abstract.php.

158  {
159  if (!is_string($columnName)) {
160  #require_once 'Zend/Db/Table/Row/Exception.php';
161  throw new Zend_Db_Table_Row_Exception('Specified column is not a string');
162  }
163  // Perform no transformation by default
164  return $columnName;
165  }

◆ _update()

_update ( )
protected

Allows pre-update logic to be applied to row. Subclasses may override this method.

Returns
void

Definition at line 809 of file Abstract.php.

810  {
811  }

◆ delete()

delete ( )

Deletes existing rows.

Returns
int The number of rows deleted.

A read-only row cannot be deleted.

Execute pre-DELETE logic

Execute cascading deletes against dependent tables

Execute the DELETE (this may throw an exception)

Execute post-DELETE logic

Reset all fields to null to indicate that the row is not there

Definition at line 595 of file Abstract.php.

596  {
600  if ($this->_readOnly === true) {
601  #require_once 'Zend/Db/Table/Row/Exception.php';
602  throw new Zend_Db_Table_Row_Exception('This row has been marked read-only');
603  }
604 
605  $where = $this->_getWhereQuery();
606 
610  $this->_delete();
611 
615  $depTables = $this->_getTable()->getDependentTables();
616  if (!empty($depTables)) {
617  $pk = $this->_getPrimaryKey();
618  foreach ($depTables as $tableClass) {
619  $t = $this->_getTableFromString($tableClass);
620  $t->_cascadeDelete($this->getTableClass(), $pk);
621  }
622  }
623 
627  $result = $this->_getTable()->delete($where);
628 
632  $this->_postDelete();
633 
637  $this->_data = array_combine(
638  array_keys($this->_data),
639  array_fill(0, count($this->_data), null)
640  );
641 
642  return $result;
643  }
_getPrimaryKey($useDirty=true)
Definition: Abstract.php:707
_getWhereQuery($useDirty=true)
Definition: Abstract.php:744
_getTableFromString($tableName)
Definition: Abstract.php:1179

◆ findDependentRowset()

findDependentRowset (   $dependentTable,
  $ruleKey = null,
Zend_Db_Table_Select  $select = null 
)

Query a dependent table to retrieve rows matching the current row.

Parameters
string | Zend_Db_Table_Abstract$dependentTable
stringOPTIONAL $ruleKey
Zend_Db_Table_SelectOPTIONAL $select
Returns
Zend_Db_Table_Rowset_Abstract Query result from $dependentTable
Exceptions
Zend_Db_Table_Row_ExceptionIf $dependentTable is not a table or is not loadable.

Definition at line 878 of file Abstract.php.

879  {
880  $db = $this->_getTable()->getAdapter();
881 
882  if (is_string($dependentTable)) {
883  $dependentTable = $this->_getTableFromString($dependentTable);
884  }
885 
886  if (!$dependentTable instanceof Zend_Db_Table_Abstract) {
887  $type = gettype($dependentTable);
888  if ($type == 'object') {
889  $type = get_class($dependentTable);
890  }
891  #require_once 'Zend/Db/Table/Row/Exception.php';
892  throw new Zend_Db_Table_Row_Exception("Dependent table must be a Zend_Db_Table_Abstract, but it is $type");
893  }
894 
895  // even if we are interacting between a table defined in a class and a
896  // table via extension, ensure to persist the definition
897  if (($tableDefinition = $this->_table->getDefinition()) !== null
898  && ($dependentTable->getDefinition() == null)) {
899  $dependentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
900  }
901 
902  if ($select === null) {
903  $select = $dependentTable->select();
904  } else {
905  $select->setTable($dependentTable);
906  }
907 
908  $map = $this->_prepareReference($dependentTable, $this->_getTable(), $ruleKey);
909 
910  for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
911  $parentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
912  $value = $this->_data[$parentColumnName];
913  // Use adapter from dependent table to ensure correct query construction
914  $dependentDb = $dependentTable->getAdapter();
915  $dependentColumnName = $dependentDb->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
916  $dependentColumn = $dependentDb->quoteIdentifier($dependentColumnName, true);
917  $dependentInfo = $dependentTable->info();
918  $type = $dependentInfo[Zend_Db_Table_Abstract::METADATA][$dependentColumnName]['DATA_TYPE'];
919  $select->where("$dependentColumn = ?", $value, $type);
920  }
921 
922  return $dependentTable->fetchAll($select);
923  }
_prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
Definition: Abstract.php:853
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
_getTableFromString($tableName)
Definition: Abstract.php:1179
$i
Definition: gallery.phtml:31

◆ findManyToManyRowset()

findManyToManyRowset (   $matchTable,
  $intersectionTable,
  $callerRefRule = null,
  $matchRefRule = null,
Zend_Db_Table_Select  $select = null 
)
Parameters
string | Zend_Db_Table_Abstract$matchTable
string | Zend_Db_Table_Abstract$intersectionTable
stringOPTIONAL $callerRefRule
stringOPTIONAL $matchRefRule
Zend_Db_Table_SelectOPTIONAL $select
Returns
Zend_Db_Table_Rowset_Abstract Query result from $matchTable
Exceptions
Zend_Db_Table_Row_ExceptionIf $matchTable or $intersectionTable is not a table class or is not loadable.

Definition at line 1001 of file Abstract.php.

1003  {
1004  $db = $this->_getTable()->getAdapter();
1005 
1006  if (is_string($intersectionTable)) {
1007  $intersectionTable = $this->_getTableFromString($intersectionTable);
1008  }
1009 
1010  if (!$intersectionTable instanceof Zend_Db_Table_Abstract) {
1011  $type = gettype($intersectionTable);
1012  if ($type == 'object') {
1013  $type = get_class($intersectionTable);
1014  }
1015  #require_once 'Zend/Db/Table/Row/Exception.php';
1016  throw new Zend_Db_Table_Row_Exception("Intersection table must be a Zend_Db_Table_Abstract, but it is $type");
1017  }
1018 
1019  // even if we are interacting between a table defined in a class and a
1020  // table via extension, ensure to persist the definition
1021  if (($tableDefinition = $this->_table->getDefinition()) !== null
1022  && ($intersectionTable->getDefinition() == null)) {
1023  $intersectionTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
1024  }
1025 
1026  if (is_string($matchTable)) {
1027  $matchTable = $this->_getTableFromString($matchTable);
1028  }
1029 
1030  if (! $matchTable instanceof Zend_Db_Table_Abstract) {
1031  $type = gettype($matchTable);
1032  if ($type == 'object') {
1033  $type = get_class($matchTable);
1034  }
1035  #require_once 'Zend/Db/Table/Row/Exception.php';
1036  throw new Zend_Db_Table_Row_Exception("Match table must be a Zend_Db_Table_Abstract, but it is $type");
1037  }
1038 
1039  // even if we are interacting between a table defined in a class and a
1040  // table via extension, ensure to persist the definition
1041  if (($tableDefinition = $this->_table->getDefinition()) !== null
1042  && ($matchTable->getDefinition() == null)) {
1043  $matchTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
1044  }
1045 
1046  if ($select === null) {
1047  $select = $matchTable->select();
1048  } else {
1049  $select->setTable($matchTable);
1050  }
1051 
1052  // Use adapter from intersection table to ensure correct query construction
1053  $interInfo = $intersectionTable->info();
1054  $interDb = $intersectionTable->getAdapter();
1055  $interName = $interInfo['name'];
1056  $interSchema = isset($interInfo['schema']) ? $interInfo['schema'] : null;
1057  $matchInfo = $matchTable->info();
1058  $matchName = $matchInfo['name'];
1059  $matchSchema = isset($matchInfo['schema']) ? $matchInfo['schema'] : null;
1060 
1061  $matchMap = $this->_prepareReference($intersectionTable, $matchTable, $matchRefRule);
1062 
1063  for ($i = 0; $i < count($matchMap[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
1064  $interCol = $interDb->quoteIdentifier('i' . '.' . $matchMap[Zend_Db_Table_Abstract::COLUMNS][$i], true);
1065  $matchCol = $interDb->quoteIdentifier('m' . '.' . $matchMap[Zend_Db_Table_Abstract::REF_COLUMNS][$i], true);
1066  $joinCond[] = "$interCol = $matchCol";
1067  }
1068  $joinCond = implode(' AND ', $joinCond);
1069 
1070  $select->from(array('i' => $interName), array(), $interSchema)
1071  ->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
1072  ->setIntegrityCheck(false);
1073 
1074  $callerMap = $this->_prepareReference($intersectionTable, $this->_getTable(), $callerRefRule);
1075 
1076  for ($i = 0; $i < count($callerMap[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
1077  $callerColumnName = $db->foldCase($callerMap[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
1078  $value = $this->_data[$callerColumnName];
1079  $interColumnName = $interDb->foldCase($callerMap[Zend_Db_Table_Abstract::COLUMNS][$i]);
1080  $interCol = $interDb->quoteIdentifier("i.$interColumnName", true);
1081  $interInfo = $intersectionTable->info();
1082  $type = $interInfo[Zend_Db_Table_Abstract::METADATA][$interColumnName]['DATA_TYPE'];
1083  $select->where($interDb->quoteInto("$interCol = ?", $value, $type));
1084  }
1085 
1086  $stmt = $select->query();
1087 
1088  $config = array(
1089  'table' => $matchTable,
1090  'data' => $stmt->fetchAll(Zend_Db::FETCH_ASSOC),
1091  'rowClass' => $matchTable->getRowClass(),
1092  'readOnly' => false,
1093  'stored' => true
1094  );
1095 
1096  $rowsetClass = $matchTable->getRowsetClass();
1097  if (!class_exists($rowsetClass)) {
1098  try {
1099  #require_once 'Zend/Loader.php';
1100  Zend_Loader::loadClass($rowsetClass);
1101  } catch (Zend_Exception $e) {
1102  #require_once 'Zend/Db/Table/Row/Exception.php';
1103  throw new Zend_Db_Table_Row_Exception($e->getMessage(), $e->getCode(), $e);
1104  }
1105  }
1106  $rowset = new $rowsetClass($config);
1107  return $rowset;
1108  }
_prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
Definition: Abstract.php:853
static loadClass($class, $dirs=null)
Definition: Loader.php:52
$config
Definition: fraud_order.php:17
const FETCH_ASSOC
Definition: Db.php:142
const SQL_WILDCARD
Definition: Select.php:66
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
_getTableFromString($tableName)
Definition: Abstract.php:1179
$i
Definition: gallery.phtml:31

◆ findParentRow()

findParentRow (   $parentTable,
  $ruleKey = null,
Zend_Db_Table_Select  $select = null 
)

Query a parent table to retrieve the single row matching the current row.

Parameters
string | Zend_Db_Table_Abstract$parentTable
stringOPTIONAL $ruleKey
Zend_Db_Table_SelectOPTIONAL $select
Returns
Zend_Db_Table_Row_Abstract Query result from $parentTable
Exceptions
Zend_Db_Table_Row_ExceptionIf $parentTable is not a table or is not loadable.

Definition at line 934 of file Abstract.php.

935  {
936  $db = $this->_getTable()->getAdapter();
937 
938  if (is_string($parentTable)) {
939  $parentTable = $this->_getTableFromString($parentTable);
940  }
941 
942  if (!$parentTable instanceof Zend_Db_Table_Abstract) {
943  $type = gettype($parentTable);
944  if ($type == 'object') {
945  $type = get_class($parentTable);
946  }
947  #require_once 'Zend/Db/Table/Row/Exception.php';
948  throw new Zend_Db_Table_Row_Exception("Parent table must be a Zend_Db_Table_Abstract, but it is $type");
949  }
950 
951  // even if we are interacting between a table defined in a class and a
952  // table via extension, ensure to persist the definition
953  if (($tableDefinition = $this->_table->getDefinition()) !== null
954  && ($parentTable->getDefinition() == null)) {
955  $parentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
956  }
957 
958  if ($select === null) {
959  $select = $parentTable->select();
960  } else {
961  $select->setTable($parentTable);
962  }
963 
964  $map = $this->_prepareReference($this->_getTable(), $parentTable, $ruleKey);
965 
966  // iterate the map, creating the proper wheres
967  for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
968  $dependentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
969  $value = $this->_data[$dependentColumnName];
970  // Use adapter from parent table to ensure correct query construction
971  $parentDb = $parentTable->getAdapter();
972  $parentColumnName = $parentDb->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
973  $parentColumn = $parentDb->quoteIdentifier($parentColumnName, true);
974  $parentInfo = $parentTable->info();
975 
976  // determine where part
977  $type = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
978  $nullable = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['NULLABLE'];
979  if ($value === null && $nullable == true) {
980  $select->where("$parentColumn IS NULL");
981  } elseif ($value === null && $nullable == false) {
982  return null;
983  } else {
984  $select->where("$parentColumn = ?", $value, $type);
985  }
986 
987  }
988 
989  return $parentTable->fetchRow($select);
990  }
_prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
Definition: Abstract.php:853
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
_getTableFromString($tableName)
Definition: Abstract.php:1179
$i
Definition: gallery.phtml:31

◆ getIterator()

getIterator ( )

Definition at line 645 of file Abstract.php.

646  {
647  return new ArrayIterator((array) $this->_data);
648  }

◆ getPrimaryKey()

getPrimaryKey (   $useDirty = true)

Retrieves an associative array of primary keys.

Parameters
bool$useDirty
Returns
array

Definition at line 733 of file Abstract.php.

734  {
735  return $this->_getPrimaryKey($useDirty);
736  }
_getPrimaryKey($useDirty=true)
Definition: Abstract.php:707

◆ getTable()

getTable ( )

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

Returns
Zend_Db_Table_Abstract|null

Definition at line 322 of file Abstract.php.

323  {
324  return $this->_table;
325  }

◆ getTableClass()

getTableClass ( )

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

Returns
string

Definition at line 375 of file Abstract.php.

376  {
377  return $this->_tableClass;
378  }

◆ init()

init ( )

Initialize object

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

Returns
void

Definition at line 313 of file Abstract.php.

314  {
315  }

◆ isConnected()

isConnected ( )

Test the connected status of the row.

Returns
boolean

Definition at line 385 of file Abstract.php.

386  {
387  return $this->_connected;
388  }

◆ isReadOnly()

isReadOnly ( )

Test the read-only status of the row.

Returns
boolean

Definition at line 395 of file Abstract.php.

396  {
397  return $this->_readOnly;
398  }

◆ offsetExists()

offsetExists (   $offset)

Proxy to __isset Required by the ArrayAccess implementation

Parameters
string$offset
Returns
boolean

Definition at line 266 of file Abstract.php.

267  {
268  return $this->__isset($offset);
269  }

◆ offsetGet()

offsetGet (   $offset)

Proxy to __get Required by the ArrayAccess implementation

Parameters
string$offset
Returns
string

Definition at line 278 of file Abstract.php.

279  {
280  return $this->__get($offset);
281  }

◆ offsetSet()

offsetSet (   $offset,
  $value 
)

Proxy to __set Required by the ArrayAccess implementation

Parameters
string$offset
mixed$value

Definition at line 290 of file Abstract.php.

291  {
292  $this->__set($offset, $value);
293  }
$value
Definition: gender.phtml:16
__set($columnName, $value)
Definition: Abstract.php:192

◆ offsetUnset()

offsetUnset (   $offset)

Proxy to __unset Required by the ArrayAccess implementation

Parameters
string$offset

Definition at line 301 of file Abstract.php.

302  {
303  return $this->__unset($offset);
304  }

◆ refresh()

refresh ( )

Refreshes properties from the database.

Returns
void

Definition at line 682 of file Abstract.php.

683  {
684  return $this->_refresh();
685  }

◆ save()

save ( )

Saves the properties to the database.

This performs an intelligent insert/update, and reloads the properties with fresh data from the table on success.

Returns
mixed The primary key value(s), as an associative array if the key is compound, or a scalar if the key is single-column.

If the _cleanData array is empty, this is an INSERT of a new row. Otherwise it is an UPDATE.

Definition at line 430 of file Abstract.php.

431  {
437  if (empty($this->_cleanData)) {
438  return $this->_doInsert();
439  } else {
440  return $this->_doUpdate();
441  }
442  }

◆ select()

select ( )

Returns an instance of the parent table's Zend_Db_Table_Select object.

Returns
Zend_Db_Table_Select

Definition at line 416 of file Abstract.php.

417  {
418  return $this->getTable()->select();
419  }

◆ setFromArray()

setFromArray ( array  $data)

Sets all data in the row from an array.

Parameters
array$data
Returns
Zend_Db_Table_Row_Abstract Provides a fluent interface

Definition at line 666 of file Abstract.php.

667  {
668  $data = array_intersect_key($data, $this->_data);
669 
670  foreach ($data as $columnName => $value) {
671  $this->__set($columnName, $value);
672  }
673 
674  return $this;
675  }
$value
Definition: gender.phtml:16
__set($columnName, $value)
Definition: Abstract.php:192

◆ setReadOnly()

setReadOnly (   $flag)

Set the read-only status of the row.

Parameters
boolean$flag
Returns
boolean

Definition at line 406 of file Abstract.php.

407  {
408  $this->_readOnly = (bool) $flag;
409  }

◆ setTable()

setTable ( Zend_Db_Table_Abstract  $table = null)

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

Parameters
Zend_Db_Table_Abstract$table
Returns
boolean
Exceptions
Zend_Db_Table_Row_Exception

Definition at line 335 of file Abstract.php.

336  {
337  if ($table == null) {
338  $this->_table = null;
339  $this->_connected = false;
340  return false;
341  }
342 
343  $tableClass = get_class($table);
344  if (! $table instanceof $this->_tableClass) {
345  #require_once 'Zend/Db/Table/Row/Exception.php';
346  throw new Zend_Db_Table_Row_Exception("The specified Table is of class $tableClass, expecting class to be instance of $this->_tableClass");
347  }
348 
349  $this->_table = $table;
350  $this->_tableClass = $tableClass;
351 
352  $info = $this->_table->info();
353 
354  if ($info['cols'] != array_keys($this->_data)) {
355  #require_once 'Zend/Db/Table/Row/Exception.php';
356  throw new Zend_Db_Table_Row_Exception('The specified Table does not have the same columns as the Row');
357  }
358 
359  if (! array_intersect((array) $this->_primary, $info['primary']) == (array) $this->_primary) {
360 
361  #require_once 'Zend/Db/Table/Row/Exception.php';
362  throw new Zend_Db_Table_Row_Exception("The specified Table '$tableClass' does not have the same primary key as the Row");
363  }
364 
365  $this->_connected = true;
366  return true;
367  }
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
$table
Definition: trigger.php:14

◆ toArray()

toArray ( )

Returns the column/value data as an array.

Returns
array

Definition at line 655 of file Abstract.php.

656  {
657  return (array)$this->_data;
658  }

Field Documentation

◆ $_cleanData

$_cleanData = array()
protected

Definition at line 54 of file Abstract.php.

◆ $_connected

$_connected = true
protected

Definition at line 78 of file Abstract.php.

◆ $_data

$_data = array()
protected

Definition at line 45 of file Abstract.php.

◆ $_modifiedFields

$_modifiedFields = array()
protected

Definition at line 62 of file Abstract.php.

◆ $_primary

$_primary
protected

Definition at line 101 of file Abstract.php.

◆ $_readOnly

$_readOnly = false
protected

Definition at line 87 of file Abstract.php.

◆ $_table

$_table = null
protected

Definition at line 69 of file Abstract.php.

◆ $_tableClass

$_tableClass = null
protected

Definition at line 94 of file Abstract.php.


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