hPagination.php

The hPagination.php helper provides a set of functions to generate dynamic pagination links for various parts of your Osclass site, including search results, comments, and generic listings. It offers flexible configuration via an associative array of parameters, which lets you customize CSS classes, link texts, URL formats, and the overall pagination behavior. Additionally, there are specialized functions for the admin panel and for displaying result ranges.

Functions Description

osc_search_pagination() – Gets the pagination links for search pagination.

osc_comments_pagination() – Gets the pagination links for comments pagination.

osc_pagination($params = null) – Gets generic pagination links.

Advanced Information

osc_search_pagination()

This function generates pagination links for search results. It checks whether a custom search URI is available:

  • If a search URI exists in the view (using View::newInstance()->_exists('search_uri')), the function sets:
    • url – The base URL concatenated with the search URI and a {PAGE} placeholder.
    • first_url – The base URL concatenated with the search URI (without the page variable).
  • Otherwise, it falls back to setting first_url using osc_update_search_url(array('iPage' => null)).

A new Pagination instance is created with these parameters, and the function returns the generated pagination links.

osc_comments_pagination()

This function builds pagination links for comments on an item. It first checks whether pagination is needed by verifying:

  • If the number of comments per page (osc_comments_per_page()) is 0,
  • If osc_item_comments_page() is "all", or
  • If the total number of comments (from osc_item_total_comments()) is less than or equal to the comments per page.

If any of these conditions are true, it returns an empty string. Otherwise, it calculates the total number of pages using ceil(osc_item_total_comments()/osc_comments_per_page()), builds a parameters array with:

  • total – Total pages
  • selected – Current comment page
  • url – URL template generated by osc_item_comments_url('{PAGE}')

A Pagination instance is then created with these parameters, and its output is returned.

osc_pagination($params = null)

This generic pagination function accepts an optional associative array $params that customizes its behavior. The available parameter keys are:

  • total: Number of total pages (default: osc_search_total_pages()).
  • selected: The current page number (starting at 0; default: osc_search_page()).
  • class_first: CSS class for the first link (default: "searchPaginationFirst").
  • class_last: CSS class for the last link (default: "searchPaginationLast").
  • class_prev: CSS class for the previous link (default: "searchPaginationPrev").
  • class_next: CSS class for the next link (default: "searchPaginationNext").
  • text_first: Text for the first link (default: "«").
  • text_prev: Text for the previous link (default: "»").
  • text_next: Text for the next link (default: "<").
  • text_last: Text for the last link (default: ">").
  • class_selected: CSS class for the selected link (default: "searchPaginationSelected").
  • class_non_selected: CSS class for non-selected links (default: "searchPaginationNonSelected").
  • delimiter: Delimiter between links (default: " ").
  • force_limits: Boolean indicating if the first/last links should always be shown even on the first/last page (default: false).
  • sides: Number of page links to show on each side of the current page (default: 2).
  • url: URL template with a {PAGE} placeholder (default: osc_update_search_url(array('iPage' => '{PAGE}'))).
  • first_url: URL for the first page without the page variable (default: osc_update_search_url(array('iPage' => null))).

The function creates a new Pagination instance using these parameters and returns the output of doPagination().

osc_show_pagination_admin($aData)

This function is used in the admin panel to display pagination links. It expects an associative array $aData containing:

  • iPage: The current page number.
  • iTotalDisplayRecords: The total number of records after filtering.
  • iDisplayLength: The number of records displayed per page.

The function calculates the total number of pages by dividing iTotalDisplayRecords by iDisplayLength (using ceil()), and builds a parameters array with:

  • total: Total pages.
  • selected: Current page number minus one (since pagination indexes start at 0).
  • url: The current admin URL with the page parameter formatted as &iPage={PAGE}.
  • sides: Number of page links to show on each side (default: 5).

It then renders a form that allows manual page input and outputs the pagination links.

osc_pagination_showing($from, $to, $filtered, $total = null)

This function returns a descriptive string indicating the range of results currently being displayed. The parameters include:

  • $from: The starting record number.
  • $to: The ending record number.
  • $filtered: The total number of records after filtering.
  • $total (optional): The overall total number of records.

If $total is provided and greater than $filtered, the function returns a string formatted as: "Showing from to to of filtered results (filtered from total total results)". Otherwise, it returns: "Showing from to to of filtered results".