eZ Publish  [4.0]
ezrangeoption.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZRangeOption class
00004 //
00005 // Created on: <17-ζΕΧ-2003 16:17:18 sp>
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 /*! \file ezrangeoption.php
00032 */
00033 
00034 /*!
00035   \class eZRangeOption ezrangeoption.php
00036   \ingroup eZDatatype
00037   \brief The class eZRangeOption does
00038 
00039 */
00040 
00041 class eZRangeOption
00042 {
00043     /*!
00044      Constructor
00045     */
00046     function eZRangeOption( $name )
00047     {
00048         $this->Name = $name;
00049         $this->Options = array();
00050         $this->OptionCount = 0;
00051     }
00052 
00053     /*!
00054      Sets the name of the option
00055     */
00056     function setName( $name )
00057     {
00058         $this->Name = $name;
00059     }
00060 
00061     /*!
00062      Returns the name of the option set.
00063     */
00064     function name()
00065     {
00066         return $this->Name;
00067     }
00068 
00069     /*!
00070      \return list of supported attributes
00071     */
00072     function attributes()
00073     {
00074         return array( 'name',
00075                       'start_value',
00076                       'stop_value',
00077                       'step_value',
00078                       'option_list' );
00079     }
00080 
00081     function hasAttribute( $name )
00082     {
00083         return in_array( $name, $this->attributes() );
00084     }
00085 
00086     function attribute( $name )
00087     {
00088         switch ( $name )
00089         {
00090             case "name" :
00091             {
00092                 return $this->Name;
00093             }break;
00094             case "start_value" :
00095             {
00096                 return $this->StartValue;
00097             }break;
00098             case "stop_value" :
00099             {
00100                 return $this->StopValue;
00101             }break;
00102             case "step_value" :
00103             {
00104                 return $this->StepValue;
00105             }break;
00106             case "option_list" :
00107             {
00108                 return $this->Options;
00109             }break;
00110             default:
00111             {
00112                 eZDebug::writeError( "Attribute '$name' does not exist", 'eZRangeOption::attribute' );
00113                 return null;
00114             }break;
00115         }
00116     }
00117 
00118     function addOption( $valueArray )
00119     {
00120         $this->Options[] = array( "id" => $this->OptionCount,
00121                                   "value" => $valueArray['value'],
00122                                   'additional_price' => 0,
00123                                   "is_default" => false );
00124 
00125         $this->OptionCount += 1;
00126     }
00127 
00128     function decodeXML( $xmlString )
00129     {
00130         $dom = new DOMDocument( '1.0', 'utf-8' );
00131         $success = $dom->loadXML( $xmlString );
00132 
00133         if ( $xmlString != "" )
00134         {
00135             // set the name of the node
00136             $rangeOptionElement = $dom->documentElement;
00137             $startValue = $rangeOptionElement->getAttribute( 'start_value' );
00138             $stopValue = $rangeOptionElement->getAttribute( 'stop_value' );
00139             $stepValue = $rangeOptionElement->getAttribute( 'step_value' );
00140             if ( $stepValue == 0 )
00141                 $stepValue = 1;
00142             $this->StartValue = $startValue;
00143             $this->StopValue = $stopValue;
00144             $this->StepValue = $stepValue;
00145 
00146 
00147             $nameNode = $dom->getElementsByTagName( "name" )->item( 0 );
00148             $this->setName( $nameNode->textContent );
00149 
00150             for ( $i = $startValue; $i <= $stopValue; $i += $stepValue )
00151             {
00152                 $this->addOption( array( 'value' => $i,
00153                                          'additional_price' => 0 ) );
00154             }
00155         }
00156         else
00157         {
00158             $this->StartValue = 0;
00159             $this->StopValue = 0;
00160             $this->StepValue = 0;
00161         }
00162     }
00163 
00164     /*!
00165      Will return the XML string for this option set.
00166     */
00167     function xmlString( )
00168     {
00169         $doc = new DOMDocument( '1.0', 'utf-8' );
00170 
00171         $root = $doc->createElement( "ezrangeoption" );
00172         $root->setAttribute( "start_value", $this->StartValue );
00173         $root->setAttribute( "stop_value", $this->StopValue );
00174         $root->setAttribute( "step_value", $this->StepValue );
00175         $doc->appendChild( $root );
00176 
00177         $name = $doc->createElement( "name", $this->Name );
00178         $root->appendChild( $name );
00179 
00180         $xml = $doc->saveXML();
00181 
00182         return $xml;
00183     }
00184 
00185     function setStartValue( $value )
00186     {
00187         $this->StartValue = $value;
00188     }
00189 
00190     function setStopValue( $value )
00191     {
00192         $this->StopValue = $value;
00193     }
00194 
00195     function setStepValue( $value )
00196     {
00197         $this->StepValue = $value;
00198     }
00199 
00200 
00201         /// Contains the Option name
00202     public $Name;
00203 
00204     /// Contains the Options
00205     public $Options;
00206 
00207     /// Contains the option counter value
00208     public $OptionCount;
00209     public $StartValue;
00210     public $StopValue;
00211     public $StepValue;
00212 }
00213 
00214 ?>