Source for file OCSP_FRMCONTR_PEAR_DATAGRID.phpclass

Documentation is available at OCSP_FRMCONTR_PEAR_DATAGRID.phpclass

  1. <?php
  2. /**
  3.   * openCSP class file OCSP_FRMCONTR_PEAR_DATAGRID.phpclass
  4.   *
  5.   * @project Open CSP-Management
  6.   * @package default
  7.   *
  8.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @since pk-26.11.2008
  12.   * @version $Id: OCSP_FRMCONTR_PEAR_DATAGRID.phpclass,v 1.2 2008/11/28 13:20:39 pitlinz Exp $
  13.   */
  14.  
  15.     // ---------------------------------------------------------
  16.     // requirements
  17.     // ---------------------------------------------------------
  18.  
  19.     pcf_require_class('OCSP_FRMCONTR_LIST',"db/forms/");
  20.     pcf_require_class('PEAR_DATAGRID_DATASOURCE_OCSP_FRMCONTR_LIST',"db/forms/helper/");
  21.     
  22.     if (!class_exists('Structures_DataGrid'))
  23.     {
  24.         @require_once("Structures" _OCSP_DIRSEP_ "DataGrid.php");
  25.         if (!class_exists('Structures_DataGrid'))
  26.         {
  27.             throw new Exception("MISSING PEAR:" Structures_DataGrid_DataSource);
  28.         }        
  29.     }
  30.     
  31.     if (!defined('PEAR_DATAGRID_MAXLIMIT'))
  32.     {
  33.         define('PEAR_DATAGRID_MAXLIMIT',18446744073709551615);
  34.     }
  35.     
  36. /**
  37.   * openCSP class OCSP_FRMCONTR_PEAR_DATAGRID
  38.   *
  39.   * @project Open CSP-Management
  40.   * @package default
  41.   *
  42.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  43.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  44.   *
  45.   * @since pk-26.11.2008
  46.   * @version $Id: OCSP_FRMCONTR_PEAR_DATAGRID.phpclass,v 1.2 2008/11/28 13:20:39 pitlinz Exp $
  47.   */
  48. {
  49.     // ---------------------------------------------------------------------------
  50.     // constants
  51.     // ---------------------------------------------------------------------------
  52.     
  53.  
  54.     // ---------------------------------------------------------------------------
  55.     // class (static)
  56.     // ---------------------------------------------------------------------------
  57.     
  58.     /*** class vars ------------------------------------------------------ */
  59.     
  60.     /*** class methods --------------------------------------------------- */
  61.     
  62.     // ---------------------------------------------------------------------------
  63.     // object vars
  64.     // ---------------------------------------------------------------------------
  65.     
  66.     /*** compostion --------------------------------------------------- */
  67.     
  68.     /**
  69.      * the data grid
  70.      *
  71.      * @var Structures_DataGrid $myPearDataGrid 
  72.      */
  73.     protected $myPearDataGrid = Null;
  74.     
  75.     /**
  76.      * the data source
  77.      * 
  78.      * @var PEAR_DATAGRID_DATASOURCE_OCSP_FRMCONTR_LIST $myPearDataSource 
  79.      */
  80.     protected $myPearDataSource = Null;
  81.         
  82.     
  83.     /*** attributes  -------------------------------------------------- */
  84.     
  85.     /**
  86.      * special sort prepended to the default list sort
  87.      *
  88.      * @var string $myDataGridSort 
  89.      */ 
  90.     protected $myDataGridSort = "";
  91.     
  92.     /**
  93.      * pear data offset
  94.      *
  95.      * @var int $myPearDataOffset 
  96.      */
  97.     protected $myPearDataOffset = 0;    
  98.     
  99.     /**
  100.      * pear data limit
  101.      *
  102.      * @var int $myPearDataLimit 
  103.      */
  104.     protected $myPearDataLimit = 0;    
  105.     
  106.     /**
  107.      * the encodung
  108.      *
  109.      * @var string 
  110.      */
  111.     protected $encoding = 'ISO-8859-15';
  112.     
  113.     // ---------------------------------------------------------------------------
  114.     // factory / construct
  115.     // ---------------------------------------------------------------------------
  116.     
  117.     /**
  118.      * constructor
  119.      *
  120.      */
  121.     public function __construct()
  122.     {
  123.         $this->myPearDataGrid = new Structures_DataGrid();
  124.     }
  125.     
  126.     // ---------------------------------------------------------------------------
  127.     // getter / setter
  128.     // ---------------------------------------------------------------------------    
  129.  
  130.     /**
  131.      * returns the grid data source object
  132.      *
  133.      * @return PEAR_DATAGRID_DATASOURCE_OCSP_FRMCONTR_LIST 
  134.      */
  135.     public function &getDataSource($debug=False)
  136.     {
  137.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_PEAR_DATAGRID::getDataSource()");
  138.         
  139.         if (!pcf_is_instance_of($this->myPearDataSource,'PEAR_DATAGRID_DATASOURCE_OCSP_FRMCONTR_LIST'))
  140.         {
  141.             $this->myPearDataSource = PEAR_DATAGRID_DATASOURCE_OCSP_FRMCONTR_LIST::factory($this,$debug);
  142.         }
  143.         return $this->myPearDataSource;
  144.     }
  145.  
  146.     /**
  147.      * returns the data grid with the source binded
  148.      *
  149.      * @param boolean $debug 
  150.      * 
  151.      * @return unknown 
  152.      */
  153.     public function &getDataGrid($debug=False)
  154.     {
  155.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_PEAR_DATAGRID::getDataGrid()");
  156.         if (!($obj_dataSource $this->myPearDataGrid->getDataSource()))
  157.         {
  158.             $this->myPearDataGrid->bindDataSource($this->getDataSource($debug));
  159.         else {
  160.             if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Datasource already set to: " get_class($obj_dataSource));
  161.         }
  162.         return $this->myPearDataGrid;
  163.     }
  164.     
  165.     /**
  166.      * returns the order by string
  167.      * 
  168.      * appends $this->myDataGridSort
  169.      *
  170.      * @param boolean $debug 
  171.      * 
  172.      * @return string (mySQL)
  173.      */
  174.     public function getOrderBy($debug=False)
  175.     {
  176.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_PEAR_DATAGRID::getOrderBy()",$this->myDataGridSort);
  177.         if (!empty($this->myDataGridSort))
  178.         {
  179.             $str_sort $this->myDataGridSort . ",";
  180.         else {
  181.             $str_sort "";
  182.         }
  183.         return $str_sort parent::getOrderBy($debug);
  184.     }
  185.     
  186.     /**
  187.      * sets the offset
  188.      *
  189.      * @param int $offset 
  190.      */
  191.     public function setOffset($offset)
  192.     {
  193.         if ($this->getOffset(!= intval($offset))
  194.         {
  195.             parent::setOffset($offset);
  196.             if (!intval($this->getLimit()))
  197.             {
  198.                 $this->setLimit(PEAR_DATAGRID_MAXLIMIT);
  199.             }
  200.             $this->invalidateValues();    
  201.         }
  202.     }
  203.     
  204.     /**
  205.      * sets the limit
  206.      * 
  207.      * @param int $limit; 
  208.      */
  209.     public function setLimit($limit)
  210.     {
  211.         if($this->getLimit(!= intval($limit))
  212.         {
  213.             parent::setLimit(intval($limit));
  214.             $this->invalidateValues();    
  215.         }
  216.     }
  217.     
  218.     
  219.     /**
  220.      * sets the data grid sort
  221.      * 
  222.      * note: forces a reload of the list values
  223.      *
  224.      * @param string $sort 
  225.      */
  226.     public function setDataGridSort($sort)
  227.     {
  228.         if ($this->myDataGridSort != $sort)
  229.         {
  230.             $this->myDataGridSort = $sort;
  231.             if ($this->valuesAreLoaded())
  232.             {
  233.                 $this->invalidateValues();
  234.             }
  235.         }
  236.     }
  237.     
  238.     
  239.     
  240.     // ---------------------------------------------------------------------------
  241.     // list db methods
  242.     // ---------------------------------------------------------------------------
  243.  
  244.     /**
  245.      * returns the number of total rows
  246.      *  
  247.      * @return int 
  248.      */
  249.     public function getNofListRows($debug=False)
  250.     {       
  251.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_PEAR_DATAGRID::getNofListRows()");
  252.         
  253.         if (!$this->valuesAreLoaded())
  254.         {
  255.             $this->loadListValues($debug);
  256.            }         
  257.            return parent::getNofListRows();
  258.     }
  259.  
  260.     public function getListRows($offset=0,$limit=PEAR_DATAGRID_MAXLIMIT,$debug=False)
  261.     {      
  262.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_PEAR_DATAGRID::getListRows");
  263.         if (!$this->valuesAreLoaded())
  264.         {
  265.             $this->loadListValues();
  266.         }
  267.  
  268.         $arr_fields $this->getMyForm()->getFields();
  269.         
  270.         $this->myListIdx = $offset;
  271.         $int_idx  0;
  272.         $int_size sizeof($this->myListValues);
  273.  
  274.         // set the global data array
  275.            $str_globalArrName="LISTROW_".$this->myForm->getId();
  276.            global ${$str_globalArrName};
  277.         
  278.         $arr_ret array();
  279.         
  280.         if ($debug)
  281.         {
  282.             echoDebugLine(__FILE__,__LINE__,"<pre>
  283.                     offset: {$offset} ({$this->myListIdx})
  284.                     int_size: {$int_size} / {$limit}
  285.                 </pre>");
  286.         }
  287.            
  288.         while(($this->myListIdx < $int_size&& (($int_idx $limit|| (intval($limit== 0)))
  289.         {
  290.             if (isset($this->myListValues[$this->myListIdx]))
  291.             {
  292.                 $this->curRow=&$this->myListValues[$this->myListIdx];
  293.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>current row</p><pre>" print_r($this->curRow,True)) "</pre>";
  294.                 
  295.                 if ($obj_tblObj=$this->myForm->getMyTblObj(True,$debug))
  296.                 {
  297.                     if ($this->lstObjValTS)
  298.                     {
  299.                         $obj_tblObj->setDBVal($this->curRow,$debug);
  300.                     } else {
  301.                         $obj_tblObj->setDBRow($this->curRow,True,$debug);
  302.                     }
  303.                     
  304.                     // check show
  305.                     if (!empty($this->userCanShowMethod&& method_exists($obj_tblObj,$this->userCanShowMethod))
  306.                     {
  307.                         eval("\$b_canShow=\$obj_tblObj->".$this->userCanShowMethod."(\$debug);");
  308.                         if (!$b_canShowcontinue;
  309.                     }
  310.                     
  311.                     if ($obj_tblObj->isPopulated())
  312.                     {
  313.                         $this->curRow=array_merge($this->curRow,$obj_tblObj->getDBVal());
  314.                     } else {
  315.                         $this->curRow=array_merge($this->curRow,$obj_tblObj->getDBRow(False,$debug));
  316.                     }
  317.                 }    
  318.  
  319.                 ${$str_globalArrName} = $this->curRow;
  320.                 
  321.                 $arr_ret[$int_idxarray();
  322.                 
  323.                 foreach($arr_fields as &$obj_field)
  324.                 {
  325.                     if ($obj_field->exportCSV(&& $obj_field->isToShow(FRM_MODE_LIST,$str_globalArrName))
  326.                     {
  327.                         $mix_listValue=(isset($this->curRow[$obj_field->getName()]$this->curRow[$obj_field->getName()Null);
  328.                         $arr_ret[$int_idx][$obj_field->getName()$obj_field->getCSV_Value($mix_listValue,$str_globalArrName,$debug);
  329.                         if (strstr($this->encoding,'ISO-8859-1'!== False)
  330.                         {
  331.                             if (OCSP_OBJ::isMultiByteStr($arr_ret[$int_idx][$obj_field->getName()]))
  332.                             {
  333.                                 $arr_ret[$int_idx][$obj_field->getName()utf8_decode($arr_ret[$int_idx][$obj_field->getName()]);
  334.                             }
  335.                         } else if (strstr($this->encoding,'UTF8')) {
  336.                             if (!OCSP_OBJ::isUTF8($arr_ret[$int_idx][$obj_field->getName()]))
  337.                             {
  338.                                 $arr_ret[$int_idx][$obj_field->getName()utf8_encode($arr_ret[$int_idx][$obj_field->getName()]);
  339.                             }
  340.                         }
  341.                     }
  342.                 }
  343.                 
  344.                 $int_idx++;
  345.             }
  346.             $this->myListIdx++;
  347.         } // while(($this->myListIdx < $int_size) && (($int_idx ....)))
  348.         return $arr_ret;
  349.         
  350.     }
  351.  
  352.     
  353. }
  354.  

Documentation generated on Thu, 08 Jan 2009 17:46:33 +0100 by phpDocumentor 1.4.0a2