File indexing completed on 2024-11-24 05:19:14

0001 <?php
0002 class Pager {
0003   private $OCSCall="";
0004   private $domain="";
0005   private $currentPage = 1;
0006 
0007   public function __construct($domain, $call) {
0008     $this->domain=$domain;
0009     $this->OCSCall=$call;
0010     $url=$_SERVER['REQUEST_URI'];
0011     $tokens = explode('/', $url);
0012     if ($tokens[sizeof($tokens)-2]=="page"){
0013       $this->currentPage=$tokens[sizeof($tokens)-1];
0014     }
0015   }
0016 
0017   public function getData() {
0018     $client = new OCSClient();
0019     return $client->get($this->OCSCall);
0020     
0021   }
0022     public function pagination() { 
0023     $data = $this->getData();
0024     $pagenumber = $this->currentPage;
0025     $itemsperpage = 0;
0026     if (isset($data["ocs"]["meta"]["itemsperpage"])){
0027       $itemsperpage = $data["ocs"]["meta"]["itemsperpage"];
0028     }
0029     if ($itemsperpage>0){
0030       $numberOfPages=ceil($data["ocs"]["meta"]["totalitems"]/$itemsperpage);
0031       echo "<div class=\"row text-center\">
0032                         <div class=\"col-lg-12\">
0033                             <ul class=\"pagination\" id=\"pagebuttons\">
0034                             <li>
0035                                     <a href=\"/plasmastore/".$this->domain."/page/1\">&laquo;</a>
0036                                 </li>";
0037       if($numberOfPages<6){
0038         for ($i=1; $i<=$numberOfPages; $i++) {
0039           if($pagenumber==$i){
0040             echo "                    
0041                       <li class=\"active\">
0042                           <a href=\"/plasmastore/".$this->domain."/page/$i\">$i</a>
0043                       </li>";
0044               } else {
0045                     echo "
0046                        <li>
0047                              <a href=\"/plasmastore/".$this->domain."/page/$i\">$i</a>
0048                          </li>";
0049              }
0050         }
0051       }
0052       else {
0053         if ($pagenumber==1) {
0054           echo "
0055           <li class=\"active\">
0056                   <a href=\"/plasmastore/".$this->domain."/page/".$pagenumber."\">$pagenumber</a>
0057               </li>";
0058         }
0059         else if ($pagenumber==2) {
0060           echo "
0061           <li>
0062                   <a href=\"/plasmastore/".$this->domain."/page/".($pagenumber-1)."\">".($pagenumber-1)."</a>
0063               </li>
0064           <li class=\"active\">
0065                   <a href=\"/plasmastore/".$this->domain."/page/".$pagenumber."\">$pagenumber</a>
0066               </li>";
0067           }
0068           else {
0069         echo "
0070           <li>
0071                   <a href=\"/plasmastore/".$this->domain."/page/".($pagenumber-1)."\">".($pagenumber-1)."</a>
0072               </li>
0073           <li class=\"active\">
0074                   <a href=\"/plasmastore/".$this->domain."/page/".$pagenumber."\">$pagenumber</a>
0075               </li>";
0076           }
0077               if ($numberOfPages-2>=$pagenumber+2){ //pagine indietro
0078                 if($pagenumber==1){
0079                   echo "
0080                 <li>
0081                     <a href=\"/plasmastore/".$this->domain."/page/".($pagenumber+1)."\">".($pagenumber+1)."</a>
0082                 </li>
0083                 <li>
0084                     <a href=\"/plasmastore/".$this->domain."/page/".($pagenumber+2)."\">".($pagenumber+2)."</a>
0085                 </li>";
0086                 }
0087                 else {
0088                 echo"
0089                 <li>
0090                     <a href=\"/plasmastore/".$this->domain."/page/".($pagenumber+1)."\">".($pagenumber+1)."</a>
0091                 </li>";
0092               }
0093               echo "
0094                 <li>
0095                     <a>...</a>
0096                 </li>
0097                 <li>
0098                     <a href=\"/plasmastore/".$this->domain."/page/".($numberOfPages-1)."\">".($numberOfPages-1)."</a>
0099                 </li>
0100                 <li>
0101                     <a href=\"/plasmastore/".$this->domain."/page/$numberOfPages\">$numberOfPages</a>
0102                 </li>";
0103 
0104               }
0105               else if ($pagenumber+2<=$numberOfPages){
0106                 echo "
0107                 <li>
0108                     <a href=\"/plasmastore/".$this->domain."/page/".($pagenumber+1)."\">".($pagenumber+1)."</a>
0109                 </li>
0110             <li>
0111                     <a href=\"/plasmastore/".$this->domain."/page/".($pagenumber+2)."\">".($pagenumber+2)."</a>
0112                 </li>";
0113               }
0114               else if ($pagenumber+1==$numberOfPages){
0115                 echo "
0116                 <li>
0117                     <a href=\"/plasmastore/".$this->domain."/page/".($pagenumber+1)."\">".($pagenumber+1)."</a>
0118                 </li>";
0119               }
0120       }
0121     
0122       echo "
0123           <li>
0124               <a href=\"/plasmastore/".$this->domain."/page/$numberOfPages\">&raquo;</a>
0125           </li>
0126                   </ul>
0127               </div>
0128           </div>";
0129     }
0130   }
0131 
0132 
0133 
0134 
0135 }
0136