Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezrangeoptiontype.php
Go to the documentation of this file.
1 <?php
17 class eZRangeOptionType extends eZDataType
18 {
19 const DEFAULT_NAME_VARIABLE = "_ezrangeoption_default_name_";
20
21 const DATA_TYPE_STRING = "ezrangeoption";
22
23 public function __construct()
24 {
25 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Range option", 'Datatype name' ),
26 array( 'serialize_supported' => true ) );
27 }
28
29 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
30 {
31 $classAttribute = $contentObjectAttribute->contentClassAttribute();
32
33 if ( $http->hasPostVariable( $base . "_data_rangeoption_name_" . $contentObjectAttribute->attribute( "id" ) ) and
34 $http->hasPostVariable( $base . '_data_rangeoption_start_value_' . $contentObjectAttribute->attribute( 'id' ) ) and
35 $http->hasPostVariable( $base . '_data_rangeoption_stop_value_' . $contentObjectAttribute->attribute( 'id' ) ) and
36 $http->hasPostVariable( $base . '_data_rangeoption_step_value_' . $contentObjectAttribute->attribute( 'id' ) ) )
37 {
38 $name = $http->postVariable( $base . "_data_rangeoption_name_" . $contentObjectAttribute->attribute( "id" ) );
39 $startValue = $http->postVariable( $base . '_data_rangeoption_start_value_' . $contentObjectAttribute->attribute( 'id' ) );
40 $stopValue = $http->postVariable( $base . '_data_rangeoption_stop_value_' . $contentObjectAttribute->attribute( 'id' ) );
41 $stepValue = $http->postVariable( $base . '_data_rangeoption_step_value_' . $contentObjectAttribute->attribute( 'id' ) );
42
43 if ( $name == '' or
44 $startValue == '' or
45 $stopValue == '' or
46 $stepValue == '' )
47 {
48 if ( ( !$classAttribute->attribute( 'is_information_collector' ) and
49 $contentObjectAttribute->validateIsRequired() ) )
50 {
51 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
52 'Missing range option input.' ) );
53 return eZInputValidator::STATE_INVALID;
54 }
55 else
56 return eZInputValidator::STATE_ACCEPTED;
57 }
58 }
59 else if ( !$classAttribute->attribute( 'is_information_collector' ) and $contentObjectAttribute->validateIsRequired() )
60 {
61 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'Missing range option input.' ) );
62 return eZInputValidator::STATE_INVALID;
63 }
64 else
65 {
66 return eZInputValidator::STATE_ACCEPTED;
67 }
68
69
70 }
71
72 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
73 {
74
75 $optionName = $http->postVariable( $base . "_data_rangeoption_name_" . $contentObjectAttribute->attribute( "id" ) );
76 if ( $http->hasPostVariable( $base . "_data_rangeoption_id_" . $contentObjectAttribute->attribute( "id" ) ) )
77 $optionIDArray = $http->postVariable( $base . "_data_rangeoption_id_" . $contentObjectAttribute->attribute( "id" ) );
78 else
79 $optionIDArray = array();
80 $optionStartValue = $http->postVariable( $base . "_data_rangeoption_start_value_" . $contentObjectAttribute->attribute( "id" ) );
81 $optionStopValue = $http->postVariable( $base . "_data_rangeoption_stop_value_" . $contentObjectAttribute->attribute( "id" ) );
82 $optionStepValue = $http->postVariable( $base . "_data_rangeoption_step_value_" . $contentObjectAttribute->attribute( "id" ) );
83
84 $option = new eZRangeOption( $optionName );
85
86 $option->setStartValue( $optionStartValue );
87 $option->setStopValue( $optionStopValue );
88 $option->setStepValue( $optionStepValue );
89
90 /* $i = 0;
91 foreach ( $optionIDArray as $id )
92 {
93 $option->addOption( array( 'value' => $optionValueArray[$i],
94 'additional_price' => $optionAdditionalPriceArray[$i] ) );
95 $i++;
96 }
97 */
98 $contentObjectAttribute->setContent( $option );
99 return true;
100 }
101
102 function storeObjectAttribute( $contentObjectAttribute )
103 {
104 $option = $contentObjectAttribute->content();
105 $contentObjectAttribute->setAttribute( "data_text", $option->xmlString() );
106 }
107
108 function objectAttributeContent( $contentObjectAttribute )
109 {
110 $option = new eZRangeOption( "" );
111 $option->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
112 return $option;
113 }
114
115 function toString( $contentObjectAttribute )
116 {
117
118 $option = $contentObjectAttribute->attribute( 'content' );
119 $optionArray = array();
120 $optionArray[] = $option->attribute( 'name' );
121 $optionArray[] = $option->attribute( 'start_value' );
122 $optionArray[] = $option->attribute( 'stop_value' );
123 $optionArray[] = $option->attribute( 'step_value' );
124
125 return implode( '|', $optionArray );
126 }
127
128
129 function fromString( $contentObjectAttribute, $string )
130 {
131 if ( $string == '' )
132 return true;
133
134 $optionArray = explode( '|', $string );
135
136 $option = new eZRangeOption( '' );
137
138 $option->Name = array_shift( $optionArray );
139 $option->StartValue = array_shift( $optionArray );
140 $option->StopValue = array_shift( $optionArray );
141 $option->StepValue = array_shift( $optionArray );
142
143
144 $contentObjectAttribute->setAttribute( "data_text", $option->xmlString() );
145
146 return $option;
147
148 }
153 function productOptionInformation( $objectAttribute, $optionID, $productItem )
154 {
155 $option = $objectAttribute->attribute( 'content' );
156 foreach( $option->attribute( 'option_list' ) as $optionArray )
157 {
158 if ( $optionArray['id'] == $optionID )
159 {
160 return array( 'id' => $optionArray['id'],
161 'name' => $option->attribute( 'name' ),
162 'value' => $optionArray['value'],
163 'additional_price' => $optionArray['additional_price'] );
164 }
165 }
166 return false;
167 }
168
169 function metaData( $contentObjectAttribute )
170 {
171 return $contentObjectAttribute->attribute( "data_text" );
172 }
173
174 function title( $contentObjectAttribute, $name = null )
175 {
176 $option = new eZRangeOption( "" );
177 $option->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
178 return $option->attribute('name');
179 }
180
181 function hasObjectAttributeContent( $contentObjectAttribute )
182 {
183 return true;
184 }
185
189 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
190 {
191 if ( $currentVersion == false )
192 {
193 $option = $contentObjectAttribute->content();
194 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
195 if ( !$option )
196 {
197 $option = new eZRangeOption( $contentClassAttribute->attribute( 'data_text1' ) );
198 }
199 else
200 {
201 $option->setName( $contentClassAttribute->attribute( 'data_text1' ) );
202 }
203 $contentObjectAttribute->setAttribute( "data_text", $option->xmlString() );
204 $contentObjectAttribute->setContent( $option );
205 }
206 }
207
208 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
209 {
210 $defaultValueName = $base . self::DEFAULT_NAME_VARIABLE . $classAttribute->attribute( 'id' );
211 if ( $http->hasPostVariable( $defaultValueName ) )
212 {
213 $defaultValueValue = $http->postVariable( $defaultValueName );
214
215 if ($defaultValueValue == ""){
216 $defaultValueValue = "";
217 }
218 $classAttribute->setAttribute( 'data_text1', $defaultValueValue );
219 return true;
220 }
221 return false;
222 }
223
224 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
225 {
226 $defaultName = $classAttribute->attribute( 'data_text1' );
227 $dom = $attributeParametersNode->ownerDocument;
228 $defaultNameNode = $dom->createElement( 'default-name' );
229 $defaultNameNode->appendChild( $dom->createTextNode( $defaultName ) );
230 $attributeParametersNode->appendChild( $defaultNameNode );
231 }
232
233 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
234 {
235 $defaultName = $attributeParametersNode->getElementsByTagName( 'default-name' )->item( 0 )->textContent;
236 $classAttribute->setAttribute( 'data_text1', $defaultName );
237 }
238
239 function serializeContentObjectAttribute( $package, $objectAttribute )
240 {
241 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
242
243 $domDocument = new DOMDocument( '1.0', 'utf-8' );
244 $success = $domDocument->loadXML( $objectAttribute->attribute( 'data_text' ) );
245
246 $importedRoot = $node->ownerDocument->importNode( $domDocument->documentElement, true );
247 $node->appendChild( $importedRoot );
248
249 return $node;
250 }
251
252 function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
253 {
254 $rootNode = $attributeNode->getElementsByTagName( 'ezrangeoption' )->item( 0 );
255 $xmlString = $rootNode ? $rootNode->ownerDocument->saveXML( $rootNode ) : '';
256 $objectAttribute->setAttribute( 'data_text', $xmlString );
257 }
258
259 function supportsBatchInitializeObjectAttribute()
260 {
261 return true;
262 }
263
264 function batchInitializeObjectAttributeData( $classAttribute )
265 {
266 $option = new eZRangeOption( $classAttribute->attribute( 'data_text1' ) );
267 return array( 'data_text' => "'" . $option->xmlString() . "'");
268 }
269 }
270
271 eZDataType::register( eZRangeOptionType::DATA_TYPE_STRING, "eZRangeOptionType" );
272
273 ?>
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDataType\register
static register( $dataTypeString, $className)
Definition: ezdatatype.php:203
eZDataType\createContentObjectAttributeDOMNode
createContentObjectAttributeDOMNode( $objectAttribute)
Definition: ezdatatype.php:1371
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
eZRangeOptionType
The class eZRangeOptionType does.
Definition: ezrangeoptiontype.php:18
eZRangeOptionType\DEFAULT_NAME_VARIABLE
const DEFAULT_NAME_VARIABLE
Definition: ezrangeoptiontype.php:19
eZRangeOptionType\productOptionInformation
productOptionInformation( $objectAttribute, $optionID, $productItem)
Definition: ezrangeoptiontype.php:153
eZRangeOptionType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezrangeoptiontype.php:181
eZRangeOptionType\unserializeContentClassAttribute
unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezrangeoptiontype.php:233
eZRangeOptionType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezrangeoptiontype.php:72
eZRangeOptionType\unserializeContentObjectAttribute
unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode)
Definition: ezrangeoptiontype.php:252
eZRangeOptionType\serializeContentClassAttribute
serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezrangeoptiontype.php:224
eZRangeOptionType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezrangeoptiontype.php:29
eZRangeOptionType\title
title( $contentObjectAttribute, $name=null)
Definition: ezrangeoptiontype.php:174
eZRangeOptionType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezrangeoptiontype.php:21
eZRangeOptionType\storeObjectAttribute
storeObjectAttribute( $contentObjectAttribute)
Definition: ezrangeoptiontype.php:102
eZRangeOptionType\toString
toString( $contentObjectAttribute)
Definition: ezrangeoptiontype.php:115
eZRangeOptionType\batchInitializeObjectAttributeData
batchInitializeObjectAttributeData( $classAttribute)
Definition: ezrangeoptiontype.php:264
eZRangeOptionType\metaData
metaData( $contentObjectAttribute)
Definition: ezrangeoptiontype.php:169
eZRangeOptionType\__construct
__construct()
Definition: ezrangeoptiontype.php:23
eZRangeOptionType\fetchClassAttributeHTTPInput
fetchClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezrangeoptiontype.php:208
eZRangeOptionType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezrangeoptiontype.php:108
eZRangeOptionType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezrangeoptiontype.php:259
eZRangeOptionType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezrangeoptiontype.php:189
eZRangeOptionType\serializeContentObjectAttribute
serializeContentObjectAttribute( $package, $objectAttribute)
Definition: ezrangeoptiontype.php:239
eZRangeOptionType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezrangeoptiontype.php:129
eZRangeOption
The class eZRangeOption does.
Definition: ezrangeoption.php:19
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.