Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezobjectrelationtype.php
Go to the documentation of this file.
1 <?php
18 class eZObjectRelationType extends eZDataType
19 {
20 const DATA_TYPE_STRING = "ezobjectrelation";
21
22 public function __construct()
23 {
24 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Object relation", 'Datatype name' ),
25 array( 'serialize_supported' => true ) );
26 }
27
28 public function isRelationType()
29 {
30 return true;
31 }
32
36 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
37 {
38 if ( $currentVersion != false )
39 {
40 $dataText = $originalContentObjectAttribute->attribute( "data_int" );
41 $contentObjectAttribute->setAttribute( "data_int", $dataText );
42 }
43 }
44
49 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
50 {
51 $postVariableName = $base . "_data_object_relation_id_" . $contentObjectAttribute->attribute( "id" );
52 if ( $http->hasPostVariable( $postVariableName ) )
53 {
54 $relatedObjectID = $http->postVariable( $postVariableName );
55 $classAttribute = $contentObjectAttribute->contentClassAttribute();
56
57 if ( $contentObjectAttribute->validateIsRequired() and $relatedObjectID == 0 )
58 {
59 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
60 'Missing objectrelation input.' ) );
61 return eZInputValidator::STATE_INVALID;
62 }
63 }
64 else if ( $contentObjectAttribute->validateIsRequired() )
65 {
66 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'Missing objectrelation input.' ) );
67 return eZInputValidator::STATE_INVALID;
68 }
69
70 return eZInputValidator::STATE_ACCEPTED;
71 }
72
76 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
77 {
78 $postVariableName = $base . "_data_object_relation_id_" . $contentObjectAttribute->attribute( "id" );
79 $haveData = false;
80 if ( $http->hasPostVariable( $postVariableName ) )
81 {
82 $relatedObjectID = $http->postVariable( $postVariableName );
83 if ( $relatedObjectID == '' )
84 $relatedObjectID = null;
85 $contentObjectAttribute->setAttribute( 'data_int', $relatedObjectID );
86 $haveData = true;
87 }
88 $fuzzyMatchVariableName = $base . "_data_object_relation_fuzzy_match_" . $contentObjectAttribute->attribute( "id" );
89 if ( $http->hasPostVariable( $fuzzyMatchVariableName ) )
90 {
91 $trans = eZCharTransform::instance();
92
93 $fuzzyMatchText = trim( $http->postVariable( $fuzzyMatchVariableName ) );
94 if ( $fuzzyMatchText != '' )
95 {
96 $fuzzyMatchText = $trans->transformByGroup( $fuzzyMatchText, 'lowercase' );
97 $classAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' );
98 if ( $classAttribute )
99 {
100 $classContent = $classAttribute->content();
101 if ( $classContent['default_selection_node'] )
102 {
103 $nodeID = $classContent['default_selection_node'];
104 $nodeList = eZContentObjectTreeNode::subTreeByNodeID( array( 'Depth' => 1 ), $nodeID );
105 $lastDiff = false;
106 $matchObjectID = false;
107 foreach ( $nodeList as $node )
108 {
109 $name = $trans->transformByGroup( trim( $node->attribute( 'name' ) ), 'lowercase' );
110 $diff = $this->fuzzyTextMatch( $name, $fuzzyMatchText );
111 if ( $diff === false )
112 continue;
113 if ( $diff == 0 )
114 {
115 $matchObjectID = $node->attribute( 'contentobject_id' );
116 break;
117 }
118 if ( $lastDiff === false or
119 $diff < $lastDiff )
120 {
121 $lastDiff = $diff;
122 $matchObjectID = $node->attribute( 'contentobject_id' );
123 }
124 }
125 if ( $matchObjectID !== false )
126 {
127 $contentObjectAttribute->setAttribute( 'data_int', $matchObjectID );
128 $haveData = true;
129 }
130 }
131 }
132 }
133 }
134 return $haveData;
135 }
136
142 function fuzzyTextMatch( $text, $match )
143 {
144 $pos = strpos( $text, $match );
145 if ( $pos !== false )
146 {
147 $diff = strlen( $text ) - ( strlen( $match ) + $pos );
148 $diff += $pos;
149 return $diff;
150 }
151 return false;
152 }
153
154 function storeClassAttributeContent( $classAttribute, $content )
155 {
156 if ( is_array( $content ) )
157 {
158 $doc = $this->createClassDOMDocument( $content );
159 $this->storeClassDOMDocument( $doc, $classAttribute );
160 return true;
161 }
162 return false;
163 }
164
165 static function storeClassDOMDocument( $doc, $classAttribute )
166 {
167 $docText = self::domString( $doc );
168 $classAttribute->setAttribute( 'data_text5', $docText );
169 }
170
171 static function storeObjectDOMDocument( $doc, $objectAttribute )
172 {
173 $docText = self::domString( $doc );
174 $objectAttribute->setAttribute( 'data_text', $docText );
175 }
176
183 static function domString( $domDocument )
184 {
185 $ini = eZINI::instance();
186 $xmlCharset = $ini->variable( 'RegionalSettings', 'ContentXMLCharset' );
187 if ( $xmlCharset == 'enabled' )
188 {
189 $charset = eZTextCodec::internalCharset();
190 }
191 else if ( $xmlCharset == 'disabled' )
192 $charset = true;
193 else
194 $charset = $xmlCharset;
195 if ( $charset !== true )
196 {
197 $charset = eZCharsetInfo::realCharsetCode( $charset );
198 }
199 $domString = $domDocument->saveXML();
200 return $domString;
201 }
202
203 static function createClassDOMDocument( $content )
204 {
205 $doc = new DOMDocument( '1.0', 'utf-8' );
206 $root = $doc->createElement( 'related-object' );
207 $constraints = $doc->createElement( 'constraints' );
208 foreach ( $content['class_constraint_list'] as $constraintClassIdentifier )
209 {
210 unset( $constraintElement );
211 $constraintElement = $doc->createElement( 'allowed-class' );
212 $constraintElement->setAttribute( 'contentclass-identifier', $constraintClassIdentifier );
213 $constraints->appendChild( $constraintElement );
214 }
215 $root->appendChild( $constraints );
216 $doc->appendChild( $root );
217 return $doc;
218 }
219
223 function storeObjectAttribute( $contentObjectAttribute )
224 {
225 $contentClassAttributeID = $contentObjectAttribute->ContentClassAttributeID;
226 $contentObjectID = $contentObjectAttribute->ContentObjectID;
227 $contentObjectVersion = $contentObjectAttribute->Version;
228 $languageCode = $contentObjectAttribute->attribute( 'language_code' );
229
231 $contentObject = $contentObjectAttribute->object();
232
233 if ( $contentObjectAttribute->ID !== null )
234 {
235 // cleanup previous relations
236 $contentObject->removeContentObjectRelation( false, $contentObjectVersion, $contentClassAttributeID, eZContentObject::RELATION_ATTRIBUTE );
237
238 // if translatable, we need to re-add the relations for other languages of (previously) published version.
239 $publishedVersionNo = $contentObject->publishedVersion();
240 if ( $contentObjectAttribute->contentClassAttributeCanTranslate() && $publishedVersionNo > 0 )
241 {
242 $existingRelations = array();
243
244 // get published translations of this attribute
245 $pubAttribute = eZContentObjectAttribute::fetch($contentObjectAttribute->ID, $publishedVersionNo );
246 if ( $pubAttribute )
247 {
248 foreach( $pubAttribute->fetchAttributeTranslations() as $attributeTranslation )
249 {
250 // skip if language is the one being saved
251 if ( $attributeTranslation->LanguageCode === $languageCode )
252 continue;
253
254 if ( $attributeTranslation->attribute( 'data_int' ) )
255 $existingRelations[$attributeTranslation->LanguageCode] = (int)$attributeTranslation->attribute( 'data_int' );
256 }
257 }
258
259 // fetch existing attribute translations for current editing version
260 foreach( $contentObjectAttribute->fetchAttributeTranslations() as $attributeTranslation )
261 {
262 if ( $attributeTranslation->LanguageCode === $languageCode )
263 continue;
264
265 if ( $attributeTranslation->attribute( 'data_int' ) )
266 $existingRelations[$attributeTranslation->LanguageCode] = (int)$attributeTranslation->attribute( 'data_int' );
267 }
268
269 // re-add existing or new relations for other languages
270 foreach( array_unique($existingRelations) as $existingObjectId )
271 {
272 $contentObject->addContentObjectRelation( $existingObjectId, $contentObjectVersion, $contentClassAttributeID, eZContentObject::RELATION_ATTRIBUTE );
273 }
274 }
275 }
276
277 $objectID = $contentObjectAttribute->attribute( 'data_int' );
278 if ( $objectID )
279 {
280 $contentObject->addContentObjectRelation( $objectID, $contentObjectVersion, $contentClassAttributeID, eZContentObject::RELATION_ATTRIBUTE );
281 }
282 }
283
284 function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
285 {
286 $selectionTypeName = 'ContentClass_ezobjectrelation_selection_type_' . $classAttribute->attribute( 'id' );
287 $state = eZInputValidator::STATE_ACCEPTED;
288 if ( $http->hasPostVariable( $selectionTypeName ) )
289 {
290 $selectionType = $http->postVariable( $selectionTypeName );
291 if ( $selectionType < 0 and
292 $selectionType > 2 )
293 {
294 $state = eZInputValidator::STATE_INVALID;
295 }
296 }
297 return $state;
298 }
299
300 function fixupClassAttributeHTTPInput( $http, $base, $classAttribute )
301 {
302 }
303
304 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
305 {
306 $selectionTypeName = 'ContentClass_ezobjectrelation_selection_type_' . $classAttribute->attribute( 'id' );
307 $content = $classAttribute->content();
308 $postVariable = 'ContentClass_ezobjectrelation_class_list_' . $classAttribute->attribute( 'id' );
309 if ( $http->hasPostVariable( $postVariable ) )
310 {
311 $constrainedList = $http->postVariable( $postVariable );
312 $constrainedClassList = array();
313 foreach ( $constrainedList as $constraint )
314 {
315 if ( trim( $constraint ) != '' )
316 $constrainedClassList[] = $constraint;
317 }
318 $content['class_constraint_list'] = $constrainedClassList;
319 $hasData = true;
320 }
321 $hasData = false;
322 if ( $http->hasPostVariable( $selectionTypeName ) )
323 {
324 $selectionType = $http->postVariable( $selectionTypeName );
325 $content['selection_type'] = $selectionType;
326 $hasData = true;
327 }
328 $helperName = 'ContentClass_ezobjectrelation_selection_fuzzy_match_helper_' . $classAttribute->attribute( 'id' );
329 if ( $http->hasPostVariable( $helperName ) )
330 {
331 $fuzzyMatchName = 'ContentClass_ezobjectrelation_selection_fuzzy_match_' . $classAttribute->attribute( 'id' );
332 $content['fuzzy_match'] = false;
333 $hasData = true;
334 if ( $http->hasPostVariable( $fuzzyMatchName ) )
335 {
336 $content['fuzzy_match'] = true;
337 }
338 }
339 if ( $hasData )
340 {
341 $classAttribute->setContent( $content );
342 return true;
343 }
344 return false;
345 }
346
347 function initializeClassAttribute( $classAttribute )
348 {
349 $xmlText = $classAttribute->attribute( 'data_text5' );
350 if ( trim( $xmlText ) == '' )
351 {
352 $content = $this->defaultClassAttributeContent();
353 return $this->storeClassAttributeContent( $classAttribute, $content );
354 }
355 }
356
357 function preStoreClassAttribute( $classAttribute, $version )
358 {
359 $content = $classAttribute->content();
360 $classAttribute->setAttribute( 'data_int1', $content['selection_type'] );
361 $classAttribute->setAttribute( 'data_int2', $content['default_selection_node'] );
362 $classAttribute->setAttribute( 'data_int3', $content['fuzzy_match'] );
363
364 $xmlContentArray = array();
365 $defaultClassAttributeContent = $this->defaultClassAttributeContent();
366 foreach( $content as $xmlKey => $xmlContent )
367 {
368 if( isset( $defaultClassAttributeContent[$xmlKey] ) )
369 {
370 $xmlContentArray[$xmlKey] = $xmlContent;
371 }
372 }
373 $this->storeClassAttributeContent( $classAttribute, $xmlContentArray );
374 }
375
380 function removeContentObjectRelation( $contentObjectAttribute )
381 {
382 $obj = $contentObjectAttribute->object();
383 $atrributeTrans = $contentObjectAttribute->fetchAttributeTranslations( );
384 // Check if current relation exists in ezcontentobject_link
385 foreach ( $atrributeTrans as $attrTarns )
386 {
387 if ( $attrTarns->attribute( 'id' ) != $contentObjectAttribute->attribute( 'id' ) )
388 if ( $attrTarns->attribute( 'data_int' ) == $contentObjectAttribute->attribute( 'data_int' ) )
389 return;
390 }
391
392 //get eZContentObjectVersion
393 $currVerobj = $obj->currentVersion();
394 // get array of ezcontentobjecttranslations
395 $transList = $currVerobj->translations( false );
396 // get count of LanguageCode in transList
397 $countTsl = count( $transList );
398 // Delete the old version from ezcontentobject_link if count of translations > 1
399 if ( $countTsl > 1 )
400 {
401 $objectID = $contentObjectAttribute->attribute( "data_int" );
402 $contentClassAttributeID = $contentObjectAttribute->ContentClassAttributeID;
403 $contentObjectID = $contentObjectAttribute->ContentObjectID;
404 $contentObjectVersion = $contentObjectAttribute->Version;
405 eZContentObject::fetch( $contentObjectID )->removeContentObjectRelation( $objectID, $contentObjectVersion, $contentClassAttributeID, eZContentObject::RELATION_ATTRIBUTE );
406 }
407 }
408
409 function customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute, $parameters )
410 {
411 switch ( $action )
412 {
413 case "set_object_relation" :
414 {
415 if ( $http->hasPostVariable( 'BrowseActionName' ) and
416 $http->postVariable( 'BrowseActionName' ) == ( 'AddRelatedObject_' . $contentObjectAttribute->attribute( 'id' ) ) and
417 $http->hasPostVariable( "SelectedObjectIDArray" ) )
418 {
419 if ( !$http->hasPostVariable( 'BrowseCancelButton' ) )
420 {
421 $selectedObjectArray = $http->hasPostVariable( "SelectedObjectIDArray" );
422 $selectedObjectIDArray = $http->postVariable( "SelectedObjectIDArray" );
423
424 // Delete the old version from ezcontentobject_link if count of translations > 1
425 $this->removeContentObjectRelation( $contentObjectAttribute );
426
427 $objectID = $selectedObjectIDArray[0];
428 $contentObjectAttribute->setAttribute( 'data_int', $objectID );
429 $contentObjectAttribute->store();
430 }
431 }
432 } break;
433
434 case "browse_object" :
435 {
436 $module = $parameters['module'];
437 $redirectionURI = $parameters['current-redirection-uri'];
438 $ini = eZINI::instance( 'content.ini' );
439
440 $browseParameters = array( 'action_name' => 'AddRelatedObject_' . $contentObjectAttribute->attribute( 'id' ),
441 'type' => 'AddRelatedObjectToDataType',
442 'browse_custom_action' => array( 'name' => 'CustomActionButton[' . $contentObjectAttribute->attribute( 'id' ) . '_set_object_relation]',
443 'value' => $contentObjectAttribute->attribute( 'id' ) ),
444 'persistent_data' => array( 'HasObjectInput' => 0 ),
445 'from_page' => $redirectionURI );
446 $browseTypeINIVariable = $ini->variable( 'ObjectRelationDataTypeSettings', 'ClassAttributeStartNode' );
447 foreach( $browseTypeINIVariable as $value )
448 {
449 list( $classAttributeID, $type ) = explode( ';',$value );
450 if ( $classAttributeID == $contentObjectAttribute->attribute( 'contentclassattribute_id' ) && strlen( $type ) > 0 )
451 {
452 $browseParameters['type'] = $type;
453 break;
454 }
455 }
456
457 $nodePlacementName = $parameters['base_name'] . '_browse_for_object_start_node';
458 if ( $http->hasPostVariable( $nodePlacementName ) )
459 {
460 $nodePlacement = $http->postVariable( $nodePlacementName );
461 if ( isset( $nodePlacement[$contentObjectAttribute->attribute( 'id' )] ) )
462 $browseParameters['start_node'] = eZContentBrowse::nodeAliasID( $nodePlacement[$contentObjectAttribute->attribute( 'id' )] );
463 }
464
465 // Fetch the list of "allowed" classes .
466 // A user can select objects of only those allowed classes when browsing.
467 $classAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' );
468 $classContent = $classAttribute->content();
469 if ( isset( $classContent['class_constraint_list'] ) )
470 {
471 $classConstraintList = $classContent['class_constraint_list'];
472 }
473 else
474 {
475 $classConstraintList = array();
476 }
477
478 if ( count($classConstraintList) > 0 )
479 {
480 $browseParameters['class_array'] = $classConstraintList;
481 }
482
483 eZContentBrowse::browse( $browseParameters,
484 $module );
485 } break;
486
487 case "remove_object" :
488 {
489 // Delete the old version from ezcontentobject_link if count of translations > 1
490 $this->removeContentObjectRelation( $contentObjectAttribute );
491
492 $contentObjectAttribute->setAttribute( 'data_int', 0 );
493 $contentObjectAttribute->store();
494 } break;
495
496 default :
497 {
498 eZDebug::writeError( "Unknown custom HTTP action: " . $action, "eZObjectRelationType" );
499 } break;
500 }
501 }
502
506 function objectAttributeContent( $contentObjectAttribute )
507 {
508 $objectID = $contentObjectAttribute->attribute( "data_int" );
509 if ( $objectID != 0 )
510 $object = eZContentObject::fetch( $objectID );
511 else
512 $object = null;
513 return $object;
514 }
515
516 static function parseXML( $xmlText )
517 {
518 $dom = new DOMDocument( '1.0', 'utf-8' );
519 $dom->loadXML( $xmlText );
520 return $dom;
521 }
522
523 function defaultClassAttributeContent()
524 {
525 return array( 'class_constraint_list' => array() );
526 }
527
532 function objectDisplayInformation( $objectAttribute, $mergeInfo = false )
533 {
534 $classAttribute = $objectAttribute->contentClassAttribute();
535 $content = $this->classAttributeContent( $classAttribute );
536 $editGrouped = ( $content['selection_type'] == 0 or
537 ( $content['selection_type'] == 1 and $content['fuzzy_match'] ) );
538
539 $info = array( 'edit' => array( 'grouped_input' => $editGrouped ),
540 'collection' => array( 'grouped_input' => $editGrouped ) );
541 return eZDataType::objectDisplayInformation( $objectAttribute, $info );
542 }
543
544 function sortKey( $contentObjectAttribute )
545 {
546 return $contentObjectAttribute->attribute( 'data_int' );
547 }
548
549 function sortKeyType()
550 {
551 return 'int';
552 }
553
554 function classAttributeContent( $classObjectAttribute )
555 {
556 $selectionType = $classObjectAttribute->attribute( "data_int1" );
557 $defaultSelectionNode = $classObjectAttribute->attribute( "data_int2" );
558 $fuzzyMatch = $classObjectAttribute->attribute( "data_int3" );
559
560 $attributeContent = array( 'selection_type' => $selectionType,
561 'default_selection_node' => $defaultSelectionNode,
562 'fuzzy_match' => $fuzzyMatch );
563
564 $attributeXMLContent = $this->defaultClassAttributeContent();
565 $xmlText = $classObjectAttribute->attribute( 'data_text5' );
566 if ( trim( $xmlText ) != '' )
567 {
568 $doc = $this->parseXML( $xmlText );
569 $attributeXMLContent = $this->createClassContentStructure( $doc );
570 }
571 return array_merge( $attributeContent, $attributeXMLContent );
572
573 }
574
575 function deleteNotVersionedStoredClassAttribute( eZContentClassAttribute $classAttribute )
576 {
577 eZContentObjectAttribute::removeRelationsByContentClassAttributeId( $classAttribute->attribute( 'id' ) );
578 }
579
580 function createClassContentStructure( $doc )
581 {
582 $content = $this->defaultClassAttributeContent();
583 $root = $doc->documentElement;
584 if ( $root !== null )
585 {
586 $constraints = $root->getElementsByTagName( 'constraints' )->item( 0 );
587 }
588 else
589 {
590 $constraints = null;
591 }
592 if ( $constraints !== null )
593 {
594 $allowedClassList = $constraints->getElementsByTagName( 'allowed-class' );
595 foreach( $allowedClassList as $allowedClass )
596 {
597 $content['class_constraint_list'][] = $allowedClass->getAttribute( 'contentclass-identifier' );
598 }
599 }
600 return $content;
601 }
602
603 function customClassAttributeHTTPAction( $http, $action, $classAttribute )
604 {
605 switch ( $action )
606 {
607 case 'browse_for_selection_node':
608 {
609 $module = $classAttribute->currentModule();
610 $customActionName = 'CustomActionButton[' . $classAttribute->attribute( 'id' ) . '_browsed_for_selection_node]';
611 eZContentBrowse::browse( array( 'action_name' => 'SelectObjectRelationNode',
612 'content' => array( 'contentclass_id' => $classAttribute->attribute( 'contentclass_id' ),
613 'contentclass_attribute_id' => $classAttribute->attribute( 'id' ),
614 'contentclass_version' => $classAttribute->attribute( 'version' ),
615 'contentclass_attribute_identifier' => $classAttribute->attribute( 'identifier' ) ),
616 'persistent_data' => array( $customActionName => '',
617 'ContentClassHasInput' => false ),
618 'description_template' => 'design:class/datatype/browse_objectrelation_placement.tpl',
619 'from_page' => $module->currentRedirectionURI() ),
620 $module );
621 } break;
622 case 'browsed_for_selection_node':
623 {
624 $nodeSelection = eZContentBrowse::result( 'SelectObjectRelationNode' );
625 if ( !is_bool( $nodeSelection ) )
626 {
627 if ( count( $nodeSelection ) > 0 )
628 {
629 $nodeID = $nodeSelection[0];
630 $content = $classAttribute->content();
631 $content['default_selection_node'] = $nodeID;
632 $classAttribute->setContent( $content );
633 }
634 }
635 } break;
636 case 'disable_selection_node':
637 {
638 $content = $classAttribute->content();
639 $content['default_selection_node'] = false;
640 $classAttribute->setContent( $content );
641 } break;
642 default:
643 {
644 eZDebug::writeError( "Unknown objectrelationlist action '$action'", __METHOD__ );
645 } break;
646 }
647 }
648
652 function metaData( $contentObjectAttribute )
653 {
654 $object = $this->objectAttributeContent( $contentObjectAttribute );
655 if ( $object )
656 {
657 // Does the related object exist in the same language as the current content attribute ?
658 if ( in_array( $contentObjectAttribute->attribute( 'language_code' ), $object->attribute( 'current' )->translationList( false, false ) ) )
659 {
660 $attributes = $object->attribute( 'current' )->contentObjectAttributes( $contentObjectAttribute->attribute( 'language_code' ) );
661 }
662 else
663 {
664 $attributes = $object->contentObjectAttributes();
665 }
666
667 return eZContentObjectAttribute::metaDataArray( $attributes, true );
668 }
669 return false;
670 }
675 function toString( $contentObjectAttribute )
676 {
677 return $contentObjectAttribute->attribute( 'data_int' );
678 }
679
680 function fromString( $contentObjectAttribute, $string )
681 {
682 if ( !is_numeric( $string ) || !eZContentObject::fetch( $string ) )
683 return false;
684
685 $contentObjectAttribute->setAttribute( 'data_int', $string );
686 return true;
687 }
688
689 function isIndexable()
690 {
691 return true;
692 }
693
697 function title( $contentObjectAttribute, $name = null )
698 {
699 $object = $this->objectAttributeContent( $contentObjectAttribute );
700 if ( $object )
701 {
702 return $object->attribute( 'name' );
703 }
704 return false;
705 }
706
707 function hasObjectAttributeContent( $contentObjectAttribute )
708 {
709 $object = $this->objectAttributeContent( $contentObjectAttribute );
710 if ( $object )
711 return true;
712 return false;
713 }
714
715 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
716 {
717 $content = $classAttribute->content();
718 $dom = $attributeParametersNode->ownerDocument;
719 $selectionTypeNode = $dom->createElement( 'selection-type' );
720 $selectionTypeNode->setAttribute( 'id', $content['selection_type'] );
721 $attributeParametersNode->appendChild( $selectionTypeNode );
722 $fuzzyMatchNode = $dom->createElement( 'fuzzy-match' );
723 $fuzzyMatchNode->setAttribute( 'id', $content['fuzzy_match'] );
724 $attributeParametersNode->appendChild( $fuzzyMatchNode );
725 if ( $content['default_selection_node'] )
726 {
727 $defaultSelectionNode = $dom->createElement( 'default-selection' );
728 $defaultSelectionNode->setAttribute( 'node-id', $content['default_selection_node'] );
729 $attributeParametersNode->appendChild( $defaultSelectionNode );
730 }
731 }
732
733 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
734 {
735 $content = $classAttribute->content();
736 $selectionTypeNode = $attributeParametersNode->getElementsByTagName( 'selection-type' )->item( 0 );
737 $content['selection_type'] = 0;
738 if ( $selectionTypeNode )
739 $content['selection_type'] = $selectionTypeNode->getAttribute( 'id' );
740
741 $fuzzyMatchNode = $attributeParametersNode->getElementsByTagName( 'fuzzy-match' )->item( 0 );
742 $content['fuzzy_match'] = false;
743 if ( $fuzzyMatchNode )
744 $content['fuzzy_match'] = $fuzzyMatchNode->getAttribute( 'id' );
745
746 $defaultSelectionNode = $attributeParametersNode->getElementsByTagName( 'default-selection' )->item( 0 );
747 $content['default_selection_node'] = false;
748 if ( $defaultSelectionNode )
749 $content['default_selection_node'] = $defaultSelectionNode->getAttribute( 'node-id' );
750
751 $classAttribute->setContent( $content );
752 $classAttribute->store();
753 }
754
758 function serializeContentObjectAttribute( $package, $objectAttribute )
759 {
760 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
761 $relatedObjectID = $objectAttribute->attribute( 'data_int' );
762
763 if ( $relatedObjectID !== null )
764 {
765 $relatedObject = eZContentObject::fetch( $relatedObjectID );
766 if ( !$relatedObject )
767 {
768 eZDebug::writeNotice( 'Related object with ID: ' . $relatedObjectID . ' does not exist.' );
769 }
770 else
771 {
772 $relatedObjectRemoteID = $relatedObject->attribute( 'remote_id' );
773 $dom = $node->ownerDocument;
774 $relatedObjectRemoteIDNode = $dom->createElement( 'related-object-remote-id' );
775 $relatedObjectRemoteIDNode->appendChild( $dom->createTextNode( $relatedObjectRemoteID ) );
776 $node->appendChild( $relatedObjectRemoteIDNode );
777 }
778 }
779
780 return $node;
781 }
782
783 function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
784 {
785 $relatedObjectRemoteIDNode = $attributeNode->getElementsByTagName( 'related-object-remote-id' )->item( 0 );
786 $relatedObjectID = null;
787
788 if ( $relatedObjectRemoteIDNode )
789 {
790 $relatedObjectRemoteID = $relatedObjectRemoteIDNode->textContent;
791 $object = eZContentObject::fetchByRemoteID( $relatedObjectRemoteID );
792 if ( $object )
793 {
794 $relatedObjectID = $object->attribute( 'id' );
795 }
796 else
797 {
798 // store remoteID so it can be used in postUnserialize
799 $objectAttribute->setAttribute( 'data_text', $relatedObjectRemoteID );
800 }
801 }
802
803 $objectAttribute->setAttribute( 'data_int', $relatedObjectID );
804 }
805
806 function postUnserializeContentObjectAttribute( $package, $objectAttribute )
807 {
808 $attributeChanged = false;
809 $relatedObjectID = $objectAttribute->attribute( 'data_int' );
810
811 if ( !$relatedObjectID )
812 {
813 // Restore cross-relations using preserved remoteID
814 $relatedObjectRemoteID = $objectAttribute->attribute( 'data_text' );
815 if ( $relatedObjectRemoteID)
816 {
817 $object = eZContentObject::fetchByRemoteID( $relatedObjectRemoteID );
818 $relatedObjectID = ( $object !== null ) ? $object->attribute( 'id' ) : null;
819
820 if ( $relatedObjectID )
821 {
822 $objectAttribute->setAttribute( 'data_int', $relatedObjectID );
823 $attributeChanged = true;
824 }
825 }
826 }
827
828 return $attributeChanged;
829 }
830
834 function removeRelatedObjectItem( $contentObjectAttribute, $objectID )
835 {
836 $contentObjectAttribute->setAttribute( "data_int", null );
837 return true;
838 }
839
840 function supportsBatchInitializeObjectAttribute()
841 {
842 return true;
843 }
844
846 }
847
848 eZDataType::register( eZObjectRelationType::DATA_TYPE_STRING, "eZObjectRelationType" );
849
850 ?>
eZCharTransform\instance
static instance()
Definition: ezchartransform.php:434
eZCharsetInfo\realCharsetCode
static realCharsetCode( $charsetCode)
Definition: ezcharsetinfo.php:186
eZContentBrowse\result
static result( $actionName, $asObject=false)
Definition: ezcontentbrowse.php:258
eZContentBrowse\nodeAliasID
static nodeAliasID( $nodeName)
Definition: ezcontentbrowse.php:224
eZContentBrowse\browse
static browse( $parameters=array(), &$module)
Definition: ezcontentbrowse.php:89
eZContentClassAttribute
Encapsulates data for a class attribute.
Definition: ezcontentclassattribute.php:19
eZContentObjectAttribute\fetch
static fetch( $id, $version, $asObject=true, $field_filters=null)
Definition: ezcontentobjectattribute.php:136
eZContentObjectAttribute\metaDataArray
static metaDataArray(&$attributes, $skipRelationAttributes=false)
Definition: ezcontentobjectattribute.php:1198
eZContentObjectAttribute\removeRelationsByContentClassAttributeId
static removeRelationsByContentClassAttributeId( $attributeId)
Definition: ezcontentobjectattribute.php:1494
eZContentObjectTreeNode\subTreeByNodeID
static subTreeByNodeID( $params=false, $nodeID=0)
Definition: ezcontentobjecttreenode.php:1940
eZContentObject\fetch
static fetch( $id, $asObject=true)
Definition: ezcontentobject.php:885
eZContentObject\fetchByRemoteID
static fetchByRemoteID( $remoteID, $asObject=true)
Definition: ezcontentobject.php:865
eZContentObject\RELATION_ATTRIBUTE
const RELATION_ATTRIBUTE
Definition: ezcontentobject.php:40
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDataType\objectDisplayInformation
objectDisplayInformation( $objectAttribute, $mergeInfo=false)
Definition: ezdatatype.php:496
eZDataType\register
static register( $dataTypeString, $className)
Definition: ezdatatype.php:203
eZDataType\storeObjectAttribute
storeObjectAttribute( $objectAttribute)
Definition: ezdatatype.php:632
eZDataType\createContentObjectAttributeDOMNode
createContentObjectAttributeDOMNode( $objectAttribute)
Definition: ezdatatype.php:1371
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
eZObjectRelationType
A content datatype which handles object relations.
Definition: ezobjectrelationtype.php:19
eZObjectRelationType\removeRelatedObjectItem
removeRelatedObjectItem( $contentObjectAttribute, $objectID)
Definition: ezobjectrelationtype.php:834
eZObjectRelationType\unserializeContentObjectAttribute
unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode)
Definition: ezobjectrelationtype.php:783
eZObjectRelationType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezobjectrelationtype.php:49
eZObjectRelationType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezobjectrelationtype.php:36
eZObjectRelationType\serializeContentClassAttribute
serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezobjectrelationtype.php:715
eZObjectRelationType\parseXML
static parseXML( $xmlText)
Definition: ezobjectrelationtype.php:516
eZObjectRelationType\classAttributeContent
classAttributeContent( $classObjectAttribute)
Definition: ezobjectrelationtype.php:554
eZObjectRelationType\sortKeyType
sortKeyType()
Definition: ezobjectrelationtype.php:549
eZObjectRelationType\storeClassAttributeContent
storeClassAttributeContent( $classAttribute, $content)
Definition: ezobjectrelationtype.php:154
eZObjectRelationType\fuzzyTextMatch
fuzzyTextMatch( $text, $match)
Definition: ezobjectrelationtype.php:142
eZObjectRelationType\customClassAttributeHTTPAction
customClassAttributeHTTPAction( $http, $action, $classAttribute)
Definition: ezobjectrelationtype.php:603
eZObjectRelationType\fixupClassAttributeHTTPInput
fixupClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezobjectrelationtype.php:300
eZObjectRelationType\postUnserializeContentObjectAttribute
postUnserializeContentObjectAttribute( $package, $objectAttribute)
Definition: ezobjectrelationtype.php:806
eZObjectRelationType\serializeContentObjectAttribute
serializeContentObjectAttribute( $package, $objectAttribute)
Definition: ezobjectrelationtype.php:758
eZObjectRelationType\domString
static domString( $domDocument)
Definition: ezobjectrelationtype.php:183
eZObjectRelationType\removeContentObjectRelation
removeContentObjectRelation( $contentObjectAttribute)
Definition: ezobjectrelationtype.php:380
eZObjectRelationType\storeClassDOMDocument
static storeClassDOMDocument( $doc, $classAttribute)
Definition: ezobjectrelationtype.php:165
eZObjectRelationType\objectDisplayInformation
objectDisplayInformation( $objectAttribute, $mergeInfo=false)
Definition: ezobjectrelationtype.php:532
eZObjectRelationType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezobjectrelationtype.php:76
eZObjectRelationType\initializeClassAttribute
initializeClassAttribute( $classAttribute)
Definition: ezobjectrelationtype.php:347
eZObjectRelationType\title
title( $contentObjectAttribute, $name=null)
Definition: ezobjectrelationtype.php:697
eZObjectRelationType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezobjectrelationtype.php:20
eZObjectRelationType\validateClassAttributeHTTPInput
validateClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezobjectrelationtype.php:284
eZObjectRelationType\__construct
__construct()
Definition: ezobjectrelationtype.php:22
eZObjectRelationType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezobjectrelationtype.php:707
eZObjectRelationType\metaData
metaData( $contentObjectAttribute)
Definition: ezobjectrelationtype.php:652
eZObjectRelationType\deleteNotVersionedStoredClassAttribute
deleteNotVersionedStoredClassAttribute(eZContentClassAttribute $classAttribute)
Definition: ezobjectrelationtype.php:575
eZObjectRelationType\isRelationType
isRelationType()
Definition: ezobjectrelationtype.php:28
eZObjectRelationType\sortKey
sortKey( $contentObjectAttribute)
Definition: ezobjectrelationtype.php:544
eZObjectRelationType\preStoreClassAttribute
preStoreClassAttribute( $classAttribute, $version)
Definition: ezobjectrelationtype.php:357
eZObjectRelationType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezobjectrelationtype.php:506
eZObjectRelationType\isIndexable
isIndexable()
Definition: ezobjectrelationtype.php:689
eZObjectRelationType\createClassDOMDocument
static createClassDOMDocument( $content)
Definition: ezobjectrelationtype.php:203
eZObjectRelationType\createClassContentStructure
createClassContentStructure( $doc)
Definition: ezobjectrelationtype.php:580
eZObjectRelationType\fetchClassAttributeHTTPInput
fetchClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezobjectrelationtype.php:304
eZObjectRelationType\defaultClassAttributeContent
defaultClassAttributeContent()
Definition: ezobjectrelationtype.php:523
eZObjectRelationType\customObjectAttributeHTTPAction
customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute, $parameters)
Definition: ezobjectrelationtype.php:409
eZObjectRelationType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezobjectrelationtype.php:840
eZObjectRelationType\toString
toString( $contentObjectAttribute)
Definition: ezobjectrelationtype.php:675
eZObjectRelationType\storeObjectDOMDocument
static storeObjectDOMDocument( $doc, $objectAttribute)
Definition: ezobjectrelationtype.php:171
eZObjectRelationType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezobjectrelationtype.php:680
eZObjectRelationType\unserializeContentClassAttribute
unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezobjectrelationtype.php:733
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZTextCodec\internalCharset
static internalCharset()
Definition: eztextcodec.php:546
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+.