public function __construct(Hayate_ORM $orm, $items = 10, $page = 1, array $where = array()) { if (!is_numeric($items) || $items <= 0) { $items = 10; } if (!is_numeric($page) || $page <= 0) { $page = 1; } $this->previous = false; $this->next = false; $this->total = $orm->count($where); if ($this->total <= $items) { $this->offset = 0; $this->pages = 1; $this->items = $orm->where($where)->findAll(); $page = 1; } else { $this->pages = ceil($this->total / $items); if ($page > $this->pages) { $page = $this->pages; } $this->offset = ($page - 1) * $items; $this->items = $orm->where($where)->findAll($items, $this->offset); if ($page > 1 && $this->pages > 1) { $this->previous = $page - 1; } if ($page < $this->pages) { $this->next = $page + 1; } } $this->page = $page; $this->layout = null; }
/** * @see Iterator::current */ public function current() { if ($this->model) { $orm = Hayate_ORM::factory($this->model); return $orm->fromArray($this->rows[$this->offset]); } return $this->rows[$this->offset]; }
public function __get($name) { if (array_key_exists($name, $this->fields)) { return $this->fields[$name]->value; } else { if (isset($this->cache[$name])) { return $this->cache[$name]; } else { if (in_array($name, $this->hasOne)) { $fk = $name . '_id'; $orm = Hayate_ORM::factory($name, $this->{$fk}); if ($orm->loaded()) { $this->cache[$name] = $orm; return $orm; } return null; } else { if (in_array($name, $this->hasMany)) { $fk = $this->class_name . '_id'; $orm = Hayate_ORM::factory($name)->where($fk, $this->{$this->primary_key})->findAll(); if ($orm instanceof Hayate_Database_Iterator) { $this->cache[$name] = $orm; return $orm; } return null; } } } } throw new Hayate_Database_Exception(sprintf(_('Field %s does not exists.'), $name)); }