Commit 6db25011 authored by Jonathan.Wage's avatar Jonathan.Wage

Added docs and enhanced fromArray()

parent c97fc19d
...@@ -661,16 +661,33 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -661,16 +661,33 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return $data; return $data;
} }
/**
* fromArray
*
* Populate a Doctrine_Collection from an array of data
*
* @param string $array
* @return void
*/
public function fromArray($array) public function fromArray($array)
{ {
$data = array(); $data = array();
foreach ($array as $row) { foreach ($array as $rowKey => $row) {
$record = $this->_table->getRecord(); $this[$rowKey]->fromArray($row);
$record->fromArray($row);
$this[] = $record;
} }
} }
/**
* exportTo
*
* Export a Doctrine_Collection to one of the supported Doctrine_Parser formats
*
* @param string $type
* @param string $deep
* @return void
*/
public function exportTo($type, $deep = false) public function exportTo($type, $deep = false)
{ {
if ($type == 'array') { if ($type == 'array') {
...@@ -679,6 +696,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -679,6 +696,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return Doctrine_Parser::dump($this->toArray($deep, true), $type); return Doctrine_Parser::dump($this->toArray($deep, true), $type);
} }
} }
/**
* importFrom
*
* Import data to a Doctrine_Collection from one of the supported Doctrine_Parser formats
*
* @param string $type
* @param string $data
* @return void
*/
public function importFrom($type, $data) public function importFrom($type, $data)
{ {
if ($type == 'array') { if ($type == 'array') {
...@@ -687,10 +714,22 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -687,10 +714,22 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return $this->fromArray(Doctrine_Parser::load($data, $type)); return $this->fromArray(Doctrine_Parser::load($data, $type));
} }
} }
/**
* getDeleteDiff
*
* @return void
*/
public function getDeleteDiff() public function getDeleteDiff()
{ {
return array_udiff($this->_snapshot, $this->data, array($this, "compareRecords")); return array_udiff($this->_snapshot, $this->data, array($this, "compareRecords"));
} }
/**
* getInsertDiff
*
* @return void
*/
public function getInsertDiff() public function getInsertDiff()
{ {
return array_udiff($this->data, $this->_snapshot, array($this, "compareRecords")); return array_udiff($this->data, $this->_snapshot, array($this, "compareRecords"));
...@@ -702,7 +741,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -702,7 +741,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/ */
protected function compareRecords($a, $b) protected function compareRecords($a, $b)
{ {
if ($a->getOid() == $b->getOid()) return 0; if ($a->getOid() == $b->getOid()) {
return 0;
}
return ($a->getOid() > $b->getOid()) ? 1 : -1; return ($a->getOid() > $b->getOid()) ? 1 : -1;
} }
...@@ -719,6 +761,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -719,6 +761,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if ($conn == null) { if ($conn == null) {
$conn = $this->_table->getConnection(); $conn = $this->_table->getConnection();
} }
$conn->beginTransaction(); $conn->beginTransaction();
$conn->transaction->addCollection($this); $conn->transaction->addCollection($this);
......
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