• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List

E:/E/GEAMP/www/openbiz/openbiz/bin/easy/EasyFormGrouping.php

00001 <?php 
00002 
00018 class EasyFormGrouping extends EasyForm
00019 {
00020        protected $m_GroupBy;
00021        
00022        protected function readMetadata(&$xmlArr)
00023     {
00024         parent::readMetaData($xmlArr);
00025        $this->m_GroupBy = isset($xmlArr["EASYFORM"]["ATTRIBUTES"]["GROUPBY"]) ? $xmlArr["EASYFORM"]["ATTRIBUTES"]["GROUPBY"] : null;    
00026     }
00027        
00028     public function fetchDataGroup()
00029     {
00030        //get group list first
00031        $dataObj = $this->getDataObj();                  
00032 
00033        if (!$dataObj) return null;
00034         if ($this->m_RefreshData)
00035             $dataObj->resetRules();
00036         else
00037             $dataObj->clearSearchRule();
00038         
00039         if(strpos($this->m_GroupBy,":")){
00040               preg_match("/\[(.*?):(.*?)\]/si",$this->m_GroupBy,$match);            
00041               $GroupFieldName = $match[1];
00042               $GroupField = $match[2];
00043                
00044         }else{
00045                
00046                $GroupField = str_replace("[","",$this->m_GroupBy);
00047                $GroupField = str_replace("]","",$GroupField);         
00048         }
00049         $GroupSQLRule="GROUP BY [$GroupField]";
00050         $dataObj->setOtherSQLRule($GroupSQLRule);
00051         
00052        //within each group, search records like before
00053         QueryStringParam::setBindValues($this->m_SearchRuleBindValues);       
00054 
00055         if ($this->m_FixSearchRule)
00056         {
00057             if ($this->m_SearchRule)
00058                 $searchRule = $this->m_SearchRule . " AND " . $this->m_FixSearchRule;
00059             else
00060                 $searchRule = $this->m_FixSearchRule;
00061         }
00062         else
00063             $searchRule = $this->m_SearchRule;
00064 
00065         $dataObj->setSearchRule($searchRule);
00066         
00067         $resultRecords = $dataObj->fetch();
00068         $this->m_TotalRecords = $dataObj->count();
00069         if ($this->m_Range && $this->m_Range > 0)
00070             $this->m_TotalPages = ceil($this->m_TotalRecords/$this->m_Range);
00071             
00072         $this->m_TotalPagesBak = $this->m_TotalPages;
00073         QueryStringParam::ReSet();
00074         //looping
00075         $i=0;
00076         $results = array();
00077         foreach($resultRecords as $record){
00078               if ($this->m_RefreshData)
00079                    $dataObj->resetRules();
00080                else
00081                    $dataObj->clearSearchRule();
00082               QueryStringParam::setBindValues($this->m_SearchRuleBindValues);
00083               $group_val = $record[$GroupField];
00084                if ($this->m_FixSearchRule)
00085                {
00086                    if ($this->m_SearchRule)
00087                        $searchRule = $this->m_SearchRule . " AND " . $this->m_FixSearchRule;
00088                    else
00089                        $searchRule = $this->m_FixSearchRule;
00090                }
00091                else
00092                    $searchRule = $this->m_SearchRule;
00093                      if($group_val){
00094                       if($searchRule!=""){
00095                                    $searchRule = $searchRule." AND [$GroupField]='$group_val'";   
00096                             }else{
00097                                    $searchRule = " [$GroupField]='$group_val'";     
00098                             }
00099                      }else{
00100                             if($searchRule!=""){
00101                                    $searchRule = $searchRule." AND [$GroupField]  is NULL";       
00102                             }else{
00103                                    $searchRule = " [$GroupField] is NULL";   
00104                             }                           
00105                      }
00106                      
00107                      $dataObj->setOtherSQLRule("");
00108                      $dataObj->setLimit(0,0);
00109                $dataObj->setSearchRule($searchRule); 
00110                $resultRecords_grouped = $dataObj->fetch();
00111                //renderTable
00112                $resultRecords_grouped_table = $this->m_DataPanel->renderTable($resultRecords_grouped);
00113                
00114                if($record[$GroupField]){
00115                      if($GroupFieldName){
00116                             $results[$record[$GroupFieldName]] = $resultRecords_grouped_table;
00117                      }else{
00118                             $results[$record[$GroupField]] = $resultRecords_grouped_table;
00119                      }
00120                }else{
00121                      $results["Empty"] = $resultRecords_grouped_table;
00122                }
00123               
00124                
00125                $i++;        
00126                QueryStringParam::ReSet();
00127         }
00128         
00129         //set active records
00130         $selectedIndex = 0;
00131         $this->getDataObj()->setActiveRecord($resultRecords[$selectedIndex]);
00132         return $results;
00133     }  
00134     
00135     public function fetchDataSet(){
00136        $this->fetchDataGroup();
00137        $resultset = parent::fetchDataSet();
00138        $this->m_TotalPages = $this->m_TotalPagesBak;
00139        return $resultset; 
00140     }
00141     
00142     public function outputAttrs()
00143     {
00144        $output = parent::outputAttrs();
00145        $output['dataGroup'] = $this->fetchDataGroup();
00146        return $output;      
00147     
00148     }         
00149 }
00150 ?>

Generated on Thu Apr 19 2012 17:09:13 for openbiz by  doxygen 1.7.2