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

File jelix-trunk-#581.patch, 5.7 kB (added by bibo, 7 months ago)

updated on laurentj comments.

  • lib/jelix/docs/ns/jforms_1.1.rng

    old new  
    312312                <attribute name="dao" /> 
    313313                <attribute name="daomethod" /> 
    314314                <attribute name="labelproperty" /> 
     315                <optional><attribute name="labelseparator" /></optional> 
    315316                <optional><attribute name="valueproperty" /></optional> 
    316317                <optional> 
    317318                    <choice> 
  • lib/jelix/forms/jFormsCompiler_jf_1_1.class.php

    old new  
    102102 
    103103            if(isset($attrs['dao'])) { 
    104104                if ( isset($attrs['profile'])) 
    105                     $profile = '\''.$attrs['profile'].'\''; 
     105                    $profile = ',\''.$attrs['profile'].'\''; 
    106106                else 
    107                     $profile = '\'\''; 
     107                    $profile = ',\'\''; 
    108108                if(isset($attrs['valueproperty'])) { 
    109109                    $daovalue = $attrs['valueproperty']; 
    110110                } else 
     
    114114                if(!isset($attrs['labelproperty'])) 
    115115                    throw new jException('jelix~formserr.attribute.missing',array('method', 'datasource',$this->sourceFile)); 
    116116 
     117                if ( isset($attrs['labelseparator'])) 
     118                    $labelSeparator = ',\''.$attrs['labelseparator'].'\''; 
     119                else 
     120                    $labelSeparator = ',\'\''; 
    117121                if(isset($attrs['criteria'])) 
    118122                    $criteria=',\''.$attrs['criteria'].'\''; 
    119123                elseif(isset($attrs['criteriafrom'])) 
     
    122126                    $criteria=''; 
    123127 
    124128                $source[]='$ctrl->datasource = new jFormsDaoDatasource(\''.$attrs['dao'].'\',\''. 
    125                                  $attrs['method'].'\',\''.$attrs['labelproperty'].'\',\''.$daovalue.'\','.$profile.$criteria.');'; 
     129                                 $attrs['method'].'\',\''.$attrs['labelproperty'].'\',\''.$daovalue.'\''.$labelSeparator.$profile.$criteria.');'; 
    126130                if($controltype == 'submit'){ 
    127131                    $source[]='$ctrl->standalone=false;'; 
    128132                } 
  • lib/jelix/forms/jFormsDatasource.class.php

    old new  
    7878 
    7979    protected $selector; 
    8080    protected $method; 
    81     protected $labelProperty; 
     81    protected $labelProperty = array(); 
     82    protected $labelSeparator; 
    8283    protected $keyProperty; 
    8384    protected $profile; 
    8485 
    8586    protected $criteria; 
    86     protected $criteriaForm
     87    protected $criteriaFrom = array()
    8788 
    8889    protected $dao = null; 
    8990 
    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){ 
    9192        $this->selector  = $selector; 
    9293        $this->profile = $profile; 
    9394        $this->method = $method ; 
    94         $this->labelProperty = $label; 
     95        $this->labelProperty = preg_split('/[\s,]+/',$label); 
     96        $this->labelSeparator = $labelSeparator; 
    9597        $this->criteria = $criteria; 
    96         $this->criteriaFrom = $criteriaFrom
     98        $this->criteriaFrom = preg_split('/[\s,]+/',$criteriaFrom)
    9799        if($key == ''){ 
    98100            $rec = jDao::createRecord($this->selector, $this->profile); 
    99101            $pfields = $rec->getPrimaryKeyNames(); 
     
    108110        if($this->criteria !== null) { 
    109111            $found = $this->dao->{$this->method}($this->criteria); 
    110112        } 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); 
    112118        } else { 
    113119            $found = $this->dao->{$this->method}(); 
    114120        } 
    115121        $result=array(); 
    116122        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 ; 
    118131        } 
    119132        return $result; 
    120133    } 
     
    122135    public function getLabel($key){ 
    123136        if($this->dao === null) $this->dao = jDao::get($this->selector, $this->profile); 
    124137        $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        } 
    127148        else 
    128149            return null; 
    129150    } 
Download in other formats: Original Format