Esempio n. 1
0
 /**
  * Sets the base URI
  * @param   string    $uri      The URI
  */
 function setUri($uri)
 {
     // Remove the order parameter name argument from the base URI
     Html::stripUriParam($uri, $this->orderUriParameter);
     $this->baseUri = Cx\Core\Routing\Url::encode_amp($uri);
 }
Esempio n. 2
0
 /**
  * Returs a string representing the complete paging HTML code for the
  * current page
  * @author  Reto Kohli <*****@*****.**> (Rewritten statically)
  * @access  public
  * @global  array     $_CONFIG        Configuration
  * @global  array     $_CORELANG      Core language
  * @param   string    $uri_parameter  Optional additional URI parameters,
  *                                    *MUST* start with an URI encoded
  *                                    ampersand (&amp;).  By reference
  * @param   string    $paging_text    The text to be put in front of the
  *                                    paging
  * @param   integer   $numof_rows     The number of rows available
  * @param   integer   $results_per_page   The optional maximum number of
  *                                    rows to be shown on a single page.
  *                                    Defaults to the corePagingLimit
  *                                    setting.
  * @param   boolean   $showeverytime  If true, the paging is shown even if
  *                                    $numof_rows is less than
  *                                    $results_per_page
  * @param   integer   $position       The optional starting position
  *                                    offset.  Defaults to null
  * @param   string    $parameter_name The optional name for the URI
  *                                    parameter.  Will be determined
  *                                    automatically if empty.
  * @return  string                    HTML code for the paging
  */
 static function get(&$uri_parameter, $paging_text, $numof_rows, $results_per_page = 0, $showeverytime = false, $position = null, $parameter_name = null)
 {
     global $_CONFIG, $_CORELANG;
     if (empty($results_per_page)) {
         $results_per_page = intval($_CONFIG['corePagingLimit']);
     }
     if ($numof_rows <= $results_per_page && !$showeverytime) {
         return '';
     }
     $parameter_name = self::getParametername($parameter_name);
     if (!isset($position)) {
         $position = self::getPosition($parameter_name);
     }
     // Fix illegal values:
     // The position must be in the range [0 .. numof_rows - 1].
     // If it's outside this range, reset it
     if ($position < 0 || $position >= $numof_rows) {
         $position = 0;
     }
     // Total number of pages: [1 .. n]
     $numof_pages = ceil($numof_rows / $results_per_page);
     // Current page number: [1 .. numof_pages]
     $page_number = 1 + intval($position / $results_per_page);
     $corr_value = $results_per_page;
     if ($numof_rows % $results_per_page) {
         $corr_value = $numof_rows % $results_per_page;
     }
     // remove all parameters otherwise the url object has parameters like &act=add
     $requestUrl = clone \Env::get('Resolver')->getUrl();
     $currentParams = $requestUrl->getParamArray();
     $requestUrl->removeAllParams();
     if (isset($currentParams['section'])) {
         $requestUrl->setParam('section', $currentParams['section']);
     }
     $requestUrl->setParams($uri_parameter);
     $firstUrl = clone $requestUrl;
     $firstUrl->setParam($parameter_name, 0);
     $lastUrl = clone $requestUrl;
     $lastUrl->setParam($parameter_name, $numof_rows - $corr_value);
     // Set up the base navigation entries
     $array_paging = array('first' => '<a class="pagingFirst" href="' . Cx\Core\Routing\Url::encode_amp($firstUrl) . '">', 'last' => '<a class="pagingLast" href="' . Cx\Core\Routing\Url::encode_amp($lastUrl) . '">', 'total' => $numof_rows, 'lower' => $numof_rows ? $position + 1 : 0, 'upper' => $numof_rows);
     if ($position + $results_per_page < $numof_rows) {
         $array_paging['upper'] = $position + $results_per_page;
     }
     // Note:  previous/next link are currently unused.
     if ($position != 0) {
         $previousUrl = clone $requestUrl;
         $previousUrl->setParam($parameter_name, $position - $results_per_page);
         $array_paging['previous_link'] = '<a href="' . Cx\Core\Routing\Url::encode_amp($previousUrl) . '">';
     }
     if ($numof_rows - $position > $results_per_page) {
         $int_new_position = $position + $results_per_page;
         $nextUrl = clone $requestUrl;
         $nextUrl->setParam($parameter_name, $int_new_position);
         $array_paging['next_link'] = '<a href="' . Cx\Core\Routing\Url::encode_amp($nextUrl) . '">';
     }
     // Add single pages, indexed by page numbers [1 .. numof_pages]
     for ($i = 1; $i <= $numof_pages; ++$i) {
         if ($i == $page_number) {
             $array_paging[$i] = '<b class="pagingPage' . $i . '">' . $i . '</b>';
         } else {
             $pageUrl = clone $requestUrl;
             $pageUrl->setParam($parameter_name, ($i - 1) * $results_per_page);
             $array_paging[$i] = '<a class="pagingPage' . $i . '" href="' . Cx\Core\Routing\Url::encode_amp($pageUrl) . '">' . $i . '</a>';
         }
     }
     $paging = $paging_text . '&nbsp;<span class="pagingLower">' . $array_paging['lower'] . '</span>&nbsp;' . $_CORELANG['TXT_TO'] . '&nbsp;<span class="pagingUpper">' . $array_paging['upper'] . '</span>&nbsp;' . $_CORELANG['TXT_FROM'] . '&nbsp;<span class="pagingTotal">' . $array_paging['total'] . '</span>';
     if ($numof_pages) {
         $paging .= '&nbsp;&nbsp;[&nbsp;' . $array_paging['first'] . '&lt;&lt;</a>&nbsp;&nbsp;' . '<span class="pagingPages">';
     }
     if ($page_number > 3) {
         $paging .= $array_paging[$page_number - 3] . '&nbsp;';
     }
     if ($page_number > 2) {
         $paging .= $array_paging[$page_number - 2] . '&nbsp;';
     }
     if ($page_number > 1) {
         $paging .= $array_paging[$page_number - 1] . '&nbsp;';
     }
     if ($numof_pages) {
         $paging .= $array_paging[$page_number] . '&nbsp;';
     }
     if ($page_number < $numof_pages - 0) {
         $paging .= $array_paging[$page_number + 1] . '&nbsp;';
     }
     if ($page_number < $numof_pages - 1) {
         $paging .= $array_paging[$page_number + 2] . '&nbsp;';
     }
     if ($page_number < $numof_pages - 2) {
         $paging .= $array_paging[$page_number + 3] . '&nbsp;';
     }
     if ($numof_pages) {
         $paging .= '</span>&nbsp;' . $array_paging['last'] . '&gt;&gt;</a>&nbsp;]';
     }
     return $paging;
 }
