Browse Source

Add assoc method into SqlResultCollection

namespace
Alexander Demidov 11 years ago
parent
commit
9e359e0c25
  1. 5
      Model/SqlResultCollection.php
  2. 6
      Model/SqlResultProvider.php

5
Model/SqlResultCollection.php

@ -37,4 +37,9 @@ class SqlResultCollection extends \ArrayIterator implements iSqlResultItems
{ {
return $this->offsetGet(0); 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);
}
} }

6
Model/SqlResultProvider.php

@ -19,7 +19,7 @@ class SqlResultProvider implements iSqlResultItems
private $result_items_base; private $result_items_base;
/** /**
* @param $result DbStatement
* @param $result DbStatement|array
*/ */
public function __construct($result) public function __construct($result)
{ {
@ -29,7 +29,11 @@ class SqlResultProvider implements iSqlResultItems
private function defineResultItems() private function defineResultItems()
{ {
if (is_null($this->result_items_base)) { if (is_null($this->result_items_base)) {
if (is_array($this->result)) {
$this->result_items_base = $this->result;
} else {
$this->result_items_base = $this->result->fetchAll(); $this->result_items_base = $this->result->fetchAll();
}
$this->result_items = $this->result_items_base; $this->result_items = $this->result_items_base;
} }
} }

Loading…
Cancel
Save