function __construct($text, $current = null, $len = 4096) { $pages = array(); $text = trim(str_replace("\r", "", $text)); // :( $titles = array(); if (strpos($text, "\n++ ") === false) { $pattern = "/^(.{1," . $len . "}\n\n).{" . $len / 2 . ",}/s"; $i = 1; while (preg_match($pattern, $text, $res)) { $text = str_replace($res[1], '', $text); $titles[$i] = $i; $pages[$i++] = $res[1]; } $pages[$i] = $text; $titles[$i] = $i; } else { $slices = preg_split('/^\\+\\+ (.*)$/m', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); for ($i = 0; $i < count($slices); $i += 2) { $id = wtk_strtoid($slices[$i]); $titles[$id] = $slices[$i]; $pages[$id] = "++ " . $slices[$i] . $slices[$i + 1]; } } parent::__construct($pages, 1, $current); $this->titles = $titles; $this->pages_id = array_keys($titles); $this->current = in_array($current, $this->pages_id) ? $current : reset($this->pages_id); }
function __construct(Iterator $data, $item_per_page = 15, $current = 1) { parent::__construct($data, $item_per_page, $current); $this->pages_count = max(1, round($data->count() / $item_per_page + 0.49)); // we need integer to use array_flip. $this->pages_id = array_map('intval', range(1, $this->pages_count)); $this->offset = ($this->current - 1) * $this->item_per_page; $this->current = min(max(1, intval($current)), $this->pages_count); }
function __construct(Wtk_Form_Model $model) { parent::__construct($model, 1, '$$init$$'); // un groupe par page $this->root = $model->getInstance(); $model->addNewSubmission('precedent', 'Précédent'); $model->addNewSubmission('continuer', 'Continuer'); try { $model->addNewSubmission('terminer', 'Terminer'); } catch (Exception $e) { } $model->addString('$$current$$', 'Current group', null); }
function __construct(Zend_Db_Table_Select $select, $count = 15, $current = 1) { $table = $select->getTable(); $this->select = $select->distinct(); $this->row_count = $table->countRows($select); $this->pages_count = intval(ceil($this->row_count / $count)); $current = min($current, $this->pages_count); // selection les tuples de cette pages. $select->limitPage($current, $count); $rowset = $table->fetchAll($select); parent::__construct($rowset, $count, $current); $this->pages_id = range(1, $this->pagesCount(), 1); }
function __construct(array $data, $current = null) { $this->pointer = null; parent::__construct($data, 1, $current); $this->pages_id = array_keys($data); $this->current = null; if ($this->pages_id) { if (in_array($current, $this->pages_id)) { $this->current = $current; } else { if ($current > ($last = end($this->pages_id))) { $this->current = $last; } else { $this->current = reset($this->pages_id); } } } }
function __construct($table, $where = array(), $order = array(), $count = 15, $current = 1) { $db = $table->getAdapter(); $info = $table->info(); // select total row count $select = $db->select()->from($info[Zend_Db_Table_Abstract::NAME], array('count' => 'COUNT(*)')); if ($where) { $select->where($where); } $stmt = $db->query($select->__toString()); $this->rowcount = $stmt->fetchColumn(); // select current page rows $current = $current ? $current : 1; $offset = ($current - 1) * $count; $data = $table->fetchAll($where, $order, $count, $offset); parent::__construct($data, $count, $current); $page_count = intval(ceil($this->rowcount / $this->item_per_page)); $this->pages_id = $this->rowcount ? range(1, $page_count) : array(); }