00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class eZRangeOption
00042 {
00043
00044
00045
00046 function eZRangeOption( $name )
00047 {
00048 $this->Name = $name;
00049 $this->Options = array();
00050 $this->OptionCount = 0;
00051 }
00052
00053
00054
00055
00056 function setName( $name )
00057 {
00058 $this->Name = $name;
00059 }
00060
00061
00062
00063
00064 function &name()
00065 {
00066 return $this->Name;
00067 }
00068
00069
00070
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 $retValue = null;
00114 return $retValue;
00115 }break;
00116 }
00117 }
00118
00119 function addOption( $valueArray )
00120 {
00121 $this->Options[] = array( "id" => $this->OptionCount,
00122 "value" => $valueArray['value'],
00123 'additional_price' => 0,
00124 "is_default" => false );
00125
00126 $this->OptionCount += 1;
00127 }
00128
00129 function decodeXML( $xmlString )
00130 {
00131 include_once( 'lib/ezxml/classes/ezxml.php' );
00132
00133 $xml = new eZXML();
00134
00135
00136 $dom =& $xml->domTree( $xmlString );
00137
00138 if ( $xmlString != "" )
00139 {
00140
00141 $rangeOptionElement =& $dom->root( );
00142
00143 $startValue = $rangeOptionElement->attributeValue( 'start_value' );
00144 $stopValue = $rangeOptionElement->attributeValue( 'stop_value' );
00145 $stepValue = $rangeOptionElement->attributeValue( 'step_value' );
00146 if ( $stepValue == 0 )
00147 $stepValue = 1;
00148 $this->StartValue = $startValue;
00149 $this->StopValue = $stopValue;
00150 $this->StepValue = $stepValue;
00151
00152
00153 $nameArray =& $dom->elementsByName( "name" );
00154 $this->setName( $nameArray[0]->textContent() );
00155
00156 for ( $i=$startValue;$i<=$stopValue;$i+=$stepValue )
00157 {
00158 $this->addOption( array( 'value' => $i,
00159 'additional_price' => 0 ) );
00160 }
00161 }
00162 else
00163 {
00164 $this->StartValue = 0;
00165 $this->StopValue = 0;
00166 $this->StepValue = 0;
00167 }
00168 }
00169
00170
00171
00172
00173 function &xmlString( )
00174 {
00175 include_once( 'lib/ezxml/classes/ezdomdocument.php' );
00176
00177 $doc = new eZDOMDocument( "Option" );
00178
00179 $root = $doc->createElementNode( "ezrangeoption" );
00180 $root->appendAttribute( $doc->createAttributeNode( "start_value", $this->StartValue ) );
00181 $root->appendAttribute( $doc->createAttributeNode( "stop_value", $this->StopValue ) );
00182 $root->appendAttribute( $doc->createAttributeNode( "step_value", $this->StepValue ) );
00183 $doc->setRoot( $root );
00184
00185 $name = $doc->createElementNode( "name" );
00186 $nameValue = $doc->createTextNode( $this->Name );
00187 $name->appendChild( $nameValue );
00188
00189 $name->setContent( $this->Name() );
00190
00191 $root->appendChild( $name );
00192
00193 $xml = $doc->toString();
00194
00195 return $xml;
00196 }
00197
00198 function setStartValue( $value )
00199 {
00200 $this->StartValue = $value;
00201 }
00202
00203 function setStopValue( $value )
00204 {
00205 $this->StopValue = $value;
00206 }
00207
00208 function setStepValue( $value )
00209 {
00210 $this->StepValue = $value;
00211 }
00212
00213
00214
00215 var $Name;
00216
00217
00218 var $Options;
00219
00220
00221 var $OptionCount;
00222 var $StartValue;
00223 var $StopValue;
00224 var $StepValue;
00225 }
00226
00227 ?>