eZ Publish  [4.0]
eztemplateoperatorelement.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZTemplateOperatorElement class
00004 //
00005 // Created on: <01-Mar-2002 13:49:50 amos>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \defgroup eZTemplateOperators Template operators
00032     \ingroup eZTemplate
00033 */
00034 
00035 /*!
00036   \class eZTemplateOperatorElement eztemplateoperatorelement.php
00037   \ingroup eZTemplateElements
00038   \brief Represents an operator element in the template tree.
00039 
00040   This class represents an operator with it's parameters.
00041 */
00042 
00043 class eZTemplateOperatorElement
00044 {
00045     /*!
00046      Initializes the operator with a name and parameters.
00047     */
00048     function eZTemplateOperatorElement( $name, $params, $resource = null, $templateName = null )
00049     {
00050         $this->Name = $name;
00051         $this->Params = $params;
00052         $this->Resource = $resource;
00053         $this->TemplateName = $templateName;
00054     }
00055 
00056     function setResourceRelation( $resource )
00057     {
00058         $this->Resource = $resource;
00059     }
00060 
00061     function setTemplateNameRelation( $templateName )
00062     {
00063         $this->TemplateName = $templateName;
00064     }
00065 
00066     function resourceRelation()
00067     {
00068         return $this->Resource;
00069     }
00070 
00071     function templateNameRelation()
00072     {
00073         return $this->TemplateName;
00074     }
00075 
00076     /*!
00077      Returns a reference to the name.
00078     */
00079     function &name()
00080     {
00081         return $this->Name;
00082     }
00083 
00084     function serializeData()
00085     {
00086         return array( 'class_name' => 'eZTemplateOperatorElement',
00087                       'parameters' => array( 'name', 'parameters', 'resource', 'template_name' ),
00088                       'variables' => array( 'name' => 'Name',
00089                                             'parameters' => 'Params',
00090                                             'resource' => 'Resource',
00091                                             'template_name' => 'TemplateName' ) );
00092     }
00093 
00094     /*!
00095      Process the operator and sets $value.
00096 
00097     */
00098     function process( $tpl, &$value, $nspace, $current_nspace )
00099     {
00100         $named_params = array();
00101         $param_list = $tpl->operatorParameterList( $this->Name );
00102         $i = 0;
00103         foreach ( $param_list as $param_name => $param_type )
00104         {
00105             if ( !isset( $this->Params[$i] ) or
00106                  $this->Params[$i]["type"] == "null" )
00107             {
00108                 if ( $param_type["required"] )
00109                 {
00110                     $tpl->warning( "eZTemplateOperatorElement", "Parameter '$param_name' ($i) missing" );
00111                     $named_params[$param_name] = $param_type["default"];
00112                 }
00113                 else
00114                 {
00115                     $named_params[$param_name] = $param_type["default"];
00116                 }
00117             }
00118             else
00119             {
00120                 $param_data = $this->Params[$i];
00121                 $named_params[$param_name] = $tpl->elementValue( $param_data, $nspace );
00122             }
00123             ++$i;
00124         }
00125         if ( $param_list !== null )
00126             $tpl->doOperator( $this, $nspace, $current_nspace, $value, $this->Name, $this->Params, $named_params );
00127         else
00128             $tpl->doOperator( $this, $nspace, $current_nspace, $value, $this->Name, $this->Params );
00129     }
00130 
00131     /*!
00132      Returns a reference to the parameter array.
00133     */
00134     function &parameters()
00135     {
00136         return $this->Params;
00137     }
00138 
00139     /// The operator name
00140     public $Name;
00141     /// The paramer array
00142     public $Params;
00143     public $Resource;
00144     public $TemplateName;
00145 }
00146 
00147 ?>