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