private function listPublicGroups($offset) { $sql = "SELECT * FROM groups WHERE active=1 AND type <> 'private' "; require_once FRAMEWORK_PATH . 'lib/pagination/pagination.class.php'; $pagination = new Pagination($this->registry); $pagination->setQuery($sql); $pagination->setOffset($offset); $pagination->setLimit(20); $pagination->setMethod('cache'); $pagination->generatePagination(); if ($pagination->getNumRowsPage() == 0) { $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'groups/no-public.tpl.php', 'footer.tpl.php'); } else { $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'groups/public.tpl.php', 'footer.tpl.php'); $this->registry->getObject('template')->getPage()->addTag('groups', array('SQL', $pagination->getCache())); $this->registry->getObject('template')->getPage()->addTag('page_number', $pagination->getCurrentPage()); $this->registry->getObject('template')->getPage()->addTag('num_pages', $pagination->getNumPages()); if ($pagination->isFirst()) { $this->registry->getObject('template')->getPage()->addTag('first', ''); $this->registry->getObject('template')->getPage()->addTag('previous', ''); } else { $this->registry->getObject('template')->getPage()->addTag('first', "<a href='groups/'>First page</a>"); $this->registry->getObject('template')->getPage()->addTag('previous', "<a href='groups/" . ($pagination->getCurrentPage() - 2) . "'>Previous page</a>"); } if ($pagination->isLast()) { $this->registry->getObject('template')->getPage()->addTag('next', ''); $this->registry->getObject('template')->getPage()->addTag('last', ''); } else { $this->registry->getObject('template')->getPage()->addTag('first', "<a href='groups/" . $pagination->getCurrentPage() . "'>Next page</a>"); $this->registry->getObject('template')->getPage()->addTag('previous', "<a href='groups/" . ($pagination->getNumPages() - 1) . "'>Last page</a>"); } } }
public static function init() { self::$currentPage = max(1, $_GET['p']); // 外部设置当前页的值 self::$pageTotal = ceil(self::$total / self::$pageSize); if (self::$currentPage - self::$pageMoreSize > self::$borderSize) { self::$leftMore = true; } if (self::$currentPage + self::$pageMoreSize < self::$pageTotal - self::$borderSize) { self::$rightMore = true; } if (self::$currentPage == 1) { self::$isFirst = true; } if (self::$currentPage == self::$pageTotal) { self::$isLast = true; } }