Exemple #1
0
 /**
  * @param      $Results
  * @param      $ElementID
  * @param null $MaxPageSize
  * @return \Epsilon\Object\Object
  */
 public static function foundationListPaging($Results, $ElementID, $MaxPageSize = null)
 {
     $CurrentPage = Input::getVar("CurrentPage", "REQUEST");
     if (is_integer($MaxPageSize)) {
         $PageSize = $MaxPageSize;
     } else {
         $PageSize = Config::MAX_PAGE_SIZE;
     }
     $Paging = new Object(['HTML' => null, 'Init' => 0, 'Max' => $PageSize, 'Results' => 0, 'PageInit' => 0, 'PageMax' => 0, 'TotalPages' => 0, 'TotalResults' => 0]);
     if (is_array($Results)) {
         $TotalResults = count($Results);
     } else {
         if (is_numeric($Results)) {
             $TotalResults = $Results;
         } else {
             $TotalResults = 0;
         }
     }
     if ($TotalResults > 0) {
         $TotalPages = self::getTotalPages($TotalResults, $PageSize);
         if ($CurrentPage > $TotalPages) {
             $CurrentPage = $TotalPages;
         } elseif (!is_numeric($CurrentPage) || !((int) $CurrentPage > 0) || (int) $CurrentPage == 0) {
             $CurrentPage = 1;
         }
         if ($CurrentPage > 1) {
             $Init = ($CurrentPage - 1) * $PageSize;
             $Max = $PageSize;
             $PageInit = ($CurrentPage - 1) * $PageSize + 1;
             $PageMax = $PageInit + $PageSize - 1;
         } else {
             $Init = 0;
             $Max = $PageSize;
             $PageInit = 1;
             $PageMax = $PageInit + $Max - 1;
         }
         if ($PageMax >= $TotalResults) {
             $PageMax = $TotalResults;
         }
         $Pages = self::getPages($CurrentPage, $TotalPages);
         $HTML = "";
         $PreviousSet = false;
         if (is_string($ElementID)) {
             $ElementID = "\"{$ElementID}\"";
         } else {
             $ElementID = "null";
         }
         $eLanguage = Factory::getLanguage();
         $PagesCount = 0;
         foreach ($Pages as $p) {
             $PagesCount++;
             if (!$PreviousSet) {
                 $Previus = $CurrentPage - 1;
                 if ($CurrentPage != 1) {
                     $HTML .= "<ul class=\"pagination text-center\" role=\"navigation\" aria-label=\"Pagination\">\n<li class=\"pagination-previous\"><a href='javascript:goToPage({$Previus}, {$ElementID})'><span class=\"show-for-sr\">page</span> " . $eLanguage->_("LIST-RESULT-PREVIOUS") . "</a></li>\n";
                 } else {
                     $HTML .= "<ul class=\"pagination text-center\" role=\"navigation\" aria-label=\"Pagination\">\n<li class=\"pagination-previous disabled\"><span class=\"show-for-sr\">page</span> " . $eLanguage->_("LIST-RESULT-PREVIOUS") . "</li>\n";
                 }
                 $PreviousSet = true;
             }
             if ($CurrentPage == $p) {
                 $HTML .= "<li class='current'><span class=\"show-for-sr\">You're on page </span > {$p}</li > \n";
             } else {
                 $HTML .= " <li><a href = 'javascript:goToPage({$p},{$ElementID})' > {$p}</a ></li > \n";
             }
             if ($PagesCount == count($Pages)) {
                 $Next = $CurrentPage + 1;
                 if ($CurrentPage != $p) {
                     $HTML .= "<li class=\"pagination-next\"><a aria-label=\"Next page\" href='javascript:goToPage({$Next},{$ElementID})'>" . $eLanguage->_("LIST-RESULT-NEXT") . " <span class=\"show-for-sr\">page</span></a></li></ul>";
                 } else {
                     $HTML .= "<li class=\"pagination-next disabled\"><span class=\"show-for-sr\">page</span>" . $eLanguage->_("LIST-RESULT-NEXT") . "</li>\n</ul>";
                 }
             }
         }
         $Paging->setProperties(['HTML' => $HTML, 'Init' => $Init, 'Max' => $Max, 'Results' => $PageMax - $PageInit + 1, 'PageInit' => $PageInit, 'PageMax' => $PageMax, 'TotalPages' => $TotalPages, 'TotalResults' => $TotalResults]);
     }
     return $Paging;
 }