Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezselectiontype.php
Go to the documentation of this file.
1 <?php
20 class eZSelectionType extends eZDataType
21 {
22 const DATA_TYPE_STRING = "ezselection";
23
24 public function __construct()
25 {
26 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Selection", 'Datatype name' ),
27 array( 'serialize_supported' => true ) );
28 }
29
35 function validateClassAttributeHTTPInput( $http, $base, $contentObjectAttribute )
36 {
37 return eZInputValidator::STATE_ACCEPTED;
38 }
39
44 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
45 {
46 $attributeContent = $this->classAttributeContent( $classAttribute );
47 $classAttributeID = $classAttribute->attribute( 'id' );
48 $isMultipleSelection = false;
49
50 if ( $http->hasPostVariable( $base . "_ezselection_ismultiple_value_" . $classAttributeID ) )
51 {
52 if( $http->postVariable( $base . "_ezselection_ismultiple_value_" . $classAttributeID ) != 0 )
53 {
54 $isMultipleSelection = true;
55 }
56 }
57
58 $currentOptions = $attributeContent['options'];
59 $hasPostData = false;
60
61 if ( $http->hasPostVariable( $base . "_ezselection_option_name_array_" . $classAttributeID ) )
62 {
63 $nameArray = $http->postVariable( $base . "_ezselection_option_name_array_" . $classAttributeID );
64
65 // Fill in new names for options
66 foreach ( array_keys( $currentOptions ) as $key )
67 {
68 $currentOptions[$key]['name'] = $nameArray[$currentOptions[$key]['id']];
69 }
70 $hasPostData = true;
71
72 }
73
74 if ( $http->hasPostVariable( $base . "_ezselection_newoption_button_" . $classAttributeID ) )
75 {
76 $currentCount = 0;
77 foreach ( $currentOptions as $option )
78 {
79 $currentCount = max( $currentCount, $option['id'] );
80 }
81 $currentCount += 1;
82 $currentOptions[] = array( 'id' => $currentCount,
83 'name' => '' );
84 $hasPostData = true;
85
86 }
87
88 if ( $http->hasPostVariable( $base . "_ezselection_removeoption_button_" . $classAttributeID ) )
89 {
90 if ( $http->hasPostVariable( $base . "_ezselection_option_remove_array_". $classAttributeID ) )
91 {
92 $removeArray = $http->postVariable( $base . "_ezselection_option_remove_array_". $classAttributeID );
93
94 foreach ( array_keys( $currentOptions ) as $key )
95 {
96 if ( isset( $removeArray[$currentOptions[$key]['id']] ) and
97 $removeArray[$currentOptions[$key]['id']] )
98 unset( $currentOptions[$key] );
99 }
100 $hasPostData = true;
101 }
102 }
103
104 if ( $hasPostData )
105 {
106
107 // Serialize XML
108 $doc = new DOMDocument( '1.0', 'utf-8' );
109 $root = $doc->createElement( "ezselection" );
110 $doc->appendChild( $root );
111
112 $options = $doc->createElement( "options" );
113
114 $root->appendChild( $options );
115 foreach ( $currentOptions as $optionArray )
116 {
117 unset( $optionNode );
118 $optionNode = $doc->createElement( "option" );
119 $optionNode->setAttribute( 'id', $optionArray['id'] );
120 $optionNode->setAttribute( 'name', $optionArray['name'] );
121
122 $options->appendChild( $optionNode );
123 }
124
125 $xml = $doc->saveXML();
126
127 $classAttribute->setAttribute( "data_text5", $xml );
128
129 if ( $isMultipleSelection == true )
130 $classAttribute->setAttribute( "data_int1", 1 );
131 else
132 $classAttribute->setAttribute( "data_int1", 0 );
133 }
134 return true;
135 }
141 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
142 {
143 $classAttribute = $contentObjectAttribute->contentClassAttribute();
144
145 if ( $http->hasPostVariable( $base . '_ezselect_selected_array_' . $contentObjectAttribute->attribute( 'id' ) ) )
146 {
147 $data = $http->postVariable( $base . '_ezselect_selected_array_' . $contentObjectAttribute->attribute( 'id' ) );
148
149 if ( $data == "" )
150 {
151 if ( !$classAttribute->attribute( 'is_information_collector' ) &&
152 $contentObjectAttribute->validateIsRequired() )
153 {
154 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
155 'Input required.' ) );
156 return eZInputValidator::STATE_INVALID;
157 }
158 }
159 }
160 else if ( !$classAttribute->attribute( 'is_information_collector' ) && $contentObjectAttribute->validateIsRequired() )
161 {
162 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'Input required.' ) );
163 return eZInputValidator::STATE_INVALID;
164 }
165 return eZInputValidator::STATE_ACCEPTED;
166 }
167
172 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
173 {
174 if ( $http->hasPostVariable( $base . '_ezselect_selected_array_' . $contentObjectAttribute->attribute( 'id' ) ) )
175 {
176 $selectOptions = $http->postVariable( $base . '_ezselect_selected_array_' . $contentObjectAttribute->attribute( 'id' ) );
177 $idString = ( is_array( $selectOptions ) ? implode( '-', $selectOptions ) : "" );
178 $contentObjectAttribute->setAttribute( 'data_text', $idString );
179 return true;
180 }
181 return false;
182 }
183
184 function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttribute )
185 {
186 if ( $http->hasPostVariable( $base . '_ezselect_selected_array_' . $contentObjectAttribute->attribute( 'id' ) ) )
187 {
188 $data = $http->postVariable( $base . '_ezselect_selected_array_' . $contentObjectAttribute->attribute( 'id' ) );
189
190 if ( $data == "" && $contentObjectAttribute->validateIsRequired() )
191 {
192 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'Input required.' ) );
193 return eZInputValidator::STATE_INVALID;
194 }
195 else
196 {
197 return eZInputValidator::STATE_ACCEPTED;
198 }
199 }
200 else
201 {
202 return eZInputValidator::STATE_INVALID;
203 }
204 }
205
209 function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute )
210 {
211 if ( $http->hasPostVariable( $base . '_ezselect_selected_array_' . $contentObjectAttribute->attribute( 'id' ) ) )
212 {
213 $selectOptions = $http->postVariable( $base . '_ezselect_selected_array_' . $contentObjectAttribute->attribute( 'id' ) );
214 $idString = ( is_array( $selectOptions ) ? implode( '-', $selectOptions ) : "" );
215 $collectionAttribute->setAttribute( 'data_text', $idString );
216 return true;
217 }
218 return false;
219 }
220
224 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
225 {
226 if ( $currentVersion != false )
227 {
228 $idString = $originalContentObjectAttribute->attribute( "data_text" );
229 $contentObjectAttribute->setAttribute( "data_text", $idString );
230 $contentObjectAttribute->store();
231 }
232 }
233
237 function objectAttributeContent( $contentObjectAttribute )
238 {
239 $idString = explode( '-', $contentObjectAttribute->attribute( 'data_text' ) );
240 return $idString;
241 }
242
246 function classAttributeContent( $classAttribute )
247 {
248 $dom = new DOMDocument( '1.0', 'utf-8' );
249 $xmlString = $classAttribute->attribute( 'data_text5' );
250 $optionArray = array();
251 if ( $xmlString != '' )
252 {
253 $success = $dom->loadXML( $xmlString );
254 if ( $success )
255 {
256 $options = $dom->getElementsByTagName( 'option' );
257
258 foreach ( $options as $optionNode )
259 {
260 $optionArray[] = array( 'id' => $optionNode->getAttribute( 'id' ),
261 'name' => $optionNode->getAttribute( 'name' ) );
262 }
263 }
264 }
265
266 if ( count( $optionArray ) == 0 )
267 {
268 $optionArray[] = array( 'id' => 0,
269 'name' => '' );
270 }
271 $attrValue = array( 'options' => $optionArray,
272 'is_multiselect' => $classAttribute->attribute( 'data_int1' ) );
273 return $attrValue;
274 }
275
279 function metaData( $contentObjectAttribute )
280 {
281 $selected = $this->objectAttributeContent( $contentObjectAttribute );
282 $classContent = $this->classAttributeContent( $contentObjectAttribute->attribute( 'contentclass_attribute' ) );
283 $return = '';
284 if ( count( $selected ) == 0)
285 {
286 return '';
287 }
288
289 $count = 0;
290 $optionArray = $classContent['options'];
291 foreach ( $selected as $id )
292 {
293 if ( $count++ != 0 )
294 $return .= ' ';
295 foreach ( $optionArray as $option )
296 {
297 $optionID = $option['id'];
298 if ( $optionID == $id )
299 $return .= $option['name'];
300 }
301 }
302 return $return;
303 }
304
305 function toString( $contentObjectAttribute )
306 {
307 $selected = $this->objectAttributeContent( $contentObjectAttribute );
308 $classContent = $this->classAttributeContent( $contentObjectAttribute->attribute( 'contentclass_attribute' ) );
309
310 if ( count( $selected ) )
311 {
312 $returnData = array();
313 $optionArray = $classContent['options'];
314 foreach ( $selected as $id )
315 {
316 foreach ( $optionArray as $option )
317 {
318 $optionID = $option['id'];
319 if ( $optionID == $id )
320 $returnData[] = $option['name'];
321 }
322 }
323 return eZStringUtils::implodeStr( $returnData, '|' );
324 }
325 return '';
326 }
327
328
329 function fromString( $contentObjectAttribute, $string )
330 {
331 if ( $string == '' )
332 return true;
333 $selectedNames = eZStringUtils::explodeStr( $string, '|' );
334 $selectedIDList = array();
335 $classContent = $this->classAttributeContent( $contentObjectAttribute->attribute( 'contentclass_attribute' ) );
336 $optionArray = $classContent['options'];
337 foreach ( $selectedNames as $name )
338 {
339 foreach ( $optionArray as $option )
340 {
341 $optionName = $option['name'];
342 if ( $optionName == $name )
343 $selectedIDList[] = $option['id'];
344 }
345 }
346 $idString = ( is_array( $selectedIDList ) ? implode( '-', $selectedIDList ) : "" );
347 $contentObjectAttribute->setAttribute( 'data_text', $idString );
348 return true;
349 }
350
354 function title( $contentObjectAttribute, $name = null )
355 {
356 $selected = $this->objectAttributeContent( $contentObjectAttribute );
357 $classContent = $this->classAttributeContent( $contentObjectAttribute->attribute( 'contentclass_attribute' ) );
358 $return = '';
359 if ( count( $selected ) )
360 {
361 $selectedNames = array();
362 foreach ( $classContent['options'] as $option )
363 {
364 if ( in_array( $option['id'], $selected ) )
365 $selectedNames[] = $option['name'];
366 }
367 $return = implode( ', ', $selectedNames );
368 }
369 return $return;
370 }
371
372 function hasObjectAttributeContent( $contentObjectAttribute )
373 {
374 $selected = $this->objectAttributeContent( $contentObjectAttribute );
375 return isset( $selected[0] ) && $selected[0] != '';
376 }
377
378 function sortKey( $contentObjectAttribute )
379 {
380 return strtolower( $contentObjectAttribute->attribute( 'data_text' ) );
381 }
382
383 function sortKeyType()
384 {
385 return 'string';
386 }
387
391 function isIndexable()
392 {
393 return true;
394 }
395
396 function isInformationCollector()
397 {
398 return true;
399 }
400
401 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
402 {
403 $isMultipleSelection = $classAttribute->attribute( 'data_int1' );
404 $xmlString = $classAttribute->attribute( 'data_text5' );
405
406 $selectionDom = new DOMDocument( '1.0', 'utf-8' );
407 $success = $selectionDom->loadXML( $xmlString );
408 $domRoot = $selectionDom->documentElement;
409 $options = $domRoot->getElementsByTagName( 'options' )->item( 0 );
410
411 $dom = $attributeParametersNode->ownerDocument;
412
413 $importedOptionsNode = $dom->importNode( $options, true );
414 $attributeParametersNode->appendChild( $importedOptionsNode );
415 $isMultiSelectNode = $dom->createElement( 'is-multiselect' );
416 $isMultiSelectNode->appendChild( $dom->createTextNode( $isMultipleSelection ) );
417 $attributeParametersNode->appendChild( $isMultiSelectNode );
418 }
419
420 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
421 {
422 $options = $attributeParametersNode->getElementsByTagName( 'options' )->item( 0 );
423
424 $doc = new DOMDocument( '1.0', 'utf-8' );
425 $root = $doc->createElement( 'ezselection' );
426 $doc->appendChild( $root );
427
428 $importedOptions = $doc->importNode( $options, true );
429 $root->appendChild( $importedOptions );
430
431 $xml = $doc->saveXML();
432 $classAttribute->setAttribute( 'data_text5', $xml );
433
434 if ( $attributeParametersNode->getElementsByTagName( 'is-multiselect' )->item( 0 )->textContent == 0 )
435 $classAttribute->setAttribute( 'data_int1', 0 );
436 else
437 $classAttribute->setAttribute( 'data_int1', 1 );
438 }
439
440 function supportsBatchInitializeObjectAttribute()
441 {
442 return true;
443 }
444 }
445
446 eZDataType::register( eZSelectionType::DATA_TYPE_STRING, "eZSelectionType" );
447 ?>
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDataType\register
static register( $dataTypeString, $className)
Definition: ezdatatype.php:203
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
eZSelectionType
Definition: ezselectiontype.php:21
eZSelectionType\serializeContentClassAttribute
serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezselectiontype.php:401
eZSelectionType\__construct
__construct()
Definition: ezselectiontype.php:24
eZSelectionType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezselectiontype.php:141
eZSelectionType\validateCollectionAttributeHTTPInput
validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezselectiontype.php:184
eZSelectionType\fetchClassAttributeHTTPInput
fetchClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezselectiontype.php:44
eZSelectionType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezselectiontype.php:172
eZSelectionType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezselectiontype.php:224
eZSelectionType\unserializeContentClassAttribute
unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezselectiontype.php:420
eZSelectionType\isIndexable
isIndexable()
Definition: ezselectiontype.php:391
eZSelectionType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezselectiontype.php:329
eZSelectionType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezselectiontype.php:440
eZSelectionType\sortKey
sortKey( $contentObjectAttribute)
Definition: ezselectiontype.php:378
eZSelectionType\validateClassAttributeHTTPInput
validateClassAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezselectiontype.php:35
eZSelectionType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezselectiontype.php:22
eZSelectionType\isInformationCollector
isInformationCollector()
Definition: ezselectiontype.php:396
eZSelectionType\toString
toString( $contentObjectAttribute)
Definition: ezselectiontype.php:305
eZSelectionType\fetchCollectionAttributeHTTPInput
fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute)
Definition: ezselectiontype.php:209
eZSelectionType\sortKeyType
sortKeyType()
Definition: ezselectiontype.php:383
eZSelectionType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezselectiontype.php:372
eZSelectionType\metaData
metaData( $contentObjectAttribute)
Definition: ezselectiontype.php:279
eZSelectionType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezselectiontype.php:237
eZSelectionType\classAttributeContent
classAttributeContent( $classAttribute)
Definition: ezselectiontype.php:246
eZSelectionType\title
title( $contentObjectAttribute, $name=null)
Definition: ezselectiontype.php:354
eZStringUtils\implodeStr
static implodeStr( $values, $delimiter='|')
Definition: ezstringutils.php:44
eZStringUtils\explodeStr
static explodeStr( $str, $delimiter='|')
Definition: ezstringutils.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+.