]> git.andy128k.dev Git - ipf.git/commitdiff
IPF_Form_Field_TreeModelChoice::_addObject is modified by andrevv
authorAlexander Meteiko <ameteiko@gmail.com>
Wed, 27 Jan 2010 16:50:45 +0000 (18:50 +0200)
committerAlexander Meteiko <ameteiko@gmail.com>
Wed, 27 Jan 2010 16:50:45 +0000 (18:50 +0200)
ipf/form/field/treemodelchoice.php

index c8f3e60480517801ae205fa845d2ca073da3f79e..69d874ecb9e3bf163641927f388ace76a07e7d8a 100644 (file)
@@ -5,7 +5,7 @@ class IPF_Form_Field_TreeModelChoice extends IPF_Form_Field_Choice{
     public $widget = 'IPF_Form_Widget_TreeSelectInput';
     protected $_models;
 
-       function __construct($params=array()){
+    function __construct($params=array()){
         parent::__construct($params);
         $this->_models = $params['models'];
         $choices = array('--------'=>'');
@@ -18,39 +18,42 @@ class IPF_Form_Field_TreeModelChoice extends IPF_Form_Field_Choice{
     protected function _getLevels(){
         $levels = array();
         foreach($this->_models as &$m){
-               $m['objects'] = IPF_ORM_Query::create()->from($m['model'])->orderby('ord')->execute();
-               $levels[] = $m['field'];
+            $m['objects'] = IPF_ORM_Query::create()->from($m['model'])->orderby('ord')->execute();
+            $levels[] = $m['field'];
         }
         return $levels;
     } 
     
-       protected function _addObject($o, &$choices,$level, $parent_id, $valname){
-               $name = str_repeat("-", $level).$o['name'];
-               $choices[$name.' ('.$valname.$o->id.')'] = $valname.$o->id;
-       }    
+    protected function _addObject($o, &$choices, $level, $valname, $name=null)
+    {
+        if (!$name)
+            $name = str_repeat("-", $level).$o['name'];
+        
+        $choices[$name.' ('.$valname.$o->id.')'] = $valname.$o->id;
+    }    
 
     protected function _collectTreeRecursive(&$choices,$level=0,$parent_id=null,$valname=''){
         foreach($this->_models[$level]['objects'] as $o){
-               if ($parent_id){
-                       $foreign = $this->_models[$level]['foreign'];
-                   if ($parent_id!=$o->$foreign)
-                       continue;
-               }
-               $this->_addObject($o, &$choices,$level, $parent_id, $valname);
-               if ($level<(count($this->_models)-1)){
-                   $this->_collectTreeRecursive(&$choices,$level+1,$o->id,$valname.$o->id.'.');
-               }
+            if ($parent_id){
+                $foreign = $this->_models[$level]['foreign'];
+                if ($parent_id!=$o->$foreign)
+                    continue;
+            }
+            $this->_addObject($o, &$choices, $level, $valname);
+            if ($level<(count($this->_models)-1)){
+                $this->_collectTreeRecursive(&$choices,$level+1,$o->id,$valname.$o->id.'.');
+            }
         }
     }
 
     function LateClean($data, $cleaned_data){
         foreach($this->_models as &$m){
-               $cleaned_data[$m['field']] = $data[$m['field']];
+            $cleaned_data[$m['field']] = $data[$m['field']];
         }
     }
 
 
-       /*
+    /*
     public function clean($value){
         parent::clean($value);
         if (in_array($value, $this->empty_values)) {