Horde_Core_Ui_Pager::render PHP Méthode

render() public méthode

Render the pager.
public render ( $data = null ) : string
Résultat string HTML code containing a centered table with the pager links.
    public function render($data = null)
    {
        $num = $this->_config['num'];
        $url = $this->_config['url'];
        $page_limit = $this->_config['page_limit'];
        $perpage = $this->_config['perpage'];
        $current_page = $this->_vars->get($this->_name);
        // Figure out how many pages there will be.
        $pages = $num / $perpage;
        if (is_integer($pages)) {
            $pages--;
        }
        $pages = (int) $pages;
        // Return nothing if there is only one page.
        if ($pages == 0 || $num == 0) {
            return '';
        }
        $html = '<div class="pager">';
        if ($current_page > 0) {
            // Create the '<< Prev' link if we are not on the first page.
            $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $current_page - 1)));
            $prev_text = isset($this->_config['previousHTML']) ? $this->_config['previousHTML'] : htmlspecialchars(Horde_Core_Translation::t("<Previous"));
            $html .= Horde::link($link, '', 'prev') . $prev_text . '</a>';
        }
        // Figure out the top & bottom display limits.
        $bottom = max(0, $current_page - $page_limit / 2 + 1);
        $top = $bottom + $page_limit - 1;
        if ($top - 1 > $pages) {
            $bottom -= $top - 1 - $pages;
            $top = $pages + 1;
        }
        // Create bottom '[x-y]' link if necessary.
        if ($bottom > 0) {
            $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $bottom - 1)));
            $html .= ' ' . Horde::link($link, '', 'prevRange') . '[' . ($bottom == 1 ? $bottom : '1-' . $bottom) . ']</a>';
        }
        // Create links to individual pages between limits.
        for ($i = $bottom; $i <= $top && $i <= $pages; ++$i) {
            if ($i == $current_page) {
                $html .= ' <strong>(' . ($i + 1) . ')</strong>';
            } elseif ($i >= 0 && $i <= $pages) {
                $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $i)));
                $html .= ' ' . Horde::link($link) . ($i + 1) . '</a>';
            }
        }
        // Create top '[x-y]' link if necessary.
        if ($top < $pages) {
            $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $top + 1)));
            $html .= ' ' . Horde::link($link, '', 'nextRange') . '[' . ($top + 2 == $pages + 1 ? $pages + 1 : $top + 2 . '-' . ($pages + 1)) . ']</a>';
        }
        // Create the 'Next>>' link if we are not on the last page.
        if ($current_page < $pages) {
            $link = $this->_link($this->_addPreserved($url->copy()->add($this->_name, $current_page + 1)));
            $next_text = isset($this->_config['nextHTML']) ? $this->_config['nextHTML'] : htmlspecialchars(Horde_Core_Translation::t("Next>"));
            $html .= ' ' . Horde::link($link, '', 'next') . $next_text . '</a>';
        }
        return $html . '</div>';
    }

Usage Example

Exemple #1
0
/* Which forums page are we on?  Default to page 0. */
$forum_page = Horde_Util::getFormData('forum_page', 0);
$forums_per_page = $prefs->getValue('forums_per_page');
$forum_start = $forum_page * $forums_per_page;
/* Get the list of forums. */
try {
    $forums_list = $forums->getForums(0, true, $sort_by, $sort_dir, true, $forum_start, $forums_per_page);
    $forums_count = $forums->countForums();
} catch (Horde_Exception_NotFound $e) {
    $forums_count = 0;
}
/* Set up the column headers. */
$col_headers = array('forum_name' => _("Forum"), 'forum_description' => _("Description"), 'message_count' => _("Posts"), 'thread_count' => _("Threads"), 'message_timestamp' => _("Last Post"), 'message_author' => _("Posted by"), 'message_date' => _("Date"));
$col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'forums');
/* Set up the template tags. */
$view = new Agora_View();
$view->col_headers = $col_headers;
$view->forums_list = $forums_list;
Horde::startBuffer();
$notification->notify(array('listeners' => 'status'));
$view->notify = Horde::endBuffer();
$view->actions = empty($actions) ? null : $actions;
/* Set up pager. */
$vars = Horde_Variables::getDefaultVariables();
$pager_ob = new Horde_Core_Ui_Pager('forum_page', $vars, array('num' => $forums_count, 'url' => 'forums.php', 'perpage' => $forums_per_page));
$pager_ob->preserve('scope', $scope);
$view->pager_link = $pager_ob->render();
$page_output->addLinkTag(array('href' => Horde::url('rss/index.php', true, -1)->add('scope', $scope), 'title' => _("Forums")));
$page_output->header(array('title' => _("All Forums")));
echo $view->render('forums');
$page_output->footer();
All Usage Examples Of Horde_Core_Ui_Pager::render
Horde_Core_Ui_Pager