From fbab711042b62a2c322a99920911bab199877259 Mon Sep 17 00:00:00 2001 From: Alexander Meteiko Date: Wed, 27 Jan 2010 18:50:45 +0200 Subject: [PATCH] IPF_Form_Field_TreeModelChoice::_addObject is modified by andrevv --- ipf/form/field/treemodelchoice.php | 39 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/ipf/form/field/treemodelchoice.php b/ipf/form/field/treemodelchoice.php index c8f3e60..69d874e 100644 --- a/ipf/form/field/treemodelchoice.php +++ b/ipf/form/field/treemodelchoice.php @@ -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)) { -- 2.49.0