|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZObjectRelationType class 00004 // 00005 // Created on: <16-Apr-2002 11:08:14 amos> 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 /*! 00032 \class eZObjectRelationType ezobjectrelationtype.php 00033 \ingroup eZDatatype 00034 \brief A content datatype which handles object relations 00035 00036 */ 00037 00038 //include_once( "kernel/classes/ezdatatype.php" ); 00039 //include_once( "lib/ezutils/classes/ezintegervalidator.php" ); 00040 //include_once( "lib/ezi18n/classes/eztranslatormanager.php" ); 00041 00042 class eZObjectRelationType extends eZDataType 00043 { 00044 const DATA_TYPE_STRING = "ezobjectrelation"; 00045 00046 /*! 00047 Initializes with a string id and a description. 00048 */ 00049 function eZObjectRelationType() 00050 { 00051 $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'kernel/classes/datatypes', "Object relation", 'Datatype name' ), 00052 array( 'serialize_supported' => true ) ); 00053 } 00054 00055 /*! 00056 Initializes the class attribute with some data. 00057 \reimp 00058 */ 00059 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute ) 00060 { 00061 if ( $currentVersion != false ) 00062 { 00063 $dataText = $originalContentObjectAttribute->attribute( "data_int" ); 00064 $contentObjectAttribute->setAttribute( "data_int", $dataText ); 00065 } 00066 } 00067 00068 /*! 00069 Validates the input and returns true if the input was 00070 valid for this datatype. 00071 */ 00072 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00073 { 00074 $postVariableName = $base . "_data_object_relation_id_" . $contentObjectAttribute->attribute( "id" ); 00075 if ( $http->hasPostVariable( $postVariableName ) ) 00076 { 00077 $relatedObjectID = $http->postVariable( $postVariableName ); 00078 $classAttribute = $contentObjectAttribute->contentClassAttribute(); 00079 00080 if ( $contentObjectAttribute->validateIsRequired() and $relatedObjectID == 0 ) 00081 { 00082 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 00083 'Missing objectrelation input.' ) ); 00084 return eZInputValidator::STATE_INVALID; 00085 } 00086 } 00087 return eZInputValidator::STATE_ACCEPTED; 00088 } 00089 00090 /*! 00091 Fetches the http post var string input and stores it in the data instance. 00092 */ 00093 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00094 { 00095 $postVariableName = $base . "_data_object_relation_id_" . $contentObjectAttribute->attribute( "id" ); 00096 $haveData = false; 00097 if ( $http->hasPostVariable( $postVariableName ) ) 00098 { 00099 $relatedObjectID = $http->postVariable( $postVariableName ); 00100 if ( $relatedObjectID == '' ) 00101 $relatedObjectID = null; 00102 $contentObjectAttribute->setAttribute( 'data_int', $relatedObjectID ); 00103 $haveData = true; 00104 } 00105 $fuzzyMatchVariableName = $base . "_data_object_relation_fuzzy_match_" . $contentObjectAttribute->attribute( "id" ); 00106 if ( $http->hasPostVariable( $fuzzyMatchVariableName ) ) 00107 { 00108 //include_once( 'lib/ezi18n/classes/ezchartransform.php' ); 00109 $trans = eZCharTransform::instance(); 00110 00111 $fuzzyMatchText = trim( $http->postVariable( $fuzzyMatchVariableName ) ); 00112 if ( $fuzzyMatchText != '' ) 00113 { 00114 $fuzzyMatchText = $trans->transformByGroup( $fuzzyMatchText, 'lowercase' ); 00115 $classAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' ); 00116 if ( $classAttribute ) 00117 { 00118 $classContent = $classAttribute->content(); 00119 if ( $classContent['default_selection_node'] ) 00120 { 00121 $nodeID = $classContent['default_selection_node']; 00122 $nodeList = eZContentObjectTreeNode::subTreeByNodeID( array( 'Depth' => 1 ), $nodeID ); 00123 $lastDiff = false; 00124 $matchObjectID = false; 00125 foreach ( $nodeList as $node ) 00126 { 00127 $name = $trans->transformByGroup( trim( $node->attribute( 'name' ) ), 'lowercase' ); 00128 $diff = $this->fuzzyTextMatch( $name, $fuzzyMatchText ); 00129 if ( $diff === false ) 00130 continue; 00131 if ( $diff == 0 ) 00132 { 00133 $matchObjectID = $node->attribute( 'contentobject_id' ); 00134 break; 00135 } 00136 if ( $lastDiff === false or 00137 $diff < $lastDiff ) 00138 { 00139 $lastDiff = $diff; 00140 $matchObjectID = $node->attribute( 'contentobject_id' ); 00141 } 00142 } 00143 if ( $matchObjectID !== false ) 00144 { 00145 $contentObjectAttribute->setAttribute( 'data_int', $matchObjectID ); 00146 $haveData = true; 00147 } 00148 } 00149 } 00150 } 00151 } 00152 return $haveData; 00153 } 00154 00155 /*! 00156 \private 00157 \return a number of how near \a $match is to \a $text, the lower the better and 0 is a perfect match. 00158 \return \c false if it does not match 00159 */ 00160 function fuzzyTextMatch( $text, $match ) 00161 { 00162 $pos = strpos( $text, $match ); 00163 if ( $pos !== false ) 00164 { 00165 $diff = strlen( $text ) - ( strlen( $match ) + $pos ); 00166 $diff += $pos; 00167 return $diff; 00168 } 00169 return false; 00170 } 00171 00172 /*! 00173 Stores relation to the ezcontentobject_link table 00174 */ 00175 function storeObjectAttribute( $contentObjectAttribute ) 00176 { 00177 $contentClassAttributeID = $contentObjectAttribute->ContentClassAttributeID; 00178 $contentObjectID = $contentObjectAttribute->ContentObjectID; 00179 $contentObjectVersion = $contentObjectAttribute->Version; 00180 00181 $obj = $contentObjectAttribute->object(); 00182 //get eZContentObjectVersion 00183 $currVerobj = $obj->version( $contentObjectVersion ); 00184 // get array of language codes 00185 $transList = $currVerobj->translations( false ); 00186 $countTsl = count( $transList ); 00187 00188 if ( ( $countTsl == 1 ) ) 00189 { 00190 eZContentObject::fetch( $contentObjectID )->removeContentObjectRelation( false, $contentObjectVersion, $contentClassAttributeID, eZContentObject::RELATION_ATTRIBUTE ); 00191 } 00192 00193 $objectID = $contentObjectAttribute->attribute( "data_int" ); 00194 00195 if ( $objectID ) 00196 { 00197 eZContentObject::fetch( $contentObjectID )->addContentObjectRelation( $objectID, $contentObjectVersion, $contentClassAttributeID, eZContentObject::RELATION_ATTRIBUTE ); 00198 } 00199 } 00200 00201 /*! 00202 \reimp 00203 */ 00204 function validateClassAttributeHTTPInput( $http, $base, $classAttribute ) 00205 { 00206 $selectionTypeName = 'ContentClass_ezobjectrelation_selection_type_' . $classAttribute->attribute( 'id' ); 00207 $state = eZInputValidator::STATE_ACCEPTED; 00208 if ( $http->hasPostVariable( $selectionTypeName ) ) 00209 { 00210 $selectionType = $http->postVariable( $selectionTypeName ); 00211 if ( $selectionType < 0 and 00212 $selectionType > 2 ) 00213 { 00214 $state = eZInputValidator::STATE_INVALID; 00215 } 00216 } 00217 return $state; 00218 } 00219 00220 /*! 00221 \reimp 00222 */ 00223 function fixupClassAttributeHTTPInput( $http, $base, $classAttribute ) 00224 { 00225 } 00226 00227 /*! 00228 \reimp 00229 */ 00230 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute ) 00231 { 00232 $selectionTypeName = 'ContentClass_ezobjectrelation_selection_type_' . $classAttribute->attribute( 'id' ); 00233 $content = $classAttribute->content(); 00234 $hasData = false; 00235 if ( $http->hasPostVariable( $selectionTypeName ) ) 00236 { 00237 $selectionType = $http->postVariable( $selectionTypeName ); 00238 $content['selection_type'] = $selectionType; 00239 $hasData = true; 00240 } 00241 $helperName = 'ContentClass_ezobjectrelation_selection_fuzzy_match_helper_' . $classAttribute->attribute( 'id' ); 00242 if ( $http->hasPostVariable( $helperName ) ) 00243 { 00244 $fuzzyMatchName = 'ContentClass_ezobjectrelation_selection_fuzzy_match_' . $classAttribute->attribute( 'id' ); 00245 $content['fuzzy_match'] = false; 00246 $hasData = true; 00247 if ( $http->hasPostVariable( $fuzzyMatchName ) ) 00248 { 00249 $content['fuzzy_match'] = true; 00250 } 00251 } 00252 if ( $hasData ) 00253 { 00254 $classAttribute->setContent( $content ); 00255 return true; 00256 } 00257 return false; 00258 } 00259 00260 function preStoreClassAttribute( $classAttribute, $version ) 00261 { 00262 $content = $classAttribute->content(); 00263 $classAttribute->setAttribute( 'data_int1', $content['selection_type'] ); 00264 $classAttribute->setAttribute( 'data_int2', $content['default_selection_node'] ); 00265 $classAttribute->setAttribute( 'data_int3', $content['fuzzy_match'] ); 00266 } 00267 00268 /*! 00269 \private 00270 Delete the old version from ezcontentobject_link if count of translations > 1 00271 */ 00272 function removeContentObjectRelation( $contentObjectAttribute ) 00273 { 00274 $obj = $contentObjectAttribute->object(); 00275 $atrributeTrans = $contentObjectAttribute->fetchAttributeTranslations( ); 00276 // Check if current relation exists in ezcontentobject_link 00277 foreach ( $atrributeTrans as $attrTarns ) 00278 { 00279 if ( $attrTarns->attribute( 'id' ) != $contentObjectAttribute->attribute( 'id' ) ) 00280 if ( $attrTarns->attribute( 'data_int' ) == $contentObjectAttribute->attribute( 'data_int' ) ) 00281 return; 00282 } 00283 00284 //get eZContentObjectVersion 00285 $currVerobj = $obj->currentVersion(); 00286 // get array of ezcontentobjecttranslations 00287 $transList = $currVerobj->translations( false ); 00288 // get count of LanguageCode in transList 00289 $countTsl = count( $transList ); 00290 // Delete the old version from ezcontentobject_link if count of translations > 1 00291 if ( $countTsl > 1 ) 00292 { 00293 $objectID = $contentObjectAttribute->attribute( "data_int" ); 00294 $contentClassAttributeID = $contentObjectAttribute->ContentClassAttributeID; 00295 $contentObjectID = $contentObjectAttribute->ContentObjectID; 00296 $contentObjectVersion = $contentObjectAttribute->Version; 00297 eZContentObject::fetch( $contentObjectID )->removeContentObjectRelation( $objectID, $contentObjectVersion, $contentClassAttributeID, eZContentObject::RELATION_ATTRIBUTE ); 00298 } 00299 } 00300 00301 /*! 00302 */ 00303 function customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute, $parameters ) 00304 { 00305 switch ( $action ) 00306 { 00307 case "set_object_relation" : 00308 { 00309 if ( $http->hasPostVariable( 'BrowseActionName' ) and 00310 $http->postVariable( 'BrowseActionName' ) == ( 'AddRelatedObject_' . $contentObjectAttribute->attribute( 'id' ) ) and 00311 $http->hasPostVariable( "SelectedObjectIDArray" ) ) 00312 { 00313 if ( !$http->hasPostVariable( 'BrowseCancelButton' ) ) 00314 { 00315 $selectedObjectArray = $http->hasPostVariable( "SelectedObjectIDArray" ); 00316 $selectedObjectIDArray = $http->postVariable( "SelectedObjectIDArray" ); 00317 00318 // Delete the old version from ezcontentobject_link if count of translations > 1 00319 $this->removeContentObjectRelation( $contentObjectAttribute ); 00320 00321 $objectID = $selectedObjectIDArray[0]; 00322 $contentObjectAttribute->setAttribute( 'data_int', $objectID ); 00323 $contentObjectAttribute->store(); 00324 } 00325 } 00326 } break; 00327 00328 case "browse_object" : 00329 { 00330 $module = $parameters['module']; 00331 $redirectionURI = $parameters['current-redirection-uri']; 00332 $ini = eZINI::instance( 'content.ini' ); 00333 00334 //include_once( 'kernel/classes/ezcontentbrowse.php' ); 00335 $browseType = 'AddRelatedObjectToDataType'; 00336 $browseTypeINIVariable = $ini->variable( 'ObjectRelationDataTypeSettings', 'ClassAttributeStartNode' ); 00337 foreach( $browseTypeINIVariable as $value ) 00338 { 00339 list( $classAttributeID, $type ) = explode( ';',$value ); 00340 if ( $classAttributeID == $contentObjectAttribute->attribute( 'contentclassattribute_id' ) && strlen( $type ) > 0 ) 00341 { 00342 $browseType = $type; 00343 break; 00344 } 00345 } 00346 eZContentBrowse::browse( array( 'action_name' => 'AddRelatedObject_' . $contentObjectAttribute->attribute( 'id' ), 00347 'type' => $browseType, 00348 'browse_custom_action' => array( 'name' => 'CustomActionButton[' . $contentObjectAttribute->attribute( 'id' ) . '_set_object_relation]', 00349 'value' => $contentObjectAttribute->attribute( 'id' ) ), 00350 'persistent_data' => array( 'HasObjectInput' => 0 ), 00351 'from_page' => $redirectionURI ), 00352 $module ); 00353 } break; 00354 00355 case "remove_object" : 00356 { 00357 // Delete the old version from ezcontentobject_link if count of translations > 1 00358 $this->removeContentObjectRelation( $contentObjectAttribute ); 00359 00360 $contentObjectAttribute->setAttribute( 'data_int', 0 ); 00361 $contentObjectAttribute->store(); 00362 } break; 00363 00364 default : 00365 { 00366 eZDebug::writeError( "Unknown custom HTTP action: " . $action, "eZObjectRelationType" ); 00367 } break; 00368 } 00369 } 00370 00371 /*! 00372 Returns the content. 00373 */ 00374 function objectAttributeContent( $contentObjectAttribute ) 00375 { 00376 $objectID = $contentObjectAttribute->attribute( "data_int" ); 00377 if ( $objectID != 0 ) 00378 $object = eZContentObject::fetch( $objectID ); 00379 else 00380 $object = null; 00381 return $object; 00382 } 00383 00384 /*! 00385 \reimp 00386 Sets \c grouped_input to \c true when browse mode is active or 00387 a dropdown with a fuzzy match is used. 00388 */ 00389 function objectDisplayInformation( $objectAttribute, $mergeInfo = false ) 00390 { 00391 $classAttribute = $objectAttribute->contentClassAttribute(); 00392 $content = $this->classAttributeContent( $classAttribute ); 00393 $editGrouped = ( $content['selection_type'] == 0 or 00394 ( $content['selection_type'] == 1 and $content['fuzzy_match'] ) ); 00395 00396 $info = array( 'edit' => array( 'grouped_input' => $editGrouped ), 00397 'collection' => array( 'grouped_input' => $editGrouped ) ); 00398 return eZDataType::objectDisplayInformation( $objectAttribute, $info ); 00399 } 00400 00401 /*! 00402 \reimp 00403 */ 00404 function sortKey( $contentObjectAttribute ) 00405 { 00406 return $contentObjectAttribute->attribute( 'data_int' ); 00407 } 00408 00409 /*! 00410 \reimp 00411 */ 00412 function sortKeyType() 00413 { 00414 return 'int'; 00415 } 00416 00417 function classAttributeContent( $classObjectAttribute ) 00418 { 00419 $selectionType = $classObjectAttribute->attribute( "data_int1" ); 00420 $defaultSelectionNode = $classObjectAttribute->attribute( "data_int2" ); 00421 $fuzzyMatch = $classObjectAttribute->attribute( "data_int3" ); 00422 return array( 'selection_type' => $selectionType, 00423 'default_selection_node' => $defaultSelectionNode, 00424 'fuzzy_match' => $fuzzyMatch ); 00425 } 00426 00427 function customClassAttributeHTTPAction( $http, $action, $classAttribute ) 00428 { 00429 switch ( $action ) 00430 { 00431 case 'browse_for_selection_node': 00432 { 00433 $module = $classAttribute->currentModule(); 00434 //include_once( 'kernel/classes/ezcontentbrowse.php' ); 00435 $customActionName = 'CustomActionButton[' . $classAttribute->attribute( 'id' ) . '_browsed_for_selection_node]'; 00436 eZContentBrowse::browse( array( 'action_name' => 'SelectObjectRelationNode', 00437 'content' => array( 'contentclass_id' => $classAttribute->attribute( 'contentclass_id' ), 00438 'contentclass_attribute_id' => $classAttribute->attribute( 'id' ), 00439 'contentclass_version' => $classAttribute->attribute( 'version' ), 00440 'contentclass_attribute_identifier' => $classAttribute->attribute( 'identifier' ) ), 00441 'persistent_data' => array( $customActionName => '', 00442 'ContentClassHasInput' => false ), 00443 'description_template' => 'design:class/datatype/browse_objectrelation_placement.tpl', 00444 'from_page' => $module->currentRedirectionURI() ), 00445 $module ); 00446 } break; 00447 case 'browsed_for_selection_node': 00448 { 00449 //include_once( 'kernel/classes/ezcontentbrowse.php' ); 00450 $nodeSelection = eZContentBrowse::result( 'SelectObjectRelationNode' ); 00451 if ( count( $nodeSelection ) > 0 ) 00452 { 00453 $nodeID = $nodeSelection[0]; 00454 $content = $classAttribute->content(); 00455 $content['default_selection_node'] = $nodeID; 00456 $classAttribute->setContent( $content ); 00457 } 00458 } break; 00459 case 'disable_selection_node': 00460 { 00461 $content = $classAttribute->content(); 00462 $content['default_selection_node'] = false; 00463 $classAttribute->setContent( $content ); 00464 } break; 00465 default: 00466 { 00467 eZDebug::writeError( "Unknown objectrelationlist action '$action'", 'eZContentObjectRelationListType::customClassAttributeHTTPAction' ); 00468 } break; 00469 } 00470 } 00471 00472 /*! 00473 Returns the meta data used for storing search indeces. 00474 */ 00475 function metaData( $contentObjectAttribute ) 00476 { 00477 $object = $this->objectAttributeContent( $contentObjectAttribute ); 00478 if ( $object ) 00479 { 00480 if ( eZContentObject::recursionProtect( $object->attribute( 'id' ) ) ) 00481 { 00482 // Does the related object exist in the same language as the current content attribute ? 00483 if ( in_array( $contentObjectAttribute->attribute( 'language_code' ), $object->attribute( 'current' )->translationList( false, false ) ) ) 00484 { 00485 $attributes = $object->attribute( 'current' )->contentObjectAttributes( $contentObjectAttribute->attribute( 'language_code' ) ); 00486 } 00487 else 00488 { 00489 $attributes = $object->contentObjectAttributes(); 00490 } 00491 00492 return eZContentObjectAttribute::metaDataArray( $attributes ); 00493 } 00494 else 00495 { 00496 return array(); 00497 } 00498 } 00499 return false; 00500 } 00501 /*! 00502 \return string representation of an contentobjectattribute data for simplified export 00503 00504 */ 00505 function toString( $contentObjectAttribute ) 00506 { 00507 return $contentObjectAttribute->attribute( 'data_int' ); 00508 } 00509 00510 function fromString( $contentObjectAttribute, $string ) 00511 { 00512 if ( !is_numeric( $string ) || !eZContentObject::fetch( $string ) ) 00513 return false; 00514 00515 $contentObjectAttribute->setAttribute( 'data_int', $string ); 00516 return true; 00517 } 00518 00519 function isIndexable() 00520 { 00521 return true; 00522 } 00523 00524 /*! 00525 Returns the content of the string for use as a title 00526 */ 00527 function title( $contentObjectAttribute, $name = null ) 00528 { 00529 $object = $this->objectAttributeContent( $contentObjectAttribute ); 00530 if ( $object ) 00531 { 00532 return $object->attribute( 'name' ); 00533 } 00534 return false; 00535 } 00536 00537 function hasObjectAttributeContent( $contentObjectAttribute ) 00538 { 00539 $object = $this->objectAttributeContent( $contentObjectAttribute ); 00540 if ( $object ) 00541 return true; 00542 return false; 00543 } 00544 00545 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00546 { 00547 $content = $classAttribute->content(); 00548 $dom = $attributeParametersNode->ownerDocument; 00549 $selectionTypeNode = $dom->createElement( 'selection-type' ); 00550 $selectionTypeNode->setAttribute( 'id', $content['selection_type'] ); 00551 $attributeParametersNode->appendChild( $selectionTypeNode ); 00552 $fuzzyMatchNode = $dom->createElement( 'fuzzy-match' ); 00553 $fuzzyMatchNode->setAttribute( 'id', $content['fuzzy_match'] ); 00554 $attributeParametersNode->appendChild( $fuzzyMatchNode ); 00555 if ( $content['default_selection_node'] ) 00556 { 00557 $defaultSelectionNode = $dom->createElement( 'default-selection' ); 00558 $defaultSelectionNode->setAttribute( 'node-id', $content['default_selection_node'] ); 00559 $attributeParametersNode->appendChild( $defaultSelectionNode ); 00560 } 00561 } 00562 00563 /*! 00564 \reimp 00565 */ 00566 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00567 { 00568 $content = $classAttribute->content(); 00569 $selectionTypeNode = $attributeParametersNode->getElementsByTagName( 'selection-type' )->item( 0 ); 00570 $content['selection_type'] = 0; 00571 if ( $selectionTypeNode ) 00572 $content['selection_type'] = $selectionTypeNode->getAttribute( 'id' ); 00573 00574 $fuzzyMatchNode = $attributeParametersNode->getElementsByTagName( 'fuzzy-match' )->item( 0 ); 00575 $content['fuzzy_match'] = false; 00576 if ( $fuzzyMatchNode ) 00577 $content['fuzzy_match'] = $fuzzyMatchNode->getAttribute( 'id' ); 00578 00579 $defaultSelectionNode = $attributeParametersNode->getElementsByTagName( 'default-selection' )->item( 0 ); 00580 $content['default_selection_node'] = false; 00581 if ( $defaultSelectionNode ) 00582 $content['default_selection_node'] = $defaultSelectionNode->getAttribute( 'node-id' ); 00583 00584 $classAttribute->setContent( $content ); 00585 $classAttribute->store(); 00586 } 00587 00588 /*! 00589 Export related object's remote_id. 00590 \reimp 00591 */ 00592 function serializeContentObjectAttribute( $package, $objectAttribute ) 00593 { 00594 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute ); 00595 $relatedObjectID = $objectAttribute->attribute( 'data_int' ); 00596 00597 if ( !is_null( $relatedObjectID ) ) 00598 { 00599 require_once( 'kernel/classes/ezcontentobject.php' ); 00600 $relatedObject = eZContentObject::fetch( $relatedObjectID ); 00601 if ( !$relatedObject ) 00602 { 00603 eZDebug::writeNotice( 'Related object with ID: ' . $relatedObjectID . ' does not exist.' ); 00604 } 00605 else 00606 { 00607 $relatedObjectRemoteID = $relatedObject->attribute( 'remote_id' ); 00608 $dom = $node->ownerDocument; 00609 $relatedObjectRemoteIDNode = $dom->createElement( 'related-object-remote-id' ); 00610 $relatedObjectRemoteIDNode->appendChild( $dom->createTextNode( $relatedObjectRemoteID ) ); 00611 $node->appendChild( $relatedObjectRemoteIDNode ); 00612 } 00613 } 00614 00615 return $node; 00616 } 00617 00618 /*! 00619 \reimp 00620 */ 00621 function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode ) 00622 { 00623 $relatedObjectRemoteIDNode = $attributeNode->getElementsByTagName( 'related-object-remote-id' )->item( 0 ); 00624 $relatedObjectID = null; 00625 00626 if ( $relatedObjectRemoteIDNode ) 00627 { 00628 $relatedObjectRemoteID = $relatedObjectRemoteIDNode->textContent; 00629 $object = eZContentObject::fetchByRemoteID( $relatedObjectRemoteID ); 00630 if ( $object ) 00631 { 00632 $relatedObjectID = $object->attribute( 'id' ); 00633 } 00634 else 00635 { 00636 // store remoteID so it can be used in postUnserialize 00637 $objectAttribute->setAttribute( 'data_text', $relatedObjectRemoteID ); 00638 } 00639 } 00640 00641 $objectAttribute->setAttribute( 'data_int', $relatedObjectID ); 00642 } 00643 00644 /*! 00645 \reimp 00646 */ 00647 function postUnserializeContentObjectAttribute( $package, $objectAttribute ) 00648 { 00649 $attributeChanged = false; 00650 $relatedObjectID = $objectAttribute->attribute( 'data_int' ); 00651 00652 if ( !$relatedObjectID ) 00653 { 00654 // Restore cross-relations using preserved remoteID 00655 $relatedObjectRemoteID = $objectAttribute->attribute( 'data_text' ); 00656 if ( $relatedObjectRemoteID) 00657 { 00658 $object = eZContentObject::fetchByRemoteID( $relatedObjectRemoteID ); 00659 $relatedObjectID = ( $object !== null ) ? $object->attribute( 'id' ) : null; 00660 00661 if ( $relatedObjectID ) 00662 { 00663 $objectAttribute->setAttribute( 'data_int', $relatedObjectID ); 00664 $attributeChanged = true; 00665 } 00666 } 00667 } 00668 00669 return $attributeChanged; 00670 } 00671 00672 /*! 00673 Removes objects with given ID from the relations list 00674 */ 00675 function removeRelatedObjectItem( $contentObjectAttribute, $objectID ) 00676 { 00677 $contentObjectAttribute->setAttribute( "data_int", null ); 00678 return true; 00679 } 00680 00681 /// \privatesection 00682 } 00683 00684 eZDataType::register( eZObjectRelationType::DATA_TYPE_STRING, "eZObjectRelationType" ); 00685 00686 ?>