Commit bfa3ef56 authored by zYne's avatar zYne

--no commit message

--no commit message
parent f787a29b
......@@ -866,7 +866,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
try {
$this->coreSetRelated($name, $value);
} catch(Doctrine_Table_Exception $e) {
throw new Doctrine_Record_Exception("Unknown property / related component '$name'.");
foreach ($this->_table->getFilters() as $filter) {
if (($value = $filter->filterSet($this, $name, $value)) !== null) {
return $value;
}
}
}
}
}
......@@ -1310,6 +1314,17 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
return isset($this->_references[$name]);
}
/**
* reference
*
* @param string $name
*/
public function reference($name)
{
if (isset($this->_references[$name])) {
return $this->_references[$name];
}
}
/**
* obtainReference
*
......@@ -1457,6 +1472,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
return $this->_node;
}
public function unshiftFilter(Doctrine_Record_Filter $filter)
{
return $this->_table->unshiftFilter($filter);
}
/**
* revert
* reverts this record to given version, this method only works if versioning plugin
......@@ -1482,7 +1502,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
return $this;
}
/**
* removeLinks
* unlink
* removes links from this record to given records
* if no ids are given, it removes all links
*
......
......@@ -35,15 +35,16 @@ class Doctrine_Record_Filter_Compound extends Doctrine_Record_Filter
protected $_aliases = array();
public function __construct(array $aliases)
{
$this->_aliases = $aliases;
}
public function init()
{
// check that all aliases exist
foreach ($aliases as $alias) {
foreach ($this->_aliases as $alias) {
$this->_table->getRelation($alias);
}
$this->_aliases = $aliases;
}
/**
* filterSet
* defines an implementation for filtering the set() method of Doctrine_Record
......@@ -52,8 +53,26 @@ class Doctrine_Record_Filter_Compound extends Doctrine_Record_Filter
*/
public function filterSet(Doctrine_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;
}
}
}
}
/**
* filterGet
* defines an implementation for filtering the get() method of Doctrine_Record
......@@ -62,6 +81,19 @@ class Doctrine_Record_Filter_Compound extends Doctrine_Record_Filter
*/
public function filterGet(Doctrine_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];
}
}
}
}
}
}
......@@ -129,20 +129,20 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*
* -- versioning
*/
protected $options = array('name' => null,
'tableName' => null,
'sequenceName' => null,
'inheritanceMap' => array(),
'enumMap' => array(),
'engine' => null,
'charset' => null,
'collation' => null,
'treeImpl' => null,
'treeOptions' => null,
'indexes' => array(),
'parents' => array(),
'versioning' => null,
);
protected $options = array('name' => null,
'tableName' => null,
'sequenceName' => null,
'inheritanceMap' => array(),
'enumMap' => array(),
'engine' => null,
'charset' => null,
'collation' => null,
'treeImpl' => null,
'treeOptions' => null,
'indexes' => array(),
'parents' => array(),
'versioning' => null,
);
/**
* @var Doctrine_Tree $tree tree object associated with this table
*/
......@@ -154,7 +154,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
/**
* @var array $_templates an array containing all templates attached to this table
*/
protected $_templates = array();
protected $_templates = array();
/**
* @var array $_filters an array containing all record filters attached to this table
*/
protected $_filters = array();
/**
......@@ -284,6 +289,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if ($this->isTree()) {
$this->getTree()->setUp();
}
$this->_filters[] = new Doctrine_Record_Filter_Standard();
$this->_repository = new Doctrine_Table_Repository($this);
}
/**
......@@ -1280,6 +1286,22 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
public function addTemplate($template, Doctrine_Template $impl)
{
$this->_templates[$template] = $impl;
return $this;
}
public function unshiftFilter(Doctrine_Record_Filter $filter)
{
$filter->setTable($this);
$filter->init();
array_unshift($this->_filters, $filter);
return $this;
}
public function getFilters()
{
return $this->_filters;
}
/**
* returns a string representation of this object
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment