|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZRangeOptionType class 00004 // 00005 // Created on: <17-Feb-2003 16:24:57 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 ezrangeoptiontype.php 00032 */ 00033 00034 /*! 00035 \class eZRangeOptionType ezrangeoptiontype.php 00036 \ingroup eZDatatype 00037 \brief The class eZRangeOptionType does 00038 00039 */ 00040 //include_once( "kernel/classes/ezdatatype.php" ); 00041 //include_once( "kernel/classes/datatypes/ezrangeoption/ezrangeoption.php" ); 00042 00043 class eZRangeOptionType extends eZDataType 00044 { 00045 const DEFAULT_NAME_VARIABLE = "_ezrangeoption_default_name_"; 00046 00047 const DATA_TYPE_STRING = "ezrangeoption"; 00048 00049 /*! 00050 Constructor 00051 */ 00052 function eZRangeOptionType() 00053 { 00054 $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'kernel/classes/datatypes', "Range option", 'Datatype name' ), 00055 array( 'serialize_supported' => true ) ); 00056 } 00057 00058 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00059 { 00060 if ( $http->hasPostVariable( $base . "_data_rangeoption_name_" . $contentObjectAttribute->attribute( "id" ) ) and 00061 $http->hasPostVariable( $base . '_data_rangeoption_start_value_' . $contentObjectAttribute->attribute( 'id' ) ) and 00062 $http->hasPostVariable( $base . '_data_rangeoption_stop_value_' . $contentObjectAttribute->attribute( 'id' ) ) and 00063 $http->hasPostVariable( $base . '_data_rangeoption_step_value_' . $contentObjectAttribute->attribute( 'id' ) ) ) 00064 { 00065 00066 $name = $http->postVariable( $base . "_data_rangeoption_name_" . $contentObjectAttribute->attribute( "id" ) ); 00067 $startValue = $http->postVariable( $base . '_data_rangeoption_start_value_' . $contentObjectAttribute->attribute( 'id' ) ); 00068 $stopValue = $http->postVariable( $base . '_data_rangeoption_stop_value_' . $contentObjectAttribute->attribute( 'id' ) ); 00069 $stepValue = $http->postVariable( $base . '_data_rangeoption_step_value_' . $contentObjectAttribute->attribute( 'id' ) ); 00070 $classAttribute = $contentObjectAttribute->contentClassAttribute(); 00071 if ( $name == '' or 00072 $startValue == '' or 00073 $stopValue == '' or 00074 $stepValue == '' ) 00075 { 00076 if ( ( !$classAttribute->attribute( 'is_information_collector' ) and 00077 $contentObjectAttribute->validateIsRequired() ) ) 00078 { 00079 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 00080 'Missing range option input.' ) ); 00081 return eZInputValidator::STATE_INVALID; 00082 } 00083 else 00084 return eZInputValidator::STATE_ACCEPTED; 00085 } 00086 } 00087 else 00088 { 00089 return eZInputValidator::STATE_ACCEPTED; 00090 } 00091 00092 00093 } 00094 00095 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00096 { 00097 00098 $optionName = $http->postVariable( $base . "_data_rangeoption_name_" . $contentObjectAttribute->attribute( "id" ) ); 00099 if ( $http->hasPostVariable( $base . "_data_rangeoption_id_" . $contentObjectAttribute->attribute( "id" ) ) ) 00100 $optionIDArray = $http->postVariable( $base . "_data_rangeoption_id_" . $contentObjectAttribute->attribute( "id" ) ); 00101 else 00102 $optionIDArray = array(); 00103 $optionStartValue = $http->postVariable( $base . "_data_rangeoption_start_value_" . $contentObjectAttribute->attribute( "id" ) ); 00104 $optionStopValue = $http->postVariable( $base . "_data_rangeoption_stop_value_" . $contentObjectAttribute->attribute( "id" ) ); 00105 $optionStepValue = $http->postVariable( $base . "_data_rangeoption_step_value_" . $contentObjectAttribute->attribute( "id" ) ); 00106 00107 $option = new eZRangeOption( $optionName ); 00108 00109 $option->setStartValue( $optionStartValue ); 00110 $option->setStopValue( $optionStopValue ); 00111 $option->setStepValue( $optionStepValue ); 00112 00113 /* $i = 0; 00114 foreach ( $optionIDArray as $id ) 00115 { 00116 $option->addOption( array( 'value' => $optionValueArray[$i], 00117 'additional_price' => $optionAdditionalPriceArray[$i] ) ); 00118 $i++; 00119 } 00120 */ 00121 $contentObjectAttribute->setContent( $option ); 00122 return true; 00123 } 00124 00125 function storeObjectAttribute( $contentObjectAttribute ) 00126 { 00127 $option = $contentObjectAttribute->content(); 00128 $contentObjectAttribute->setAttribute( "data_text", $option->xmlString() ); 00129 } 00130 00131 function objectAttributeContent( $contentObjectAttribute ) 00132 { 00133 $option = new eZRangeOption( "" ); 00134 $option->decodeXML( $contentObjectAttribute->attribute( "data_text" ) ); 00135 return $option; 00136 } 00137 00138 function toString( $contentObjectAttribute ) 00139 { 00140 00141 $option = $contentObjectAttribute->attribute( 'content' ); 00142 $optionArray = array(); 00143 $optionArray[] = $option->attribute( 'name' ); 00144 $optionArray[] = $option->attribute( 'start_value' ); 00145 $optionArray[] = $option->attribute( 'stop_value' ); 00146 $optionArray[] = $option->attribute( 'step_value' ); 00147 00148 return implode( '|', $optionArray ); 00149 } 00150 00151 00152 function fromString( $contentObjectAttribute, $string ) 00153 { 00154 if ( $string == '' ) 00155 return true; 00156 00157 $optionArray = explode( '|', $string ); 00158 00159 $option = new eZRangeOption( '' ); 00160 00161 $option->Name = array_shift( $optionArray ); 00162 $option->StartValue = array_shift( $optionArray ); 00163 $option->StopValue = array_shift( $optionArray ); 00164 $option->StepValue = array_shift( $optionArray ); 00165 00166 00167 $contentObjectAttribute->setAttribute( "data_text", $option->xmlString() ); 00168 00169 return $option; 00170 00171 } 00172 /*! 00173 Finds the option which has the ID that matches \a $optionID, if found it returns 00174 an option structure. 00175 */ 00176 function productOptionInformation( $objectAttribute, $optionID, $productItem ) 00177 { 00178 $option = $objectAttribute->attribute( 'content' ); 00179 foreach( $option->attribute( 'option_list' ) as $optionArray ) 00180 { 00181 if ( $optionArray['id'] == $optionID ) 00182 { 00183 return array( 'id' => $optionArray['id'], 00184 'name' => $option->attribute( 'name' ), 00185 'value' => $optionArray['value'], 00186 'additional_price' => $optionArray['additional_price'] ); 00187 } 00188 } 00189 return false; 00190 } 00191 00192 function metaData( $contentObjectAttribute ) 00193 { 00194 return $contentObjectAttribute->attribute( "data_text" ); 00195 } 00196 00197 function title( $contentObjectAttribute, $name = null ) 00198 { 00199 $option = new eZRangeOption( "" ); 00200 $option->decodeXML( $contentObjectAttribute->attribute( "data_text" ) ); 00201 return $option->attribute('name'); 00202 } 00203 00204 function hasObjectAttributeContent( $contentObjectAttribute ) 00205 { 00206 return true; 00207 } 00208 00209 /*! 00210 Sets the default value. 00211 */ 00212 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute ) 00213 { 00214 if ( $currentVersion == false ) 00215 { 00216 $option = $contentObjectAttribute->content(); 00217 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute(); 00218 if ( !$option ) 00219 { 00220 $option = new eZRangeOption( $contentClassAttribute->attribute( 'data_text1' ) ); 00221 } 00222 else 00223 { 00224 $option->setName( $contentClassAttribute->attribute( 'data_text1' ) ); 00225 } 00226 $contentObjectAttribute->setAttribute( "data_text", $option->xmlString() ); 00227 $contentObjectAttribute->setContent( $option ); 00228 } 00229 } 00230 00231 /*! 00232 \reimp 00233 */ 00234 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute ) 00235 { 00236 $defaultValueName = $base . self::DEFAULT_NAME_VARIABLE . $classAttribute->attribute( 'id' ); 00237 if ( $http->hasPostVariable( $defaultValueName ) ) 00238 { 00239 $defaultValueValue = $http->postVariable( $defaultValueName ); 00240 00241 if ($defaultValueValue == ""){ 00242 $defaultValueValue = ""; 00243 } 00244 $classAttribute->setAttribute( 'data_text1', $defaultValueValue ); 00245 return true; 00246 } 00247 return false; 00248 } 00249 00250 /*! 00251 \reimp 00252 */ 00253 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00254 { 00255 $defaultName = $classAttribute->attribute( 'data_text1' ); 00256 $dom = $attributeParametersNode->ownerDocument; 00257 $defaultNameNode = $dom->createElement( 'default-name' ); 00258 $defaultNameNode->appendChild( $dom->createTextNode( $defaultName ) ); 00259 $attributeParametersNode->appendChild( $defaultNameNode ); 00260 } 00261 00262 /*! 00263 \reimp 00264 */ 00265 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00266 { 00267 $defaultName = $attributeParametersNode->getElementsByTagName( 'default-name' )->item( 0 )->textContent; 00268 $classAttribute->setAttribute( 'data_text1', $defaultName ); 00269 } 00270 00271 /*! 00272 \reimp 00273 */ 00274 function serializeContentObjectAttribute( $package, $objectAttribute ) 00275 { 00276 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute ); 00277 00278 $domDocument = new DOMDocument( '1.0', 'utf-8' ); 00279 $success = $domDocument->loadXML( $objectAttribute->attribute( 'data_text' ) ); 00280 00281 $importedRoot = $node->ownerDocument->importNode( $domDocument->documentElement, true ); 00282 $node->appendChild( $importedRoot ); 00283 00284 return $node; 00285 } 00286 00287 /*! 00288 \reimp 00289 */ 00290 function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode ) 00291 { 00292 $rootNode = $attributeNode->getElementsByTagName( 'ezrangeoption' )->item( 0 ); 00293 $xmlString = $rootNode ? $rootNode->ownerDocument->saveXML( $rootNode ) : ''; 00294 $objectAttribute->setAttribute( 'data_text', $xmlString ); 00295 } 00296 } 00297 00298 eZDataType::register( eZRangeOptionType::DATA_TYPE_STRING, "eZRangeOptionType" ); 00299 00300 ?>