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 include_once( "kernel/classes/ezdatatype.php" );
00041 include_once( "kernel/classes/datatypes/ezrangeoption/ezrangeoption.php" );
00042
00043 define( "EZ_RANGEOPTION_DEFAULT_NAME_VARIABLE", "_ezrangeoption_default_name_" );
00044
00045
00046 define( "EZ_DATATYPESTRING_RANGEOPTION", "ezrangeoption" );
00047
00048 class eZRangeOptionType extends eZDataType
00049 {
00050
00051
00052
00053 function eZRangeOptionType()
00054 {
00055 $this->eZDataType( EZ_DATATYPESTRING_RANGEOPTION, ezi18n( 'kernel/classes/datatypes', "Range option", 'Datatype name' ),
00056 array( 'serialize_supported' => true ) );
00057 }
00058
00059 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00060 {
00061 if ( $http->hasPostVariable( $base . "_data_rangeoption_name_" . $contentObjectAttribute->attribute( "id" ) ) and
00062 $http->hasPostVariable( $base . '_data_rangeoption_start_value_' . $contentObjectAttribute->attribute( 'id' ) ) and
00063 $http->hasPostVariable( $base . '_data_rangeoption_stop_value_' . $contentObjectAttribute->attribute( 'id' ) ) and
00064 $http->hasPostVariable( $base . '_data_rangeoption_step_value_' . $contentObjectAttribute->attribute( 'id' ) ) )
00065 {
00066
00067 $name = $http->postVariable( $base . "_data_rangeoption_name_" . $contentObjectAttribute->attribute( "id" ) );
00068 $startValue = $http->postVariable( $base . '_data_rangeoption_start_value_' . $contentObjectAttribute->attribute( 'id' ) );
00069 $stopValue = $http->postVariable( $base . '_data_rangeoption_stop_value_' . $contentObjectAttribute->attribute( 'id' ) );
00070 $stepValue = $http->postVariable( $base . '_data_rangeoption_step_value_' . $contentObjectAttribute->attribute( 'id' ) );
00071 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00072 if ( $name == '' or
00073 $startValue == '' or
00074 $stopValue == '' or
00075 $stepValue == '' )
00076 {
00077 if ( ( !$classAttribute->attribute( 'is_information_collector' ) and
00078 $contentObjectAttribute->validateIsRequired() ) )
00079 {
00080 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00081 'Missing range option input.' ) );
00082 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00083 }
00084 else
00085 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00086 }
00087 }
00088 else
00089 {
00090 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00091 }
00092
00093
00094 }
00095
00096 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00097 {
00098
00099 $optionName = $http->postVariable( $base . "_data_rangeoption_name_" . $contentObjectAttribute->attribute( "id" ) );
00100 if ( $http->hasPostVariable( $base . "_data_rangeoption_id_" . $contentObjectAttribute->attribute( "id" ) ) )
00101 $optionIDArray = $http->postVariable( $base . "_data_rangeoption_id_" . $contentObjectAttribute->attribute( "id" ) );
00102 else
00103 $optionIDArray = array();
00104 $optionStartValue = $http->postVariable( $base . "_data_rangeoption_start_value_" . $contentObjectAttribute->attribute( "id" ) );
00105 $optionStopValue = $http->postVariable( $base . "_data_rangeoption_stop_value_" . $contentObjectAttribute->attribute( "id" ) );
00106 $optionStepValue = $http->postVariable( $base . "_data_rangeoption_step_value_" . $contentObjectAttribute->attribute( "id" ) );
00107
00108 $option = new eZRangeOption( $optionName );
00109
00110 $option->setStartValue( $optionStartValue );
00111 $option->setStopValue( $optionStopValue );
00112 $option->setStepValue( $optionStepValue );
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 $contentObjectAttribute->setContent( $option );
00123 return true;
00124 }
00125
00126 function storeObjectAttribute( &$contentObjectAttribute )
00127 {
00128 $option =& $contentObjectAttribute->content();
00129 $contentObjectAttribute->setAttribute( "data_text", $option->xmlString() );
00130 }
00131
00132 function &objectAttributeContent( &$contentObjectAttribute )
00133 {
00134 $option = new eZRangeOption( "" );
00135 $option->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
00136 return $option;
00137 }
00138
00139 function toString( $contentObjectAttribute )
00140 {
00141
00142 $option = $contentObjectAttribute->attribute( 'content' );
00143 $optionArray = array();
00144 $optionArray[] = $option->attribute( 'name' );
00145 $optionArray[] = $option->attribute( 'start_value' );
00146 $optionArray[] = $option->attribute( 'stop_value' );
00147 $optionArray[] = $option->attribute( 'step_value' );
00148
00149 return implode( '|', $optionArray );
00150 }
00151
00152
00153 function fromString( &$contentObjectAttribute, $string )
00154 {
00155 if ( $string == '' )
00156 return true;
00157
00158 $optionArray = explode( '|', $string );
00159
00160 $option = new eZRangeOption( '' );
00161
00162 $option->Name = array_shift( $optionArray );
00163 $option->StartValue = array_shift( $optionArray );
00164 $option->StopValue = array_shift( $optionArray );
00165 $option->StepValue = array_shift( $optionArray );
00166
00167
00168 $contentObjectAttribute->setAttribute( "data_text", $option->xmlString() );
00169
00170 return $option;
00171
00172 }
00173
00174
00175
00176
00177 function productOptionInformation( &$objectAttribute, $optionID, &$productItem )
00178 {
00179 $option =& $objectAttribute->attribute( 'content' );
00180 foreach( $option->attribute( 'option_list' ) as $optionArray )
00181 {
00182 if ( $optionArray['id'] == $optionID )
00183 {
00184 return array( 'id' => $optionArray['id'],
00185 'name' => $option->attribute( 'name' ),
00186 'value' => $optionArray['value'],
00187 'additional_price' => $optionArray['additional_price'] );
00188 }
00189 }
00190 return false;
00191 }
00192
00193 function metaData( $contentObjectAttribute )
00194 {
00195 return $contentObjectAttribute->attribute( "data_text" );
00196 }
00197
00198 function title( &$contentObjectAttribute )
00199 {
00200 $option = new eZRangeOption( "" );
00201 $option->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
00202 return $option->attribute('name');
00203 }
00204
00205 function hasObjectAttributeContent( &$contentObjectAttribute )
00206 {
00207 return true;
00208 }
00209
00210
00211
00212
00213 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
00214 {
00215 if ( $currentVersion == false )
00216 {
00217 $option =& $contentObjectAttribute->content();
00218 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
00219 if ( !$option )
00220 {
00221 $option = new eZRangeOption( $contentClassAttribute->attribute( 'data_text1' ) );
00222 }
00223 else
00224 {
00225 $option->setName( $contentClassAttribute->attribute( 'data_text1' ) );
00226 }
00227 $contentObjectAttribute->setAttribute( "data_text", $option->xmlString() );
00228 $contentObjectAttribute->setContent( $option );
00229 }
00230 }
00231
00232
00233
00234
00235 function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
00236 {
00237 $defaultValueName = $base . EZ_RANGEOPTION_DEFAULT_NAME_VARIABLE . $classAttribute->attribute( 'id' );
00238 if ( $http->hasPostVariable( $defaultValueName ) )
00239 {
00240 $defaultValueValue = $http->postVariable( $defaultValueName );
00241
00242 if ($defaultValueValue == ""){
00243 $defaultValueValue = "";
00244 }
00245 $classAttribute->setAttribute( 'data_text1', $defaultValueValue );
00246 return true;
00247 }
00248 return false;
00249 }
00250
00251
00252
00253
00254 function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00255 {
00256 $defaultName = $classAttribute->attribute( 'data_text1' );
00257 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'default-name', $defaultName ) );
00258 }
00259
00260
00261
00262
00263 function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00264 {
00265 $defaultName = $attributeParametersNode->elementTextContentByName( 'default-name' );
00266 $classAttribute->setAttribute( 'data_text1', $defaultName );
00267 }
00268
00269
00270
00271
00272 function serializeContentObjectAttribute( &$package, &$objectAttribute )
00273 {
00274 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
00275
00276 $xml = new eZXML();
00277 $domDocument = $xml->domTree( $objectAttribute->attribute( 'data_text' ) );
00278 $node->appendChild( $domDocument->root() );
00279
00280 return $node;
00281 }
00282
00283
00284
00285
00286 function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode )
00287 {
00288 $rootNode = $attributeNode->firstChild();
00289 $xmlString = $rootNode->attributeValue( 'local_name' ) == 'data-text' ? '' : $rootNode->toString( 0 );
00290 $objectAttribute->setAttribute( 'data_text', $xmlString );
00291 }
00292 }
00293
00294 eZDataType::register( EZ_DATATYPESTRING_RANGEOPTION, "ezrangeoptiontype" );
00295
00296 ?>