eZ Publish  [trunk]
ezkerneloperator.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the eZKernelOperator class.
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package kernel
00009  */
00010 
00011 /*!
00012   \class eZKerneloperator ezkerneloperator.php
00013   \brief The class eZKernelOperator does handles eZ Publish preferences
00014 
00015 */
00016 class eZKernelOperator
00017 {
00018     /*!
00019      Initializes the object with the name $name
00020     */
00021     function eZKernelOperator( $name = "ezpreference" )
00022     {
00023         $this->Operators = array( $name );
00024     }
00025 
00026     /*!
00027       Returns the template operators.
00028     */
00029     function operatorList()
00030     {
00031         return $this->Operators;
00032     }
00033 
00034     /*!
00035      \return true to tell the template engine that the parameter list exists per operator type.
00036     */
00037     function namedParameterPerOperator()
00038     {
00039         return true;
00040     }
00041 
00042     /*!
00043      See eZTemplateOperator::namedParameterList()
00044     */
00045     function namedParameterList()
00046     {
00047         return array( 'ezpreference' => array( 'name' => array( 'type' => 'string',
00048                                                                 'required' => true,
00049                                                                 'default' => false ) ) );
00050     }
00051 
00052     function operatorTemplateHints()
00053     {
00054         return array( 'ezpreference' => array( 'input' => false,
00055                                                'output' => true,
00056                                                'parameters' => 1,
00057                                                'element-transformation' => true,
00058                                                'transform-parameters' => true,
00059                                                'input-as-parameter' => false,
00060                                                'element-transformation-func' => 'preferencesTransformation') );
00061     }
00062 
00063     function preferencesTransformation( $operatorName, &$node, $tpl, &$resourceData,
00064                                         $element, $lastElement, $elementList, $elementTree, &$parameters )
00065     {
00066         if ( count( $parameters[0] ) == 0 )
00067             return false;
00068         $values = array();
00069         if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
00070         {
00071             $name = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
00072             $nameText = eZPHPCreator::variableText( $name, 0, 0, false );
00073         }
00074         else
00075         {
00076             $nameText = '%1%';
00077             $values[] = $parameters[0];
00078         }
00079         return array( eZTemplateNodeTool::createCodePieceElement( "%output% = eZPreferences::value( $nameText );\n",
00080                                                                   $values ) );
00081     }
00082 
00083     function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
00084     {
00085         switch ( $operatorName )
00086         {
00087             case 'ezpreference':
00088             {
00089                 $name = $namedParameters['name'];
00090                 $value = eZPreferences::value( $name );
00091                 $operatorValue = $value;
00092             }break;
00093 
00094             default:
00095             {
00096                 eZDebug::writeError( "Unknown kernel operator: $operatorName" );
00097             }break;
00098         }
00099     }
00100     public $Operators;
00101 }
00102 ?>