public function index()
 {
     $p_var = Config::getPaginationVariable();
     $current_page = array_get($this->context, 'current_page');
     $total_pages = array_get($this->context, 'total_pages');
     $pages_to_show = $this->fetchParam('pages_to_show', 5, 'is_numeric', false, false);
     $q_strings = URL::sanitize($_GET);
     // catch less than 1 total pages
     if ($total_pages <= 1) {
         return 0;
     }
     $listing = '';
     $lower = max(1, min(floor($current_page - ($pages_to_show - 1) / 2), $total_pages - $pages_to_show + 1));
     $upper = $lower + min($total_pages, $pages_to_show) - 1;
     for ($i = $lower; $i <= $upper; $i++) {
         if ($i == $current_page) {
             $listing .= '<li class="active">';
         } else {
             $listing .= '<li>';
         }
         $q = http_build_query(array_merge($q_strings, array($p_var => $i)));
         $listing .= '<a href="{{ url }}?' . $q . '">' . $i . '</a></li>';
     }
     return $listing;
 }
Example #2
0
    /**
     * Paginates a list of entries
     *
     * @return string
     */
    public function pagination()
    {
        // grab common parameters
        $settings = $this->parseCommonParameters();

        // grab content set based on the common parameters
        $content_set = $this->getContentSet($settings);

        // grab limit as page size
        $limit = $this->fetchParam('limit', 10, 'is_numeric'); // defaults to none

        // count the content available
        $count = $content_set->count();

        $pagination_variable = Config::getPaginationVariable();
        $page                = Request::get($pagination_variable, 1);

        $data                       = array();
        $data['total_items']        = (int) max(0, $count);
        $data['items_per_page']     = (int) max(1, $limit);
        $data['total_pages']        = (int) ceil($count / $limit);
        $data['current_page']       = (int) min(max(1, $page), max(1, $page));
        $data['current_first_item'] = (int) min((($page - 1) * $limit) + 1, $count);
        $data['current_last_item']  = (int) min($data['current_first_item'] + $limit - 1, $count);
        $data['previous_page']      = ($data['current_page'] > 1) ? "?{$pagination_variable}=" . ($data['current_page'] - 1) : FALSE;
        $data['next_page']          = ($data['current_page'] < $data['total_pages']) ? "?{$pagination_variable}=" . ($data['current_page'] + 1) : FALSE;
        $data['first_page']         = ($data['current_page'] === 1) ? FALSE : "?{$pagination_variable}=1";
        $data['last_page']          = ($data['current_page'] >= $data['total_pages']) ? FALSE : "?{$pagination_variable}=" . $data['total_pages'];
        $data['offset']             = (int) (($data['current_page'] - 1) * $limit);

        return Parse::template($this->content, $data);
    }
Example #3
0
File: url.php Project: nob/joi
 /**
  * Gets the value of pagination in the current URL
  *
  * @return int
  */
 public static function getCurrentPaginationPage()
 {
     return Helper::pick(Request::get(Config::getPaginationVariable()), 1);
 }
Example #4
0
File: statamic.php Project: nob/joi
 public static function get_pagination_variable()
 {
     Log::warn("Use of Statamic::get_pagination_variable() is deprecated. Use Config::getPaginationVariable() instead.", "core", "Statamic");
     return Config::getPaginationVariable();
 }
 public static function createPaginationData($count, $limit)
 {
     $q_strings = URL::sanitize($_GET);
     $p_var = Config::getPaginationVariable();
     $page = Request::get($p_var, 1);
     $current_page = (int) min(max(1, $page), max(1, $page));
     $data = array();
     $data['current_page'] = $current_page;
     $data['total_items'] = (int) max(0, $count);
     $data['items_per_page'] = (int) max(1, $limit);
     $data['total_pages'] = (int) ceil($count / $limit);
     $data['current_first_item'] = (int) min(($page - 1) * $limit + 1, $count);
     $data['current_last_item'] = (int) min($data['current_first_item'] + $limit - 1, $count);
     $data['offset'] = (int) (($current_page - 1) * $limit);
     $data['previous_page'] = $current_page > 1 ? '?' . http_build_query(array_merge($q_strings, array($p_var => $current_page - 1))) : FALSE;
     $data['next_page'] = $current_page < $data['total_pages'] ? '?' . http_build_query(array_merge($q_strings, array($p_var => $current_page + 1))) : FALSE;
     $data['first_page'] = $current_page === 1 ? FALSE : '?' . http_build_query(array_merge($q_strings, array($p_var => 1)));
     $data['last_page'] = $current_page >= $data['total_pages'] ? FALSE : '?' . http_build_query(array_merge($q_strings, array($p_var => $data['total_pages'])));
     return $data;
 }
