Files
majestic/Model/SqlResultCollection.php

45 lines
896 B
PHP
Raw Normal View History

2014-06-02 18:58:49 +04:00
<?php namespace Majestic\Model;
2014-06-02 18:58:49 +04:00
class SqlResultCollection extends \ArrayIterator implements iSqlResultItems
{
private $items;
public function __construct($items)
{
$this->items = $items;
foreach ($items as $item) {
parent::append($item);
}
}
/**
* @return DbStatement[]
*/
public function fetchAll()
{
return (array) $this;
}
/**
* @param $field
* @return mixed
*/
public function fetchField($field)
{
$item = $this->offsetGet(0);
return $item->{$field};
}
/**
* @return mixed
*/
public function fetch()
{
return $this->offsetGet(0);
}
public function assoc($field, $assoc_as_array = false) {
$sql_result_provider = new SqlResultProvider($this->items);
return $sql_result_provider->assoc($field, $assoc_as_array);
}
}