Ticket #581: jelix-trunk-#xxx.patch

File jelix-trunk-#xxx.patch, 4.6 kB (added by bibo, 8 months ago)

rapid patch

  • lib/jelix/forms/jFormsCompiler_jf_1_1.class.php

    old new  
    109109                    throw new jException('jelix~formserr.attribute.missing',array('method', 'datasource',$this->sourceFile)); 
    110110                if(!isset($attrs['labelproperty'])) 
    111111                    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                } 
    112118 
    113119                if(isset($attrs['criteria'])) 
    114120                    $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                } 
    117127                else 
    118128                    $criteria=''; 
    119129 
    120130                $source[]='$ctrl->datasource = new jFormsDaoDatasource(\''.$attrs['dao'].'\',\''. 
    121                                 $attrs['method'].'\',\''.$attrs['labelproperty'].'\',\''.$daovalue.'\''.$criteria.');'; 
     131                                $attrs['method'].'\','.$label.',\''.$daovalue.'\''.$criteria.');'; 
    122132                if($controltype == 'submit'){ 
    123133                    $source[]='$ctrl->standalone=false;'; 
    124134                } 
  • lib/jelix/forms/jFormsDatasource.class.php

    old new  
    33* @package     jelix 
    44* @subpackage  forms 
    55* @author      Laurent Jouanneau 
    6 * @contributor 
     6* @contributor Dominique Papin 
    77* @copyright   2006-2007 Laurent Jouanneau 
     8* @copyright   2008 Dominique Papin 
    89* @link        http://www.jelix.org 
    910* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
    1011*/ 
     
    1718 */ 
    1819interface jIFormsDatasource { 
    1920    /** 
    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 
    2122     * an associative array  key => label 
    2223     * @param jFormsBase $form  the form 
    2324     * @return array the data 
     
    2627 
    2728    /** 
    2829     * Return the label corresponding to the given key 
    29      * @param string $key the key  
     30     * @param string $key the key 
    3031     * @return string the label 
    3132     */ 
    3233    public function getLabel($key); 
     
    8990        $this->selector  = $selector; 
    9091        $this->method = $method ; 
    9192        $this->labelProperty = $label; 
     93        $this->separator = null ; 
     94        if (is_array($this->labelProperty)) 
     95            $this->separator = array_pop($this->labelProperty); 
    9296        $this->criteria = $criteria; 
    9397        $this->criteriaFrom = $criteriaFrom; 
    9498        if($key == ''){ 
     
    105109        if($this->criteria !== null) { 
    106110            $found = $this->dao->{$this->method}($this->criteria); 
    107111        } 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); 
    109117        } else { 
    110118            $found = $this->dao->{$this->method}(); 
    111119        } 
    112120        $result=array(); 
    113121        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 ; 
    115130        } 
    116131        return $result; 
    117132    } 
     
    126141    } 
    127142 
    128143} 
    129  
Download in other formats: Original Format