This commit is contained in:
parent
b3cf15a1dd
commit
9ea8d5da70
@ -46,21 +46,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
*/
|
||||
protected $reference;
|
||||
/**
|
||||
* @var string $reference_field the reference field of the collection
|
||||
* @var string $referenceField the reference field of the collection
|
||||
*/
|
||||
protected $reference_field;
|
||||
protected $referenceField;
|
||||
/**
|
||||
* @var Doctrine_Relation the record this collection is related to, if any
|
||||
*/
|
||||
protected $relation;
|
||||
/**
|
||||
* @var boolean $expandable whether or not this collection has been expanded
|
||||
*/
|
||||
protected $expandable = true;
|
||||
/**
|
||||
* @var array $expanded
|
||||
*/
|
||||
protected $expanded = array();
|
||||
/**
|
||||
* @var string $keyColumn the name of the column that is used for collection key mapping
|
||||
*/
|
||||
@ -110,27 +102,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
/**
|
||||
* setAggregateValue
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function setAggregateValue($name, $value)
|
||||
{
|
||||
$this->aggregateValues[$name] = $value;
|
||||
}
|
||||
/**
|
||||
* getAggregateValue
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAggregateValue($name)
|
||||
{
|
||||
return $this->aggregateValues[$name];
|
||||
}
|
||||
/**
|
||||
* this method is automatically called when this Doctrine_Collection is serialized
|
||||
*
|
||||
@ -178,26 +149,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
$this->keyColumn = $name;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* isExpanded
|
||||
*
|
||||
* whether or not an offset batch has been expanded
|
||||
* @return boolean
|
||||
*/
|
||||
public function isExpanded($offset)
|
||||
{
|
||||
return isset($this->expanded[$offset]);
|
||||
}
|
||||
/**
|
||||
* isExpandable
|
||||
*
|
||||
* whether or not this collection is expandable
|
||||
* @return boolean
|
||||
*/
|
||||
public function isExpandable()
|
||||
{
|
||||
return $this->expandable;
|
||||
}
|
||||
/**
|
||||
* setKeyColumn
|
||||
*
|
||||
@ -269,15 +220,15 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
|| $relation instanceof Doctrine_Relation_LocalKey
|
||||
) {
|
||||
|
||||
$this->reference_field = $relation->getForeign();
|
||||
$this->referenceField = $relation->getForeign();
|
||||
|
||||
$value = $record->get($relation->getLocal());
|
||||
|
||||
foreach ($this->getNormalIterator() as $record) {
|
||||
if ($value !== null) {
|
||||
$record->set($this->reference_field, $value, false);
|
||||
$record->set($this->referenceField, $value, false);
|
||||
} else {
|
||||
$record->set($this->reference_field, $this->reference, false);
|
||||
$record->set($this->referenceField, $this->reference, false);
|
||||
}
|
||||
}
|
||||
} elseif ($relation instanceof Doctrine_Relation_Association) {
|
||||
@ -293,127 +244,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
/**
|
||||
* expand
|
||||
* expands the collection
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function expand($key)
|
||||
{
|
||||
$where = array();
|
||||
$params = array();
|
||||
$limit = null;
|
||||
$offset = null;
|
||||
|
||||
switch (get_class($this)) {
|
||||
case "Doctrine_Collection_Offset":
|
||||
$limit = $this->getLimit();
|
||||
$offset = (floor($key / $limit) * $limit);
|
||||
|
||||
if ( ! $this->expandable && isset($this->expanded[$offset])) {
|
||||
return false;
|
||||
}
|
||||
$fields = implode(", ",$this->table->getColumnNames());
|
||||
break;
|
||||
default:
|
||||
if ( ! $this->expandable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! isset($this->reference)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = $this->reference->obtainIdentifier();
|
||||
|
||||
if (empty($id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (get_class($this)) {
|
||||
case "Doctrine_Collection_Immediate":
|
||||
$fields = implode(", ",$this->table->getColumnNames());
|
||||
break;
|
||||
default:
|
||||
$fields = implode(", ",$this->table->getPrimaryKeys());
|
||||
};
|
||||
};
|
||||
|
||||
if (isset($this->relation)) {
|
||||
if ($this->relation instanceof Doctrine_Relation_ForeignKey) {
|
||||
$params[] = $this->reference->getIncremented();
|
||||
$where[] = $this->reference_field." = ?";
|
||||
|
||||
if ( ! isset($offset)) {
|
||||
$ids = $this->getPrimaryKeys();
|
||||
|
||||
if ( ! empty($ids)) {
|
||||
$where[] = $this->table->getIdentifier()." NOT IN (".substr(str_repeat("?, ",count($ids)),0,-2).")";
|
||||
$params = array_merge($params,$ids);
|
||||
}
|
||||
|
||||
$this->expandable = false;
|
||||
}
|
||||
|
||||
} elseif ($this->relation instanceof Doctrine_Relation_Association) {
|
||||
|
||||
$asf = $this->relation->getAssociationFactory();
|
||||
$query = 'SELECT '.$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented();
|
||||
|
||||
$table = $fk->getTable();
|
||||
$graph = new Doctrine_Query($table->getConnection());
|
||||
|
||||
$q = 'FROM ' . $table->getComponentName() . ' WHERE ' . $table->getComponentName() . '.' . $table->getIdentifier()." IN ($query)";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$query = "SELECT ".$fields." FROM ".$this->table->getTableName();
|
||||
|
||||
// apply column aggregation inheritance
|
||||
$map = $this->table->inheritanceMap;
|
||||
foreach ($map as $k => $v) {
|
||||
$where[] = $k." = ?";
|
||||
$params[] = $v;
|
||||
}
|
||||
if ( ! empty($where)) {
|
||||
$query .= " WHERE ".implode(" AND ",$where);
|
||||
}
|
||||
|
||||
$coll = $this->table->execute($query, $params, $limit, $offset);
|
||||
|
||||
if ( ! isset($offset)) {
|
||||
foreach ($coll as $record) {
|
||||
if (isset($this->reference_field)) {
|
||||
$record->set($this->reference_field,$this->reference, false);
|
||||
}
|
||||
$this->reference->addReference($record, $this->relation);
|
||||
}
|
||||
} else {
|
||||
$i = $offset;
|
||||
|
||||
foreach ($coll as $record) {
|
||||
if (isset($this->reference)) {
|
||||
$this->reference->addReference($record, $this->relation, $i);
|
||||
} else {
|
||||
$this->data[$i] = $record;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$this->expanded[$offset] = true;
|
||||
|
||||
// check if the fetched collection's record count is smaller
|
||||
// than the query limit, if so this collection has been expanded to its max size
|
||||
|
||||
if (count($coll) < $limit) {
|
||||
$this->expandable = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $coll;
|
||||
}
|
||||
/**
|
||||
* remove
|
||||
* removes a specified collection element
|
||||
@ -467,8 +297,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
if ($key === null) {
|
||||
$record = $this->table->create();
|
||||
|
||||
if (isset($this->reference_field)) {
|
||||
$record->set($this->reference_field, $this->reference, false);
|
||||
if (isset($this->referenceField)) {
|
||||
$record->set($this->referenceField, $this->reference, false);
|
||||
}
|
||||
|
||||
$this->data[] = $record;
|
||||
@ -478,19 +308,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
|
||||
|
||||
if ( ! isset($this->data[$key])) {
|
||||
$this->expand($key);
|
||||
|
||||
if ( ! isset($this->data[$key])) {
|
||||
$this->data[$key] = $this->table->create();
|
||||
}
|
||||
if (isset($this->reference_field)) {
|
||||
if (isset($this->referenceField)) {
|
||||
$value = $this->reference->get($this->relation->getLocal());
|
||||
|
||||
if ($value !== null) {
|
||||
$this->data[$key]->set($this->reference_field, $value, false);
|
||||
$this->data[$key]->set($this->referenceField, $value, false);
|
||||
} else {
|
||||
|
||||
$this->data[$key]->set($this->reference_field, $this->reference, false);
|
||||
$this->data[$key]->set($this->referenceField, $this->reference, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -512,7 +339,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
} else {
|
||||
$list[] = $record->getIncremented();
|
||||
}
|
||||
};
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
/**
|
||||
@ -542,8 +369,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
*/
|
||||
public function set($key, Doctrine_Record $record)
|
||||
{
|
||||
if (isset($this->reference_field)) {
|
||||
$record->set($this->reference_field, $this->reference, false);
|
||||
if (isset($this->referenceField)) {
|
||||
$record->set($this->referenceField, $this->reference, false);
|
||||
}
|
||||
$this->data[$key] = $record;
|
||||
}
|
||||
@ -555,8 +382,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
*/
|
||||
public function add(Doctrine_Record $record,$key = null)
|
||||
{
|
||||
if (isset($this->reference_field)) {
|
||||
$record->set($this->reference_field, $this->reference, false);
|
||||
if (isset($this->referenceField)) {
|
||||
$record->set($this->referenceField, $this->reference, false);
|
||||
}
|
||||
/**
|
||||
* for some weird reason in_array cannot be used here (php bug ?)
|
||||
@ -720,7 +547,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
|
||||
foreach ($this as $key => $record) {
|
||||
$record->save($conn);
|
||||
};
|
||||
}
|
||||
|
||||
$conn->commit();
|
||||
}
|
||||
|
@ -111,10 +111,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* @var array $references an array containing all the references
|
||||
*/
|
||||
private $references = array();
|
||||
/**
|
||||
* @var array $originals an array containing all the original references
|
||||
*/
|
||||
private $originals = array();
|
||||
/**
|
||||
* @var integer $index this index is used for creating object identifiers
|
||||
*/
|
||||
@ -611,8 +607,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
}
|
||||
}
|
||||
|
||||
if ($err)
|
||||
if ($err) {
|
||||
throw new Doctrine_Record_State_Exception('Unknown record state ' . $state);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* refresh
|
||||
@ -622,7 +619,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* this record represents does not exist anymore)
|
||||
* @return boolean
|
||||
*/
|
||||
final public function refresh()
|
||||
public function refresh()
|
||||
{
|
||||
$id = $this->obtainIdentifier();
|
||||
if ( ! is_array($id)) {
|
||||
@ -661,7 +658,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* @throws Doctrine_Record_Exception When the primary key of this record doesn't match the primary key fetched from a collection
|
||||
* @return void
|
||||
*/
|
||||
final public function factoryRefresh()
|
||||
public function factoryRefresh()
|
||||
{
|
||||
$this->_data = $this->_table->getData();
|
||||
$old = $this->_id;
|
||||
@ -670,8 +667,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->prepareIdentifiers();
|
||||
|
||||
if ($this->_id != $old)
|
||||
if ($this->_id != $old) {
|
||||
throw new Doctrine_Record_Exception("The refreshed primary key doesn't match the one in the record memory.", Doctrine::ERR_REFRESH);
|
||||
}
|
||||
|
||||
$this->_state = Doctrine_Record::STATE_CLEAN;
|
||||
$this->_modified = array();
|
||||
@ -684,7 +682,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
*
|
||||
* @return object Doctrine_Table a Doctrine_Table object
|
||||
*/
|
||||
final public function getTable()
|
||||
public function getTable()
|
||||
{
|
||||
return $this->_table;
|
||||
}
|
||||
@ -694,7 +692,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
*
|
||||
* @return array an array containing all the properties
|
||||
*/
|
||||
final public function getData()
|
||||
public function getData()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
@ -707,7 +705,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* @throws Doctrine_Record_Exception if trying to get an unknown property
|
||||
* @return mixed
|
||||
*/
|
||||
|
||||
public function rawGet($name)
|
||||
{
|
||||
if ( ! isset($this->_data[$name])) {
|
||||
@ -718,7 +715,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* load
|
||||
* loads all the unitialized properties from the database
|
||||
@ -1164,19 +1160,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
{
|
||||
return new Doctrine_Record_Iterator($this);
|
||||
}
|
||||
/**
|
||||
* getOriginals
|
||||
* returns an original collection of related component
|
||||
*
|
||||
* @return Doctrine_Collection|false
|
||||
*/
|
||||
public function obtainOriginals($name)
|
||||
{
|
||||
if (isset($this->originals[$name])) {
|
||||
return $this->originals[$name];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* deletes this data access object and all the related composites
|
||||
* this operation is isolated by a transaction
|
||||
@ -1255,17 +1238,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$this->_modified = array();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* assignOriginals
|
||||
*
|
||||
* @param string $alias
|
||||
* @param Doctrine_Collection $coll
|
||||
* @return void
|
||||
*/
|
||||
public function assignOriginals($alias, Doctrine_Collection $coll)
|
||||
{
|
||||
$this->originals[$alias] = $coll;
|
||||
}
|
||||
/**
|
||||
* returns the primary keys of this object
|
||||
*
|
||||
@ -1347,24 +1319,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function lazyInitRelated(Doctrine_Collection $coll, Doctrine_Relation $connector)
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
* addReference
|
||||
* @param Doctrine_Record $record
|
||||
* @param mixed $key
|
||||
* @return void
|
||||
*/
|
||||
public function addReference(Doctrine_Record $record, Doctrine_Relation $connector, $key = null)
|
||||
{
|
||||
$alias = $connector->getAlias();
|
||||
|
||||
$this->references[$alias]->add($record, $key);
|
||||
$this->originals[$alias]->add($record, $key);
|
||||
}
|
||||
/**
|
||||
* getReferences
|
||||
* @return array all references
|
||||
@ -1373,17 +1327,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
{
|
||||
return $this->references;
|
||||
}
|
||||
/**
|
||||
* setRelated
|
||||
*
|
||||
* @param string $alias
|
||||
* @param Doctrine_Access $coll
|
||||
*/
|
||||
final public function setRelated($alias, Doctrine_Access $coll)
|
||||
{
|
||||
$this->references[$alias] = $coll;
|
||||
$this->originals[$alias] = $coll;
|
||||
}
|
||||
/**
|
||||
* loadReference
|
||||
* loads a related component
|
||||
@ -1394,7 +1337,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
*/
|
||||
final public function loadReference($name)
|
||||
{
|
||||
|
||||
$fk = $this->_table->getRelation($name);
|
||||
|
||||
if ($fk->isOneToOne()) {
|
||||
@ -1404,7 +1346,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$coll = $fk->fetchRelatedFor($this);
|
||||
|
||||
$this->references[$name] = $coll;
|
||||
$this->originals[$name] = clone $coll;
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -1562,17 +1503,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$this->_table->setOption($name, $value);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* index
|
||||
* defines a foreignKey
|
||||
*
|
||||
* @param array $definition the definition array
|
||||
* @return void
|
||||
*/
|
||||
public function foreignKey(array $definition = array())
|
||||
{
|
||||
return $this->_table->addForeignKey($definition);
|
||||
}
|
||||
/**
|
||||
* index
|
||||
* defines or retrieves an index
|
||||
|
Loading…
x
Reference in New Issue
Block a user