2007-09-21 22:01:08 +04:00
|
|
|
<?php
|
2007-09-23 02:02:58 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.phpdoctrine.com>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Doctrine_Resource_Collection
|
|
|
|
*
|
|
|
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
|
|
* @package Doctrine
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @version $Revision$
|
|
|
|
* @category Object Relational Mapping
|
|
|
|
* @link www.phpdoctrine.com
|
|
|
|
* @since 1.0
|
|
|
|
*/
|
2007-09-21 22:01:08 +04:00
|
|
|
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-23 02:02:58 +04:00
|
|
|
}
|