00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 include_once( "lib/ezdb/classes/ezdb.php" );
00039 include_once( "kernel/classes/ezpersistentobject.php" );
00040 include_once( "kernel/classes/eznodeassignment.php" );
00041 include_once( "kernel/classes/ezcontentobject.php" );
00042
00043 include_once( "kernel/classes/ezcontentobjectattribute.php" );
00044 include_once( "kernel/classes/ezcontentobjecttranslation.php" );
00045 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00046 include_once( "kernel/classes/ezcontentclassattribute.php" );
00047
00048
00049 define( "EZ_VERSION_STATUS_DRAFT", 0 );
00050 define( "EZ_VERSION_STATUS_PUBLISHED", 1 );
00051 define( "EZ_VERSION_STATUS_PENDING", 2 );
00052 define( "EZ_VERSION_STATUS_ARCHIVED", 3 );
00053 define( "EZ_VERSION_STATUS_REJECTED", 4 );
00054 define( "EZ_VERSION_STATUS_INTERNAL_DRAFT", 5 );
00055
00056
00057
00058 class eZContentObjectVersion extends eZPersistentObject
00059 {
00060 function eZContentObjectVersion( $row=array() )
00061 {
00062 $this->ContentObjectAttributeArray = false;
00063 $this->DataMap = false;
00064 $this->TempNode = null;
00065 $this->VersionName = null;
00066 $this->VersionNameCache = array();
00067 $this->eZPersistentObject( $row );
00068 }
00069
00070 function definition()
00071 {
00072 return array( "fields" => array( 'id' => array( 'name' => 'ID',
00073 'datatype' => 'integer',
00074 'default' => 0,
00075 'required' => true ),
00076 'contentobject_id' => array( 'name' => 'ContentObjectID',
00077 'datatype' => 'integer',
00078 'default' => 0,
00079 'required' => true,
00080 'foreign_class' => 'eZContentObject',
00081 'foreign_attribute' => 'id',
00082 'multiplicity' => '1..*' ),
00083 'creator_id' => array( 'name' => 'CreatorID',
00084 'datatype' => 'integer',
00085 'default' => 0,
00086 'required' => true,
00087 'foreign_class' => 'eZUser',
00088 'foreign_attribute' => 'id',
00089 'multiplicity' => '1..*' ),
00090 'version' => array( 'name' => 'Version',
00091 'datatype' => 'integer',
00092 'default' => 0,
00093 'required' => true ),
00094 'status' => array( 'name' => 'Status',
00095 'datatype' => 'integer',
00096 'default' => 0,
00097 'required' => true ),
00098 'created' => array( 'name' => 'Created',
00099 'datatype' => 'integer',
00100 'default' => 0,
00101 'required' => true ),
00102 'modified' => array( 'name' => 'Modified',
00103 'datatype' => 'integer',
00104 'default' => 0,
00105 'required' => true ),
00106 'workflow_event_pos' => array( 'name' => 'WorkflowEventPos',
00107 'datatype' => 'integer',
00108 'default' => 0,
00109 'required' => true ),
00110 'user_id' => array( 'name' => 'UserID',
00111 'datatype' => 'integer',
00112 'default' => 0,
00113 'required' => true,
00114 'foreign_class' => 'eZUser',
00115 'foreign_attribute' => 'contentobject_id',
00116 'multiplicity' => '1..*' ),
00117 'language_mask' => array( 'name' => 'LanguageMask',
00118 'datatype' => 'integer',
00119 'default' => 0,
00120 'required' => true ),
00121 'initial_language_id' => array( 'name' => 'InitialLanguageID',
00122 'datatype' => 'integer',
00123 'default' => 0,
00124 'required' => true,
00125 'foreign_class' => 'eZContentLanguage',
00126 'foreign_attribute' => 'id',
00127 'multiplicity' => '1..*' ) ),
00128 'keys' => array( 'id' ),
00129 'function_attributes' => array(
00130 'creator' => 'creator',
00131 "name" => "name",
00132 "version_name" => "versionName",
00133 'main_parent_node_id' => 'mainParentNodeID',
00134 "contentobject_attributes" => "contentObjectAttributes",
00135 "related_contentobject_array" => "relatedContentObjectArray",
00136 'reverse_related_object_list' => "reverseRelatedObjectList",
00137 'parent_nodes' => 'parentNodes',
00138 "can_read" => "canVersionRead",
00139 'can_remove' => 'canVersionRemove',
00140 "data_map" => "dataMap",
00141 'node_assignments' => 'nodeAssignments',
00142 'contentobject' => 'contentObject',
00143 'initial_language' => 'initialLanguage',
00144 'language_list' => 'translations',
00145 'translation' => 'translation',
00146 'translation_list' => 'defaultTranslationList',
00147 'complete_translation_list' => 'translationList',
00148 'temp_main_node' => 'tempMainNode' ),
00149 'class_name' => "eZContentObjectVersion",
00150 "increment_key" => "id",
00151 'sort' => array( 'version' => 'asc' ),
00152 'name' => 'ezcontentobject_version' );
00153 }
00154
00155 function statusList( $limit = false )
00156 {
00157 if ( $limit == 'remove' )
00158 {
00159 $versions = array( array( 'name' => 'Draft', 'id' => EZ_VERSION_STATUS_DRAFT ),
00160 array( 'name' => 'Pending', 'id' => EZ_VERSION_STATUS_PENDING ),
00161 array( 'name' => 'Archived', 'id' => EZ_VERSION_STATUS_ARCHIVED ),
00162 array( 'name' => 'Rejected', 'id' => EZ_VERSION_STATUS_REJECTED ) );
00163 }
00164 else
00165 {
00166 $versions = array( array( 'name' => 'Draft', 'id' => EZ_VERSION_STATUS_DRAFT ),
00167 array( 'name' => 'Published', 'id' => EZ_VERSION_STATUS_PUBLISHED ),
00168 array( 'name' => 'Pending', 'id' => EZ_VERSION_STATUS_PENDING ),
00169 array( 'name' => 'Archived', 'id' => EZ_VERSION_STATUS_ARCHIVED ),
00170 array( 'name' => 'Rejected', 'id' => EZ_VERSION_STATUS_REJECTED ) );
00171 }
00172 return $versions;
00173 }
00174
00175
00176
00177
00178 function fetch( $id, $asObject = true )
00179 {
00180 return eZPersistentObject::fetchObject( eZContentObjectVersion::definition(),
00181 null,
00182 array( 'id' => $id ),
00183 $asObject );
00184 }
00185
00186 function fetchVersion( $version, $contentObjectID, $asObject = true )
00187 {
00188 $ret = eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),
00189 null, array( "version" => $version,
00190 "contentobject_id" => $contentObjectID
00191 ),
00192 null, null,
00193 $asObject );
00194 return isset( $ret[0] ) ? $ret[0] : false;
00195 }
00196
00197 function fetchUserDraft( $objectID, $userID )
00198 {
00199 $versions = eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),
00200 null, array( 'creator_id' => $userID,
00201 'contentobject_id' => $objectID,
00202 'status' => array( array( EZ_VERSION_STATUS_DRAFT, EZ_VERSION_STATUS_INTERNAL_DRAFT ) ) ),
00203 array( 'version' => 'asc' ), null,
00204 true );
00205 if ( $versions === null or
00206 count( $versions ) == 0 )
00207 return null;
00208 return $versions[0];
00209 }
00210
00211 function fetchForUser( $userID, $status = EZ_VERSION_STATUS_DRAFT )
00212 {
00213 return eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),
00214 null, array( 'creator_id' => $userID,
00215 'status' => $status
00216 ),
00217 null, null,
00218 true );
00219 }
00220
00221 function fetchFiltered( $filters, $offset, $limit )
00222 {
00223 $limits = null;
00224 if ( $offset or $limit )
00225 $limits = array( 'offset' => $offset,
00226 'length' => $limit );
00227 return eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),
00228 null, $filters,
00229 null, $limits,
00230 true );
00231 }
00232
00233
00234
00235
00236
00237 function &tempMainNode()
00238 {
00239 if ( $this->TempNode !== null )
00240 return $this->TempNode;
00241 $object =& $this->contentObject();
00242 if ( $object->attribute( 'status' ) == EZ_CONTENT_OBJECT_STATUS_DRAFT )
00243 {
00244 $nodeAssignments =& $this->nodeAssignments();
00245 $mainNodeAssignment = null;
00246 for ( $i = 0; $i < count( $nodeAssignments ); ++$i )
00247 {
00248 $nodeAssignment =& $nodeAssignments[$i];
00249 if ( $nodeAssignment->attribute( 'is_main' ) )
00250 {
00251 $mainNodeAssignment =& $nodeAssignment;
00252 break;
00253 }
00254 }
00255 if ( $mainNodeAssignment === null and
00256 count( $nodeAssignments ) > 0 )
00257 $mainNodeAssignment =& $nodeAssignments[0];
00258 if ( $mainNodeAssignment )
00259 {
00260 $this->TempNode =& $mainNodeAssignment->tempNode();
00261 }
00262 }
00263 else if ( $object->attribute( 'status' ) == EZ_CONTENT_OBJECT_STATUS_PUBLISHED )
00264 {
00265 $mainNode =& $object->mainNode();
00266 if ( is_object( $mainNode ) )
00267 {
00268 $this->TempNode = eZContentObjectTreeNode::create( $mainNode->attribute( 'parent_node_id' ),
00269 $mainNode->attribute( 'contentobject_id' ),
00270 $this->attribute( 'version' ),
00271 $mainNode->attribute( 'sort_field' ),
00272 $mainNode->attribute( 'sort_order' ) );
00273 $this->TempNode->setName( $mainNode->Name );
00274 }
00275 }
00276 return $this->TempNode;
00277 }
00278
00279
00280
00281
00282 function &name( $lang = false )
00283 {
00284 if ( $this->VersionName !== null )
00285 return $this->VersionName;
00286 $this->VersionName = eZContentObject::versionLanguageName( $this->attribute( 'contentobject_id' ),
00287 $this->attribute( 'version' ),
00288 $lang );
00289 if ( $lang !== false )
00290 {
00291 $contentObject =& $this->contentObject();
00292 if ( $contentObject )
00293 {
00294 $tmpVar = $contentObject->name( $lang );
00295 return $tmpVar;
00296 }
00297 }
00298 if ( $this->VersionName === false )
00299 {
00300 $contentObject =& $this->contentObject();
00301 if ( $contentObject )
00302 {
00303 $this->VersionName = $contentObject->name( false, $lang );
00304 }
00305 }
00306 return $this->VersionName;
00307 }
00308
00309
00310
00311
00312 function &versionName( $lang = false )
00313 {
00314 if ( !$lang )
00315 {
00316 $lang = $this->initialLanguageCode();
00317 }
00318
00319 if ( isset( $this->VersionNameCache[$lang] ) )
00320 return $this->VersionNameCache[$lang];
00321
00322 $object =& $this->attribute( 'contentobject' );
00323 if ( !$object )
00324 {
00325 $retValue = false;
00326 return $retValue;
00327 }
00328
00329 $class =& $object->attribute( 'content_class' );
00330 if ( !$class )
00331 {
00332 $retValue = false;
00333 return $retValue;
00334 }
00335
00336 $this->VersionNameCache[$lang] = $class->contentObjectName( $object,
00337 $this->attribute( 'version' ),
00338 $lang );
00339 return $this->VersionNameCache[$lang];
00340 }
00341
00342
00343
00344
00345
00346
00347 function &canVersionRead( )
00348 {
00349 if ( !isset( $this->Permissions["can_versionread"] ) )
00350 {
00351 $this->Permissions["can_versionread"] = $this->checkAccess( 'versionread' );
00352 }
00353 $p = ( $this->Permissions["can_versionread"] == 1 );
00354 return $p;
00355 }
00356
00357
00358
00359
00360
00361
00362 function &canVersionRemove( )
00363 {
00364 if ( !isset( $this->Permissions['can_versionremove'] ) )
00365 {
00366 $this->Permissions['can_versionremove'] = $this->checkAccess( 'versionremove' );
00367 }
00368 $p = ( $this->Permissions['can_versionremove'] == 1 );
00369 return $p;
00370 }
00371
00372 function checkAccess( $functionName, $originalClassID = false, $parentClassID = false, $returnAccessList = false, $language = false )
00373 {
00374 $classID = $originalClassID;
00375 $user =& eZUser::currentUser();
00376 $userID = $user->attribute( 'contentobject_id' );
00377 $accessResult = $user->hasAccessTo( 'content' , $functionName );
00378 $accessWord = $accessResult['accessWord'];
00379 $object =& $this->attribute( 'contentobject' );
00380 $objectClassID = $object->attribute( 'contentclass_id' );
00381 if ( ! $classID )
00382 {
00383 $classID = $objectClassID;
00384 }
00385
00386 include_once( 'kernel/classes/ezcontentlanguage.php' );
00387
00388
00389 $originalLanguage = $language;
00390 if ( is_string( $language ) && strlen( $language ) > 0 )
00391 {
00392 $language = eZContentLanguage::idByLocale( $language );
00393 }
00394 else
00395 {
00396 $language = false;
00397 }
00398
00399
00400
00401 $languageList = false;
00402
00403
00404 if ( $functionName == 'create' )
00405 {
00406 return false;
00407 }
00408
00409 if ( $functionName == 'edit' )
00410 {
00411
00412 if ( !in_array( $this->attribute( 'status' ),
00413 array( EZ_VERSION_STATUS_DRAFT,
00414 EZ_VERSION_STATUS_INTERNAL_DRAFT,
00415 EZ_VERSION_STATUS_PENDING ) ) ||
00416 $this->attribute( 'creator_id' ) != $userID )
00417 {
00418 return false;
00419 }
00420 return true;
00421 }
00422
00423 if ( $functionName == 'versionremove' and $this->attribute( 'status' ) == EZ_VERSION_STATUS_PUBLISHED )
00424 {
00425 return 0;
00426 }
00427
00428 if ( $accessWord == 'yes' )
00429 {
00430 return 1;
00431 }
00432 elseif ( $accessWord == 'no' )
00433 {
00434 if ( $functionName == 'edit' )
00435 {
00436
00437 if ( $object && $object->attribute( 'current_version' ) == 1 && !$object->attribute( 'status' ) )
00438 {
00439 $mainNode = eZNodeAssignment::fetchForObject( $object->attribute( 'id' ), $object->attribute( 'current_version' ) );
00440 $parentObj = $mainNode[0]->attribute( 'parent_contentobject' );
00441 $result = $parentObj->checkAccess( 'create', $object->attribute( 'contentclass_id' ),
00442 $parentObj->attribute( 'contentclass_id' ), false, $originalLanguage );
00443 return $result;
00444 }
00445 else
00446 {
00447 return 0;
00448 }
00449 }
00450
00451 return 0;
00452 }
00453 else
00454 {
00455 $policies =& $accessResult['policies'];
00456
00457 foreach ( array_keys( $policies ) as $key )
00458 {
00459 $limitationList[] =& $policies[$key];
00460 }
00461
00462 if ( count( $limitationList ) > 0 )
00463 {
00464 $access = 'denied';
00465 foreach ( array_keys( $limitationList ) as $key )
00466 {
00467 $limitationArray =& $limitationList[ $key ];
00468 if ( $access == 'allowed' )
00469 {
00470 break;
00471 }
00472
00473 if ( isset( $limitationArray['Subtree' ] ) )
00474 {
00475 $checkedSubtree = false;
00476 }
00477 else
00478 {
00479 $checkedSubtree = true;
00480 $accessSubtree = false;
00481 }
00482 if ( isset( $limitationArray['Node'] ) )
00483 {
00484 $checkedNode = false;
00485 }
00486 else
00487 {
00488 $checkedNode = true;
00489 $accessNode = false;
00490 }
00491 foreach ( $limitationArray as $key => $limitation )
00492 {
00493 $access = 'denied';
00494
00495 if ( $key == 'Class' )
00496 {
00497 if ( $functionName == 'create' and !$originalClassID )
00498 $access = 'allowed';
00499 else if ( $functionName == 'create' and in_array( $classID, $limitation ) )
00500 $access = 'allowed';
00501 elseif ( in_array( $objectClassID, $limitation ) )
00502 $access = 'allowed';
00503 else
00504 {
00505 $access = 'denied';
00506 break;
00507 }
00508 }
00509 elseif ( $key == 'Status' )
00510 {
00511 if ( in_array( $this->attribute( 'status' ), $limitation ) )
00512 $access = 'allowed';
00513 else
00514 {
00515 $access = 'denied';
00516 break;
00517 }
00518 }
00519 elseif ( $key == 'Section' || $key == 'User_Section' )
00520 {
00521 if ( in_array( $object->attribute( 'section_id' ), $limitation ) )
00522 $access = 'allowed';
00523 else
00524 {
00525 $access = 'denied';
00526 break;
00527 }
00528 }
00529 elseif ( $key == 'Language' )
00530 {
00531 $languageMask = 0;
00532
00533
00534 if ( $functionName == 'create' )
00535 {
00536
00537 if ( $language !== false )
00538 {
00539 $languageMask = $language;
00540 }
00541 else
00542 {
00543
00544
00545
00546 $languageMask = -1;
00547 }
00548 }
00549 else
00550 {
00551 if ( $language !== false )
00552 {
00553 if ( $languageList === false )
00554 {
00555 $languageMask = $this->attribute( 'initial_language_id' );
00556
00557
00558
00559 $languageMask &= $language;
00560 }
00561 }
00562 else
00563 {
00564 $languageMask = $this->attribute( 'initial_language_id' );
00565 }
00566 }
00567
00568 $limitMask = eZContentLanguage::maskByLocale( $limitationArray[$key] );
00569 if ( ( $languageMask & $limitMask ) != 0 )
00570 {
00571 $access = 'allowed';
00572 }
00573 else
00574 {
00575 $access = 'denied';
00576 }
00577 }
00578 elseif ( $key == 'Owner' )
00579 {
00580 if ( $this->attribute( 'creator_id' ) == $userID )
00581 $access = 'allowed';
00582 else
00583 {
00584 $access = 'denied';
00585 break;
00586 }
00587 }
00588 elseif ( $key == 'Node' )
00589 {
00590 $accessNode = false;
00591 $contentObjectID = $this->attribute( 'contentobject_id' );
00592 foreach ( $limitation as $nodeID )
00593 {
00594 $node = eZContentObjectTreeNode::fetch( $nodeID, false, false );
00595 $limitationObjectID = $node['contentobject_id'];
00596 if ( $contentObjectID == $limitationObjectID )
00597 {
00598 $access = 'allowed';
00599 $accessNode = true;
00600 break;
00601 }
00602 }
00603 if ( $access == 'denied' && $checkedSubtree && !$accessSubtree )
00604 {
00605 break;
00606 }
00607 else
00608 {
00609 $access = 'allowed';
00610 }
00611 $checkedNode = true;
00612 }
00613 elseif ( $key == 'Subtree' )
00614 {
00615 $accessSubtree = false;
00616 $contentObject = $this->attribute( 'contentobject' );
00617 foreach ( $contentObject->attribute( 'assigned_nodes' ) as $assignedNode )
00618 {
00619 $path = $assignedNode->attribute( 'path_string' );
00620 $subtreeArray =& $limitation;
00621 foreach ( $subtreeArray as $subtreeString )
00622 {
00623 if ( strstr( $path, $subtreeString ) )
00624 {
00625 $access = 'allowed';
00626 $accessSubtree = true;
00627 break;
00628 }
00629 }
00630 if ( $access == 'allowed' )
00631 {
00632 break;
00633 }
00634 }
00635 if ( $access != 'allowed' )
00636 {
00637 foreach( $this->attribute( 'node_assignments' ) as $nodeAssignment )
00638 {
00639 $parentNode = $nodeAssignment->attribute( 'parent_node_obj' );
00640 $path = $parentNode->attribute( 'path_string' );
00641 $subtreeArray =& $limitation;
00642 foreach ( $subtreeArray as $subtreeString )
00643 {
00644 if ( strstr( $path, $subtreeString ) )
00645 {
00646 $access = 'allowed';
00647 $accessSubtree = true;
00648 break;
00649 }
00650 }
00651 if ( $access == 'allowed' )
00652 {
00653 break;
00654 }
00655 }
00656 }
00657 if ( $access == 'denied' && $checkedNode && !$accessNode )
00658 {
00659 break;
00660 }
00661 else
00662 {
00663 $access = 'allowed';
00664 }
00665 $checkedSubtree = true;
00666 }
00667 elseif ( $key == 'User_Subtree' )
00668 {
00669 $contentObject = $this->attribute( 'contentobject' );
00670 foreach ( $contentObject->attribute( 'assigned_nodes' ) as $assignedNode )
00671 {
00672 $path = $assignedNode->attribute( 'path_string' );
00673 $subtreeArray =& $limitation;
00674 foreach ( $subtreeArray as $subtreeString )
00675 {
00676 if ( strstr( $path, $subtreeString ) )
00677 {
00678 $access = 'allowed';
00679 $accessSubtree = true;
00680 break;
00681 }
00682 }
00683 if ( $access == 'allowed' )
00684 {
00685 break;
00686 }
00687 }
00688 if ( $access != 'allowed' )
00689 {
00690 foreach( $this->attribute( 'node_assignments' ) as $nodeAssignment )
00691 {
00692 $parentNode = $nodeAssignment->attribute( 'parent_node_obj' );
00693 $path = $parentNode->attribute( 'path_string' );
00694 $subtreeArray =& $limitation;
00695 foreach ( $subtreeArray as $subtreeString )
00696 {
00697 if ( strstr( $path, $subtreeString ) )
00698 {
00699 $access = 'allowed';
00700 break;
00701 }
00702 }
00703 if ( $access == 'allowed' )
00704 {
00705 break;
00706 }
00707 }
00708 }
00709 if ( $access == 'denied' )
00710 {
00711 break;
00712 }
00713 }
00714 }
00715 }
00716
00717 if ( $access == 'denied' )
00718 {
00719 return 0;
00720 }
00721 else
00722 {
00723 return 1;
00724 }
00725 }
00726 }
00727 }
00728
00729 function &contentObject()
00730 {
00731 if( !isset( $this->ContentObject ) )
00732 {
00733 $this->ContentObject =& eZContentObject::fetch( $this->attribute( 'contentobject_id' ) );
00734 }
00735 return $this->ContentObject;
00736 }
00737
00738
00739
00740
00741
00742 function &mainParentNodeID()
00743 {
00744 $temp = eZNodeAssignment::fetchForObject( $this->attribute( 'contentobject_id' ), $this->attribute( 'version' ), 1 );
00745 if ( $temp == null )
00746 {
00747 $mainParentNodeID = 1;
00748 }
00749 else
00750 {
00751 $mainParentNodeID = $temp[0]->attribute( 'parent_node' );
00752 }
00753 return $mainParentNodeID;
00754 }
00755
00756 function &parentNodes( )
00757 {
00758 $retNodes = array();
00759 $nodeAssignmentList = eZNodeAssignment::fetchForObject( $this->attribute( 'contentobject_id' ), $this->attribute( 'version' ) );
00760 foreach ( array_keys( $nodeAssignmentList ) as $key )
00761 {
00762 $nodeAssignment =& $nodeAssignmentList[$key];
00763 $retNodes[] =& $nodeAssignment;
00764 }
00765 return $retNodes;
00766 }
00767 function &nodeAssignments()
00768 {
00769 $nodeAssignmentList = eZNodeAssignment::fetchForObject( $this->attribute( 'contentobject_id' ), $this->attribute( 'version' ) );
00770 return $nodeAssignmentList;
00771 }
00772
00773 function &assignToNode( $nodeID, $main = 0, $fromNodeID = 0, $sortField = null, $sortOrder = null,
00774 $remoteID = 0 )
00775 {
00776 if ( $fromNodeID == 0 && ( $this->attribute( 'status' ) == EZ_VERSION_STATUS_DRAFT ||
00777 $this->attribute( 'status' ) == EZ_VERSION_STATUS_INTERNAL_DRAFT ) )
00778 $fromNodeID = -1;
00779 $nodeRow = array( 'contentobject_id' => $this->attribute( 'contentobject_id' ),
00780 'contentobject_version' => $this->attribute( 'version' ),
00781 'parent_node' => $nodeID,
00782 'is_main' => $main,
00783 'remote_id' => $remoteID,
00784 'from_node_id' => $fromNodeID );
00785 if ( $sortField !== null )
00786 $nodeRow['sort_field'] = $sortField;
00787 if ( $sortOrder !== null )
00788 $nodeRow['sort_order'] = ( $sortOrder ? 1 : 0 );
00789
00790 $nodeAssignment = eZNodeAssignment::create( $nodeRow );
00791 $nodeAssignment->store();
00792 return $nodeAssignment;
00793 }
00794
00795
00796
00797
00798
00799 function removeAssignment( $nodeID )
00800 {
00801 $nodeAssignmentList =& $this->attribute( 'node_assignments' );
00802 $db =& eZDb::instance();
00803 $db->begin();
00804
00805 foreach ( array_keys( $nodeAssignmentList ) as $key )
00806 {
00807 $nodeAssignment =& $nodeAssignmentList[$key];
00808 if ( $nodeAssignment->attribute( 'parent_node' ) == $nodeID )
00809 {
00810 $nodeAssignment->remove();
00811 }
00812 }
00813 $db->commit();
00814 }
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841 function &dataMap()
00842 {
00843 if ( $this->ContentObjectAttributeArray === false )
00844 {
00845 $data =& $this->contentObjectAttributes();
00846
00847 $this->ContentObjectAttributeArray =& $data;
00848 }
00849 else
00850 {
00851 $data =& $this->ContentObjectAttributeArray;
00852 }
00853
00854 if ( $this->DataMap == false )
00855 {
00856 $ret = array();
00857 foreach( $data as $key => $item )
00858 {
00859 $identifier = $item->contentClassAttributeIdentifier();
00860 $ret[$identifier] =& $data[$key];
00861 }
00862 $this->DataMap =& $ret;
00863 }
00864 else
00865 {
00866 $ret =& $this->DataMap;
00867 }
00868 return $ret;
00869 }
00870
00871 function resetDataMap()
00872 {
00873 $this->ContentObjectAttributeArray = false;
00874 $this->DataMap = false;
00875 return $this->DataMap;
00876 }
00877
00878
00879
00880
00881 function &relatedContentObjectArray()
00882 {
00883 $objectID = $this->attribute( 'contentobject_id' );
00884 $relatedArray =& eZContentObject::relatedContentObjectArray( $this->Version, $objectID );
00885 return $relatedArray;
00886 }
00887
00888 function create( $contentobjectID, $userID = false, $version = 1, $initialLanguageCode = false )
00889 {
00890 if ( $userID === false )
00891 {
00892 $user =& eZUser::currentUser();
00893 $userID =& $user->attribute( 'contentobject_id' );
00894 }
00895 $time = time();
00896
00897 if ( $initialLanguageCode == false )
00898 {
00899 $initialLanguageCode = eZContentObject::defaultLanguage();
00900 }
00901
00902 $initialLanguageID = eZContentLanguage::idByLocale( $initialLanguageCode );
00903
00904 $row = array(
00905 "contentobject_id" => $contentobjectID,
00906 'initial_language_id' => $initialLanguageID,
00907 'language_mask' => 0,
00908 "version" => $version,
00909 "created" => $time,
00910 "modified" => $time,
00911 'creator_id' => $userID );
00912 return new eZContentObjectVersion( $row );
00913 }
00914
00915
00916
00917
00918
00919 function &reverseRelatedObjectList()
00920 {
00921 $objectID = $this->attribute( 'contentobject_id' );
00922 $reverseRelatedArray =& eZContentObject::reverseRelatedObjectList( $this->Version, $objectID );
00923 return $reverseRelatedArray;
00924 }
00925
00926
00927
00928
00929
00930 function remove()
00931 {
00932 $contentobjectID = $this->attribute( 'contentobject_id' );
00933 $versionNum = $this->attribute( 'version' );
00934
00935 $contentObjectTranslations =& $this->translations();
00936
00937 foreach ( array_keys( $contentObjectTranslations ) as $contentObjectTranslationKey )
00938 {
00939 $contentObjectTranslation =& $contentObjectTranslations[$contentObjectTranslationKey];
00940 $contentObjectAttributes =& $contentObjectTranslation->objectAttributes();
00941 foreach ( array_keys( $contentObjectAttributes ) as $attributeKey )
00942 {
00943 $attribute =& $contentObjectAttributes[$attributeKey];
00944 $attribute->remove( $attribute->attribute( 'id' ), $versionNum );
00945 }
00946 }
00947 $db =& eZDB::instance();
00948 $db->begin();
00949 $db->query( "DELETE FROM ezcontentobject_link
00950 WHERE from_contentobject_id=$contentobjectID AND from_contentobject_version=$versionNum" );
00951 $db->query( "DELETE FROM eznode_assignment
00952 WHERE contentobject_id=$contentobjectID AND contentobject_version=$versionNum" );
00953
00954 $db->query( 'DELETE FROM ezcontentobject_version
00955 WHERE id=' . $this->attribute( 'id' ) );
00956
00957 $contentobject = $this->attribute( 'contentobject' );
00958 if ( is_object( $contentobject ) )
00959 {
00960 if ( !$contentobject->hasRemainingVersions() )
00961 {
00962 $contentobject->purge();
00963 }
00964
00965 $version = $contentobject->CurrentVersion;
00966 if ( $contentobject->CurrentVersion == $versionNum )
00967 {
00968
00969 $candidateToBeCurrent = $db->arrayQuery( "SELECT version
00970 FROM ezcontentobject_version
00971 WHERE contentobject_id={$contentobject->ID} AND
00972 version!={$contentobject->CurrentVersion}
00973 ORDER BY modified DESC",
00974 array( 'offset' => 0, 'limit' => 1 ) );
00975
00976 if ( isset($candidateToBeCurrent[0]['version']) && is_numeric($candidateToBeCurrent[0]['version']) )
00977 {
00978 $contentobject->CurrentVersion = $candidateToBeCurrent[0]['version'];
00979 $contentobject->store();
00980 }
00981 }
00982 }
00983 $db->query( "DELETE FROM ezcontentobject_name
00984 WHERE contentobject_id=$contentobjectID AND content_version=$versionNum" );
00985
00986 $db->commit();
00987 }
00988
00989
00990
00991
00992
00993 function removeTranslation( $languageCode )
00994 {
00995
00996 $versionNum = $this->attribute( 'version' );
00997
00998 $contentObjectAttributes =& $this->contentObjectAttributes( $languageCode );
00999
01000 $db =& eZDB::instance();
01001 $db->begin();
01002 foreach ( array_keys( $contentObjectAttributes ) as $attributeKey )
01003 {
01004 $attribute =& $contentObjectAttributes[$attributeKey];
01005 $attribute->remove( $attribute->attribute( 'id' ), $versionNum );
01006 }
01007 $db->commit();
01008
01009 $this->updateLanguageMask();
01010 }
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023 function removeVersions( $versionStatus = false, $limit = false, $expiryTime = false, $fetchPortionSize = 50 )
01024 {
01025 $statuses = array( EZ_VERSION_STATUS_DRAFT,
01026 EZ_VERSION_STATUS_PENDING,
01027 EZ_VERSION_STATUS_ARCHIVED,
01028 EZ_VERSION_STATUS_REJECTED,
01029 EZ_VERSION_STATUS_INTERNAL_DRAFT );
01030 if ( $versionStatus === false )
01031 {
01032 $versionStatus = $statuses;
01033 }
01034 else if ( !is_array( $versionStatus ) )
01035 {
01036 $versionStatus = array( $versionStatus );
01037 }
01038
01039 $versionStatus = array_unique( $versionStatus );
01040 $checkIntersect = array_intersect( $versionStatus, $statuses );
01041 if ( count( $checkIntersect ) != count( $versionStatus ) )
01042 {
01043 eZDebug::writeError( 'Invalid version status was passed in.', 'eZContentObjectVersion::removeVersions()' );
01044 return false;
01045 }
01046
01047 if ( $limit !== false and ( !is_numeric( $limit ) or $limit < 0 ) )
01048 {
01049 eZDebug::writeError( '$limit must be either false or positive numeric value.', 'eZContentObjectVersion::removeVersions()' );
01050 return false;
01051 }
01052
01053 if ( !is_numeric( $fetchPortionSize ) or $fetchPortionSize < 1 )
01054 $fetchPortionSize = 50;
01055
01056 $filters = array();
01057 $filters['status'] = array( $versionStatus );
01058 if ( $expiryTime !== false )
01059 $filters['modified'] = array( '<', $expiryTime );
01060
01061 $processedCount = 0;
01062 while ( $processedCount < $limit or !$limit )
01063 {
01064
01065 $tmpLimit = ( !$limit or ( $limit - $processedCount ) > $fetchPortionSize ) ?
01066 $fetchPortionSize : $limit - $processedCount;
01067 $versions = eZContentObjectVersion::fetchFiltered( $filters, 0, $tmpLimit );
01068 if ( count( $versions ) < 1 )
01069 break;
01070
01071 $db =& eZDB::instance();
01072 $db->begin();
01073 foreach ( $versions as $version )
01074 {
01075 $version->remove();
01076 }
01077 $db->commit();
01078 $processedCount += count( $versions );
01079 }
01080 return $processedCount;
01081 }
01082
01083
01084
01085
01086
01087 function clone( $newVersionNumber, $userID, $contentObjectID = false, $status = EZ_VERSION_STATUS_DRAFT )
01088 {
01089 $time = time();
01090 $clonedVersion = $this;
01091 $clonedVersion->setAttribute( 'id', null );
01092 if ( $contentObjectID !== false )
01093 $clonedVersion->setAttribute( 'contentobject_id', $contentObjectID );
01094 $clonedVersion->setAttribute( 'version', $newVersionNumber );
01095 $clonedVersion->setAttribute( 'created', $time );
01096 $clonedVersion->setAttribute( 'modified', $time );
01097 $clonedVersion->setAttribute( 'creator_id', $userID );
01098 if ( $status !== false )
01099 $clonedVersion->setAttribute( 'status', $status );
01100 return $clonedVersion;
01101 }
01102
01103
01104
01105
01106
01107
01108 function &translations( $asObject = true )
01109 {
01110 $translationList =& $this->translationList( false, $asObject );
01111 return $translationList;
01112 }
01113
01114
01115
01116
01117
01118
01119
01120 function &translation( $asObject = true )
01121 {
01122 $translation = false;
01123 return $translation;
01124 }
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134 function &translationList( $language = false, $asObject = true )
01135 {
01136 $db =& eZDB::instance();
01137
01138 $languageSQL = '';
01139 if ( $language !== false )
01140 {
01141 $language = $db->escapeString( $language );
01142 $languageSQL = "AND language_code!='$language'";
01143 }
01144
01145 $query = "SELECT DISTINCT language_code
01146 FROM ezcontentobject_attribute
01147 WHERE contentobject_id='$this->ContentObjectID' AND version='$this->Version'
01148 $languageSQL
01149 ORDER BY language_code";
01150
01151 $languageCodes = $db->arrayQuery( $query );
01152
01153 $translations = array();
01154 if ( $asObject )
01155 {
01156 foreach ( $languageCodes as $languageCode )
01157 {
01158 $translations[] = new eZContentObjectTranslation( $this->ContentObjectID, $this->Version, $languageCode["language_code"] );
01159 }
01160 }
01161 else
01162 {
01163 foreach ( $languageCodes as $languageCode )
01164 {
01165 $translations[] = $languageCode["language_code"];
01166 }
01167 }
01168
01169 return $translations;
01170 }
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180 function &defaultTranslationList()
01181 {
01182 $defaultTranslationList = $this->translationList();
01183 return $defaultTranslationList;
01184 }
01185
01186
01187
01188
01189
01190 function &contentObjectAttributes( $languageCode = false, $asObject = true )
01191 {
01192 if ( $languageCode == false )
01193 {
01194 if ( $this->Status == EZ_VERSION_STATUS_DRAFT || $this->Status == EZ_VERSION_STATUS_INTERNAL_DRAFT || $this->Status == EZ_VERSION_STATUS_PENDING )
01195 {
01196 $languageCode = $this->initialLanguageCode();
01197 }
01198 else if ( $this->CurrentLanguage )
01199 {
01200 $languageCode = $this->CurrentLanguage;
01201 }
01202 }
01203
01204 $attributes = eZContentObjectVersion::fetchAttributes( $this->Version, $this->ContentObjectID, $languageCode, $asObject );
01205 return $attributes;
01206 }
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216 function fetchAttributes( $version, $contentObjectID, $language = false, $asObject = true )
01217 {
01218 $db =& eZDB::instance();
01219 $language = $db->escapeString( $language );
01220 $contentObjectID = (int) $contentObjectID;
01221 $version =(int) $version;
01222 $query = "SELECT ezcontentobject_attribute.*, ezcontentclass_attribute.identifier as classattribute_identifier,
01223 ezcontentclass_attribute.can_translate, ezcontentclass_attribute.serialized_name_list as attribute_serialized_name_list
01224 FROM ezcontentobject_attribute, ezcontentclass_attribute, ezcontentobject_version
01225 WHERE
01226 ezcontentclass_attribute.version = '0' AND
01227 ezcontentclass_attribute.id = ezcontentobject_attribute.contentclassattribute_id AND
01228 ezcontentobject_attribute.version = '$version' AND
01229 ezcontentobject_attribute.contentobject_id = '$contentObjectID' AND
01230 ezcontentobject_version.contentobject_id = '$contentObjectID' AND
01231 ezcontentobject_version.version = '$version' AND ".
01232 ( ( $language )? "ezcontentobject_attribute.language_code = '$language'": eZContentLanguage::sqlFilter( 'ezcontentobject_attribute', 'ezcontentobject_version' ) ).
01233 " ORDER by
01234 ezcontentclass_attribute.placement ASC";
01235
01236 $attributeArray = $db->arrayQuery( $query );
01237
01238 $returnAttributeArray = array();
01239 foreach ( $attributeArray as $attribute )
01240 {
01241 $attr = new eZContentObjectAttribute( $attribute );
01242
01243 $attr->setContentClassAttributeIdentifier( $attribute['classattribute_identifier'] );
01244
01245 $dataType = $attr->dataType();
01246
01247 if ( is_object( $dataType ) &&
01248 $dataType->Attributes["properties"]["translation_allowed"] &&
01249 $attribute['can_translate'] )
01250 $attr->setContentClassAttributeCanTranslate( 1 );
01251 else
01252 $attr->setContentClassAttributeCanTranslate( 0 );
01253
01254 $attr->setContentClassAttributeName( eZContentClassAttribute::nameFromSerializedString( $attribute['attribute_serialized_name_list'] ) );
01255
01256 $returnAttributeArray[] = $attr;
01257 }
01258 return $returnAttributeArray;
01259 }
01260
01261
01262
01263
01264
01265
01266
01267 function mapLanguage( $language, $options )
01268 {
01269 if ( isset( $options['language_map'][$language] ) )
01270 {
01271 return $options['language_map'][$language];
01272 }
01273 return $language;
01274 }
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292 function &unserialize( &$domNode, &$contentObject, $ownerID, $sectionID, $activeVersion, $firstVersion, &$nodeList, &$options, &$package, $handlerType = 'ezcontentobject' )
01293 {
01294 $oldVersion = $domNode->attributeValue( 'version' );
01295 $status = $domNode->attributeValue( 'status' );
01296 $languageNodeArray = $domNode->elementsByName( 'object-translation' );
01297
01298 $initialLanguage = false;
01299 $importedLanguages = $options['language_array'];
01300 $currentLanguages = array();
01301 foreach( $languageNodeArray as $languageNode )
01302 {
01303 $language = eZContentObjectVersion::mapLanguage( $languageNode->attributeValue( 'language' ), $options );
01304 if ( in_array( $language, $importedLanguages ) )
01305 {
01306 $currentLanguages[] = $language;
01307 }
01308 }
01309 foreach ( eZContentLanguage::prioritizedLanguages() as $language )
01310 {
01311 if ( in_array( $language->attribute( 'locale' ), $currentLanguages ) )
01312 {
01313 $initialLanguage = $language->attribute( 'locale' );
01314 break;
01315 }
01316 }
01317 if ( !$initialLanguage )
01318 {
01319 $initialLanguage = $currentLanguages[0];
01320 }
01321
01322 if ( $firstVersion )
01323 {
01324 $contentObjectVersion = $contentObject->version( 1 );
01325 }
01326 else
01327 {
01328
01329 $contentObjectVersion = $contentObject->createNewVersionIn( $initialLanguage );
01330 }
01331
01332 include_once( 'lib/ezlocale/classes/ezdateutils.php' );
01333 $created = eZDateUtils::textToDate( $domNode->attributeValue( 'created' ) );
01334 $modified = eZDateUtils::textToDate( $domNode->attributeValue( 'modified' ) );
01335 $contentObjectVersion->setAttribute( 'created', $created );
01336 $contentObjectVersion->setAttribute( 'modified', $modified );
01337
01338 $contentObjectVersion->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
01339 $contentObjectVersion->store();
01340
01341 $db =& eZDB::instance();
01342 $db->begin();
01343 foreach( $languageNodeArray as $languageNode )
01344 {
01345 $language = eZContentObjectVersion::mapLanguage( $languageNode->attributeValue( 'language' ), $options );
01346
01347 if ( !in_array( $language, $importedLanguages ) )
01348 {
01349 continue;
01350 }
01351
01352 $attributeArray =& $contentObjectVersion->contentObjectAttributes( $language );
01353 if ( count( $attributeArray ) == 0)
01354 {
01355 $hasTranslation = eZContentLanguage::fetchByLocale( $language );
01356
01357 if ( !$hasTranslation )
01358 {
01359
01360 $locale =& eZLocale::instance( $language );
01361
01362 if ( $locale->isValid() )
01363 {
01364 eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() );
01365 $hasTranslation = true;
01366 }
01367 else
01368 $hasTranslation = false;
01369 }
01370
01371 if ( $hasTranslation )
01372 {
01373
01374 $originalContentAttributes =& $contentObjectVersion->contentObjectAttributes( $initialLanguage );
01375 foreach ( array_keys( $originalContentAttributes ) as $contentAttributeKey )
01376 {
01377 $originalContentAttribute =& $originalContentAttributes[$contentAttributeKey];
01378 $contentAttribute =& $originalContentAttribute->translateTo( $language );
01379 $contentAttribute->sync();
01380 $attributeArray[] =& $contentAttribute;
01381 }
01382 }
01383
01384
01385 $objectName = $languageNode->attributeValue( 'object_name' );
01386 if ( $objectName )
01387 $contentObject->setName( $objectName, $contentObjectVersion->attribute( 'version' ), $language );
01388 }
01389
01390 foreach( array_keys( $attributeArray ) as $attributeKey )
01391 {
01392 $attribute =& $attributeArray[$attributeKey];
01393
01394 $attributeIdentifier =& $attribute->attribute( 'contentclass_attribute_identifier' );
01395
01396 $attributeDomNode =& $languageNode->elementByAttributeValue( 'identifier', $attributeIdentifier );
01397 if ( !$attributeDomNode )
01398 {
01399 continue;
01400 }
01401
01402 $attribute->unserialize( $package, $attributeDomNode );
01403 $attribute->store();
01404 }
01405 }
01406
01407 $objectRelationList = $domNode->elementByName( 'object-relation-list' );
01408 if ( $objectRelationList )
01409 {
01410 $objectRelationArray = $objectRelationList->elementsByName( 'related-object-remote-id' );
01411 foreach( $objectRelationArray as $objectRelation )
01412 {
01413 $relatedObjectRemoteID = $objectRelation->textContent();
01414 if ( $relatedObjectRemoteID )
01415 {
01416 $object = eZContentObject::fetchByRemoteID( $relatedObjectRemoteID );
01417 $relatedObjectID = ( $object !== null ) ? $object->attribute( 'id' ) : null;
01418
01419 if ( $relatedObjectID )
01420 {
01421 $contentObject->addContentObjectRelation( $relatedObjectID, $contentObjectVersion->attribute( 'version' ) );
01422 }
01423 else
01424 {
01425 if ( !isset( $options['suspended-relations'] ) )
01426 {
01427 $options['suspended-relations'] = array();
01428 }
01429
01430 $options['suspended-relations'][] = array( 'related-object-remote-id' => $relatedObjectRemoteID,
01431 'contentobject-id' => $contentObject->attribute( 'id' ),
01432 'contentobject-version' => $contentObjectVersion->attribute( 'version' ) );
01433 }
01434 }
01435 }
01436 }
01437
01438 $nodeAssignmentNodeList = $domNode->elementByName( 'node-assignment-list' );
01439 $nodeAssignmentNodeArray = $nodeAssignmentNodeList->elementsByName( 'node-assignment' );
01440 foreach( $nodeAssignmentNodeArray as $nodeAssignmentNode )
01441 {
01442 $result = eZContentObjectTreeNode::unserialize( $nodeAssignmentNode,
01443 $contentObject,
01444 $contentObjectVersion->attribute( 'version' ),
01445 ( $oldVersion == $activeVersion ? 1 : 0 ),
01446 $nodeList,
01447 $options,
01448 $handlerType );
01449 if ( $result === false )
01450 {
01451 $db->commit();
01452 $retValue = false;
01453 return $retValue;
01454 }
01455 }
01456
01457 $contentObjectVersion->store();
01458 $db->commit();
01459
01460 return $contentObjectVersion;
01461 }
01462
01463 function postUnserialize( &$package )
01464 {
01465 $transltaions =& $this->translations( false );
01466 foreach( $transltaions as $language )
01467 {
01468 $attributeArray =& $this->contentObjectAttributes( $language );
01469 foreach( array_keys( $attributeArray ) as $key )
01470 {
01471 $attribute =& $attributeArray[$key];
01472 $attribute->postUnserialize( $package );
01473 }
01474 }
01475 }
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487 function serialize( &$package, $options = false, $contentNodeIDArray = false, $topNodeIDArray = false )
01488 {
01489 include_once( 'lib/ezxml/classes/ezdomdocument.php' );
01490 include_once( 'lib/ezxml/classes/ezdomnode.php' );
01491 $versionNode = new eZDOMNode();
01492
01493 include_once( 'lib/ezlocale/classes/ezdateutils.php' );
01494
01495 $versionNode->setName( 'version' );
01496 $versionNode->setPrefix( 'ezobject' );
01497 $versionNode->appendAttribute( eZDOMDocument::createAttributeNode( 'version', $this->Version, 'ezremote' ) );
01498 $versionNode->appendAttribute( eZDOMDocument::createAttributeNode( 'status', $this->Status, 'ezremote' ) );
01499 $versionNode->appendAttribute( eZDOMDocument::createAttributeNode( 'created', eZDateUtils::rfc1123Date( $this->attribute( 'created' ) ), 'ezremote' ) );
01500 $versionNode->appendAttribute( eZDOMDocument::createAttributeNode( 'modified', eZDateUtils::rfc1123Date( $this->attribute( 'modified' ) ), 'ezremote' ) );
01501
01502 $translationList = $this->translationList( false, false );
01503 $contentObject = $this->attribute( 'contentobject' );
01504
01505 $db =& eZDB::instance();
01506 $db->begin();
01507 $allowedLanguages = $options['language_array'];
01508 if ( $options['only_initial_language'] )
01509 {
01510 $initialLanguageCode = $this->initialLanguageCode();
01511 if ( !in_array( $initialLanguageCode, $allowedLanguages ) )
01512 {
01513
01514
01515 return false;
01516 }
01517
01518 $allowedLanguages = array( $initialLanguageCode );
01519 }
01520 $exportedLanguages = array();
01521 foreach ( $translationList as $translationItem )
01522 {
01523 $language = $translationItem;
01524 if ( !in_array( $language, $allowedLanguages ) )
01525 {
01526 continue;
01527 }
01528
01529 $translationNode = new eZDOMNode();
01530 $translationNode->setName( 'object-translation' );
01531 $translationNode->setPrefix( 'ezobject' );
01532 $translationNode->appendAttribute( eZDOMDocument::createAttributeNode( 'language', $language ) );
01533
01534
01535 $objectName = $contentObject->name( $this->Version, $language );
01536 if ( $objectName )
01537 {
01538 $translationNode->appendAttribute( eZDOMDocument::createAttributeNode( 'object_name', $objectName ) );
01539 }
01540 else
01541 {
01542 eZDebug::writeWarning( sprintf( "Name for object %s of version %s in translation %s not found",
01543 $contentObject->attribute( 'id' ),
01544 $this->Version,
01545 $language ) );
01546 }
01547
01548 $attributes = $this->contentObjectAttributes( $language );
01549 foreach ( $attributes as $attribute )
01550 {
01551 $translationNode->appendChild( $attribute->serialize( $package ) );
01552 }
01553
01554 $versionNode->appendChild( $translationNode );
01555 unset( $translationNode );
01556 $exportedLanguages[] = $language;
01557 }
01558
01559 $nodeAssignmentListNode = new eZDOMNode();
01560 $nodeAssignmentListNode->setName( 'node-assignment-list' );
01561 $nodeAssignmentListNode->setPrefix( 'ezobject' );
01562 $versionNode->appendChild( $nodeAssignmentListNode );
01563
01564 $contentNodeArray = eZContentObjectTreeNode::fetchByContentObjectID( $this->ContentObjectID, true, $this->Version );
01565 foreach( $contentNodeArray as $contentNode )
01566 {
01567 unset( $contentNodeDOMNode );
01568 $contentNodeDOMNode = $contentNode->serialize( $options, $contentNodeIDArray, $topNodeIDArray );
01569 if ( $contentNodeDOMNode !== false )
01570 {
01571 $nodeAssignmentListNode->appendChild( $contentNodeDOMNode );
01572 }
01573 }
01574 $initialLanguage = $this->attribute( 'initial_language' );
01575 $initialLanguageCode = $initialLanguage->attribute( 'locale' );
01576 if ( in_array( $initialLanguageCode, $exportedLanguages ) )
01577 {
01578 $versionNode->appendAttribute( eZDOMDocument::createAttributeNode( 'initial_language', $initialLanguageCode ) );
01579 }
01580
01581 if ( $options['related_objects'] === 'selected' )
01582 {
01583 $relatedObjectArray = eZContentObject::relatedContentObjectList( $this->Version, $contentObject->ID, 0, false, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_COMMON ) );
01584 if ( count( $relatedObjectArray ) )
01585 {
01586 $relationListNode = new eZDOMNode();
01587 $relationListNode->setName( 'object-relation-list' );
01588 $relationListNode->setPrefix( 'ezobject' );
01589
01590 foreach( array_keys( $relatedObjectArray ) as $Key )
01591 {
01592 $relatedObject =& $relatedObjectArray[$Key];
01593 $relatedObjectRemoteID = $relatedObject->attribute( 'remote_id' );
01594
01595 $relationNode = eZDOMDocument::createElementTextNode( 'related-object-remote-id', $relatedObjectRemoteID );
01596
01597 $relationListNode->appendChild( $relationNode );
01598 }
01599 $versionNode->appendChild( $relationListNode );
01600 }
01601 }
01602
01603 $db->commit();
01604 return $versionNode;
01605 }
01606
01607
01608
01609
01610 function &creator()
01611 {
01612 if ( isset( $this->CreatorID ) and $this->CreatorID )
01613 {
01614 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
01615 if ( $this->CreatorID != 0 )
01616 $creator = & eZContentObject::fetch( $this->CreatorID );
01617 else
01618 $creator = null;
01619 }
01620 else
01621 $creator = null;
01622 return $creator;
01623 }
01624
01625
01626
01627
01628
01629 function unpublish()
01630 {
01631 if ( $this->attribute( 'status' ) == EZ_VERSION_STATUS_PUBLISHED )
01632 {
01633 $this->setAttribute( 'status', EZ_VERSION_STATUS_ARCHIVED );
01634 $parentNodeList =& $this->attribute( 'parent_nodes' );
01635 $parentNodeIDList = array();
01636 foreach( array_keys( $parentNodeList ) as $key )
01637 {
01638 $parentNode =& $parentNodeList[$key];
01639 $parentNodeIDList[] = $parentNode->attribute( 'parent_node' );
01640 }
01641 if ( count( $parentNodeIDList ) == 0 )
01642 {
01643 eZDebug::writeWarning( $this, "unable to get parent nodes for version" );
01644 return;
01645 }
01646 $parentNodeIDString = implode( ',' , $parentNodeIDList );
01647 $contentObjectID = $this->attribute( 'contentobject_id' );
01648 $version = $this->attribute( 'version' );
01649 $db =& eZDb::instance();
01650 $query = "update ezcontentobject_tree
01651 set contentobject_is_published = '0'
01652 where parent_node_id in ( $parentNodeIDString ) and
01653 contentobject_id = $contentObjectID and
01654 contentobject_version = $version" ;
01655 $db->query( $query );
01656 }
01657 else
01658 {
01659 eZDebug::writeWarning( $this, "trying to unpublish non published version");
01660 }
01661
01662 }
01663
01664
01665
01666
01667
01668 function &nonTranslationList()
01669 {
01670 $translationList =& eZContentObject::translationList();
01671 if ( $translationList === null )
01672 {
01673 $retValue = null;
01674 return $retValue;
01675 }
01676
01677 $translations =& $this->translations( false );
01678 $nonTranslationList = array();
01679 foreach ( $translationList as $translationItem )
01680 {
01681 $locale = $translationItem->attribute( 'locale_code' );
01682 if ( !in_array( $locale, $translations ) )
01683 $nonTranslationList[] = $translationItem;
01684 }
01685 return $nonTranslationList;
01686 }
01687
01688 function &languageMask()
01689 {
01690 $mask = (int)$this->attribute( 'language_mask' );
01691 return $mask;
01692 }
01693
01694 function updateLanguageMask( $mask = false, $forceStore = true )
01695 {
01696 if ( $mask == false )
01697 {
01698 $mask = eZContentLanguage::maskByLocale( $this->translationList( false, false ), true );
01699 }
01700
01701 $this->setAttribute( 'language_mask', $mask );
01702
01703 if ( $forceStore )
01704 {
01705 $this->store();
01706 }
01707 }
01708
01709 function &initialLanguage()
01710 {
01711 $initialLanguage = eZContentLanguage::fetch( $this->InitialLanguageID );
01712
01713 return $initialLanguage;
01714 }
01715
01716 function initialLanguageCode()
01717 {
01718 $initialLanguage = $this->initialLanguage();
01719
01720 $initialLanguageCode = $initialLanguage !== false ? $initialLanguage->attribute( 'locale' ) : false;
01721
01722 return $initialLanguageCode;
01723 }
01724
01725 function nonTranslatableAttributesToUpdate( )
01726 {
01727 $object = $this->contentObject();
01728 $version = $this->attribute( 'version' );
01729 $objectID = $object->attribute( 'id' );
01730 $initialLanguageID = $object->attribute( 'initial_language_id' );
01731 $db =& eZDB::instance();
01732
01733 $attributeRows = $db->arrayQuery( "SELECT ezcontentobject_attribute.id, ezcontentobject_attribute.version
01734 FROM ezcontentobject_version,
01735 ezcontentobject_attribute,
01736 ezcontentclass_attribute
01737 WHERE
01738 ezcontentobject_version.contentobject_id='$objectID'
01739 AND ( ezcontentobject_version.status in ( " .
01740 EZ_VERSION_STATUS_DRAFT . ", " . EZ_VERSION_STATUS_PENDING . ", " . EZ_VERSION_STATUS_INTERNAL_DRAFT .
01741 " ) OR ( ezcontentobject_version.status = '1' AND ezcontentobject_version.version = '$version' ) )
01742 AND ezcontentobject_attribute.contentobject_id=ezcontentobject_version.contentobject_id
01743 AND ezcontentobject_attribute.version=ezcontentobject_version.version
01744 AND ezcontentobject_attribute.language_id!='$initialLanguageID'
01745 AND ezcontentobject_attribute.contentclassattribute_id=ezcontentclass_attribute.id
01746 AND ezcontentclass_attribute.can_translate=0" );
01747
01748 $attributes = array();
01749 foreach( $attributeRows as $row )
01750 {
01751 $attributes[] = eZContentObjectAttribute::fetch( $row['id'], $row['version'] );
01752 }
01753 return $attributes;
01754 }
01755
01756 function setAlwaysAvailableLanguageID( $languageID )
01757 {
01758 $db =& eZDB::instance();
01759 $db->begin();
01760
01761 $objectID = $this->attribute( 'contentobject_id' );
01762 $version = $this->attribute( 'version' );
01763
01764
01765 $sql = "UPDATE ezcontentobject_attribute SET language_id=";
01766 if ( $db->databaseName() == 'oracle' )
01767 {
01768 $sql .= "bitand( language_id, -2 )";
01769 }
01770 else
01771 {
01772 $sql .= "language_id & ~1";
01773 }
01774 $sql .= " WHERE contentobject_id = '$objectID' AND version = '$version'";
01775 $db->query( $sql );
01776
01777 if ( $languageID != false )
01778 {
01779 $newLanguageID = $languageID | 1;
01780
01781 $sql = "UPDATE ezcontentobject_attribute
01782 SET language_id='$newLanguageID'
01783 WHERE language_id='$languageID' AND contentobject_id = '$objectID' AND version = '$version'";
01784 $db->query( $sql );
01785 }
01786
01787 $db->commit();
01788 }
01789
01790 function clearAlwaysAvailableLanguageID()
01791 {
01792 $this->setAlwaysAvailableLanguageID( false );
01793 }
01794
01795
01796
01797
01798
01799
01800 function hasConflicts( $editLanguage = false )
01801 {
01802 $object =& $this->contentObject();
01803 if ( !$editLanguage )
01804 $editLanguage = $this->initialLanguageCode();
01805
01806
01807 $versions =& $object->versions( true, array( 'conditions' => array( 'status' => array( array( EZ_VERSION_STATUS_PUBLISHED, EZ_VERSION_STATUS_ARCHIVED ) ),
01808 'language_code' => $editLanguage ) ) );
01809
01810 $conflictVersions = array();
01811 foreach ( array_keys( $versions ) as $key )
01812 {
01813 $version =& $versions[$key];
01814 if ( $version->attribute( 'modified' ) > $this->attribute( 'created' ) )
01815 {
01816 $conflictVersions[] =& $version;
01817 }
01818 }
01819 if ( !count( $conflictVersions ) )
01820 return false;
01821 else
01822 return $conflictVersions;
01823 }
01824
01825 var $CurrentLanguage = false;
01826 }
01827
01828 ?>