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
00042
00043
00044
00045
00046
00047
00048
00049
00050 include_once( "lib/ezxml/classes/ezxml.php" );
00051
00052 class eZOption
00053 {
00054
00055
00056 function eZOption( $name )
00057 {
00058 $this->Name = $name;
00059 $this->Options = array();
00060 $this->OptionCount = 0;
00061 }
00062
00063
00064
00065
00066 function setName( $name )
00067 {
00068 $this->Name = $name;
00069 }
00070
00071
00072
00073
00074
00075 function &name()
00076 {
00077 return $this->Name;
00078 }
00079
00080
00081
00082
00083 function addOption( $valueArray )
00084 {
00085 $value = isset( $valueArray['value'] ) ? $valueArray['value'] : '';
00086 $additional_price = isset( $valueArray['additional_price'] ) ? $valueArray['additional_price'] : '';
00087 $this->Options[] = array( "id" => $this->OptionCount,
00088 "value" => $value,
00089 'additional_price' => $additional_price,
00090 "is_default" => false );
00091
00092 $this->OptionCount += 1;
00093 }
00094
00095 function insertOption( $valueArray, $beforeID )
00096 {
00097 array_splice( $this->Options, $beforeID, 0 , array( array( "id" => $this->OptionCount,
00098 "value" => $valueArray['value'],
00099 'additional_price' => $valueArray['additional_price'],
00100 "is_default" => false ) ) );
00101 $this->OptionCount += 1;
00102 }
00103
00104 function removeOptions( $array_remove )
00105 {
00106 $options =& $this->Options;
00107 $shiftvalue = 0;
00108 foreach( $array_remove as $id )
00109 {
00110 array_splice( $options, $id - $shiftvalue, 1 );
00111 $shiftvalue++;
00112 }
00113 $this->OptionCount -= $shiftvalue;
00114 }
00115
00116 function attributes()
00117 {
00118 return array( 'name',
00119 'option_list' );
00120 }
00121
00122 function hasAttribute( $name )
00123 {
00124 return in_array( $name, $this->attributes() );
00125 }
00126
00127 function &attribute( $name )
00128 {
00129 switch ( $name )
00130 {
00131 case "name" :
00132 {
00133 return $this->Name;
00134 }break;
00135 case "option_list" :
00136 {
00137 return $this->Options;
00138 }break;
00139 default:
00140 {
00141 eZDebug::writeError( "Attribute '$name' does not exist", 'eZOption::attribute' );
00142 $retValue = null;
00143 return $retValue;
00144 }break;
00145 }
00146 }
00147
00148
00149
00150
00151 function decodeXML( $xmlString )
00152 {
00153 $xml = new eZXML();
00154
00155
00156 $dom =& $xml->domTree( $xmlString );
00157
00158 if ( $xmlString != "" )
00159 {
00160
00161 $nameArray = $dom->elementsByName( "name" );
00162 $this->setName( $nameArray[0]->textContent() );
00163
00164 $optionArray = $dom->elementsByName( "option" );
00165 $this->OptionCount = 0;
00166 if ( is_array( $optionArray ) )
00167 {
00168 foreach ( $optionArray as $option )
00169 {
00170 $this->addOption( array( 'value' => $option->textContent(),
00171 'additional_price' => $option->attributeValue( 'additional_price' ) ) );
00172 }
00173 }
00174 }
00175 else
00176 {
00177 $this->addOption( "" );
00178 $this->addOption( "" );
00179 }
00180 }
00181
00182
00183
00184
00185 function &xmlString( )
00186 {
00187 $doc = new eZDOMDocument( "Option" );
00188
00189 $root = $doc->createElementNode( "ezoption" );
00190 $doc->setRoot( $root );
00191
00192 $name = $doc->createElementNode( "name" );
00193 $nameValue = $doc->createTextNode( $this->Name );
00194 $name->appendChild( $nameValue );
00195
00196 $name->setContent( $this->Name() );
00197
00198 $root->appendChild( $name );
00199
00200 $options = $doc->createElementNode( "options" );
00201
00202 $root->appendChild( $options );
00203 $id=0;
00204 foreach ( $this->Options as $option )
00205 {
00206 unset( $optionNode );
00207 $optionNode = $doc->createElementNode( "option" );
00208 $optionNode->appendAttribute( $doc->createAttributeNode( "id", $option['id'] ) );
00209 $optionNode->appendAttribute( $doc->createAttributeNode( 'additional_price', $option['additional_price'] ) );
00210 unset( $optionValueNode );
00211 $optionValueNode = $doc->createTextNode( $option["value"] );
00212 $optionNode->appendChild( $optionValueNode );
00213
00214 $options->appendChild( $optionNode );
00215 }
00216
00217 $xml = $doc->toString();
00218
00219 return $xml;
00220 }
00221
00222
00223 var $Name;
00224
00225
00226 var $Options;
00227
00228
00229 var $OptionCount;
00230 }
00231
00232 ?>