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

E:/E/GEAMP/www/openbiz/openbiz/bin/easy/element/TreeListbox.php

00001 <?php 
00002 include_once ("Listbox.php");
00003 class TreeListbox extends Listbox
00004 {
00005     public $m_SelectFieldName;
00006 
00007     protected function getDOFromList(&$list, $selectFrom)
00008     {
00009         // from Database
00010         $pos0 = strpos($selectFrom, "[");
00011         $pos1 = strpos($selectFrom, "]");
00012 
00013         if ($pos0 > 0 && $pos1 > $pos0)
00014         {  // select from bizObj
00015             // support BizObjName[BizFieldName] or BizObjName[BizFieldName4Text:BizFieldName4Value]
00016             $bizObjName = substr($selectFrom, 0, $pos0);
00017             $pos3 = strpos($selectFrom, ":");
00018             if($pos3 > $pos0 && $pos3 < $pos1)
00019             {
00020                 $fieldName = substr($selectFrom, $pos0 + 1, $pos3 - $pos0 - 1);
00021                 $fieldName_v = substr($selectFrom, $pos3 + 1, $pos1 - $pos3 - 1);
00022             }
00023             else
00024             {
00025                 $fieldName = substr($selectFrom, $pos0 + 1, $pos1 - $pos0 - 1);
00026                 $fieldName_v = $fieldName;
00027             }
00028             $this->m_SelectFieldName = $fieldName; 
00029             $commaPos = strpos($selectFrom, ",", $pos1);
00030             $commaPos2 = strpos($selectFrom, ",", $commaPos+1);
00031             
00032             if ($commaPos > $pos1)
00033             {
00034                             if($commaPos2){
00035                      $searchRule = trim(substr($selectFrom, $commaPos + 1, ($commaPos2-$commaPos-1)));
00036                             }
00037                             else
00038                             {
00039                                    $searchRule = trim(substr($selectFrom, $commaPos + 1));
00040                             }
00041             }
00042 
00043             if ($commaPos2 > $commaPos)
00044                 $rootSearchRule = trim(substr($selectFrom, $commaPos2 + 1));
00045                 
00046             $bizObj = BizSystem::getObject($bizObjName);
00047             if (!$bizObj)
00048                 return;
00049 
00050             $recList = array();
00051 
00052             $oldAssoc = $bizObj->m_Association;
00053             $bizObj->m_Association = null;
00054 
00055             if ($searchRule)
00056             {
00057                 $searchRule = Expression::evaluateExpression($searchRule, $this->getFormObj());
00058             }
00059                      
00060             if($rootSearchRule)
00061             {
00062               $rootSearchRule = Expression::evaluateExpression($rootSearchRule, $this->getFormObj());                  
00063             }else{
00064               $rootSearchRule = "[PId]=0 OR [PId]='' OR [PId] is NULL";
00065             }
00066             
00067             $recListTree = $bizObj->fetchTree($rootSearchRule,100,$searchRule);
00068             $bizObj->m_Association = $oldAssoc;
00069 
00070             if (!$recListTree) return; // bugfix : error if data blank
00071 
00072             foreach($recListTree as $recListTreeNode)
00073             {
00074                 $this->tree2array($recListTreeNode, $recList);
00075             }
00076 
00077             foreach ($recList as $rec)
00078             {
00079                 $list[$i]['val'] = $rec[$fieldName_v];
00080                 $list[$i]['txt'] = $rec[$fieldName];
00081                 $i++;
00082             }
00083             return;
00084         }
00085     }
00086 
00087     private function tree2array($tree,&$array,$level=0)
00088     {
00089         if(!is_array($array))
00090         {
00091             $array=array();
00092         }
00093 
00094         $treeNodeArray = array(
00095                 "Level" => $level,
00096                 "Id" => $tree->m_Id,
00097                 "PId" => $tree->m_PId,
00098         );
00099         foreach ($tree->m_Record as $key=>$value)
00100         {
00101             $treeNodeArray[$key] = $value;
00102         }
00103         $treeNodeArray[$this->m_SelectFieldName] = "+".str_repeat("--", $level).$treeNodeArray[$this->m_SelectFieldName];
00104 
00105         array_push($array, $treeNodeArray);
00106         $level++;
00107         if(is_array($tree->m_ChildNodes))
00108         {
00109             foreach($tree->m_ChildNodes as $treeNode)
00110             {
00111                 $this->tree2array($treeNode, $array, $level);
00112             }
00113         }
00114         return $array;
00115     }
00116 }
00117 ?>

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