Ticket #581: jelix-trunk-#xxx.patch
| File jelix-trunk-#xxx.patch, 4.6 kB (added by bibo, 8 months ago) |
|---|
-
lib/jelix/forms/jFormsCompiler_jf_1_1.class.php
old new 109 109 throw new jException('jelix~formserr.attribute.missing',array('method', 'datasource',$this->sourceFile)); 110 110 if(!isset($attrs['labelproperty'])) 111 111 throw new jException('jelix~formserr.attribute.missing',array('method', 'datasource',$this->sourceFile)); 112 else { 113 if ( strpos( $attrs['labelproperty'], 'array' ) === FALSE ) 114 $label='\''.$attrs['labelproperty'].'\''; 115 else 116 $label=$attrs['labelproperty']; 117 } 112 118 113 119 if(isset($attrs['criteria'])) 114 120 $criteria=',\''.$attrs['criteria'].'\''; 115 elseif(isset($attrs['criteriafrom'])) 116 $criteria=',null,\''.$attrs['criteriafrom'].'\''; 121 elseif(isset($attrs['criteriafrom'])) { 122 if ( strpos( $attrs['criteriafrom'], 'array' ) === FALSE ) 123 $criteria=',null,\''.$attrs['criteriafrom'].'\''; 124 else 125 $criteria=',null,'.$attrs['criteriafrom']; 126 } 117 127 else 118 128 $criteria=''; 119 129 120 130 $source[]='$ctrl->datasource = new jFormsDaoDatasource(\''.$attrs['dao'].'\',\''. 121 $attrs['method'].'\', \''.$attrs['labelproperty'].'\',\''.$daovalue.'\''.$criteria.');';131 $attrs['method'].'\','.$label.',\''.$daovalue.'\''.$criteria.');'; 122 132 if($controltype == 'submit'){ 123 133 $source[]='$ctrl->standalone=false;'; 124 134 } -
lib/jelix/forms/jFormsDatasource.class.php
old new 3 3 * @package jelix 4 4 * @subpackage forms 5 5 * @author Laurent Jouanneau 6 * @contributor 6 * @contributor Dominique Papin 7 7 * @copyright 2006-2007 Laurent Jouanneau 8 * @copyright 2008 Dominique Papin 8 9 * @link http://www.jelix.org 9 10 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 10 11 */ … … 17 18 */ 18 19 interface jIFormsDatasource { 19 20 /** 20 * load and returns data to fill a control. The returned array should be 21 * load and returns data to fill a control. The returned array should be 21 22 * an associative array key => label 22 23 * @param jFormsBase $form the form 23 24 * @return array the data … … 26 27 27 28 /** 28 29 * Return the label corresponding to the given key 29 * @param string $key the key 30 * @param string $key the key 30 31 * @return string the label 31 32 */ 32 33 public function getLabel($key); … … 89 90 $this->selector = $selector; 90 91 $this->method = $method ; 91 92 $this->labelProperty = $label; 93 $this->separator = null ; 94 if (is_array($this->labelProperty)) 95 $this->separator = array_pop($this->labelProperty); 92 96 $this->criteria = $criteria; 93 97 $this->criteriaFrom = $criteriaFrom; 94 98 if($key == ''){ … … 105 109 if($this->criteria !== null) { 106 110 $found = $this->dao->{$this->method}($this->criteria); 107 111 } else if ($this->criteriaFrom !== null) { 108 $found = $this->dao->{$this->method}($form->getData($this->criteriaFrom)); 112 $args = array() ; 113 foreach( (array)$this->criteriaFrom as $criteria ) { 114 array_push( $args, $form->getData($criteria) ) ; 115 } 116 $found = call_user_func_array( array(&$this->dao, $this->method), $args); 109 117 } else { 110 118 $found = $this->dao->{$this->method}(); 111 119 } 112 120 $result=array(); 113 121 foreach($found as $obj){ 114 $result[$obj->{$this->keyProperty}] = $obj->{$this->labelProperty}; 122 $label = '' ; 123 foreach( (array)$this->labelProperty as $property ) { 124 if (!empty( $obj->{$property})) 125 $label .= $obj->{$property}.$this->separator; 126 } 127 if ($this->separator) 128 $label = substr($label, 0, -strlen($this->separator)); 129 $result[$obj->{$this->keyProperty}] = $label ; 115 130 } 116 131 return $result; 117 132 } … … 126 141 } 127 142 128 143 } 129
