RvTwoClasses
[ class tree: RvTwoClasses ] [ index: RvTwoClasses ] [ all elements ]

Source for file searchResult.php

Documentation is available at searchResult.php

  1. <?php
  2.  
  3. /**
  4.  * <b>Class Description</b>: Wrapper class for an array of data that can be stored in the session array and
  5.  * accessed by subsequent AJAX calls for client scrolling through the data set in small chunks. *
  6.  * @since : 29/04/2009
  7.  * @author Jan van der Breggen
  8.  * @package RvTwoClasses
  9.  * 
  10.  ***/
  11.  
  12. {
  13.  
  14.     private $data = array();
  15.     private $resultsPerPage = 0;
  16.     private $numberOfResults = 0;
  17.     private $currentPage = -1;
  18.     private $numberOfPages = 0;
  19.     private $cursor = 0;
  20.     private $columns = array();
  21.  
  22.  
  23.     function __construct($data$resultsPerPage$idField 'id')
  24.     {
  25.         $this->data = $this->makeDataArray($data$idField);
  26.         $this->columns = $this->makeColumnArray();
  27.         //print_r($data);
  28.         $this->resultsPerPage = $resultsPerPage;
  29.         $this->numberOfResults = count($data);
  30.         $this->numberOfPages = (integer)($this->numberOfResults / $this->resultsPerPage);
  31.         if (fmod((float)$this->numberOfResults(float)$this->resultsPerPage<> 0)
  32.         {
  33.             $this->numberOfPages++;
  34.         }
  35.         
  36.     }
  37.     
  38.     function makeColumnArray(){
  39.         if (count($this->data)>0){
  40.             return array_keys(current($this->data));            
  41.         }
  42.         return array();
  43.     }
  44.  
  45.     function getColumns()
  46.     {
  47.         return $this->columns;
  48.     }
  49.     
  50.     function makeDataArray($data$idField)
  51.     {
  52.  
  53.         $newData array();
  54.         foreach ($data as $record)
  55.         {
  56.             $newData[$record[$idField]] $record;
  57.         }
  58.         return $newData;
  59.     }
  60.  
  61.     function getSelectValues($idField$arg1$arg2 '')
  62.     {
  63.     $result array();
  64.     foreach ($this->data as $record){
  65.     $result[$record[$idField]]"$record[$arg1] $record[$arg2]";
  66.     }
  67.     return $result;
  68.     
  69.     
  70.     }
  71.  
  72.     function getNextPage()
  73.     {
  74.  
  75.         return $this->getPage($this->currentPage + 1);
  76.  
  77.         /*
  78.         $page = array();
  79.         if($this->currentPage+2>$this->numberOfPages){
  80.         $page = array_slice($this->data, $this->cursor, $this->numberOfResults-1);
  81.         } else {
  82.         $page = array_slice($this->data, $this->cursor, $this->resultsPerPage);
  83.         }
  84.         $this->currentPage++;
  85.         $this->cursor += count($page);
  86.         return $page;
  87.         */
  88.  
  89.  
  90.     }
  91.  
  92.  
  93.     function getPreviousPage()
  94.     {
  95.         return $this->getPage($this->currentPage - 1);
  96.     }
  97.  
  98.     function getPage($number)
  99.     {
  100.         if ($number == $this->numberOfPages)
  101.         {
  102.             $page array_slice($this->data$number $this->resultsPerPage$this->
  103.                 numberOfResults - 1);
  104.         else
  105.         {
  106.             $page array_slice($this->data$number $this->resultsPerPage$this->
  107.                 resultsPerPage);
  108.  
  109.         }
  110.         $this->cursor = ($number $this->resultsPerPagecount($page);
  111.         $this->currentPage = $number;
  112.         return $page;
  113.     }
  114.  
  115.     function getCurrentPageNumber()
  116.     {
  117.         return $this->currentPage;
  118.     }
  119.  
  120.     function getCurrentPageNumberForDisplay()
  121.     {
  122.         return $this->currentPage + 1;
  123.     }
  124.  
  125.     function getNumberOfPages()
  126.     {
  127.         return $this->numberOfPages;
  128.     }
  129.  
  130.     function getNumberOfResults()
  131.     {
  132.         return count($this->data);
  133.     }
  134.  
  135.  
  136.     function nextPagesLeft()
  137.     {
  138.         if ($this->currentPage == $this->numberOfPages - 1)
  139.             return false;
  140.         return true;
  141.     }
  142.  
  143.     function previousPagesLeft()
  144.     {
  145.         if ($this->currentPage == 0)
  146.             return false;
  147.         return true;
  148.     }
  149.  
  150.     function getResultByID($id)
  151.     {
  152.         return $this->data[$id];
  153.     }
  154.  
  155. }
  156.  
  157. ?>

Documentation generated on Mon, 18 May 2009 11:22:17 +0200 by phpDocumentor 1.4.1