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.

44 lines
896 B

11 years ago
11 years ago
  1. <?php namespace Majestic\Model;
  2. class SqlResultCollection extends \ArrayIterator implements iSqlResultItems
  3. {
  4. private $items;
  5. public function __construct($items)
  6. {
  7. $this->items = $items;
  8. foreach ($items as $item) {
  9. parent::append($item);
  10. }
  11. }
  12. /**
  13. * @return DbStatement[]
  14. */
  15. public function fetchAll()
  16. {
  17. return (array) $this;
  18. }
  19. /**
  20. * @param $field
  21. * @return mixed
  22. */
  23. public function fetchField($field)
  24. {
  25. $item = $this->offsetGet(0);
  26. return $item->{$field};
  27. }
  28. /**
  29. * @return mixed
  30. */
  31. public function fetch()
  32. {
  33. return $this->offsetGet(0);
  34. }
  35. public function assoc($field, $assoc_as_array = false) {
  36. $sql_result_provider = new SqlResultProvider($this->items);
  37. return $sql_result_provider->assoc($field, $assoc_as_array);
  38. }
  39. }