Esempio n. 3
0
 /**
  * Returs a string representing the complete paging HTML code for the
  * current page
  * @author  Reto Kohli <*****@*****.**> (Rewritten statically)
  * @access  public
  * @global  array     $_CONFIG        Configuration
  * @global  array     $_CORELANG      Core language
  * @param   string    $uri_parameter  Optional additional URI parameters,
  *                                    *MUST* start with an URI encoded
  *                                    ampersand (&amp;).  By reference
  * @param   string    $paging_text    The text to be put in front of the
  *                                    paging
  * @param   integer   $numof_rows     The number of rows available
  * @param   integer   $results_per_page   The optional maximum number of
  *                                    rows to be shown on a single page.
  *                                    Defaults to the corePagingLimit
  *                                    setting.
  * @param   boolean   $showeverytime  If true, the paging is shown even if
  *                                    $numof_rows is less than
  *                                    $results_per_page
  * @param   integer   $position       The optional starting position
  *                                    offset.  Defaults to null
  * @param   string    $parameter_name The optional name for the URI
  *                                    parameter.  Will be determined
  *                                    automatically if empty.
  * @return  string                    HTML code for the paging
  */
 static function get(&$uri_parameter, $paging_text, $numof_rows, $results_per_page = 0, $showeverytime = false, $position = null, $parameter_name = null)
 {
     global $_CONFIG, $_CORELANG;
     $headIncludes = array();
     if (empty($results_per_page)) {
         $results_per_page = intval($_CONFIG['corePagingLimit']);
     }
     if ($numof_rows <= $results_per_page && !$showeverytime) {
         return '';
     }
     $parameter_name = self::getParametername($parameter_name);
     if (!isset($position)) {
         $position = self::getPosition($parameter_name);
     }
     // Fix illegal values:
     // The position must be in the range [0 .. numof_rows - 1].
     // If it's outside this range, reset it
     if ($position < 0 || $position >= $numof_rows) {
         $position = 0;
     }
     // Total number of pages: [1 .. n]
     $numof_pages = ceil($numof_rows / $results_per_page);
     // Current page number: [1 .. numof_pages]
     $page_number = 1 + intval($position / $results_per_page);
     $corr_value = $results_per_page;
     if ($numof_rows % $results_per_page) {
         $corr_value = $numof_rows % $results_per_page;
     }
     // remove all parameters otherwise the url object has parameters like &act=add
     $requestUrl = clone \Env::get('Resolver')->getUrl();
     $currentParams = $requestUrl->getParamArray();
     $requestUrl->removeAllParams();
     if (isset($currentParams['section'])) {
         $requestUrl->setParam('section', $currentParams['section']);
     }
     $requestUrl->setParams($uri_parameter);
     $firstUrl = clone $requestUrl;
     $firstUrl->setParam($parameter_name, 0);
     $lastUrl = clone $requestUrl;
     $lastUrl->setParam($parameter_name, $numof_rows - $corr_value);
     // Set up the base navigation entries
     $array_paging = array('first' => '<a class="pagingFirst" href="' . Cx\Core\Routing\Url::encode_amp($firstUrl) . '" rel="nofollow">', 'last' => '<a class="pagingLast" href="' . Cx\Core\Routing\Url::encode_amp($lastUrl) . '" rel="nofollow">', 'total' => $numof_rows, 'lower' => $numof_rows ? $position + 1 : 0, 'upper' => $numof_rows);
     if ($position + $results_per_page < $numof_rows) {
         $array_paging['upper'] = $position + $results_per_page;
     }
     // Note:  previous/next link are currently unused.
     if ($position != 0) {
         $previousUrl = clone $requestUrl;
         $previousUrl->setParam($parameter_name, $position - $results_per_page);
         $array_paging['previous_link'] = '<a href="' . Cx\Core\Routing\Url::encode_amp($previousUrl) . '">';
         $link = new \Cx\Core\Html\Model\Entity\HtmlElement('link');
         $link->setAttribute('href', $previousUrl->toString());
         $link->setAttribute('rel', 'prev');
         $headIncludes[] = $link;
     }
     if ($numof_rows - $position > $results_per_page) {
         $int_new_position = $position + $results_per_page;
         $nextUrl = clone $requestUrl;
         $nextUrl->setParam($parameter_name, $int_new_position);
         $array_paging['next_link'] = '<a href="' . Cx\Core\Routing\Url::encode_amp($nextUrl) . '">';
         $link = new \Cx\Core\Html\Model\Entity\HtmlElement('link');
         $link->setAttribute('href', $nextUrl->toString());
         $link->setAttribute('rel', 'next');
         $headIncludes[] = $link;
     }
     // TODO: This is a temporary solution for setting HEAD_INCLUDES.
     //       The proper and correct way will by handled by the
     //       upcoming implementation of the response object.
     if ($headIncludes) {
         \Cx\Core\Core\Controller\Cx::instanciate()->getTemplate()->setVariable('HEAD_INCLUDES', join("\n", $headIncludes));
     }
     // Add single pages, indexed by page numbers [1 .. numof_pages]
     for ($i = 1; $i <= $numof_pages; ++$i) {
         if ($i == $page_number) {
             $array_paging[$i] = '<b class="pagingPage' . $i . '">' . $i . '</b>';
         } else {
             $pageUrl = clone $requestUrl;
             $pageUrl->setParam($parameter_name, ($i - 1) * $results_per_page);
             $array_paging[$i] = '<a class="pagingPage' . $i . '" href="' . Cx\Core\Routing\Url::encode_amp($pageUrl) . '">' . $i . '</a>';
         }
     }
     $paging = $paging_text . '&nbsp;<span class="pagingLower">' . $array_paging['lower'] . '</span>&nbsp;' . $_CORELANG['TXT_TO'] . '&nbsp;<span class="pagingUpper">' . $array_paging['upper'] . '</span>&nbsp;' . $_CORELANG['TXT_FROM'] . '&nbsp;<span class="pagingTotal">' . $array_paging['total'] . '</span>';
     if ($numof_pages) {
         $paging .= '&nbsp;&nbsp;[&nbsp;' . $array_paging['first'] . '&lt;&lt;</a>&nbsp;&nbsp;' . '<span class="pagingPages">';
     }
     if ($page_number > 3) {
         $paging .= $array_paging[$page_number - 3] . '&nbsp;';
     }
     if ($page_number > 2) {
         $paging .= $array_paging[$page_number - 2] . '&nbsp;';
     }
     if ($page_number > 1) {
         $paging .= $array_paging[$page_number - 1] . '&nbsp;';
     }
     if ($numof_pages) {
         $paging .= $array_paging[$page_number] . '&nbsp;';
     }
     if ($page_number < $numof_pages - 0) {
         $paging .= $array_paging[$page_number + 1] . '&nbsp;';
     }
     if ($page_number < $numof_pages - 1) {
         $paging .= $array_paging[$page_number + 2] . '&nbsp;';
     }
     if ($page_number < $numof_pages - 2) {
         $paging .= $array_paging[$page_number + 3] . '&nbsp;';
     }
     if ($numof_pages) {
         $paging .= '</span>&nbsp;' . $array_paging['last'] . '&gt;&gt;</a>&nbsp;]';
     }
     return $paging;
 }