Tdt\Core\Pager::calculateLimitAndOffset PHP Method

calculateLimitAndOffset() public static method

Calculate the limit and offset based on the request string parameters.
public static calculateLimitAndOffset ( $limit = null )
    public static function calculateLimitAndOffset($limit = null)
    {
        if (empty($limit)) {
            $limit = self::$DEFAULT_PAGE_SIZE;
        }
        $limit = \Input::get('limit', $limit);
        $offset = \Input::get('offset', 0);
        // Calculate the limit and offset, if only page and optionally page_size are given
        $page = \Input::get('page', 1);
        if ($offset == 0 && $page > 1) {
            $page_size = \Input::get('page_size', $limit);
            // Don't do extra work when page and page_size are also default values
            if ($page > 1 || $page_size != $limit) {
                $offset = ($page - 1) * $page_size;
                $limit = $page_size;
            } elseif ($page == -1) {
                $limit = PHP_INT_MAX;
                $offset = 0;
            }
        } elseif ($limit == -1) {
            $limit = PHP_INT_MAX;
        }
        return array((int) $limit, (int) $offset);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Create the DCAT document of the published (non-draft) resources
  *
  * @param $pieces array of uri pieces
  * @return mixed \Data object with a graph of DCAT information
  */
 private function createDcat()
 {
     $ns = $this->dcat->getNamespaces();
     foreach ($ns as $prefix => $uri) {
         \EasyRdf_Namespace::set($prefix, $uri);
     }
     // Apply paging when fetching the definitions
     list($limit, $offset) = Pager::calculateLimitAndOffset();
     $definition_count = $this->definitions->countPublished();
     $definitions = $this->definitions->getAllPublished($limit, $offset);
     $oldest = $this->definitions->getOldest();
     $describedDefinitions = array();
     // Add the source type description to the definition
     foreach ($definitions as $definition) {
         $definition = array_merge($definition, $this->definitions->getFullDescription($definition['collection_uri'] . '/' . $definition['resource_name']));
         array_push($describedDefinitions, $definition);
     }
     $graph = $this->dcat->getDcatDocument($describedDefinitions, $oldest);
     // Return the dcat feed in our internal data object
     $data_result = new Data();
     $data_result->data = $graph;
     $data_result->is_semantic = true;
     $data_result->paging = Pager::calculatePagingHeaders($limit, $offset, $definition_count);
     // Add the semantic configuration for the ARC graph
     $data_result->semantic = new \stdClass();
     $data_result->semantic->conf = array('ns' => $ns);
     $data_result->definition = new \stdClass();
     $data_result->definition->resource_name = 'dcat';
     $data_result->definition->collection_uri = 'info';
     return $data_result;
 }
All Usage Examples Of Tdt\Core\Pager::calculateLimitAndOffset