Example #6
0
 /**
  * Paginate search results
  * 
  * @return string
  */
 public function pagination()
 {
     // determine configuration
     $dataset = $this->fetch('dataset', null, false, false, false);
     $parameters = $this->gatherParameters();
     $config = $this->tasks->loadDataset($dataset, $parameters);
     // short-circuit this if no query
     if (!trim($config['query'])) {
         return Parse::tagLoop($this->content, array(array('no_query' => true, '_query' => '')));
     }
     // do search
     $output = $this->tasks->lookUp($config['query'], $config);
     // get limit
     $limit = $config['limit'] ? $config['limit'] : 10;
     // get the query variables
     $query_var = $config['query_variable'];
     $query = urlencode($config['query']);
     // count the content available
     $count = count($output);
     // take page_limit into account
     if ($config['page_limit'] && $count > $config['page_limit'] * $limit) {
         $count = $config['page_limit'] * $limit;
     }
     // check for errors
     if (isset($output[0]['no_results']) || isset($output[0]['no_query'])) {
         return Parse::tagLoop($this->content, $output);
     }
     $pagination_variable = Config::getPaginationVariable();
     $page = Request::get($pagination_variable, 1);
     $data = array('total_items' => (int) max(0, $count), 'items_per_page' => (int) max(1, $limit), 'total_pages' => (int) ceil($count / $limit), 'current_page' => (int) min(max(1, $page), max(1, $page)), 'current_first_item' => (int) min(($page - 1) * $limit + 1, $count));
     $data['current_last_item'] = (int) min($data['current_first_item'] + $limit - 1, $count);
     $data['previous_page'] = $data['current_page'] > 1 ? "?{$pagination_variable}=" . ($data['current_page'] - 1) . "&{$query_var}={$query}" : FALSE;
     $data['next_page'] = $data['current_page'] < $data['total_pages'] ? "?{$pagination_variable}=" . ($data['current_page'] + 1) . "&{$query_var}={$query}" : FALSE;
     $data['first_page'] = $data['current_page'] === 1 ? FALSE : "?{$pagination_variable}=1&{$query_var}={$query}";
     $data['last_page'] = $data['current_page'] >= $data['total_pages'] ? FALSE : "?{$pagination_variable}=" . $data['total_pages'] . "&{$query_var}={$query}";
     $data['offset'] = (int) (($data['current_page'] - 1) * $limit);
     return Parse::template($this->content, $data);
 }
Example #7
0
 /**
  * Paginates a list of entries
  *
  * @return string
  */
 public function pagination()
 {
     $folders = $this->fetchParam('folder', ltrim($this->fetchParam('from', URL::getCurrent()), "/"));
     $folders = $folders === "/" ? "" : $folders;
     if ($this->fetchParam('taxonomy', false, null, true, null)) {
         $taxonomy_parts = Taxonomy::getCriteria(URL::getCurrent());
         $taxonomy_type = $taxonomy_parts[0];
         $taxonomy_slug = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);
         $content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $folders);
     } else {
         $content_set = ContentService::getContentByFolders($folders);
     }
     // grab limit as page size
     $limit = $this->fetchParam('limit', 10, 'is_numeric');
     // defaults to none
     // filter
     $content_set->filter(array('show_all' => $this->fetchParam('show_hidden', false, null, true, false), 'since' => $this->fetchParam('since'), 'until' => $this->fetchParam('until'), 'show_past' => $this->fetchParam('show_past', TRUE, NULL, TRUE), 'show_future' => $this->fetchParam('show_future', FALSE, NULL, TRUE), 'type' => 'entries', 'conditions' => trim($this->fetchParam('conditions', ""))));
     // sort
     $content_set->sort($this->fetchParam('sort_by', 'order_key'), $this->fetchParam('sort_dir'));
     // count the content available
     $count = $content_set->count();
     $pagination_variable = Config::getPaginationVariable();
     $page = Request::get($pagination_variable, 1);
     $data = array();
     $data['total_items'] = (int) max(0, $count);
     $data['items_per_page'] = (int) max(1, $limit);
     $data['total_pages'] = (int) ceil($count / $limit);
     $data['current_page'] = (int) min(max(1, $page), max(1, $page));
     $data['current_first_item'] = (int) min(($page - 1) * $limit + 1, $count);
     $data['current_last_item'] = (int) min($data['current_first_item'] + $limit - 1, $count);
     $data['previous_page'] = $data['current_page'] > 1 ? "?{$pagination_variable}=" . ($data['current_page'] - 1) : FALSE;
     $data['next_page'] = $data['current_page'] < $data['total_pages'] ? "?{$pagination_variable}=" . ($data['current_page'] + 1) : FALSE;
     $data['first_page'] = $data['current_page'] === 1 ? FALSE : "?{$pagination_variable}=1";
     $data['last_page'] = $data['current_page'] >= $data['total_pages'] ? FALSE : "?{$pagination_variable}=" . $data['total_pages'];
     $data['offset'] = (int) (($data['current_page'] - 1) * $limit);
     return Parse::template($this->content, $data);
 }