2007-09-21 22:01:08 +04:00
|
|
|
<?php
|
|
|
|
class Doctrine_Resource_Collection extends Doctrine_Access implements Countable, IteratorAggregate
|
|
|
|
{
|
|
|
|
public $data = array();
|
|
|
|
public $config = array();
|
|
|
|
public $model = null;
|
|
|
|
|
2007-09-22 05:32:48 +04:00
|
|
|
public function __construct($model, $config)
|
2007-09-21 22:19:19 +04:00
|
|
|
{
|
|
|
|
$this->model = $model;
|
2007-09-22 05:32:48 +04:00
|
|
|
$this->config = $config;
|
2007-09-21 22:19:19 +04:00
|
|
|
}
|
|
|
|
|
2007-09-21 22:01:08 +04:00
|
|
|
public function count()
|
|
|
|
{
|
|
|
|
return count($data);
|
|
|
|
}
|
|
|
|
|
2007-09-22 05:32:48 +04:00
|
|
|
public function get($get)
|
|
|
|
{
|
|
|
|
if (isset($this->data[$get])) {
|
|
|
|
return $this->data[$get];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function set($set, $value)
|
|
|
|
{
|
|
|
|
$this->data[$set] = $value;
|
|
|
|
}
|
|
|
|
|
2007-09-21 22:01:08 +04:00
|
|
|
public function getIterator()
|
|
|
|
{
|
|
|
|
$data = $this->data;
|
|
|
|
|
|
|
|
return new ArrayIterator($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFirst()
|
|
|
|
{
|
2007-09-21 22:43:27 +04:00
|
|
|
return isset($this->data[0]) ? $this->data[0]:null;
|
2007-09-21 22:01:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function toArray()
|
|
|
|
{
|
|
|
|
$array = array();
|
2007-09-22 05:32:48 +04:00
|
|
|
|
2007-09-21 22:34:10 +04:00
|
|
|
foreach ($this->data as $key => $record) {
|
2007-09-21 22:01:08 +04:00
|
|
|
$array[$key] = $record->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
2007-09-21 22:34:10 +04:00
|
|
|
|
|
|
|
public function save()
|
|
|
|
{
|
|
|
|
foreach ($this->data as $record) {
|
|
|
|
$record->save();
|
|
|
|
}
|
|
|
|
}
|
2007-09-21 22:01:08 +04:00
|
|
|
}
|