Commit 91ffb084 authored by doctrine's avatar doctrine

[amadeus] added getFirst() method

parent f6fa905e
...@@ -32,7 +32,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -32,7 +32,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
/** /**
* @var boolean $expandable whether or not this collection has been expanded * @var boolean $expandable whether or not this collection has been expanded
*/ */
protected $expandable = true; protected $expandable = true;
/** /**
* @var array $expanded * @var array $expanded
*/ */
...@@ -51,7 +51,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -51,7 +51,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/ */
public function __construct(Doctrine_Table $table) { public function __construct(Doctrine_Table $table) {
$this->table = $table; $this->table = $table;
$name = $table->getAttribute(Doctrine::ATTR_COLL_KEY); $name = $table->getAttribute(Doctrine::ATTR_COLL_KEY);
if($name !== null) { if($name !== null) {
$this->generator = new Doctrine_IndexGenerator($name); $this->generator = new Doctrine_IndexGenerator($name);
...@@ -85,7 +85,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -85,7 +85,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
unset($vars['generator']); unset($vars['generator']);
$vars['table'] = $vars['table']->getComponentName(); $vars['table'] = $vars['table']->getComponentName();
return serialize($vars); return serialize($vars);
} }
/** /**
...@@ -97,13 +97,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -97,13 +97,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function unserialize($serialized) { public function unserialize($serialized) {
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
$session = $manager->getCurrentSession(); $session = $manager->getCurrentSession();
$array = unserialize($serialized); $array = unserialize($serialized);
foreach($array as $name => $values) { foreach($array as $name => $values) {
$this->$name = $values; $this->$name = $values;
} }
$this->table = $session->getTable($this->table); $this->table = $session->getTable($this->table);
$this->expanded = array(); $this->expanded = array();
...@@ -141,7 +141,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -141,7 +141,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function getGenerator() { public function getGenerator() {
return $this->generator; return $this->generator;
} }
/** /**
* @return array * @return array
*/ */
public function getData() { public function getData() {
...@@ -153,6 +153,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -153,6 +153,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function addData(array $data) { public function addData(array $data) {
$this->data[] = $data; $this->data[] = $data;
} }
/**
* @return mixed
*/
public function getFirst() {
return $this->data[0];
}
/** /**
* @return mixed * @return mixed
*/ */
...@@ -168,7 +174,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -168,7 +174,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if($relation instanceof Doctrine_ForeignKey || if($relation instanceof Doctrine_ForeignKey ||
$relation instanceof Doctrine_LocalKey) { $relation instanceof Doctrine_LocalKey) {
$this->reference_field = $relation->getForeign(); $this->reference_field = $relation->getForeign();
$value = $record->get($relation->getLocal()); $value = $record->get($relation->getLocal());
...@@ -206,10 +212,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -206,10 +212,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if( ! $this->expandable && isset($this->expanded[$offset])) if( ! $this->expandable && isset($this->expanded[$offset]))
return false; return false;
$fields = implode(", ",$this->table->getColumnNames()); $fields = implode(", ",$this->table->getColumnNames());
break; break;
default: default:
if( ! $this->expandable) if( ! $this->expandable)
return false; return false;
...@@ -239,7 +245,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -239,7 +245,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if( ! isset($offset)) { if( ! isset($offset)) {
$ids = $this->getPrimaryKeys(); $ids = $this->getPrimaryKeys();
if( ! empty($ids)) { if( ! empty($ids)) {
$where[] = $this->table->getIdentifier()." NOT IN (".substr(str_repeat("?, ",count($ids)),0,-2).")"; $where[] = $this->table->getIdentifier()." NOT IN (".substr(str_repeat("?, ",count($ids)),0,-2).")";
$params = array_merge($params,$ids); $params = array_merge($params,$ids);
...@@ -250,20 +256,20 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -250,20 +256,20 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
} elseif($this->relation instanceof Doctrine_Association) { } elseif($this->relation instanceof Doctrine_Association) {
$asf = $this->relation->getAssociationFactory(); $asf = $this->relation->getAssociationFactory();
$query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented(); $query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented();
$table = $fk->getTable(); $table = $fk->getTable();
$graph = new Doctrine_DQL_Parser($table->getSession()); $graph = new Doctrine_DQL_Parser($table->getSession());
$q = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$table->getIdentifier()." IN ($query)"; $q = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$table->getIdentifier()." IN ($query)";
} }
} }
$query = "SELECT ".$fields." FROM ".$this->table->getTableName(); $query = "SELECT ".$fields." FROM ".$this->table->getTableName();
// apply column aggregation inheritance // apply column aggregation inheritance
foreach($this->table->getInheritanceMap() as $k => $v) { foreach($this->table->getInheritanceMap() as $k => $v) {
$where[] = $k." = ?"; $where[] = $k." = ?";
...@@ -290,7 +296,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -290,7 +296,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->reference->addReference($record, $this->relation, $i); $this->reference->addReference($record, $this->relation, $i);
} else } else
$this->data[$i] = $record; $this->data[$i] = $record;
$i++; $i++;
} }
...@@ -316,7 +322,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -316,7 +322,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
} }
$removed = $this->data[$key]; $removed = $this->data[$key];
unset($this->data[$key]); unset($this->data[$key]);
return $removed; return $removed;
} }
...@@ -386,7 +392,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -386,7 +392,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return count($this->data); return count($this->data);
} }
/** /**
* set * set
* @param integer $key * @param integer $key
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
...@@ -432,7 +438,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -432,7 +438,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* populate * populate
* *
* @param Doctrine_Query $query * @param Doctrine_Query $query
* @param integer $key * @param integer $key
*/ */
public function populate(Doctrine_Hydrate $query) { public function populate(Doctrine_Hydrate $query) {
$name = $this->table->getComponentName(); $name = $this->table->getComponentName();
...@@ -457,7 +463,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -457,7 +463,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->data[$i] = $record; $this->data[$i] = $record;
unset($this->data[$k]); unset($this->data[$k]);
} }
} }
} }
} }
/** /**
......
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