/** * ライブラリパッケージを一覧する * @param string $path */ public function find($path = null) { $object_list = array(); $pattern = $this->map_arg('pattern'); if ($pattern !== null) { $path = vsprintf($pattern, func_get_args()); } $path = Path::slash(Path::absolute($this->base(), Path::slash($path, false, true)), null, true) . 'packages.csv'; $query = $this->in_vars('query'); $paginator = new \org\rhaco\Paginator(30, $this->in_vars('page', 1)); if (is_file($path)) { foreach (file($path) as $line) { $line = trim($line); if ($line != '') { if (empty($query) || stripos($line, $query) !== false) { list($package, $summary) = explode(',', $line, 2); $model = new Model(); $model->package($package); $model->summary($summary); $paginator->add($model); } } } } $this->vars('object_list', $paginator->contents()); $this->vars('paginator', $paginator->vars(array('query' => $query))); }
eq(10, $p->which_last(3)); $p = new \org\rhaco\Paginator(3, 2); $list = array(1, 2, 3, 4, 5, 6, 7, 8, 9); foreach ($list as $v) { $p->add($v); } eq(array(4, 5, 6), $p->contents()); eq(2, $p->current()); eq(1, $p->first()); eq(3, $p->last()); eq(9, $p->total()); $p = new \org\rhaco\Paginator(3, 2); $list = array(1, 2, 3, 4, 5); foreach ($list as $v) { $p->add($v); } eq(array(4, 5), $p->contents()); eq(2, $p->current()); eq(1, $p->first()); eq(2, $p->last()); eq(5, $p->total()); $p = new \org\rhaco\Paginator(3); $list = array(1, 2); foreach ($list as $v) { $p->add($v); } eq(array(1, 2), $p->contents()); eq(1, $p->current()); eq(1, $p->first()); eq(1, $p->last()); eq(2, $p->total());