return $this->_values[$fieldName];
}
- try {
- if ( ! isset($this->_references[$fieldName]) && $load) {
- $rel = $this->_table->getRelation($fieldName);
- $this->_references[$fieldName] = $rel->fetchRelatedFor($this);
- }
- return $this->_references[$fieldName];
- } catch (IPF_ORM_Exception_Table $e) {
- foreach ($this->_table->getFilters() as $filter) {
- if (($value = $filter->filterGet($this, $fieldName, $value)) !== null) {
- return $value;
- }
- }
+ if (!isset($this->_references[$fieldName]) && $load) {
+ $rel = $this->_table->getRelation($fieldName);
+ $this->_references[$fieldName] = $rel->fetchRelatedFor($this);
}
+ return $this->_references[$fieldName];
}
public function mapValue($name, $value)
}
}
} else {
- try {
- $this->coreSetRelated($fieldName, $value);
- } catch (IPF_ORM_Exception_Table $e) {
- foreach ($this->_table->getFilters() as $filter) {
- if (($value = $filter->filterSet($this, $fieldName, $value)) !== null) {
- break;
- }
- }
- }
+ $this->coreSetRelated($fieldName, $value);
}
return $this;
return $this;
}
- public function unshiftFilter(IPF_ORM_Record_Filter $filter)
- {
- return $this->_table->unshiftFilter($filter);
- }
-
public function unlink($alias, $ids = array())
{
$ids = (array) $ids;
}
}
- public function bindQueryParts(array $queryParts)
- {
- $this->_table->bindQueryParts($queryParts);
- return $this;
- }
-
public function loadGenerator(IPF_ORM_Record_Generator $generator)
{
$generator->initialize($this->_table);
+++ /dev/null
-<?php
-
-abstract class IPF_ORM_Record_Filter
-{
- protected $_table;
-
- public function setTable(IPF_ORM_Table $table)
- {
- $this->_table = $table;
- }
-
- public function getTable()
- {
- return $this->_table;
- }
-
- abstract public function filterSet(IPF_ORM_Record $record, $name, $value);
- abstract public function filterGet(IPF_ORM_Record $record, $name);
-}
\ No newline at end of file
+++ /dev/null
-<?php
-
-class IPF_ORM_Record_Filter_Compound extends IPF_ORM_Record_Filter
-{
- protected $_aliases = array();
-
- public function __construct(array $aliases)
- {
- $this->_aliases = $aliases;
- }
- public function init()
- {
- // check that all aliases exist
- foreach ($this->_aliases as $alias) {
- $this->_table->getRelation($alias);
- }
- }
-
- public function filterSet(IPF_ORM_Record $record, $name, $value)
- {
- foreach ($this->_aliases as $alias) {
- if ( ! $record->exists()) {
- if (isset($record[$alias][$name])) {
- $record[$alias][$name] = $value;
-
- return $record;
- }
- } else {
- // we do not want to execute N + 1 queries here, hence we cannot use get()
- if (($ref = $record->reference($alias)) !== null) {
- if (isset($ref[$name])) {
- $ref[$name] = $value;
- }
-
- return $record;
- }
- }
- }
- }
-
- public function filterGet(IPF_ORM_Record $record, $name)
- {
- foreach ($this->_aliases as $alias) {
- if ( ! $record->exists()) {
- if (isset($record[$alias][$name])) {
- return $record[$alias][$name];
- }
- } else {
- // we do not want to execute N + 1 queries here, hence we cannot use get()
- if (($ref = $record->reference($alias)) !== null) {
- if (isset($ref[$name])) {
- return $ref[$name];
- }
- }
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-<?php
-
-class IPF_ORM_Record_Filter_Standard extends IPF_ORM_Record_Filter
-{
- public function filterSet(IPF_ORM_Record $record, $name, $value)
- {
- throw new IPF_ORM_Exception(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
- }
-
- public function filterGet(IPF_ORM_Record $record, $name)
- {
- throw new IPF_ORM_Exception(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
- }
-}
\ No newline at end of file
protected $_parser;
protected $_templates = array();
- protected $_filters = array();
protected $_generators = array();
protected $_invokedMethods = array();
$name::setUp($this);
- $this->_filters[] = new IPF_ORM_Record_Filter_Standard();
$this->_repository = new IPF_ORM_Table_Repository($this);
}
return $record;
}
- final public function getProxy($id = null)
- {
- if ($id !== null) {
- $identifierColumnNames = $this->getIdentifierColumnNames();
- $query = 'SELECT ' . implode(', ', (array) $identifierColumnNames)
- . ' FROM ' . $this->getTableName()
- . ' WHERE ' . implode(' = ? && ', (array) $identifierColumnNames) . ' = ?';
- $query = $this->applyInheritance($query);
-
- $params = array_merge(array($id), array_values($this->_options['inheritanceMap']));
-
- $this->_data = $this->_conn->execute($query, $params)->fetch(PDO::FETCH_ASSOC);
-
- if ($this->_data === false)
- return false;
- }
- return $this->getRecord();
- }
-
final public function applyInheritance($where)
{
if ( ! empty($this->_options['inheritanceMap'])) {
return $this->_options['queryParts'][$queryPart];
}
- public function unshiftFilter(IPF_ORM_Record_Filter $filter)
- {
- $filter->setTable($this);
-
- $filter->init();
-
- array_unshift($this->_filters, $filter);
-
- return $this;
- }
-
- public function getFilters()
- {
- return $this->_filters;
- }
-
public function __toString()
{
return IPF_ORM_Utils::getTableAsString($this);