Source for file TableWidget.php

Documentation is available at TableWidget.php

  1. <?php
  2.  
  3. if(!defined('LAYOUT_GENERATOR')){
  4.     define('LAYOUT_GENERATOR','TableWidgetLayout');    
  5. }
  6.  
  7. class TableWidget extends WidgetGenerator{
  8.  
  9.     public function generate($columns){
  10.     //generate the record widget
  11.     $path dirname(__FILE__)."/../crudify.php -d ".DOCTRINE_PATH" -g DefaultWidget -l TableRowLayout -w ".CRUD_CLASS."RecordRow ".CRUD_FILE;
  12.     echo $path;
  13.     echo `$path`;
  14.     $buffer='<?php
  15. /**
  16.  * This file was generated by the Alia Toolkit. For more information, please see alia.sourceforge.net
  17.  */
  18.  
  19.  
  20.  
  21. /**
  22.  * '.CRUD_WIDGET.' class
  23.  * 
  24.  * @uses AWidget
  25.  */
  26. class '.CRUD_WIDGET.' extends AWidget{
  27.     const recordClass=\''.CRUD_CLASS.'\';
  28.     
  29.  
  30.     
  31.  
  32.  
  33.     private $records;
  34.     private $page;
  35.     private $recordsPerPage = 15;
  36.  
  37.  
  38.     function __construct($page=1){
  39.         parent::__construct();
  40.         
  41.         $this->defineSignal("nextPage");
  42.         $this->setpage($page);
  43.         $this->fetchRecords();
  44.         $this->buildLayout();
  45.  
  46.  
  47.     }
  48.     
  49.  
  50.     function setPage($page){
  51.         
  52.         
  53.         
  54.         if( $page <1){
  55.             throw new Exception("$page is not a valid page number!");
  56.         }
  57.         $this->page = $page;
  58.             }
  59.     
  60.     function setRecordsPerPage($count){
  61.         if(! is_int($count) || $count <1){
  62.             throw new Exception("$count is not a valid positive number!");
  63.         }
  64.         $this->recordsPerPage = $count;
  65.     }
  66.     
  67.     function fetchRecords(){
  68.         $this->records  = Doctrine_Query::create()
  69.                           ->from(self::recordClass." a")
  70.                           ->limit($this->recordsPerPage." OFFSET ". ($this->page - 1)*$this->recordsPerPage )
  71.                           ->execute();
  72.     }
  73.     
  74.  
  75.     /**
  76.      * builds the layout and widgets that go in it. 
  77.      * 
  78.      * @access public
  79.      * @return void
  80.      */
  81.     function buildLayout(){
  82.         //delete all the old widgets, if any
  83.         if($this->getLayout()){
  84.             $widgets = $this->getLayout()->getWidgets();
  85.             foreach($widgets as $k=>$widget){
  86.                 $widget->clearConnections();
  87.                 //AObjectRegistry::instance()->unsetObject($widgets[$k]);
  88.                 unset($widgets[$k]);
  89.             }
  90.             $layout = $this->getLayout();
  91.         }
  92.         $layout = new AHTMLLayout($this,"/templates/'.CRUD_WIDGET.'Edit.tpl");
  93.         $this->setLayout($layout);
  94.         $x=0;
  95.         
  96.         foreach($this->records as $record){
  97.             $widget = new '.CRUD_CLASS.'RecordRow($record);
  98.             $layout->addWidget($widget);
  99.         }
  100.         $button = new APushButton("<< Prev");
  101.         $layout->addWidget($button,"prevButton");
  102.         Alia::connect($button,"clicked",$this,"previousPage");
  103.     
  104.         $button = new APushButton("Next >>");
  105.         $layout->addWidget($button,"nextButton");
  106.         Alia::connect($button,"clicked",$this,"nextPage");
  107.  
  108.  
  109.     }
  110.  
  111.     public function nextPage(){
  112.         $this->changePage(1);
  113.     }
  114.     
  115.     public function previousPage(){
  116.         $this->changePage(1);
  117.     }
  118.     function changePage($direction){
  119.         if($this->page <2 && $direction < 0){
  120.             $this->setPage(1);
  121.         }else{
  122.             $this->setpage($this->page + $direction);
  123.         }
  124.         $this->fetchRecords();
  125.         $this->buildLayout();
  126.         $this->redraw();
  127.     }
  128.  
  129.  
  130.  
  131.  
  132. }
  133. ';
  134.  
  135.         return $buffer;    
  136.     
  137.     }
  138. }

Documentation generated on Fri, 11 Jul 2008 13:28:45 -0400 by phpDocumentor 1.4.2