[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/demos/quickstart/protected/pages/Controls/Samples/TPager/ -> Sample1.php (source)

   1  <?php
   2  
   3  class Sample1 extends TPage
   4  {
   5      /**
   6       * Returns total number of data items.
   7       * In DB-driven applications, this typically requires
   8       * execution of an SQL statement with COUNT function.
   9       * Here we simply return a constant number.
  10       */
  11  	protected function getDataItemCount()
  12      {
  13          return 19;
  14      }
  15  
  16      /**
  17       * Fetches a page of data.
  18       * In DB-driven applications, this can be achieved by executing
  19       * an SQL query with LIMIT clause.
  20       */
  21  	protected function getData($offset,$limit)
  22      {
  23          $data=array(
  24              array('id'=>'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true),
  25              array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true),
  26              array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true),
  27              array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false),
  28              array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true),
  29              array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false),
  30              array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true),
  31              array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true),
  32              array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false),
  33              array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true),
  34              array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true),
  35              array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false),
  36              array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true),
  37              array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true),
  38              array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false),
  39              array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true),
  40              array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false),
  41              array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false),
  42              array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false),
  43          );
  44          return array_slice($data,$offset,$limit);
  45      }
  46  
  47      /**
  48       * Determines which page of data to be displayed and
  49       * populates the datalist with the fetched data.
  50       */
  51  	protected function populateData()
  52      {
  53          $offset=$this->DataList->CurrentPageIndex*$this->DataList->PageSize;
  54          $limit=$this->DataList->PageSize;
  55          if($offset+$limit>$this->DataList->VirtualItemCount)
  56              $limit=$this->DataList->VirtualItemCount-$offset;
  57          $data=$this->getData($offset,$limit);
  58          $this->DataList->DataSource=$data;
  59          $this->DataList->dataBind();
  60      }
  61  
  62  	public function onLoad($param)
  63      {
  64          parent::onLoad($param);
  65          if(!$this->IsPostBack)
  66          {
  67              $this->DataList->VirtualItemCount=$this->DataItemCount;
  68              $this->populateData();
  69          }
  70      }
  71  
  72      /**
  73       * Event handler to the OnPageIndexChanged event of pagers.
  74       */
  75  	public function pageChanged($sender,$param)
  76      {
  77          $this->DataList->CurrentPageIndex=$param->NewPageIndex;
  78          $this->populateData();
  79      }
  80  }
  81  
  82  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7