You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.2 KiB
61 lines
1.2 KiB
<?php namespace Majestic\Model;
|
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
class SqlResultCollection extends \ArrayIterator implements iSqlResultItems, Arrayable
|
|
{
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* Get the collection of items as a plain array.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function toArray()
|
|
{
|
|
return array_map(function($value)
|
|
{
|
|
return $value instanceof ArrayableInterface ? $value->toArray() : $value;
|
|
|
|
}, $this->items);
|
|
}
|
|
}
|