Ticket #581: jelix-trunk-#581.patch
| File jelix-trunk-#581.patch, 5.7 kB (added by bibo, 7 months ago) |
|---|
-
lib/jelix/docs/ns/jforms_1.1.rng
old new 312 312 <attribute name="dao" /> 313 313 <attribute name="daomethod" /> 314 314 <attribute name="labelproperty" /> 315 <optional><attribute name="labelseparator" /></optional> 315 316 <optional><attribute name="valueproperty" /></optional> 316 317 <optional> 317 318 <choice> -
lib/jelix/forms/jFormsCompiler_jf_1_1.class.php
old new 102 102 103 103 if(isset($attrs['dao'])) { 104 104 if ( isset($attrs['profile'])) 105 $profile = ' \''.$attrs['profile'].'\'';105 $profile = ',\''.$attrs['profile'].'\''; 106 106 else 107 $profile = ' \'\'';107 $profile = ',\'\''; 108 108 if(isset($attrs['valueproperty'])) { 109 109 $daovalue = $attrs['valueproperty']; 110 110 } else … … 114 114 if(!isset($attrs['labelproperty'])) 115 115 throw new jException('jelix~formserr.attribute.missing',array('method', 'datasource',$this->sourceFile)); 116 116 117 if ( isset($attrs['labelseparator'])) 118 $labelSeparator = ',\''.$attrs['labelseparator'].'\''; 119 else 120 $labelSeparator = ',\'\''; 117 121 if(isset($attrs['criteria'])) 118 122 $criteria=',\''.$attrs['criteria'].'\''; 119 123 elseif(isset($attrs['criteriafrom'])) … … 122 126 $criteria=''; 123 127 124 128 $source[]='$ctrl->datasource = new jFormsDaoDatasource(\''.$attrs['dao'].'\',\''. 125 $attrs['method'].'\',\''.$attrs['labelproperty'].'\',\''.$daovalue.'\' ,'.$profile.$criteria.');';129 $attrs['method'].'\',\''.$attrs['labelproperty'].'\',\''.$daovalue.'\''.$labelSeparator.$profile.$criteria.');'; 126 130 if($controltype == 'submit'){ 127 131 $source[]='$ctrl->standalone=false;'; 128 132 } -
lib/jelix/forms/jFormsDatasource.class.php
old new 78 78 79 79 protected $selector; 80 80 protected $method; 81 protected $labelProperty; 81 protected $labelProperty = array(); 82 protected $labelSeparator; 82 83 protected $keyProperty; 83 84 protected $profile; 84 85 85 86 protected $criteria; 86 protected $criteriaF orm;87 protected $criteriaFrom = array(); 87 88 88 89 protected $dao = null; 89 90 90 function __construct ($selector ,$method , $label, $key, $ profile='', $criteria=null, $criteriaFrom=null){91 function __construct ($selector ,$method , $label, $key, $labelSeparator='', $profile='', $criteria=null, $criteriaFrom=null){ 91 92 $this->selector = $selector; 92 93 $this->profile = $profile; 93 94 $this->method = $method ; 94 $this->labelProperty = $label; 95 $this->labelProperty = preg_split('/[\s,]+/',$label); 96 $this->labelSeparator = $labelSeparator; 95 97 $this->criteria = $criteria; 96 $this->criteriaFrom = $criteriaFrom;98 $this->criteriaFrom = preg_split('/[\s,]+/',$criteriaFrom); 97 99 if($key == ''){ 98 100 $rec = jDao::createRecord($this->selector, $this->profile); 99 101 $pfields = $rec->getPrimaryKeyNames(); … … 108 110 if($this->criteria !== null) { 109 111 $found = $this->dao->{$this->method}($this->criteria); 110 112 } else if ($this->criteriaFrom !== null) { 111 $found = $this->dao->{$this->method}($form->getData($this->criteriaFrom)); 113 $args = array() ; 114 foreach( (array)$this->criteriaFrom as $criteria ) { 115 array_push( $args, $form->getData($criteria) ) ; 116 } 117 $found = call_user_func_array( array($this->dao, $this->method), $args); 112 118 } else { 113 119 $found = $this->dao->{$this->method}(); 114 120 } 115 121 $result=array(); 116 122 foreach($found as $obj){ 117 $result[$obj->{$this->keyProperty}] = $obj->{$this->labelProperty}; 123 $label = '' ; 124 foreach( (array)$this->labelProperty as $property ) { 125 if (!empty( $obj->{$property})) 126 $label .= $obj->{$property}.$this->labelSeparator; 127 } 128 if ($this->labelSeparator != '') 129 $label = substr($label, 0, -strlen($this->labelSeparator)); 130 $result[$obj->{$this->keyProperty}] = $label ; 118 131 } 119 132 return $result; 120 133 } … … 122 135 public function getLabel($key){ 123 136 if($this->dao === null) $this->dao = jDao::get($this->selector, $this->profile); 124 137 $rec = $this->dao->get($key); 125 if($rec) 126 return $rec->{$this->labelProperty}; 138 if($rec) { 139 $label = '' ; 140 foreach( (array)$this->labelProperty as $property ) { 141 if (!empty( $rec->{$property})) 142 $label .= $rec->{$property}.$this->labelSeparator; 143 } 144 if ($this->labelSeparator != '') 145 $label = substr($label, 0, -strlen($this->labelSeparator)); 146 return $label ; 147 } 127 148 else 128 149 return null; 129 150 }
