예제 #1
0
$format = $sf_data->getRaw('format');
$use_keys = in_array('keys', $format);
$text_html = in_array('html', $format);
$add_gpx_track = in_array('track', $format);
$add_all_fields = in_array('full', $format);
$add_conditions = $add_all_fields || in_array('cond', $format);
$add_text = !in_array('notext', $format);
if (!isset($items) && $nb_results > 0) {
    $items = $pager->getResults('array', ESC_RAW);
    $items = Language::parseListItems($items, c2cTools::module2model($module));
} elseif ($nb_results == 0) {
    $items = array();
    $totalItems = $startIndex = $count = $hasPreviousPage = $hasNextPage = 0;
}
if (isset($pager)) {
    $totalItems = $pager->getNbResults();
    $startIndex = $pager->getMaxPerPage() * ($pager->getPage() - 1) + 1;
    $count = min($pager->getMaxPerPage(), $pager->getNbResults() - ($pager->getPage() - 1) * $pager->getMaxPerPage());
    $hasPreviousPage = $pager->getPage() != 1;
    $hasNextPage = $pager->getPage() != $pager->getLastPage() && $nb_results;
}
// compute prev and next uris
if ($hasPreviousPage || $hasNextPage) {
    $uri = _addUrlParameters(_getBaseUri(), array('page'));
    $uri .= _getSeparator($uri) . 'page=';
}
$features = array();
foreach ($items as $item) {
    $features[] = json_decode(get_partial($module . '/jsonlist_body', array('item' => $item, 'use_keys' => $use_keys, 'text_html' => $text_html, 'add_gpx_track' => $add_gpx_track, 'add_conditions' => $add_conditions, 'add_all_fields' => $add_all_fields, 'add_text' => $add_text)));
}
echo json_encode(array('type' => 'FeatureCollection', 'metadata' => array('totalItems' => $totalItems, 'nbItems' => $count, 'startIndex' => $startIndex, 'currentPage' => sfContext::getInstance()->getRequest()->getUri(), 'nextPage' => $hasNextPage ? absolute_link(url_for($uri . $pager->getNextPage())) : null, 'previousPage' => $hasPreviousPage ? absolute_link(url_for($uri . $pager->getPreviousPage())) : null, 'baseLanguage' => __('meta_language'), 'generated' => date(DATE_RFC2822)), 'features' => $features), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
예제 #2
0
function pager_navigation($pager, $class = array())
{
    sfLoader::loadHelpers(array('General'));
    $navigation = '';
    if ($pager->haveToPaginate()) {
        $context = sfContext::getInstance();
        $request = $context->getRequest();
        $orderby_params = array('orderby', 'orderby2', 'orderby3');
        $order_params = array('order', 'order2', 'order3');
        $orderby_list = c2cTools::getRequestParameterArray($orderby_params);
        $order_list = c2cTools::getRequestParameterArray($order_params);
        $params = array();
        foreach ($orderby_params as $key => $orderby_param) {
            $params[$orderby_param] = $orderby_list[$key];
            $params[$order_params[$key]] = $order_list[$key];
        }
        $uri = _addUrlParameters(_getBaseUri(), array(), $params);
        $uri .= _getSeparator($uri) . 'page=';
        // First and previous pages
        if ($pager->getPage() != 1) {
            $navigation .= link_to(picto_tag('action_first', __('first page')), $uri . '1');
            $navigation .= ' ';
            $navigation .= link_to(picto_tag('action_back', __('previous page')), $uri . $pager->getPreviousPage());
            $navigation .= '  ';
        }
        // Pages one by one
        $links = array();
        foreach ($pager->getLinks() as $page) {
            $links[] = link_to_unless($page == $pager->getPage(), $page, $uri . $page);
        }
        $navigation .= implode('  ', $links);
        // Next and last pages
        if ($pager->getPage() != $pager->getLastPage()) {
            $navigation .= '  ';
            $navigation .= link_to(picto_tag('action_next', __('next page')), $uri . $pager->getNextPage());
            $navigation .= ' ';
            $navigation .= link_to(picto_tag('action_last', __('last page')), $uri . $pager->getLastPage());
        }
    }
    $class[] = 'pages_navigation';
    return '<div class="' . implode(' ', $class) . '">' . $navigation . '</div>';
}