Show
Ignore:
Timestamp:
08/08/06 23:10:42 (2 years ago)
Author:
schst
Message:

Fixed bug #155: patTemplate now automatically handles nested objects.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/patTemplate.php

    r438 r441  
    716716    * @see      addVar(), addRows(), addGlobalVar(), addGlobalVars() 
    717717    */ 
    718     function addVars( $template, $variables, $prefix = '' ) 
    719     { 
    720         $template   =   strtolower( $template ); 
    721         $prefix     =   strtoupper( $prefix ); 
    722         $variables  =   array_change_key_case( $variables, CASE_UPPER ); 
     718    function addVars($template, $variables, $prefix = '') { 
     719 
     720        $template   =   strtolower($template); 
     721        $prefix     =   strtoupper($prefix); 
     722        $variables  =   array_change_key_case($variables, CASE_UPPER); 
    723723 
    724724        foreach ($variables as $varname => $value) { 
     
    810810    function addObject( $template, $object, $prefix = '', $ignorePrivate = false ) 
    811811    { 
    812         if( is_array( $object ) ) { 
     812        if (is_array($object)) { 
    813813            $rows = array(); 
    814             foreach($object as $o) { 
    815                 array_push( $rows, $this->getObjectVars($o, $ignorePrivate) ); 
     814            foreach ($object as $o) { 
     815                array_push($rows, $this->getObjectVars($o, $ignorePrivate)); 
    816816            } 
    817817 
    818818            return $this->addRows( $template, $rows, $prefix ); 
    819819        } elseif (is_object($object)) { 
    820             return $this->addVars( $template, $this->getObjectVars($object, $ignorePrivate), $prefix ); 
     820            return $this->addVars($template, $this->getObjectVars($object, $ignorePrivate), $prefix); 
    821821        } 
    822822        return false; 
     
    17431743        foreach( $this->_templates[$template]['vars'] as $key => $value ) 
    17441744        { 
    1745             if( is_array( $value ) ) 
    1746             { 
    1747                 if( count( $this->_templates[$template]['currentDependencies'] ) == 1 ) 
    1748                 { 
    1749                     $child  =   $this->_templates[$template]['currentDependencies'][0]; 
     1745            if (is_array($value) || is_object($value)) { 
     1746                if (count($this->_templates[$template]['currentDependencies'] ) == 1) { 
     1747                    $child = $this->_templates[$template]['currentDependencies'][0]; 
     1748                } else { 
     1749                    if (isset($this->_templates[$template]['attributes']['child'])) { 
     1750                        $child = $this->_templates[$template]['attributes']['child']; 
     1751                    } else { 
     1752                        continue; 
     1753                    } 
    17501754                } 
    1751                 else 
    1752                 { 
    1753                    if( isset( $this->_templates[$template]['attributes']['child'] ) ) 
    1754                        $child = $this->_templates[$template]['attributes']['child']
    1755                    else 
    1756                        continue
     1755 
     1756                $this->setAttribute( $child, 'autoclear', 'yes' ); 
     1757                if (is_object($value)) { 
     1758                    $this->addObject($child, $value, $key . '_')
     1759                } else { 
     1760                    $this->addVar( $child, $key, $value )
    17571761                } 
    1758  
    1759                 $this->setAttribute( $child, 'autoclear', 'yes' ); 
    1760                 $this->addVar( $child, $key, $value ); 
    17611762                continue; 
    17621763            }