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
00039
00040
00041
00042 include_once( "lib/ezdb/classes/ezdb.php" );
00043 include_once( 'lib/ezlocale/classes/ezlocale.php' );
00044 include_once( "kernel/classes/ezpersistentobject.php" );
00045 include_once( "kernel/classes/ezcontentobjectversion.php" );
00046 include_once( "kernel/classes/ezcontentobjectattribute.php" );
00047 include_once( "kernel/classes/ezcontentclass.php" );
00048 include_once( "kernel/classes/ezcontentobjecttreenode.php" );
00049 include_once( 'kernel/classes/ezcontentlanguage.php' );
00050 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00051
00052 define( "EZ_CONTENT_OBJECT_STATUS_DRAFT", 0 );
00053 define( "EZ_CONTENT_OBJECT_STATUS_PUBLISHED", 1 );
00054 define( "EZ_CONTENT_OBJECT_STATUS_ARCHIVED", 2 );
00055
00056 define( "EZ_PACKAGE_CONTENTOBJECT_ERROR_NO_CLASS", 1 );
00057 define( "EZ_PACKAGE_CONTENTOBJECT_ERROR_EXISTS", 2 );
00058 define( "EZ_PACKAGE_CONTENTOBJECT_ERROR_NODE_EXISTS", 3 );
00059 define( "EZ_PACKAGE_CONTENTOBJECT_ERROR_MODIFIED", 101 );
00060 define( "EZ_PACKAGE_CONTENTOBJECT_ERROR_HAS_CHILDREN", 102 );
00061
00062 define( "EZ_PACKAGE_CONTENTOBJECT_REPLACE", 1 );
00063 define( "EZ_PACKAGE_CONTENTOBJECT_SKIP", 2 );
00064 define( "EZ_PACKAGE_CONTENTOBJECT_NEW", 3 );
00065 define( "EZ_PACKAGE_CONTENTOBJECT_DELETE", 4 );
00066 define( "EZ_PACKAGE_CONTENTOBJECT_KEEP", 5 );
00067
00068 define( "EZ_CONTENT_OBJECT_RELATION_COMMON", 1 << 0 );
00069 define( "EZ_CONTENT_OBJECT_RELATION_EMBED", 1 << 1 );
00070 define( "EZ_CONTENT_OBJECT_RELATION_LINK", 1 << 2 );
00071 define( "EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE", 1 << 3 );
00072
00073 class eZContentObject extends eZPersistentObject
00074 {
00075 function eZContentObject( $row )
00076 {
00077 $this->eZPersistentObject( $row );
00078 $this->ClassIdentifier = false;
00079 if ( isset( $row['contentclass_identifier'] ) )
00080 $this->ClassIdentifier = $row['contentclass_identifier'];
00081 $this->ClassName = false;
00082 if ( isset( $row['contentclass_name'] ) )
00083 $this->ClassName = $row['contentclass_name'];
00084 if ( isset( $row['serialized_name_list'] ) )
00085 $this->ClassName = eZContentClass::nameFromSerializedString( $row['serialized_name_list'] );
00086
00087 $this->CurrentLanguage = false;
00088 if ( isset( $row['content_translation'] ) )
00089 {
00090 $this->CurrentLanguage = $row['content_translation'];
00091 }
00092 else if ( isset( $row['real_translation'] ) )
00093 {
00094 $this->CurrentLanguage = $row['real_translation'];
00095 }
00096 else if ( isset( $row['language_mask'] ) )
00097 {
00098 $topPriorityLanguage = eZContentLanguage::topPriorityLanguageByMask( $row['language_mask'] );
00099 if ( $topPriorityLanguage )
00100 {
00101 $this->CurrentLanguage = $topPriorityLanguage->attribute( 'locale' );
00102 }
00103 }
00104 }
00105
00106 function definition()
00107 {
00108 return array( "fields" => array( "id" => array( 'name' => 'ID',
00109 'datatype' => 'integer',
00110 'default' => 0,
00111 'required' => true ),
00112 "section_id" => array( 'name' => "SectionID",
00113 'datatype' => 'integer',
00114 'default' => 0,
00115 'required' => true,
00116 'foreign_class' => 'eZSection',
00117 'foreign_attribute' => 'id',
00118 'multiplicity' => '1..*' ),
00119 "owner_id" => array( 'name' => "OwnerID",
00120 'datatype' => 'integer',
00121 'default' => 0,
00122 'required' => true,
00123 'foreign_class' => 'eZUser',
00124 'foreign_attribute' => 'contentobject_id',
00125 'multiplicity' => '1..*'),
00126 "contentclass_id" => array( 'name' => "ClassID",
00127 'datatype' => 'integer',
00128 'default' => 0,
00129 'required' => true,
00130 'foreign_class' => 'eZContentClass',
00131 'foreign_attribute' => 'id',
00132 'multiplicity' => '1..*' ),
00133 "name" => array( 'name' => "Name",
00134 'datatype' => 'string',
00135 'default' => '',
00136 'required' => true ),
00137 "is_published" => array( 'name' => "IsPublished",
00138 'datatype' => 'integer',
00139 'default' => 0,
00140 'required' => true ),
00141 "published" => array( 'name' => "Published",
00142 'datatype' => 'integer',
00143 'default' => 0,
00144 'required' => true ),
00145 "modified" => array( 'name' => "Modified",
00146 'datatype' => 'integer',
00147 'default' => 0,
00148 'required' => true ),
00149 "current_version" => array( 'name' => "CurrentVersion",
00150 'datatype' => 'integer',
00151 'default' => 0,
00152 'required' => true ),
00153 "status" => array( 'name' => "Status",
00154 'datatype' => 'integer',
00155 'default' => 0,
00156 'required' => true ),
00157 'remote_id' => array( 'name' => "RemoteID",
00158 'datatype' => 'string',
00159 'default' => '',
00160 'required' => true ),
00161 'language_mask' => array( 'name' => 'LanguageMask',
00162 'datatype' => 'integer',
00163 'default' => 0,
00164 'required' => true ),
00165 'initial_language_id' => array( 'name' => 'InitialLanguageID',
00166 'datatype' => 'integer',
00167 'default' => 0,
00168 'required' => true,
00169 'foreign_class' => 'eZContentLanguage',
00170 'foreign_attribute' => 'id',
00171 'multiplicity' => '1..*' ) ),
00172 "keys" => array( "id" ),
00173 "function_attributes" => array( "current" => "currentVersion",
00174 'versions' => 'versions',
00175 'author_array' => 'authorArray',
00176 "class_name" => "className",
00177 "content_class" => "contentClass",
00178 "contentobject_attributes" => "contentObjectAttributes",
00179 "owner" => "owner",
00180 "related_contentobject_array" => "relatedContentObjectList",
00181 "related_contentobject_count" => "relatedContentObjectCount",
00182 'reverse_related_contentobject_array' => 'reverseRelatedObjectList',
00183 'reverse_related_contentobject_count' => 'reverseRelatedObjectCount',
00184 "linked_contentobject_array" => "linkedContentObjectList",
00185 "linked_contentobject_count" => "linkedContentObjectCount",
00186 'reverse_linked_contentobject_array' => 'reverseLinkedObjectList',
00187 'reverse_linked_contentobject_count' => 'reverseLinkedObjectCount',
00188 "embedded_contentobject_array" => "embeddedContentObjectList",
00189 "embedded_contentobject_count" => "embeddedContentObjectCount",
00190 'reverse_embedded_contentobject_array' => 'reverseEmbeddedObjectList',
00191 'reverse_embedded_contentobject_count' => 'reverseEmbeddedObjectCount',
00192 "can_read" => "canRead",
00193 "can_pdf" => "canPdf",
00194 "can_diff" => "canDiff",
00195 "can_create" => "canCreate",
00196 "can_create_class_list" => "canCreateClassList",
00197 "can_edit" => "canEdit",
00198 "can_translate" => "canTranslate",
00199 "can_remove" => "canRemove",
00200 "can_move" => "canMoveFrom",
00201 "can_move_from" => "canMoveFrom",
00202 'can_view_embed' => 'canViewEmbed',
00203 "data_map" => "dataMap",
00204 "main_parent_node_id" => "mainParentNodeID",
00205 "assigned_nodes" => "assignedNodes",
00206 "parent_nodes" => "parentNodeIDArray",
00207 "main_node_id" => "mainNodeID",
00208 "main_node" => "mainNode",
00209 "default_language" => "defaultLanguage",
00210 "content_action_list" => "contentActionList",
00211 "class_identifier" => "contentClassIdentifier",
00212 'class_group_id_list' => 'contentClassGroupIDList',
00213 'name' => 'name',
00214 'match_ingroup_id_list' => 'matchIngroupIDList',
00215 'remote_id' => 'remoteID',
00216 'current_language' => 'currentLanguage',
00217 'current_language_object' => 'currentLanguageObject',
00218 'initial_language' => 'initialLanguage',
00219 'initial_language_code' => 'initialLanguageCode',
00220 'available_languages' => 'availableLanguages',
00221 'language_codes' => 'availableLanguages',
00222 'language_js_array' => 'availableLanguagesJsArray',
00223 'languages' => 'languages',
00224 'all_languages' => 'allLanguages',
00225 'can_edit_languages' => 'canEditLanguages',
00226 'can_create_languages' => 'canCreateLanguages',
00227 'always_available' => 'isAlwaysAvailable' ),
00228 "increment_key" => "id",
00229 "class_name" => "eZContentObject",
00230 "sort" => array( "id" => "asc" ),
00231 "name" => "ezcontentobject" );
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241 function &matchIngroupIDList()
00242 {
00243 include_once( 'lib/ezutils/classes/ezini.php' );
00244 $contentINI =& eZINI::instance( 'content.ini' );
00245 $inList = false;
00246 if( $contentINI->variable( 'ContentOverrideSettings', 'EnableClassGroupOverride' ) == 'true' )
00247 {
00248 $contentClass =& $this->contentClass();
00249 $inList =& $contentClass->attribute( 'ingroup_id_list' );
00250 }
00251 return $inList;
00252 }
00253
00254
00255
00256
00257
00258
00259 function store()
00260 {
00261
00262 global $eZContentObjectContentObjectCache;
00263 unset( $eZContentObjectContentObjectCache[$this->ID] );
00264 global $eZContentObjectDataMapCache;
00265 unset( $eZContentObjectDataMapCache[$this->ID] );
00266 global $eZContentObjectVersionCache;
00267 unset( $eZContentObjectVersionCache[$this->ID] );
00268
00269 $db =& eZDB::instance();
00270 $db->begin();
00271 $this->storeNodeModified();
00272 eZPersistentObject::store();
00273 $db->commit();
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283 function clearCache( $idArray = array() )
00284 {
00285 if ( is_numeric( $idArray ) )
00286 $idArray = array( $idArray );
00287
00288
00289 if ( count( $idArray ) == 0 )
00290 {
00291 unset( $GLOBALS['eZContentObjectContentObjectCache'] );
00292 unset( $GLOBALS['eZContentObjectDataMapCache'] );
00293 unset( $GLOBALS['eZContentObjectVersionCache'] );
00294
00295 return;
00296 }
00297
00298
00299 global $eZContentObjectContentObjectCache;
00300 global $eZContentObjectDataMapCache;
00301 global $eZContentObjectVersionCache;
00302 foreach ( $idArray as $objectID )
00303 {
00304 unset( $eZContentObjectContentObjectCache[$objectID] );
00305 unset( $eZContentObjectDataMapCache[$objectID] );
00306 unset( $eZContentObjectVersionCache[$objectID] );
00307 }
00308 }
00309
00310
00311
00312
00313
00314
00315 function storeNodeModified()
00316 {
00317 if ( is_numeric( $this->ID ) )
00318 {
00319 $nodeArray =& $this->assignedNodes();
00320
00321 $db =& eZDB::instance();
00322 $db->begin();
00323 foreach ( array_keys( $nodeArray ) as $key )
00324 {
00325 $nodeArray[$key]->updateAndStoreModified();
00326 }
00327 $db->commit();
00328 }
00329 }
00330
00331 function &name( $version = false , $lang = false )
00332 {
00333 if ( isset( $this->Name ) && !$version && !$lang )
00334 {
00335 return $this->Name;
00336 }
00337 if ( !$version )
00338 {
00339 $version = $this->attribute( 'current_version' );
00340 }
00341 if ( !$lang && $this->CurrentLanguage )
00342 {
00343 $lang = $this->CurrentLanguage;
00344 }
00345
00346 $objectID = $this->attribute( 'id' );
00347 $name =& $this->versionLanguageName( $objectID, $version, $lang );
00348 return $name;
00349 }
00350
00351 function names()
00352 {
00353 $version = $this->attribute( 'current_version' );
00354 $id = $this->attribute( 'id' );
00355
00356 $db =& eZDb::instance();
00357 $rows = $db->arrayQuery( "SELECT name, real_translation FROM ezcontentobject_name WHERE contentobject_id = '$id' AND content_version='$version'" );
00358 $names = array();
00359 foreach ( $rows as $row )
00360 {
00361 $names[$row['real_translation']] = $row['name'];
00362 }
00363
00364 return $names;
00365 }
00366
00367 function &versionLanguageName( $contentObjectID, $version, $lang = false )
00368 {
00369 $name = false;
00370 if ( !$contentObjectID > 0 || !$version > 0 )
00371 {
00372 eZDebug::writeNotice( "There is no object name for version($version) of the content object ($contentObjectID) in language($lang)", 'eZContentObject::versionLanguageName' );
00373 return $name;
00374 }
00375 $db =& eZDb::instance();
00376 $contentObjectID =(int) $contentObjectID;
00377 if ( !$lang )
00378 {
00379
00380 $query = "SELECT initial_language_id FROM ezcontentobject WHERE id='$contentObjectID'";
00381 $rows = $db->arrayQuery( $query );
00382 if ( $rows )
00383 {
00384 $languageID = $rows[0]['initial_language_id'];
00385 $language = eZContentLanguage::fetch( $languageID );
00386 if ( $language )
00387 {
00388 $lang = $language->attribute( 'locale' );
00389 }
00390 else
00391 {
00392 return $name;
00393 }
00394 }
00395 else
00396 {
00397 return $name;
00398 }
00399 }
00400 $lang = $db->escapeString( $lang );
00401 $version = (int) $version;
00402
00403 $initialLanguage = $this->attribute( 'initial_language_id' );
00404
00405 $query= "SELECT name, content_translation
00406 FROM ezcontentobject_name
00407 WHERE contentobject_id = '$contentObjectID'
00408 AND content_version = '$version'
00409 AND ( content_translation = '$lang' OR language_id = '$initialLanguage' )";
00410 $result = $db->arrayQuery( $query );
00411
00412 $resCount = count( $result );
00413 if( $resCount < 1 )
00414 {
00415 eZDebug::writeNotice( "There is no object name for version($version) of the content object ($contentObjectID) in language($lang)", 'eZContentObject::versionLanguageName' );
00416 }
00417 else if( $resCount > 1 )
00418 {
00419
00420 foreach( $result as $row )
00421 {
00422 if( $row['content_translation'] == $lang )
00423 {
00424 $name = $row['name'];
00425 break;
00426 }
00427 }
00428 }
00429 else
00430 {
00431
00432 $name = $result[0]['name'];
00433 }
00434
00435 return $name;
00436 }
00437
00438
00439
00440
00441 function setCachedName( $name )
00442 {
00443 $this->Name = $name;
00444 }
00445
00446
00447
00448
00449
00450
00451 function setName( $objectName, $versionNum = false, $languageCode = false )
00452 {
00453 $initialLanguage = $this->initialLanguage();
00454 $initialLanguageCode = $initialLanguage->attribute( 'locale' );
00455 $db =& eZDB::instance();
00456
00457 if ( $languageCode == false )
00458 {
00459 $languageCode = $initialLanguageCode;
00460 }
00461 $languageCode = $db->escapeString( $languageCode );
00462 if ( $languageCode == $initialLanguageCode )
00463 {
00464 $this->Name = $objectName;
00465 }
00466
00467 if ( !$versionNum )
00468 {
00469 $versionNum = $this->attribute( 'current_version' );
00470 }
00471 $objectID =(int) $this->attribute( 'id' );
00472 $versionNum =(int) $versionNum;
00473
00474 $languageID =(int) eZContentLanguage::idByLocale( $languageCode );
00475
00476 $objectName = $db->escapeString( $objectName );
00477
00478 $db->begin();
00479
00480
00481
00482
00483 $rows = $db->arrayQuery( "SELECT COUNT(*) AS count FROM ezcontentobject_name WHERE contentobject_id = '$objectID'
00484 AND content_version = '$versionNum' AND content_translation ='$languageCode'" );
00485 if ( $rows[0]['count'] )
00486 {
00487 $db->query( "UPDATE ezcontentobject_name SET name='$objectName'
00488 WHERE
00489 contentobject_id = '$objectID' AND
00490 content_version = '$versionNum' AND
00491 content_translation ='$languageCode'" );
00492 }
00493 else
00494 {
00495 $db->query( "INSERT INTO ezcontentobject_name( contentobject_id,
00496 name,
00497 content_version,
00498 content_translation,
00499 real_translation,
00500 language_id )
00501 VALUES( '$objectID',
00502 '$objectName',
00503 '$versionNum',
00504 '$languageCode',
00505 '$languageCode',
00506 '$languageID' )" );
00507 }
00508
00509 $db->commit();
00510 }
00511
00512
00513
00514
00515
00516 function &dataMap()
00517 {
00518 return $this->fetchDataMap();
00519 }
00520
00521
00522
00523
00524
00525
00526 function &fetchDataMap( $version = false, $language = false )
00527 {
00528
00529 global $eZContentObjectDataMapCache;
00530
00531 if ( $version == false )
00532 $version = $this->attribute( 'current_version' );
00533
00534 if ( $language == false )
00535 {
00536 $language = $this->CurrentLanguage;
00537 }
00538
00539 if ( !$language || !isset( $eZContentObjectDataMapCache[$this->ID][$version][$language] ) )
00540 {
00541 $data =& $this->contentObjectAttributes( true, $version, $language );
00542
00543 if ( !$language )
00544 {
00545 $language = $this->CurrentLanguage;
00546 }
00547
00548
00549 $this->ContentObjectAttributeArray[$version][$language] =& $data;
00550 $eZContentObjectDataMapCache[$this->ID][$version][$language] =& $data;
00551 }
00552 else
00553 {
00554 $data =& $eZContentObjectDataMapCache[$this->ID][$version][$language];
00555 }
00556
00557 if ( !isset( $this->DataMap[$version][$language] ) )
00558 {
00559 $ret = array();
00560 foreach( $data as $key => $item )
00561 {
00562 $identifier = $item->contentClassAttributeIdentifier();
00563 $ret[$identifier] =& $data[$key];
00564 }
00565 $this->DataMap[$version][$language] =& $ret;
00566 }
00567 else
00568 {
00569 $ret =& $this->DataMap[$version][$language];
00570 }
00571 return $ret;
00572 }
00573
00574 function resetDataMap()
00575 {
00576 $this->ContentObjectAttributeArray = array();
00577 $this->DataMap = array();
00578 return $this->DataMap;
00579 }
00580
00581
00582
00583
00584 function &owner()
00585 {
00586 if ( $this->OwnerID != 0 )
00587 $owner =& eZContentObject::fetch( $this->OwnerID );
00588 else
00589 $owner = null;
00590 return $owner;
00591 }
00592
00593
00594
00595
00596 function &contentClassGroupIDList()
00597 {
00598 $contentClass =& $this->contentClass();
00599 $groupIDList =& $contentClass->attribute( 'ingroup_id_list' );
00600 return $groupIDList;
00601 }
00602
00603
00604
00605
00606
00607
00608 function &contentClassIdentifier()
00609 {
00610 if ( !is_numeric( $this->ClassID ) )
00611 {
00612 $retValue = null;
00613 return $retValue;
00614 }
00615
00616 if ( $this->ClassIdentifier !== false )
00617 return $this->ClassIdentifier;
00618
00619 $db =& eZDB::instance();
00620 $id = (int)$this->ClassID;
00621 $sql = "SELECT identifier FROM ezcontentclass WHERE id=$id and version=0";
00622 $rows = $db->arrayQuery( $sql );
00623 if ( count( $rows ) > 0 )
00624 {
00625 $this->ClassIdentifier = $rows[0]['identifier'];
00626 }
00627 return $this->ClassIdentifier;
00628 }
00629
00630
00631
00632
00633 function &contentClass()
00634 {
00635 if ( !is_numeric( $this->ClassID ) )
00636 {
00637 $retValue = null;
00638 return $retValue;
00639 }
00640
00641 $contentClass = eZContentClass::fetch( $this->ClassID );
00642 return $contentClass;
00643 }
00644
00645
00646
00647
00648 function &remoteID()
00649 {
00650 $remoteID = eZPersistentObject::attribute( 'remote_id', true );
00651
00652
00653 if ( $remoteID === null and $this->attribute( 'id' ) )
00654 {
00655 $db =& eZDB::instance();
00656 $resultArray = $db->arrayQuery( "SELECT remote_id FROM ezcontentobject WHERE id = '" . $this->attribute( 'id' ) . "'" );
00657 if ( count( $resultArray ) == 1 )
00658 {
00659 $remoteID = $resultArray[0]['remote_id'];
00660 $this->setAttribute( 'remote_id', $remoteID );
00661 }
00662 }
00663
00664 if ( !$remoteID )
00665 {
00666 $this->setAttribute( 'remote_id', md5( (string)mt_rand() . (string)mktime() ) );
00667 if ( $this->attribute( 'id' ) !== null )
00668 $this->sync( array( 'remote_id' ) );
00669 $remoteID = eZPersistentObject::attribute( 'remote_id', true );
00670 }
00671
00672 return $remoteID;
00673 }
00674
00675 function &mainParentNodeID()
00676 {
00677 $retParenNodeID = eZContentObjectTreeNode::getParentNodeId( $this->attribute( 'main_node_id' ) );
00678 return $retParenNodeID;
00679 }
00680
00681
00682
00683
00684 function &fetchByRemoteID( $remoteID, $asObject = true )
00685 {
00686 $db =& eZDB::instance();
00687 $remoteID =$db->escapeString( $remoteID );
00688 $resultArray = $db->arrayQuery( 'SELECT id FROM ezcontentobject WHERE remote_id=\'' . $remoteID . '\'' );
00689 if ( count( $resultArray ) != 1 )
00690 $object = null;
00691 else
00692 $object =& eZContentObject::fetch( $resultArray[0]['id'], $asObject );
00693 return $object;
00694 }
00695
00696
00697
00698
00699
00700 function &fetch( $id, $asObject = true )
00701 {
00702 global $eZContentObjectContentObjectCache;
00703
00704
00705
00706 if ( !isset( $eZContentObjectContentObjectCache[$id] ) or $asObject === false )
00707 {
00708 $db =& eZDB::instance();
00709
00710 $resArray = $db->arrayQuery( eZContentObject::createFetchSQLString( $id ) );
00711
00712 $objectArray = array();
00713 if ( count( $resArray ) == 1 && $resArray !== false )
00714 {
00715 $objectArray =& $resArray[0];
00716 }
00717 else
00718 {
00719 eZDebug::writeError( "Object not found ($id)", 'eZContentObject::fetch()' );
00720 $retValue = null;
00721 return $retValue;
00722 }
00723
00724 if ( $asObject )
00725 {
00726 $obj = new eZContentObject( $objectArray );
00727 $eZContentObjectContentObjectCache[$id] =& $obj;
00728 }
00729 else
00730 {
00731 return $objectArray;
00732 }
00733
00734 return $obj;
00735 }
00736 else
00737 {
00738 return $eZContentObjectContentObjectCache[$id];
00739 }
00740 }
00741
00742
00743
00744
00745
00746
00747
00748 function exists( $id )
00749 {
00750 global $eZContentObjectContentObjectCache;
00751
00752
00753 if ( isset( $eZContentObjectContentObjectCache[$id] ) )
00754 return true;
00755
00756
00757 $db =& eZDB::instance();
00758
00759 $resArray = $db->arrayQuery( eZContentObject::createFetchSQLString( $id ) );
00760
00761 if ( $resArray !== false and count( $resArray ) == 1 )
00762 {
00763 return true;
00764 }
00765
00766 return false;
00767
00768 }
00769
00770
00771
00772
00773
00774 function createFetchSQLString( $id )
00775 {
00776 $id = (int) $id;
00777
00778 $fetchSQLString = "SELECT ezcontentobject.*,
00779 ezcontentclass.serialized_name_list as serialized_name_list,
00780 ezcontentclass.identifier as contentclass_identifier,
00781 ezcontentclass.is_container as is_container
00782 FROM
00783 ezcontentobject,
00784 ezcontentclass
00785 WHERE
00786 ezcontentobject.id='$id' AND
00787 ezcontentclass.id = ezcontentobject.contentclass_id AND
00788 ezcontentclass.version=0";
00789
00790 return $fetchSQLString;
00791 }
00792
00793
00794
00795
00796
00797 function &fetchByNodeID( $nodeID, $asObject = true )
00798 {
00799 global $eZContentObjectContentObjectCache;
00800 $nodeID = (int)$nodeID;
00801
00802 $useVersionName = true;
00803 if ( $useVersionName )
00804 {
00805 $versionNameTables = ', ezcontentobject_name ';
00806 $versionNameTargets = ', ezcontentobject_name.name as name, ezcontentobject_name.real_translation ';
00807
00808 $versionNameJoins = " and ezcontentobject.id = ezcontentobject_name.contentobject_id and
00809 ezcontentobject.current_version = ezcontentobject_name.content_version and ".
00810 eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' );
00811 }
00812
00813 $db =& eZDB::instance();
00814
00815 $query = "SELECT ezcontentobject.* $versionNameTargets
00816 FROM
00817 ezcontentobject,
00818 ezcontentobject_tree
00819 $versionNameTables
00820 WHERE
00821 ezcontentobject_tree.node_id=$nodeID AND
00822 ezcontentobject.id=ezcontentobject_tree.contentobject_id AND
00823 ezcontentobject.current_version=ezcontentobject_tree.contentobject_version
00824 $versionNameJoins";
00825
00826 $resArray = $db->arrayQuery( $query );
00827
00828 $objectArray = array();
00829 if ( count( $resArray ) == 1 && $resArray !== false )
00830 {
00831 $objectArray =& $resArray[0];
00832 }
00833 else
00834 {
00835 eZDebug::writeError( 'Object not found', 'eZContentObject::fetch()' );
00836 $retValue = null;
00837 return $retValue;
00838 }
00839
00840 if ( $asObject )
00841 {
00842 $obj = new eZContentObject( $objectArray );
00843 $eZContentObjectContentObjectCache[$objectArray['id']] =& $obj;
00844 }
00845 else
00846 {
00847 return $objectArray;
00848 }
00849
00850 return $obj;
00851 }
00852
00853
00854
00855
00856 function &fetchIDArray( $idArray, $asObject = true )
00857 {
00858 global $eZContentObjectContentObjectCache;
00859
00860 $uniqueIDArray = array_unique( $idArray );
00861
00862 $useVersionName = true;
00863 if ( $useVersionName )
00864 {
00865 $versionNameTables = ', ezcontentobject_name ';
00866 $versionNameTargets = ', ezcontentobject_name.name as name, ezcontentobject_name.real_translation ';
00867
00868 $versionNameJoins = " and ezcontentobject.id = ezcontentobject_name.contentobject_id and
00869 ezcontentobject.current_version = ezcontentobject_name.content_version and ".
00870 eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' );
00871 }
00872
00873 $db =& eZDB::instance();
00874
00875 $objectInSQL = $db->implodeWithTypeCast( ', ', $uniqueIDArray, 'int' );
00876 $query = "SELECT ezcontentclass.serialized_name_list as class_serialized_name_list, ezcontentobject.* $versionNameTargets
00877 FROM
00878 ezcontentclass,
00879 ezcontentobject
00880 $versionNameTables
00881 WHERE
00882 ezcontentclass.id=ezcontentobject.contentclass_id AND
00883 ezcontentobject.id IN ( $objectInSQL )
00884 $versionNameJoins";
00885
00886 $resRowArray = $db->arrayQuery( $query );
00887
00888 $objectRetArray = array();
00889 foreach ( $resRowArray as $resRow )
00890 {
00891 $objectID = $resRow['id'];
00892 $resRow['class_name'] = eZContentClass::nameFromSerializedString( $resRow['class_serialized_name_list'] );
00893 if ( $asObject )
00894 {
00895 $obj = new eZContentObject( $resRow );
00896 $obj->ClassName = $resRow['class_name'];
00897 $eZContentObjectContentObjectCache[$objectID] = $obj;
00898 $objectRetArray[$objectID] = $obj;
00899 }
00900 else
00901 {
00902 $objectRetArray[$objectID] =& $resRow;
00903 }
00904 }
00905 return $objectRetArray;
00906 }
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916 function fetchList( $asObject = true, $conditions = null, $offset = false, $limit = false )
00917 {
00918 $limitation = null;
00919 if ( $offset !== false or
00920 $limit !== false )
00921 $limitation = array( 'offset' => $offset,
00922 'length' => $limit );
00923 return eZPersistentObject::fetchObjectList( eZContentObject::definition(),
00924 null,
00925 $conditions, null, $limitation,
00926 $asObject );
00927 }
00928
00929 function fetchFilteredList( $conditions = null, $offset = false, $limit = false, $asObject = true )
00930 {
00931 $limits = null;
00932 if ( $offset or $limit )
00933 $limits = array( 'offset' => $offset,
00934 'length' => $limit );
00935 return eZPersistentObject::fetchObjectList( eZContentObject::definition(),
00936 null,
00937 $conditions, null, $limits,
00938 $asObject );
00939 }
00940
00941
00942
00943
00944
00945 function fetchListCount( $conditions = null )
00946 {
00947 $rows = eZPersistentObject::fetchObjectList( eZContentObject::definition(),
00948 array(),
00949 $conditions,
00950 false,
00951 null,
00952 false, false,
00953 array( array( 'operation' => 'count( * )',
00954 'name' => 'count' ) ) );
00955 return $rows[0]['count'];
00956 }
00957
00958 function fetchSameClassList( $contentClassID, $asObject = true, $offset = false, $limit = false )
00959 {
00960 $conditions = array( 'contentclass_id' => $contentClassID );
00961 return eZContentObject::fetchFilteredList( $conditions, $offset, $limit, $asObject );
00962 }
00963
00964 function fetchSameClassListCount( $contentClassID )
00965 {
00966 $result = eZPersistentObject::fetchObjectList( eZContentObject::definition(),
00967 array(),
00968 array( "contentclass_id" => $contentClassID ),
00969 false, null,
00970 false, false,
00971 array( array( 'operation' => 'count( * )',
00972 'name' => 'count' ) ) );
00973 return $result[0]['count'];
00974 }
00975
00976
00977
00978
00979 function ¤tVersion( $asObject = true )
00980 {
00981 $currentVersion = eZContentObjectVersion::fetchVersion( $this->attribute( "current_version" ), $this->ID, $asObject );
00982 return $currentVersion;
00983 }
00984
00985
00986
00987
00988 function &version( $version, $asObject = true )
00989 {
00990 if ( $asObject )
00991 {
00992 global $eZContentObjectVersionCache;
00993
00994 if ( !isset( $eZContentObjectVersionCache ) )
00995 $eZContentObjectVersionCache = array();
00996
00997 if ( array_key_exists( $this->ID, $eZContentObjectVersionCache ) &&
00998 array_key_exists( $version, $eZContentObjectVersionCache[$this->ID] ) )
00999 {
01000 return $eZContentObjectVersionCache[$this->ID][$version];
01001 }
01002 else
01003 {
01004 $eZContentObjectVersionCache[$this->ID][$version] = eZContentObjectVersion::fetchVersion( $version, $this->ID, $asObject );
01005 return $eZContentObjectVersionCache[$this->ID][$version];
01006 }
01007 }
01008 else
01009 {
01010 $versionArray = eZContentObjectVersion::fetchVersion( $version, $this->ID, $asObject );
01011 return $versionArray;
01012 }
01013 }
01014
01015
01016
01017
01018
01019
01020 function &versions( $asObject = true, $parameters = array() )
01021 {
01022 $conditions = array( "contentobject_id" => $this->ID );
01023 if ( isset( $parameters['conditions'] ) )
01024 {
01025 if ( isset( $parameters['conditions']['status'] ) )
01026 $conditions['status'] = $parameters['conditions']['status'];
01027 if ( isset( $parameters['conditions']['creator_id'] ) )
01028 $conditions['creator_id'] = $parameters['conditions']['creator_id'];
01029 if ( isset( $parameters['conditions']['language_code'] ) )
01030 {
01031 $conditions['initial_language_id'] = eZContentLanguage::idByLocale( $parameters['conditions']['language_code'] );
01032 }
01033 if ( isset( $parameters['conditions']['initial_language_id'] ) )
01034 {
01035 $conditions['initial_language_id'] = $parameters['conditions']['initial_language_id'];
01036 }
01037 }
01038
01039 $objectList = eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),
01040 null, $conditions,
01041 null, null,
01042 $asObject );
01043
01044 return $objectList;
01045 }
01046
01047
01048
01049
01050 function hasRemainingVersions()
01051 {
01052 $remainingVersions = $this->versions( false );
01053 if ( !is_array( $remainingVersions ) or
01054 count( $remainingVersions ) == 0 )
01055 {
01056 return false;
01057 }
01058 return true;
01059 }
01060
01061 function createInitialVersion( $userID, $initialLanguageCode = false )
01062 {
01063 return eZContentObjectVersion::create( $this->attribute( "id" ), $userID, 1, $initialLanguageCode );
01064 }
01065
01066 function &createNewVersionIn( $languageCode, $copyFromLanguageCode = false, $copyFromVersion = false, $versionCheck = true, $status = EZ_VERSION_STATUS_DRAFT )
01067 {
01068 $newVersion = $this->createNewVersion( $copyFromVersion, $versionCheck, $languageCode, $copyFromLanguageCode, $status );
01069 return $newVersion;
01070 }
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081 function createNewVersion( $copyFromVersion = false, $versionCheck = true, $languageCode = false, $copyFromLanguageCode = false, $status = EZ_VERSION_STATUS_DRAFT )
01082 {
01083 $db =& eZDB::instance();
01084 $db->begin();
01085
01086 if ( $versionCheck )
01087 {
01088 $contentINI =& eZINI::instance( 'content.ini' );
01089 $versionlimit = $contentINI->variable( 'VersionManagement', 'DefaultVersionHistoryLimit' );
01090 $limitList = $contentINI->variable( 'VersionManagement', 'VersionHistoryClass' );
01091 $classID = $this->attribute( 'contentclass_id' );
01092 foreach ( array_keys ( $limitList ) as $key )
01093 {
01094 if ( $classID == $key )
01095 $versionlimit =& $limitList[$key];
01096 }
01097 if ( $versionlimit < 2 )
01098 $versionlimit = 2;
01099 $versionCount = $this->getVersionCount();
01100 if ( $versionCount >= $versionlimit )
01101 {
01102
01103 $params = array( 'conditions'=> array( 'status' => 3 ) );
01104 $versions =& $this->versions( true, $params );
01105 if ( count( $versions ) > 0 )
01106 {
01107 $modified = $versions[0]->attribute( 'modified' );
01108 $removeVersion =& $versions[0];
01109 foreach ( array_keys( $versions ) as $versionKey )
01110 {
01111 $version =& $versions[$versionKey];
01112 $currentModified = $version->attribute( 'modified' );
01113 if ( $currentModified < $modified )
01114 {
01115 $modified = $currentModified;
01116 $removeVersion = $version;
01117 }
01118 }
01119 $removeVersion->remove();
01120 }
01121 }
01122 }
01123
01124
01125 $nextVersionNumber = $this->nextVersion();
01126
01127 if ( $copyFromVersion == false )
01128 $version =& $this->currentVersion();
01129 else
01130 $version =& $this->version( $copyFromVersion );
01131
01132 if ( !$languageCode )
01133 {
01134 $initialLanguage = $version->initialLanguage();
01135 if ( !$initialLanguage )
01136 {
01137 $initialLanguage = $this->initialLanguage();
01138 }
01139
01140 if ( $initialLanguage )
01141 {
01142 $languageCode = $initialLanguage->attribute( 'locale' );
01143 }
01144 }
01145
01146 $copiedVersion = $this->copyVersion( $this, $version, $nextVersionNumber, false, $status, $languageCode, $copyFromLanguageCode );
01147
01148
01149
01150
01151 $parentMap = array();
01152 $copiedNodeAssignmentList =& $copiedVersion->attribute( 'node_assignments' );
01153 foreach ( $copiedNodeAssignmentList as $copiedNodeAssignment )
01154 {
01155 $parentMap[$copiedNodeAssignment->attribute( 'parent_node' )] = $copiedNodeAssignment;
01156 }
01157 $nodes =& $this->assignedNodes();
01158 foreach ( $nodes as $node )
01159 {
01160 $remoteID = 0;
01161
01162 if ( isset( $parentMap[$node->attribute( 'parent_node_id' )] ) )
01163 {
01164 $copiedNodeAssignment = $parentMap[$node->attribute( 'parent_node_id' )];
01165 $remoteID = $copiedNodeAssignment->attribute( 'remote_id' );
01166 $copiedNodeAssignment->purge();
01167 }
01168 $newNodeAssignment = $copiedVersion->assignToNode( $node->attribute( 'parent_node_id' ), $node->attribute( 'is_main' ), 0,
01169 $node->attribute( 'sort_field' ), $node->attribute( 'sort_order' ),
01170 $remoteID );
01171
01172 $newNodeAssignment->setAttribute( 'op_code', $newNodeAssignment->attribute( 'op_code' ) & ~1 );
01173 $newNodeAssignment->store();
01174 }
01175
01176 $db->commit();
01177 return $copiedVersion;
01178 }
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189 function copyVersion( &$newObject, &$version, $newVersionNumber, $contentObjectID = false, $status = EZ_VERSION_STATUS_DRAFT, $languageCode = false, $copyFromLanguageCode = false )
01190 {
01191 $user =& eZUser::currentUser();
01192 $userID =& $user->attribute( 'contentobject_id' );
01193
01194 $nodeAssignmentList =& $version->attribute( 'node_assignments' );
01195
01196 $db =& eZDB::instance();
01197 $db->begin();
01198
01199
01200 foreach ( array_keys( $nodeAssignmentList ) as $key )
01201 {
01202 $nodeAssignment =& $nodeAssignmentList[$key];
01203
01204 if ( $nodeAssignment->attribute( 'remote_id' ) == 0 )
01205 {
01206 continue;
01207 }
01208 $clonedAssignment = $nodeAssignment->clone( $newVersionNumber, $contentObjectID );
01209 $clonedAssignment->setAttribute( 'op_code', EZ_NODE_ASSIGNMENT_OP_CODE_SET );
01210 $clonedAssignment->store();
01211 }
01212
01213 $currentVersionNumber = $version->attribute( "version" );
01214 $contentObjectTranslations =& $version->translations();
01215
01216 $clonedVersion = $version->clone( $newVersionNumber, $userID, $contentObjectID, $status );
01217
01218 if ( $contentObjectID != false )
01219 {
01220 if ( $clonedVersion->attribute( 'status' ) == EZ_VERSION_STATUS_PUBLISHED )
01221 $clonedVersion->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
01222 }
01223
01224 $clonedVersion->store();
01225
01226
01227
01228 $this->copyContentObjectRelations( $currentVersionNumber, $newVersionNumber, $contentObjectID );
01229
01230 $languageCodeToCopy = false;
01231 if ( $languageCode && in_array( $languageCode, $this->availableLanguages() ) )
01232 {
01233 $languageCodeToCopy = $languageCode;
01234 }
01235 if ( $copyFromLanguageCode && in_array( $copyFromLanguageCode, $this->availableLanguages() ) )
01236 {
01237 $languageCodeToCopy = $copyFromLanguageCode;
01238 }
01239
01240 $haveCopied = false;
01241 if ( !$languageCode || $languageCodeToCopy )
01242 {
01243 foreach ( array_keys( $contentObjectTranslations ) as $contentObjectTranslationKey )
01244 {
01245 $contentObjectTranslation =& $contentObjectTranslations[$contentObjectTranslationKey];
01246
01247 if ( $languageCode != false && $contentObjectTranslation->attribute( 'language_code' ) != $languageCodeToCopy )
01248 {
01249 continue;
01250 }
01251
01252 $contentObjectAttributes =& $contentObjectTranslation->objectAttributes();
01253
01254 foreach ( array_keys( $contentObjectAttributes ) as $attributeKey )
01255 {
01256 $attribute =& $contentObjectAttributes[$attributeKey];
01257 $clonedAttribute = $attribute->clone( $newVersionNumber, $currentVersionNumber, $contentObjectID, $languageCode );
01258 $clonedAttribute->sync();
01259 eZDebugSetting::writeDebug( 'kernel-content-object-copy', $clonedAttribute, 'copyVersion:cloned attribute' );
01260 }
01261
01262 $haveCopied = true;
01263 }
01264 }
01265
01266 if ( !$haveCopied && $languageCode )
01267 {
01268 $class =& $this->contentClass();
01269 $classAttributes =& $class->fetchAttributes();
01270 foreach ( array_keys( $classAttributes ) as $attributeKey )
01271 {
01272 $classAttribute =& $classAttributes[$attributeKey];
01273 if ( $classAttribute->attribute( 'can_translate' ) == 1 )
01274 {
01275 $classAttribute->instantiate( $contentObjectID? $contentObjectID: $this->attribute( 'id' ), $languageCode, $newVersionNumber );
01276 }
01277 else
01278 {
01279
01280
01281
01282
01283
01284
01285 $initialLangID = !$this->isAlwaysAvailable() ? $this->attribute( 'initial_language_id' ) : $this->attribute( 'initial_language_id' ) | 1;
01286 $contentAttribute = eZContentObjectAttribute::fetchByClassAttributeID( $classAttribute->attribute( 'id' ),
01287 $this->attribute( 'id' ),
01288 $this->attribute( 'current_version' ),
01289 $initialLangID );
01290 if ( $contentAttribute )
01291 {
01292 $newAttribute = $contentAttribute->clone( $newVersionNumber, $currentVersionNumber, $contentObjectID, $languageCode );
01293 $newAttribute->sync();
01294 }
01295 else
01296 {
01297 $classAttribute->instantiate( $contentObjectID? $contentObjectID: $this->attribute( 'id' ), $languageCode, $newVersionNumber );
01298 }
01299 }
01300 }
01301 }
01302
01303 if ( $languageCode )
01304 {
01305 $clonedVersion->setAttribute( 'initial_language_id', eZContentLanguage::idByLocale( $languageCode ) );
01306 $clonedVersion->updateLanguageMask();
01307 }
01308
01309 $db->commit();
01310
01311 return $clonedVersion;
01312 }
01313
01314
01315
01316
01317 function create( $name, $contentclassID, $userID, $sectionID = 1, $version = 1, $languageCode = false )
01318 {
01319 if ( $languageCode == false )
01320 {
01321 $languageCode = eZContentObject::defaultLanguage();
01322 }
01323
01324 $languageID = eZContentLanguage::idByLocale( $languageCode );
01325
01326 $row = array(
01327 "name" => $name,
01328 "current_version" => $version,
01329 'initial_language_id' => $languageID,
01330 'language_mask' => $languageID,
01331 "contentclass_id" => $contentclassID,
01332 "permission_id" => 1,
01333 "parent_id" => 0,
01334 "main_node_id" => 0,
01335 "owner_id" => $userID,
01336 "section_id" => $sectionID,
01337 'remote_id' => md5( (string)mt_rand() . (string)mktime() ) );
01338
01339 return new eZContentObject( $row );
01340 }
01341
01342
01343
01344
01345
01346 function clone()
01347 {
01348 $contentObject = $this;
01349 $contentObject->setAttribute( 'id', null );
01350 $contentObject->setAttribute( 'published', time() );
01351 $contentObject->setAttribute( 'modified', time() );
01352 return $contentObject;
01353 }
01354
01355
01356
01357
01358
01359
01360 function ©( $allVersions = true )
01361 {
01362 eZDebugSetting::writeDebug( 'kernel-content-object-copy', 'Copy start, all versions=' . $allVersions ? 'true' : 'false', 'copy' );
01363 $user =& eZUser::currentUser();
01364 $userID =& $user->attribute( 'contentobject_id' );
01365
01366 $contentObject = $this->clone();
01367 $contentObject->setAttribute( 'current_version', 1 );
01368 $contentObject->setAttribute( 'owner_id', $userID );
01369
01370
01371 $newRemoteID = md5( (string)mt_rand() . (string)mktime() );
01372 $contentObject->setAttribute( 'remote_id', $newRemoteID );
01373
01374 $db =& eZDB::instance();
01375 $db->begin();
01376 $contentObject->store();
01377
01378 $contentObject->setName( $this->attribute('name') );
01379 eZDebugSetting::writeDebug( 'kernel-content-object-copy', $contentObject, 'contentObject' );
01380
01381
01382 $versionList = array();
01383 if ( $allVersions )
01384 {
01385 $versions =& $this->versions();
01386 for ( $i = 0; $i < count( $versions ); ++$i )
01387 {
01388 $versionID = $versions[$i]->attribute( 'version' );
01389 $versionList[$versionID] =& $versions[$i];
01390 }
01391 }
01392 else
01393 {
01394 $versionList[1] =& $this->currentVersion();
01395 }
01396
01397 $versionKeys = array_keys( $versionList );
01398 foreach ( $versionKeys as $versionNumber )
01399 {
01400 $currentContentObjectVersion =& $versionList[$versionNumber];
01401 $currentVersionNumber = $currentContentObjectVersion->attribute( 'version' );
01402
01403 $contentObject->setName( $currentContentObjectVersion->name(), $versionNumber );
01404 foreach( $contentObject->translationStringList() as $languageCode )
01405 {
01406 $contentObject->setName( $currentContentObjectVersion->name( false, $languageCode ), $versionNumber, $languageCode );
01407 }
01408
01409 $contentObjectVersion = $this->copyVersion( $contentObject, $currentContentObjectVersion,
01410 $versionNumber, $contentObject->attribute( 'id' ),
01411 false );
01412
01413 if ( $currentVersionNumber == $this->attribute( 'current_version' ) )
01414 {
01415 $parentMap = array();
01416 $copiedNodeAssignmentList =& $contentObjectVersion->attribute( 'node_assignments' );
01417 foreach ( $copiedNodeAssignmentList as $$copiedNodeAssignment )
01418 {
01419 $parentMap[$copiedNodeAssignment->attribute( 'parent_node' )] = $copiedNodeAssignment;
01420 }
01421
01422 $nodes =& $this->assignedNodes();
01423 foreach ( $nodes as $node )
01424 {
01425 $remoteID = 0;
01426
01427 if ( isset( $parentMap[$node->attribute( 'parent_node_id' )] ) )
01428 {
01429 $copiedNodeAssignment = $parentMap[$node->attribute( 'parent_node_id' )];
01430 unset( $parentMap[$node->attribute( 'parent_node_id' )] );
01431 $remoteID = $copiedNodeAssignment->attribute( 'remote_id' );
01432 $copiedNodeAssignment->purge();
01433 }
01434 $newNodeAssignment = $contentObjectVersion->assignToNode( $node->attribute( 'parent_node_id' ), $node->attribute( 'is_main' ), 0,
01435 $node->attribute( 'sort_field' ), $node->attribute( 'sort_order' ),
01436 $remoteID );
01437 }
01438 }
01439
01440 eZDebugSetting::writeDebug( 'kernel-content-object-copy', $contentObjectVersion, 'Copied version' );
01441 }
01442
01443
01444 if ( $allVersions )
01445 $contentObject->setAttribute( 'current_version', $this->attribute( 'current_version' ) );
01446
01447 $contentObject->setAttribute( 'status', EZ_CONTENT_OBJECT_STATUS_DRAFT );
01448
01449 $contentObject->store();
01450
01451 $db->commit();
01452
01453 eZDebugSetting::writeDebug( 'kernel-content-object-copy', 'Copy done', 'copy' );
01454 return $contentObject;
01455 }
01456
01457
01458
01459
01460
01461
01462
01463 function revertTo( $version )
01464 {
01465 $db =& eZDB::instance();
01466 $db->begin();
01467
01468
01469 $contentobjectAttributes = $this->allContentObjectAttributes( $this->ID );
01470 foreach ( $contentobjectAttributes as $contentobjectAttribute )
01471 {
01472 $contentobjectAttributeVersion = $contentobjectAttribute->attribute("version");
01473 if( $contentobjectAttributeVersion > $version )
01474 {
01475 $classAttribute =& $contentobjectAttribute->contentClassAttribute();
01476 $dataType = $classAttribute->dataType();
01477 $dataType->deleteStoredObjectAttribute( $contentobjectAttribute, $contentobjectAttributeVersion );
01478 }
01479 }
01480 $version =(int) $version;
01481 $db->query( "DELETE FROM ezcontentobject_attribute
01482 WHERE contentobject_id='$this->ID' AND version>'$version'" );
01483
01484 $db->query( "DELETE FROM ezcontentobject_version
01485 WHERE contentobject_id='$this->ID' AND version>'$version'" );
01486
01487 $db->query( "DELETE FROM eznode_assignment
01488 WHERE contentobject_id='$this->ID' AND contentobject_version > '$version'" );
01489
01490 $this->CurrentVersion = $version;
01491 $this->store();
01492 $db->commit();
01493 }
01494
01495
01496
01497
01498
01499
01500 function copyRevertTo( $version, $language = false )
01501 {
01502 $versionObject = $this->createNewVersionIn( $language, false, $version );
01503
01504 return $versionObject->attribute( 'version' );
01505 }
01506
01507 function fixReverseRelations ( $objectID, $mode = false )
01508 {
01509 $db =& eZDB::instance();
01510 $objectID = (int) $objectID;
01511
01512
01513 $result = $db->arrayQuery( "SELECT attr.*
01514 FROM ezcontentobject_link link,
01515 ezcontentobject_attribute attr
01516 WHERE link.from_contentobject_id=attr.contentobject_id AND
01517 link.from_contentobject_version=attr.version AND
01518 link.contentclassattribute_id=attr.contentclassattribute_id AND
01519 link.to_contentobject_id=$objectID" );
01520 if ( count( $result ) > 0 )
01521 {
01522 include_once( "kernel/classes/ezcontentcachemanager.php" );
01523 foreach( $result as $row )
01524 {
01525 $attr = new eZContentObjectAttribute( $row );
01526 $dataType = $attr->dataType();
01527 $dataType->fixRelatedObjectItem( $attr, $objectID, $mode );
01528 eZContentCacheManager::clearObjectViewCache( $attr->attribute( 'contentobject_id' ), true );
01529 }
01530 }
01531 }
01532
01533 function removeReverseRelations( $objectID )
01534 {
01535 $db =& eZDB::instance();
01536 $objectID = (int) $objectID;
01537
01538 $relatingObjects = $this->reverseRelatedObjectList( false, false, 0, false, array( 'AllRelations' => true ) );
01539
01540
01541
01542 $result = $db->arrayQuery( "SELECT attr.*
01543 FROM ezcontentobject_link link,
01544 ezcontentobject_attribute attr
01545 WHERE link.from_contentobject_id=attr.contentobject_id AND
01546 link.from_contentobject_version=attr.version AND
01547 link.contentclassattribute_id=attr.contentclassattribute_id AND
01548 link.to_contentobject_id=$objectID" );
01549
01550
01551 if ( count( $result ) > 0 )
01552 {
01553 include_once( "kernel/classes/ezcontentcachemanager.php" );
01554 foreach( $result as $row )
01555 {
01556 $attr = new eZContentObjectAttribute( $row );
01557 $dataType = $attr->dataType();
01558 $dataType->removeRelatedObjectItem( $attr, $objectID );
01559 eZContentCacheManager::clearObjectViewCache( $attr->attribute( 'contentobject_id' ), true );
01560 $attr->storeData();
01561 }
01562 }
01563
01564
01565 foreach ( $relatingObjects as $fromObject )
01566 {
01567 $fromObjectID = $fromObject->attribute( 'id' );
01568 $fromObjectVersion = $fromObject->attribute( 'current_version' );
01569 $contentObjectID = $this->attribute( 'id' );
01570 $fromObject->removeContentObjectRelation( $contentObjectID, $fromObjectVersion, $fromObjectID, false );
01571 }
01572 }
01573
01574
01575
01576
01577
01578
01579
01580 function purge( $id = false )
01581 {
01582 if ( is_numeric( $id ) )
01583 {
01584 $delID = $id;
01585 $contentobject =& eZContentObject::fetch( $delID );
01586 }
01587 else
01588 {
01589 $delID = $this->ID;
01590 $contentobject =& $this;
01591 }
01592
01593 include_once( "kernel/classes/ezaudit.php" );
01594 eZAudit::writeAudit( 'content-delete', array( 'Object ID' => $delID, 'Content Name' => $contentobject->attribute( 'name' ),
01595 'Comment' => 'Purged the current object: eZContentObject::purge()' ) );
01596
01597 $db =& eZDB::instance();
01598
01599 $db->begin();
01600
01601 $contentobjectAttributes = $contentobject->allContentObjectAttributes( $delID );
01602
01603 foreach ( $contentobjectAttributes as $contentobjectAttribute )
01604 {
01605 $dataType = $contentobjectAttribute->dataType();
01606 if ( !$dataType )
01607 continue;
01608 $dataType->deleteStoredObjectAttribute( $contentobjectAttribute );
01609 }
01610
01611 include_once( 'kernel/classes/ezinformationcollection.php' );
01612 eZInformationCollection::removeContentObject( $delID );
01613
01614 include_once( 'kernel/classes/ezcontentobjecttrashnode.php' );
01615 eZContentObjectTrashNode::purgeForObject( $delID );
01616
01617 $db->query( "DELETE FROM ezcontentobject_tree
01618 WHERE contentobject_id='$delID'" );
01619
01620 $db->query( "DELETE FROM ezcontentobject_attribute
01621 WHERE contentobject_id='$delID'" );
01622
01623 $db->query( "DELETE FROM ezcontentobject_version
01624 WHERE contentobject_id='$delID'" );
01625
01626 $db->query( "DELETE FROM ezcontentobject_name
01627 WHERE contentobject_id='$delID'" );
01628
01629 $db->query( "DELETE FROM ezcontentobject
01630 WHERE id='$delID'" );
01631
01632 $db->query( "DELETE FROM eznode_assignment
01633 WHERE contentobject_id = '$delID'" );
01634
01635 $db->query( "DELETE FROM ezuser_role
01636 WHERE contentobject_id = '$delID'" );
01637
01638 $db->query( "DELETE FROM ezuser_discountrule
01639 WHERE contentobject_id = '$delID'" );
01640
01641 eZContentObject::fixReverseRelations( $delID, 'remove' );
01642
01643 include_once( "kernel/classes/ezsearch.php" );
01644 eZSearch::removeObject( $contentobject );
01645
01646
01647 $sql = 'SELECT DISTINCT ezproductcollection_item.productcollection_id
01648 FROM ezbasket, ezwishlist, ezproductcollection_item
01649 WHERE ( ezproductcollection_item.productcollection_id=ezbasket.productcollection_id OR
01650 ezproductcollection_item.productcollection_id=ezwishlist.productcollection_id ) AND
01651 ezproductcollection_item.contentobject_id=' . $delID;
01652 $rows = $db->arrayQuery( $sql );
01653 if ( count( $rows ) > 0 )
01654 {
01655 $countElements = 50;
01656 $deletedArray = array();
01657
01658 foreach ( $rows as $row )
01659 {
01660 $deletedArray[] = $row['productcollection_id'];
01661 }
01662
01663 $splitted = array_chunk( $deletedArray, $countElements );
01664 include_once( "kernel/classes/ezproductcollectionitem.php" );
01665 include_once( "kernel/classes/ezwishlist.php" );
01666
01667 foreach ( $splitted as $value )
01668 {
01669 eZPersistentObject::removeObject( eZProductCollectionItem::definition(), array( 'productcollection_id' => array( $value, '' ) ) );
01670 eZPersistentObject::removeObject( eZWishList::definition(), array( 'productcollection_id' => array( $value, '' ) ) );
01671 }
01672 }
01673 $db->query( 'UPDATE ezproductcollection_item
01674 SET contentobject_id = 0
01675 WHERE contentobject_id = ' . $delID );
01676
01677 $db->query( "DELETE FROM ezcontentobject_link
01678 WHERE from_contentobject_id = '$delID' OR to_contentobject_id = '$delID'" );
01679
01680
01681 $db->query( "DELETE FROM ezuservisit
01682 WHERE user_id = '$delID'" );
01683
01684 $db->query( "UPDATE ezcontentobject_version
01685 SET creator_id = 0
01686 WHERE creator_id = '$delID'" );
01687
01688 $db->query( "UPDATE ezcontentobject
01689 SET owner_id = 0
01690 WHERE owner_id = '$delID'" );
01691
01692 include_once( "kernel/classes/ezworkflowtype.php" );
01693 if ( isset( $GLOBALS["eZWorkflowTypeObjects"] ) and is_array( $GLOBALS["eZWorkflowTypeObjects"] ) )
01694 {
01695 $registeredTypes =& $GLOBALS["eZWorkflowTypeObjects"];
01696 }
01697 else
01698 {
01699 $registeredTypes = eZWorkFlowType::fetchRegisteredTypes();
01700 }
01701
01702
01703 foreach ( array_keys( $registeredTypes ) as $registeredTypeKey )
01704 {
01705 $registeredType = $registeredTypes[$registeredTypeKey];
01706 $registeredType->cleanupAfterRemoving( array( 'DeleteContentObject' => $delID ) );
01707 }
01708
01709 $db->commit();
01710 }
01711
01712
01713
01714
01715
01716 function remove( $id = false, $nodeID = null )
01717 {
01718 $delID = $this->ID;
01719 if ( is_numeric( $id ) )
01720 {
01721 $delID = $id;
01722 $contentobject =& eZContentObject::fetch( $delID );
01723 }
01724 else
01725 {
01726 $contentobject =& $this;
01727 }
01728
01729 include_once( "kernel/classes/ezaudit.php" );
01730 eZAudit::writeAudit( 'content-delete', array( 'Object ID' => $delID, 'Content Name' => $contentobject->attribute( 'name' ),
01731 'Comment' => 'Setted archived status for the current object: eZContentObject::remove()' ) );
01732
01733 $nodes = $contentobject->attribute( 'assigned_nodes' );
01734
01735 include_once( "kernel/classes/ezsearch.php" );
01736 if ( $nodeID === null or count( $nodes ) <= 1 )
01737 {
01738 $db =& eZDB::instance();
01739 $db->begin();
01740 $mainNodeKey = false;
01741 foreach ( array_keys( $nodes ) as $key )
01742 {
01743 $node =& $nodes[$key];
01744 if ( $node->attribute( 'main_node_id' ) == $node->attribute( 'node_id' ) )
01745 {
01746 $mainNodeKey = $key;
01747 }
01748 else
01749 {
01750 $node->remove();
01751 }
01752 }
01753
01754 if ( $mainNodeKey !== false )
01755 {
01756 $nodes[$mainNodeKey]->removeNodeFromTree( true );
01757 }
01758
01759 $contentobject->setAttribute( 'status', EZ_CONTENT_OBJECT_STATUS_ARCHIVED );
01760 eZSearch::removeObject( $contentobject );
01761 $contentobject->store();
01762 eZContentObject::fixReverseRelations( $delID, 'trash' );
01763
01764 $db->commit();
01765
01766 }
01767 else if ( $nodeID !== null )
01768 {
01769 $node = eZContentObjectTreeNode::fetch( $nodeID , false );
01770 if ( is_object( $node ) )
01771 {
01772 if ( $node->attribute( 'main_node_id' ) == $nodeID )
01773 {
01774 $db =& eZDB::instance();
01775 $db->begin();
01776 foreach ( array_keys( $nodes ) as $key )
01777 {
01778 $additionalNode =& $nodes[$key];
01779 if ( $additionalNode->attribute( 'node_id' ) != $node->attribute( 'main_node_id' ) )
01780 {
01781 $additionalNode->remove();
01782 }
01783 }
01784
01785 $node->removeNodeFromTree( true );
01786 $contentobject->setAttribute( 'status', EZ_CONTENT_OBJECT_STATUS_ARCHIVED );
01787 eZSearch::removeObject( $contentobject );
01788 $contentobject->store();
01789 eZContentObject::fixReverseRelations( $delID, 'trash' );
01790 $db->commit();
01791 }
01792 else
01793 {
01794 eZContentObjectTreeNode::remove( $nodeID );
01795 }
01796 }
01797 }
01798 else
01799 {
01800 eZContentObjectTreeNode::remove( $nodeID );
01801 }
01802 }
01803
01804
01805
01806
01807
01808
01809 function cleanupInternalDrafts( $userID = false, $timeDuration = 86400 )
01810 {
01811 if ( !is_numeric( $timeDuration ) ||
01812 $timeDuration < 0 )
01813 {
01814 eZDebug::writeError( "The time duration must be a positive numeric value (timeDuration = $timeDuration)",
01815 'eZContentObject::cleanupInternalDrafts()' );
01816 return;
01817 }
01818
01819 if ( $userID === false )
01820 {
01821 $userID = eZUser::currentUserID();
01822 }
01823
01824 $parameters = array( 'conditions' => array( 'status' => EZ_VERSION_STATUS_INTERNAL_DRAFT,
01825 'creator_id' => $userID ) );
01826
01827 $expiryTime = mktime() - $timeDuration;
01828 foreach ( $this->versions( true, $parameters ) as $possibleVersion )
01829 {
01830 if ( $possibleVersion->attribute( 'modified' ) < $expiryTime )
01831 {
01832 $possibleVersion->remove();
01833 }
01834 }
01835 }
01836
01837
01838
01839
01840
01841
01842
01843 function cleanupAllInternalDrafts( $userID = false, $timeDuration = 86400 )
01844 {
01845 if ( !is_numeric( $timeDuration ) ||
01846 $timeDuration < 0 )
01847 {
01848 eZDebug::writeError( "The time duration must be a positive numeric value (timeDuration = $timeDuration)",
01849 'eZContentObject::cleanupAllInternalDrafts()' );
01850 return;
01851 }
01852
01853
01854 if ( $userID === false )
01855 {
01856 $userID = eZUser::currentUserID();
01857 }
01858
01859 include_once( 'kernel/classes/ezcontentobjectversion.php' );
01860 $untouchedDrafts = eZContentObjectVersion::fetchForUser( $userID, EZ_VERSION_STATUS_INTERNAL_DRAFT );
01861
01862 $expiryTime = mktime() - $timeDuration;
01863 foreach ( $untouchedDrafts as $untouchedDraft )
01864 {
01865 if ( $untouchedDraft->attribute( 'modified' ) < $expiryTime )
01866 {
01867 $untouchedDraft->remove();
01868 }
01869 }
01870 }
01871
01872
01873
01874
01875 function allContentObjectAttributes( $contentObjectID, $asObject = true )
01876 {
01877 return eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
01878 null,
01879 array("contentobject_id" => $contentObjectID ),
01880 null,
01881 null,
01882 $asObject );
01883 }
01884
01885
01886
01887
01888
01889
01890
01891 function &contentObjectAttributes( $asObject = true, $version = false, $language = false, $contentObjectAttributeID = false, $distinctItemsOnly = false )
01892 {
01893 $db =& eZDB::instance();
01894 if ( $version == false )
01895 {
01896 $version = $this->CurrentVersion;
01897 }
01898 else
01899 {
01900 $version = (int) $version;
01901 }
01902
01903 if ( $language === false )
01904 {
01905 $language = $this->CurrentLanguage;
01906 }
01907
01908 if ( is_string( $language ) )
01909 $language = $db->escapeString( $language );
01910
01911 if ( $contentObjectAttributeID !== false )
01912 $contentObjectAttributeID =(int) $contentObjectAttributeID;
01913
01914
01915 if ( !$language || !isset( $this->ContentObjectAttributes[$version][$language] ) )
01916 {
01917
01918 $versionText = "AND\n ezcontentobject_attribute.version = '$version'";
01919 if ( $language )
01920 {
01921 $languageText = "AND\n ezcontentobject_attribute.language_code = '$language'";
01922 }
01923 else
01924 {
01925 $languageText = "AND\n ".eZContentLanguage::sqlFilter( 'ezcontentobject_attribute', 'ezcontentobject_version' );
01926 }
01927 $attributeIDText = false;
01928 if ( $contentObjectAttributeID )
01929 $attributeIDText = "AND\n ezcontentobject_attribute.id = '$contentObjectAttributeID'";
01930 $distinctText = false;
01931 if ( $distinctItemsOnly )
01932 $distinctText = "GROUP BY ezcontentobject_attribute.id";
01933 $query = "SELECT ezcontentobject_attribute.*, ezcontentclass_attribute.identifier as identifier FROM
01934 ezcontentobject_attribute, ezcontentclass_attribute, ezcontentobject_version
01935 WHERE
01936 ezcontentclass_attribute.version = '0' AND
01937 ezcontentclass_attribute.id = ezcontentobject_attribute.contentclassattribute_id AND
01938 ezcontentobject_version.contentobject_id = '$this->ID' AND
01939 ezcontentobject_version.version = '$version' AND
01940 ezcontentobject_attribute.contentobject_id = '$this->ID' $versionText $languageText $attributeIDText
01941 $distinctText
01942 ORDER BY
01943 ezcontentclass_attribute.placement ASC,
01944 ezcontentobject_attribute.language_code ASC";
01945
01946 $attributeArray = $db->arrayQuery( $query );
01947
01948 if ( !$language && $attributeArray )
01949 {
01950 $language = $attributeArray[0]['language_code'];
01951 $this->CurrentLanguage = $language;
01952 }
01953
01954 $returnAttributeArray = array();
01955 foreach ( $attributeArray as $attribute )
01956 {
01957 $attr = new eZContentObjectAttribute( $attribute );
01958 $attr->setContentClassAttributeIdentifier( $attribute['identifier'] );
01959 $returnAttributeArray[] = $attr;
01960 }
01961
01962 if ( $language !== null and $version !== null )
01963 $this->ContentObjectAttributes[$version][$language] =& $returnAttributeArray;
01964 }
01965 else
01966 {
01967
01968 $returnAttributeArray =& $this->ContentObjectAttributes[$version][$language];
01969 }
01970
01971 return $returnAttributeArray;
01972 }
01973
01974
01975
01976
01977 function setContentObjectAttributes( &$attributes, $version, $language )
01978 {
01979 $this->ContentObjectAttributes[$version][$language] =& $attributes;
01980 }
01981
01982
01983
01984
01985
01986
01987 function fillNodeListAttributes( &$nodeList, $asObject = true )
01988 {
01989 $db =& eZDB::instance();
01990
01991 if ( count( $nodeList ) > 0 )
01992 {
01993 $keys = array_keys( $nodeList );
01994 $objectArray = array();
01995 $tmpLanguageObjectList = array();
01996 $whereSQL = '';
01997 $count = count( $nodeList );
01998 $i = 0;
01999 foreach ( $keys as $key )
02000 {
02001 $object =& $nodeList[$key]->attribute( 'object' );
02002
02003 $language = $object->currentLanguage();
02004 $tmpLanguageObjectList[$object->attribute( 'id' )] = $language;
02005 $objectArray = array( 'id' => $object->attribute( 'id' ),
02006 'language' => $language,
02007 'version' => $nodeList[$key]->attribute( 'contentobject_version' ) );
02008
02009 $whereSQL .= "( ezcontentobject_attribute.version = '" . $nodeList[$key]->attribute( 'contentobject_version' ) . "' AND
02010 ezcontentobject_attribute.contentobject_id = '" . $object->attribute( 'id' ) . "' AND
02011 ezcontentobject_attribute.language_code = '" . $language . "' ) ";
02012
02013 $i++;
02014 if ( $i < $count )
02015 $whereSQL .= ' OR ';
02016 }
02017
02018 $query = "SELECT ezcontentobject_attribute.*, ezcontentclass_attribute.identifier as identifier FROM
02019 ezcontentobject_attribute, ezcontentclass_attribute
02020 WHERE
02021 ezcontentclass_attribute.version = '0' AND
02022 ezcontentclass_attribute.id = ezcontentobject_attribute.contentclassattribute_id AND
02023 ( $whereSQL )
02024 ORDER BY
02025 ezcontentobject_attribute.contentobject_id, ezcontentclass_attribute.placement ASC";
02026
02027 $attributeArray = $db->arrayQuery( $query );
02028
02029 $tmpAttributeObjectList = array();
02030 $returnAttributeArray = array();
02031 foreach ( $attributeArray as $attribute )
02032 {
02033 unset( $attr );
02034 $attr = new eZContentObjectAttribute( $attribute );
02035 $attr->setContentClassAttributeIdentifier( $attribute['identifier'] );
02036
02037 $tmpAttributeObjectList[$attr->attribute( 'contentobject_id' )][] = $attr;
02038 }
02039
02040 $keys = array_keys( $nodeList );
02041 foreach ( $keys as $key )
02042 {
02043 unset( $node );
02044 $node = $nodeList[$key];
02045
02046 unset( $object );
02047 $object = $node->attribute( 'object' );
02048 $attributes =& $tmpAttributeObjectList[$object->attribute( 'id' )];
02049 $object->setContentObjectAttributes( $attributes, $node->attribute( 'contentobject_version' ), $tmpLanguageObjectList[$object->attribute( 'id' )] );
02050 $node->setContentObject( $object );
02051
02052 $nodeList[$key] =& $node;
02053 }
02054 }
02055 }
02056
02057 function resetInputRelationList()
02058 {
02059 $this->InputRelationList = array( EZ_CONTENT_OBJECT_RELATION_EMBED => array(),
02060 EZ_CONTENT_OBJECT_RELATION_LINK => array() );
02061 }
02062
02063 function appendInputRelationList( $addingIDList, $relationType )
02064 {
02065 if ( !is_array( $addingIDList ) )
02066 {
02067 $addingIDList = array( ( int ) $addingIDList );
02068 }
02069 elseif ( !count( $addingIDList ) )
02070 {
02071 return;
02072 }
02073 $relationType = ( int ) $relationType;
02074 if ( !$this->InputRelationList )
02075 {
02076 $this->resetInputRelationList();
02077 }
02078
02079 foreach ( array_keys( $this->InputRelationList ) as $inputRelationType )
02080 {
02081 if ( $inputRelationType & $relationType )
02082 {
02083 $this->InputRelationList[$inputRelationType] = array_merge( $this->InputRelationList[$inputRelationType], $addingIDList );
02084 }
02085 }
02086 }
02087
02088 function commitInputRelations( $editVersion )
02089 {
02090 foreach ( $this->InputRelationList as $relationType => $relatedObjectIDArray )
02091 {
02092 $oldRelatedObjectArray = $this->relatedObjects( $editVersion, false, 0, false, array( 'AllRelations' => $relationType ) );
02093
02094 foreach ( $oldRelatedObjectArray as $oldRelatedObject )
02095 {
02096 $oldRelatedObjectID = $oldRelatedObject->ID;
02097 if ( !in_array( $oldRelatedObjectID, $relatedObjectIDArray ) )
02098 {
02099 $this->removeContentObjectRelation( $oldRelatedObjectID, $editVersion, false, 0, $relationType );
02100 }
02101 $relatedObjectIDArray = array_diff( $relatedObjectIDArray, array( $oldRelatedObjectID ) );
02102 }
02103
02104 foreach ( $relatedObjectIDArray as $relatedObjectID )
02105 {
02106 $this->addContentObjectRelation( $relatedObjectID, $editVersion, false, 0, $relationType );
02107 }
02108 }
02109 return true;
02110 }
02111
02112 function validateInput( &$contentObjectAttributes, $attributeDataBaseName,
02113 $inputParameters = false, $parameters = array() )
02114 {
02115 $result = array( 'unvalidated-attributes' => array(),
02116 'validated-attributes' => array(),
02117 'status-map' => array(),
02118 'require-fixup' => false,
02119 'input-validated' => true );
02120 $parameters = array_merge( array( 'prefix-name' => false ),
02121 $parameters );
02122 if ( $inputParameters )
02123 {
02124 $result['unvalidated-attributes'] =& $inputParameters['unvalidated-attributes'];
02125 $result['validated-attributes'] =& $inputParameters['validated-attributes'];
02126 }
02127 $unvalidatedAttributes =& $result['unvalidated-attributes'];
02128 $validatedAttributes =& $result['validated-attributes'];
02129 $statusMap =& $result['status-map'];
02130 if ( !$inputParameters )
02131 $inputParameters = array( 'unvalidated-attributes' => &$unvalidatedAttributes,
02132 'validated-attributes' => &$validatedAttributes );
02133 $requireFixup =& $result['require-fixup'];
02134 $inputValidated =& $result['input-validated'];
02135 $http =& eZHTTPTool::instance();
02136
02137 $this->resetInputRelationList();
02138
02139 $editVersion = null;
02140 $defaultLanguage = $this->initialLanguageCode();
02141 foreach( array_keys( $contentObjectAttributes ) as $key )
02142 {
02143 $contentObjectAttribute =& $contentObjectAttributes[$key];
02144 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
02145 $editVersion = $contentObjectAttribute->attribute('version');
02146
02147
02148 $currentLanguage = $contentObjectAttribute->attribute( 'language_code' );
02149
02150 $isTranslation = false;
02151 if ( $currentLanguage != $defaultLanguage )
02152 $isTranslation = true;
02153
02154
02155
02156
02157 $doNotValidate = false;
02158 if ( $isTranslation )
02159 {
02160 if ( !$contentClassAttribute->attribute( 'can_translate' ) )
02161 $doNotValidate = true;
02162 }
02163
02164 if ( $doNotValidate == true )
02165 {
02166 $status = EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
02167 }
02168 else
02169 {
02170 $status = $contentObjectAttribute->validateInput( $http, $attributeDataBaseName,
02171 $inputParameters, $parameters );
02172 }
02173 $statusMap[$contentObjectAttribute->attribute( 'id' )] = array( 'value' => $status,
02174 'attribute' => &$contentObjectAttribute );
02175
02176 if ( $status == EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE )
02177 $requireFixup = true;
02178 else if ( $status == EZ_INPUT_VALIDATOR_STATE_INVALID )
02179 {
02180 $inputValidated = false;
02181 $dataType = $contentObjectAttribute->dataType();
02182 $attributeName = $dataType->attribute( 'information' );
02183 $attributeName = $attributeName['name'];
02184 $description = $contentObjectAttribute->attribute( 'validation_error' );
02185 $validationNameArray[] = $contentClassAttribute->attribute( 'name' );
02186 $validationName = implode( '->', $validationNameArray );
02187 $hasValidationError = $contentObjectAttribute->attribute( 'has_validation_error' );
02188 if ( $hasValidationError )
02189 {
02190 if ( !$description )
02191 $description = false;
02192 $validationNameArray = array();
02193 if ( $parameters['prefix-name'] )
02194 $validationNameArray = $parameters['prefix-name'];
02195 }
02196 else
02197 {
02198 if ( !$description )
02199 $description = 'unknown error';
02200 }
02201 $unvalidatedAttributes[] = array( 'id' => $contentObjectAttribute->attribute( 'id' ),
02202 'identifier' => $contentClassAttribute->attribute( 'identifier' ),
02203 'name' => $validationName,
02204 'description' => $description );
02205 }
02206 else if ( $status == EZ_INPUT_VALIDATOR_STATE_ACCEPTED )
02207 {
02208 $dataType = $contentObjectAttribute->dataType();
02209 $attributeName = $dataType->attribute( 'information' );
02210 $attributeName = $attributeName['name'];
02211 if ( $contentObjectAttribute->attribute( 'validation_log' ) != null )
02212 {
02213 $description = $contentObjectAttribute->attribute( 'validation_log' );
02214 if ( !$description )
02215 $description = false;
02216 $validationName = $contentClassAttribute->attribute( 'name' );
02217 if ( $parameters['prefix-name'] )
02218 $validationName = $parameters['prefix-name'] . '->' . $validationName;
02219 $validatedAttributes[] = array( 'id' => $contentObjectAttribute->attribute( 'id' ),
02220 'identifier' => $contentClassAttribute->attribute( 'identifier' ),
02221 'name' => $validationName,
02222 'description' => $description );
02223 }
02224 }
02225 }
02226
02227 if ( $editVersion !== null )
02228 {
02229 $this->commitInputRelations( $editVersion );
02230 }
02231 $this->resetInputRelationList();
02232
02233 return $result;
02234 }
02235
02236 function fixupInput( &$contentObjectAttributes, $attributeDataBaseName )
02237 {
02238 $http =& eZHTTPTool::instance();
02239 foreach ( array_keys( $contentObjectAttributes ) as $key )
02240 {
02241 $contentObjectAttribute =& $contentObjectAttributes[$key];
02242 $contentObjectAttribute->fixupInput( $http, $attributeDataBaseName );
02243 }
02244 }
02245
02246 function fetchInput( &$contentObjectAttributes, $attributeDataBaseName,
02247 $customActionAttributeArray, $customActionParameters )
02248 {
02249 $result = array( 'attribute-input-map' => array() );
02250 $attributeInputMap =& $result['attribute-input-map'];
02251 $http =& eZHTTPTool::instance();
02252
02253 $defaultLanguage = $this->initialLanguageCode();
02254
02255 $dataMap =& $this->attribute( 'data_map' );
02256 foreach ( array_keys( $contentObjectAttributes ) as $key )
02257 {
02258 $contentObjectAttribute =& $contentObjectAttributes[$key];
02259 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
02260
02261
02262 $currentLanguage = $contentObjectAttribute->attribute( 'language_code' );
02263
02264 $isTranslation = false;
02265 if ( $currentLanguage != $defaultLanguage )
02266 $isTranslation = true;
02267
02268
02269 $fetchInput = true;
02270 if ( $isTranslation == true )
02271 {
02272 if ( !$contentClassAttribute->attribute( 'can_translate' ) )
02273 {
02274 $fetchInput = false;
02275 }
02276 }
02277
02278
02279
02280 if ( $fetchInput )
02281 {
02282 if ( $contentObjectAttribute->fetchInput( $http, $attributeDataBaseName ) )
02283 {
02284 $attributeInputMap[$contentObjectAttribute->attribute('id')] = true;
02285 $dataMap[$contentObjectAttribute->attribute( 'contentclass_attribute_identifier' )] =& $contentObjectAttribute;
02286 }
02287
02288
02289 $this->handleCustomHTTPActions( $contentObjectAttribute, $attributeDataBaseName,
02290 $customActionAttributeArray, $customActionParameters );
02291 }
02292
02293 }
02294 return $result;
02295 }
02296
02297 function handleCustomHTTPActions( &$contentObjectAttribute, $attributeDataBaseName,
02298 $customActionAttributeArray, $customActionParameters )
02299 {
02300 $http =& eZHTTPTool::instance();
02301 $customActionParameters['base_name'] = $attributeDataBaseName;
02302 if ( isset( $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )] ) )
02303 {
02304 $customActionAttributeID = $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )]['id'];
02305 $customAction = $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )]['value'];
02306 $contentObjectAttribute->customHTTPAction( $http, $customAction, $customActionParameters );
02307 }
02308
02309 $contentObjectAttribute->handleCustomHTTPActions( $http, $attributeDataBaseName,
02310 $customActionAttributeArray, $customActionParameters );
02311 }
02312
02313 function handleAllCustomHTTPActions( $attributeDataBaseName,
02314 $customActionAttributeArray, $customActionParameters,
02315 $objectVersion = false )
02316 {
02317 $http =& eZHTTPTool::instance();
02318 $contentObjectAttributes =& $this->contentObjectAttributes( true, $objectVersion );
02319 $oldAttributeDataBaseName = $customActionParameters['base_name'];
02320 $customActionParameters['base_name'] = $attributeDataBaseName;
02321 foreach( array_keys( $contentObjectAttributes ) as $key )
02322 {
02323 $contentObjectAttribute =& $contentObjectAttributes[$key];
02324 if ( isset( $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )] ) )
02325 {
02326 $customActionAttributeID = $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )]['id'];
02327 $customAction = $customActionAttributeArray[$contentObjectAttribute->attribute( 'id' )]['value'];
02328 $contentObjectAttribute->customHTTPAction( $http, $customAction, $customActionParameters );
02329 }
02330
02331 $contentObjectAttribute->handleCustomHTTPActions( $http, $attributeDataBaseName,
02332 $customActionAttributeArray, $customActionParameters );
02333 }
02334 $customActionParameters['base_name'] = $oldAttributeDataBaseName;
02335 }
02336
02337 function recursionProtectionStart()
02338 {
02339 $GLOBALS["ez_content_object_recursion_protect"] = array();
02340 }
02341
02342 function recursionProtect( $id )
02343 {
02344 if ( isset( $GLOBALS["ez_content_object_recursion_protect"][$id] ) )
02345 {
02346 return false;
02347 }
02348 else
02349 {
02350 $GLOBALS["ez_content_object_recursion_protect"][$id] = true;
02351 return true;
02352 }
02353 }
02354
02355 function recursionProtectionEnd()
02356 {
02357 unset( $GLOBALS["ez_content_object_recursion_protect"] );
02358 }
02359
02360
02361
02362
02363
02364 function storeInput( &$contentObjectAttributes,
02365 $attributeInputMap )
02366 {
02367 $db =& eZDB::instance();
02368 $db->begin();
02369 foreach ( array_keys( $contentObjectAttributes ) as $key )
02370 {
02371 $contentObjectAttribute =& $contentObjectAttributes[$key];
02372
02373 if ( isset( $attributeInputMap[$contentObjectAttribute->attribute('id')] ) )
02374 {
02375 $contentObjectAttribute->store();
02376 }
02377 }
02378 $db->commit();
02379 unset( $this->ContentObjectAttributes );
02380 }
02381
02382
02383
02384
02385 function nextVersion()
02386 {
02387 $db =& eZDB::instance();
02388 $versions = $db->arrayQuery( "SELECT ( MAX( version ) + 1 ) AS next_id FROM ezcontentobject_version
02389 WHERE contentobject_id='$this->ID'" );
02390 return $versions[0]["next_id"];
02391
02392 }
02393
02394
02395
02396
02397 function previousVersion()
02398 {
02399 $db =& eZDB::instance();
02400 $versions = $db->arrayQuery( "SELECT version FROM ezcontentobject_version
02401 WHERE contentobject_id='$this->ID'
02402 ORDER BY version DESC", array( 'limit' => 2 ) );
02403 if ( count( $versions ) > 1 and isset( $versions[1]['version'] ) )
02404 {
02405 return $versions[1]['version'];
02406 }
02407 else
02408 {
02409 return false;
02410 }
02411 }
02412
02413
02414
02415
02416 function getVersionCount()
02417 {
02418 $db =& eZDB::instance();
02419 $versionCount = $db->arrayQuery( "SELECT ( COUNT( version ) ) AS version_count FROM ezcontentobject_version
02420 WHERE contentobject_id='$this->ID'" );
02421 return $versionCount[0]["version_count"];
02422
02423 }
02424
02425 function ¤tLanguage()
02426 {
02427 return $this->CurrentLanguage;
02428 }
02429
02430 function ¤tLanguageObject()
02431 {
02432 if ( $this->CurrentLanguage )
02433 {
02434 $language = eZContentLanguage::fetchByLocale( $this->CurrentLanguage );
02435 }
02436 else
02437 {
02438 $language = false;
02439 }
02440
02441 return $language;
02442 }
02443
02444 function setCurrentLanguage( $lang )
02445 {
02446 $this->CurrentLanguage = $lang;
02447 $this->Name = null;
02448 }
02449
02450 function &initialLanguage()
02451 {
02452 $initialLanguage = isset( $this->InitialLanguageID ) ? eZContentLanguage::fetch( $this->InitialLanguageID ) : false;
02453
02454 return $initialLanguage;
02455 }
02456
02457 function &initialLanguageCode()
02458 {
02459 $initialLanguage =& $this->initialLanguage();
02460
02461 $initialLanguageCode = $initialLanguage !== false ? $initialLanguage->attribute( 'locale' ) : false;
02462
02463 return $initialLanguageCode;
02464 }
02465
02466
02467
02468
02469
02470
02471
02472
02473 function &addLocation( $parentNodeID, $asObject = false )
02474 {
02475 $node =& eZContentObjectTreeNode::addChild( $this->ID, $parentNodeID, true, $this->CurrentVersion );
02476
02477 $data = array( 'contentobject_id' => $this->ID,
02478 'contentobject_version' => $this->attribute( 'current_version' ),
02479 'parent_node' => $parentNodeID,
02480 'is_main' => 0 );
02481 $nodeAssignment = eZNodeAssignment::create( $data );
02482 $nodeAssignment->setAttribute( 'op_code', EZ_NODE_ASSIGNMENT_OP_CODE_CREATE_NOP );
02483 $nodeAssignment->store();
02484
02485 if ( $asObject )
02486 {
02487 return $node;
02488 }
02489 else
02490 {
02491 return $node->attribute( 'node_id' );
02492 }
02493 }
02494
02495
02496
02497
02498
02499
02500 function addContentObjectRelation( $toObjectID, $fromObjectVersion = false, $fromObjectID = false, $attributeID = 0, $relationType = EZ_CONTENT_OBJECT_RELATION_COMMON )
02501 {
02502 if ( $attributeID !== 0 )
02503 {
02504 $relationType = EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE;
02505 }
02506
02507 $relationType =(int) $relationType;
02508 if ( ( $relationType & EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE ) != 0 &&
02509 $relationType != EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE )
02510 {
02511 eZDebug::writeWarning( "Object relation type conflict", "eZContentObject::addContentObjectRelation");
02512 }
02513
02514 $db =& eZDB::instance();
02515
02516 if ( !$fromObjectVersion )
02517 $fromObjectVersion = $this->CurrentVersion;
02518
02519 if ( !$fromObjectID )
02520 $fromObjectID = $this->ID;
02521
02522 if ( !is_numeric( $toObjectID ) )
02523 {
02524 eZDebug::writeError( "Related object ID (toObjectID): '$toObjectID', is not a numeric value.",
02525 "eZContentObject::addContentObjectRelation" );
02526 return false;
02527 }
02528 $fromObjectID =(int) $fromObjectID;
02529 $attributeID =(int) $attributeID;
02530 $fromObjectVersion =(int) $fromObjectVersion;
02531 $relationBaseType = ( $relationType & EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE ) ?
02532 EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE :
02533 EZ_CONTENT_OBJECT_RELATION_COMMON | EZ_CONTENT_OBJECT_RELATION_EMBED | EZ_CONTENT_OBJECT_RELATION_LINK;
02534 $relationTypeMatch = $db->bitAnd( 'relation_type', $relationBaseType );
02535 $query = "SELECT count(*) AS count
02536 FROM ezcontentobject_link
02537 WHERE from_contentobject_id=$fromObjectID AND
02538 from_contentobject_version=$fromObjectVersion AND
02539 to_contentobject_id=$toObjectID AND
02540 $relationTypeMatch != 0 AND
02541 contentclassattribute_id=$attributeID AND
02542 op_code='0'";
02543 $count = $db->arrayQuery( $query );
02544
02545 if ( !isset( $count[0]['count'] ) || $count[0]['count'] == '0' )
02546 {
02547 $db->begin();
02548 $db->query( "INSERT INTO ezcontentobject_link ( from_contentobject_id, from_contentobject_version, to_contentobject_id, contentclassattribute_id, relation_type )
02549 VALUES ( $fromObjectID, $fromObjectVersion, $toObjectID, $attributeID, $relationType )" );
02550
02551 if ( $attributeID == 0 && $fromObjectVersion != $this->CurrentVersion )
02552 {
02553 $db->query( "INSERT INTO ezcontentobject_link ( from_contentobject_id, from_contentobject_version, to_contentobject_id, contentclassattribute_id, op_code, relation_type )
02554 VALUES ( $fromObjectID, $fromObjectVersion, $toObjectID, $attributeID, '1', $relationType )" );
02555 }
02556 $db->commit();
02557 }
02558 elseif ( isset( $count[0]['count'] ) &&
02559 $count[0]['count'] != '0' &&
02560 $attributeID == 0 &&
02561 (EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE & $relationType) == 0 )
02562 {
02563 $db->begin();
02564 $newRelationType = $db->bitOr( 'relation_type', $relationType );
02565 $db->query( "UPDATE ezcontentobject_link
02566 SET relation_type = $newRelationType
02567 WHERE from_contentobject_id=$fromObjectID AND
02568 from_contentobject_version=$fromObjectVersion AND
02569 to_contentobject_id=$toObjectID AND
02570 contentclassattribute_id=$attributeID AND
02571 op_code='0'" );
02572
02573 if ( $attributeID == 0 && $fromObjectVersion != $this->CurrentVersion )
02574 {
02575 $db->query( "INSERT INTO ezcontentobject_link ( from_contentobject_id, from_contentobject_version, to_contentobject_id, contentclassattribute_id, op_code, relation_type )
02576 VALUES ( $fromObjectID, $fromObjectVersion, $toObjectID, $attributeID, '1', $relationType )" );
02577 }
02578 $db->commit();
02579 }
02580 }
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593 function removeContentObjectRelation( $toObjectID = false, $fromObjectVersion = false, $fromObjectID = false, $attributeID = 0, $relationType = EZ_CONTENT_OBJECT_RELATION_COMMON )
02594 {
02595 $db =& eZDB::instance();
02596
02597 if ( !$fromObjectVersion )
02598 $fromObjectVersion = $this->CurrentVersion;
02599 $fromObjectVersion = (int) $fromObjectVersion;
02600 if ( !$fromObjectID )
02601 $fromObjectID = $this->ID;
02602 $fromObjectID =(int) $fromObjectID;
02603
02604 if ( $toObjectID !== false )
02605 {
02606 $toObjectID =(int) $toObjectID;
02607 $toObjectCondition = "AND to_contentobject_id=$toObjectID";
02608 }
02609 else
02610 $toObjectCondition = '';
02611
02612 if ( $attributeID !== false )
02613 {
02614 $attributeID =(int) $attributeID;
02615 $classAttributeCondition = "AND contentclassattribute_id=$attributeID";
02616 }
02617 else
02618 $classAttributeCondition = '';
02619
02620 $lastRelationType = 0;
02621 $db->begin();
02622
02623 if ( !$attributeID && $fromObjectVersion != $this->CurrentVersion )
02624 {
02625 $rows = $db->arrayQuery( "SELECT * FROM ezcontentobject_link
02626 WHERE from_contentobject_id=$fromObjectID
02627 AND from_contentobject_version=$fromObjectVersion
02628 AND contentclassattribute_id='0'
02629 $toObjectCondition
02630 AND op_code='0'" );
02631 foreach ( $rows as $row )
02632 {
02633 $db->query( "INSERT INTO ezcontentobject_link ( from_contentobject_id, from_contentobject_version, to_contentobject_id, contentclassattribute_id, op_code, relation_type )
02634 VALUES ( $fromObjectID, $fromObjectVersion, " . $row['to_contentobject_id'] . ", '0', '-1', $relationType )" );
02635 $lastRelationType = (int) $row['relation_type'];
02636 }
02637 }
02638
02639 if ( 0 !== ( EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE & $relationType ) ||
02640 0 != $attributeID ||
02641 $relationType == $lastRelationType )
02642 {
02643 $db->query( "DELETE FROM ezcontentobject_link
02644 WHERE from_contentobject_id=$fromObjectID AND
02645 from_contentobject_version=$fromObjectVersion $classAttributeCondition $toObjectCondition AND
02646 op_code='0'" );
02647 }
02648 else
02649 {
02650 if ( $db->databaseName() == 'oracle' )
02651 {
02652 $notRelationType = - ( $relationType + 1 );
02653 $db->query( "UPDATE ezcontentobject_link
02654 SET relation_type = " . $db->bitAnd( 'relation_type', $notRelationType ) . "
02655 WHERE from_contentobject_id=$fromObjectID AND
02656 from_contentobject_version=$fromObjectVersion $classAttributeCondition $toObjectCondition AND
02657 op_code='0'" );
02658 }
02659 else
02660 {
02661 $db->query( "UPDATE ezcontentobject_link
02662 SET relation_type = ( relation_type & ".(~$relationType)." )
02663 WHERE from_contentobject_id=$fromObjectID AND
02664 from_contentobject_version=$fromObjectVersion $classAttributeCondition $toObjectCondition AND
02665 op_code='0'" );
02666 }
02667 }
02668
02669 $db->commit();
02670
02671 }
02672
02673 function copyContentObjectRelations( $currentVersion, $newVersion, $newObjectID = false )
02674 {
02675 $objectID = $this->ID;
02676 if ( !$newObjectID )
02677 {
02678 $newObjectID = $objectID;
02679 }
02680
02681 $db =& eZDB::instance();
02682 $db->begin();
02683
02684 $relations = $db->arrayQuery( "SELECT to_contentobject_id, op_code, relation_type FROM ezcontentobject_link
02685 WHERE contentclassattribute_id='0'
02686 AND from_contentobject_id='$objectID'
02687 AND from_contentobject_version='$currentVersion'" );
02688 foreach ( $relations as $relation )
02689 {
02690 $toContentObjectID = $relation['to_contentobject_id'];
02691 $opCode = $relation['op_code'];
02692 $relationType = $relation['relation_type'];
02693 $db->query( "INSERT INTO ezcontentobject_link( contentclassattribute_id,
02694 from_contentobject_id,
02695 from_contentobject_version,
02696 to_contentobject_id,
02697 op_code,
02698 relation_type )
02699 VALUES ( '0', '$newObjectID', '$newVersion', '$toContentObjectID', '$opCode', '$relationType' )" );
02700 }
02701
02702 $db->commit();
02703 }
02704
02705 function isObjectRelationTyped()
02706 {
02707 $siteIni =& eZINI::instance( 'site.ini' );
02708 if ( $siteIni->hasVariable( 'BackwardCompatibilitySettings', 'ObjectRelationTyped' ) )
02709 {
02710 if ( 'enabled' == $siteIni->variable( 'BackwardCompatibilitySettings', 'ObjectRelationTyped' ) )
02711 {
02712 return true;
02713 }
02714 }
02715 return false;
02716 }
02717
02718 function relationTypeMask( $allRelations = false )
02719 {
02720 $relationTypeMask = EZ_CONTENT_OBJECT_RELATION_COMMON |
02721 EZ_CONTENT_OBJECT_RELATION_EMBED;
02722
02723 if ( eZContentObject::isObjectRelationTyped() )
02724 {
02725 $relationTypeMask |= EZ_CONTENT_OBJECT_RELATION_LINK;
02726 }
02727
02728 if ( $allRelations )
02729 {
02730 $relationTypeMask |= EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE;
02731 }
02732
02733 return $relationTypeMask;
02734 }
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758 function &relatedObjects( $fromObjectVersion = false,
02759 $objectID = false,
02760 $attributeID = 0,
02761 $groupByAttribute = false,
02762 $params = false,
02763 $reverseRelatedObjects = false )
02764 {
02765 if ( $fromObjectVersion == false )
02766 $fromObjectVersion = isset( $this->CurrentVersion ) ? $this->CurrentVersion : false;
02767 $fromObjectVersion =(int) $fromObjectVersion;
02768 if( !$objectID )
02769 $objectID = $this->ID;
02770 $objectID =(int) $objectID;
02771
02772 $db =& eZDB::instance();
02773 $sortingString = '';
02774 $sortingInfo = array( 'attributeFromSQL' => '',
02775 'attributeWhereSQL' => '' );
02776
02777 $showInvisibleNodesCond = '';
02778 $showInvisibleNodesTable = '';
02779
02780
02781
02782 if ( is_array( $params ) )
02783 {
02784 if ( isset( $params['SortBy'] ) )
02785 {
02786 $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $params['SortBy'] );
02787 $sortingString = ' ORDER BY ' . $sortingInfo['sortingFields'];
02788 }
02789 if ( isset( $params['IgnoreVisibility'] ) )
02790 {
02791 $ignoreVisibility = $params['IgnoreVisibility'];
02792 if ( !$ignoreVisibility )
02793 {
02794 $showInvisibleNodesCond = ' AND ezcontentobject_tree.contentobject_id = ezcontentobject.id
02795 AND ezcontentobject_tree.is_invisible = 0 ';
02796 $showInvisibleNodesTable = ', ezcontentobject_tree';
02797 }
02798 }
02799 }
02800
02801 $relationTypeMasking = '';
02802 $relationTypeMask = isset( $params['AllRelations'] ) ? $params['AllRelations'] : ( $attributeID === false );
02803 if ( $attributeID && ( $relationTypeMask === false || $relationTypeMask === EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE ) )
02804 {
02805 $attributeID =(int) $attributeID;
02806 $relationTypeMasking .= " AND contentclassattribute_id=$attributeID ";
02807 $relationTypeMask = EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE;
02808 }
02809 elseif ( is_bool( $relationTypeMask ) )
02810 {
02811 $relationTypeMask = eZContentObject::relationTypeMask( $relationTypeMask );
02812 }
02813
02814 if ( $db->databaseName() == 'oracle' )
02815 {
02816 $relationTypeMasking .= " AND bitand( relation_type, $relationTypeMask ) <> 0 ";
02817 }
02818 else
02819 {
02820 $relationTypeMasking .= " AND ( relation_type & $relationTypeMask ) <> 0 ";
02821 }
02822
02823
02824 $versionNameTables = ', ezcontentobject_name ';
02825 $versionNameTargets = ', ezcontentobject_name.name as name, ezcontentobject_name.real_translation ';
02826
02827 $versionNameJoins = " AND ezcontentobject.id = ezcontentobject_name.contentobject_id AND
02828 ezcontentobject.current_version = ezcontentobject_name.content_version AND ";
02829 $versionNameJoins .= eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' );
02830
02831 $fromOrToContentObjectID = $reverseRelatedObjects == false ? " AND ezcontentobject.id=ezcontentobject_link.to_contentobject_id AND
02832 ezcontentobject_link.from_contentobject_id='$objectID' AND
02833 ezcontentobject_link.from_contentobject_version='$fromObjectVersion' "
02834 : " AND ezcontentobject.id=ezcontentobject_link.from_contentobject_id AND
02835 ezcontentobject_link.to_contentobject_id=$objectID AND
02836 ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version ";
02837 $query = "SELECT ";
02838
02839 if ( $groupByAttribute )
02840 {
02841 $query .= "ezcontentobject_link.contentclassattribute_id, ";
02842 }
02843 $query .= "
02844 ezcontentclass.serialized_name_list AS class_serialized_name_list,
02845 ezcontentclass.identifier as contentclass_identifier,
02846 ezcontentclass.is_container as is_container,
02847 ezcontentobject.* $versionNameTargets
02848 FROM
02849 ezcontentclass,
02850 ezcontentobject,
02851 ezcontentobject_link
02852 $versionNameTables
02853 $showInvisibleNodesTable
02854 $sortingInfo[attributeFromSQL]
02855 WHERE
02856 ezcontentclass.id=ezcontentobject.contentclass_id AND
02857 ezcontentclass.version=0 AND
02858 ezcontentobject.status=" . EZ_CONTENT_OBJECT_STATUS_PUBLISHED . " AND
02859 $sortingInfo[attributeWhereSQL]
02860 ezcontentobject_link.op_code='0'
02861 $relationTypeMasking
02862 $fromOrToContentObjectID
02863 $showInvisibleNodesCond
02864 $versionNameJoins
02865 $sortingString";
02866 $relatedObjects = $db->arrayQuery( $query );
02867
02868 $ret = array();
02869 foreach ( $relatedObjects as $object )
02870 {
02871 $obj = new eZContentObject( $object );
02872 $obj->ClassName = eZContentClass::nameFromSerializedString( $object['class_serialized_name_list'] );
02873
02874 if ( !$groupByAttribute )
02875 {
02876 $ret[] = $obj;
02877 }
02878 else
02879 {
02880 $classAttrID = $object['contentclassattribute_id'];
02881
02882 if ( !isset( $ret[$classAttrID] ) )
02883 $ret[$classAttrID] = array();
02884
02885 $ret[$classAttrID][] = $obj;
02886 }
02887 }
02888 return $ret;
02889 }
02890
02891
02892
02893
02894
02895
02896
02897
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911 function &relatedContentObjectList( $fromObjectVersion = false,
02912 $fromObjectID = false,
02913 $attributeID = 0,
02914 $groupByAttribute = false,
02915 $params = false )
02916 {
02917 eZDebugSetting::writeDebug( 'kernel-content-object-related-objects', $fromObjectID, "objectID" );
02918 $result = get_class( $this ) == 'ezcontentobject' ? $this->relatedObjects( $fromObjectVersion, $fromObjectID, $attributeID, $groupByAttribute, $params )
02919 : eZContentObject::relatedObjects( $fromObjectVersion, $fromObjectID, $attributeID, $groupByAttribute, $params );
02920 return $result;
02921 }
02922
02923
02924
02925
02926 function &linkedContentObjectList( $fromObjectVersion = false, $fromObjectID = false )
02927 {
02928 $linkedList =& $this->relatedObjects( $fromObjectVersion, $fromObjectID, 0, false, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_LINK ) );
02929 return $linkedList;
02930 }
02931
02932
02933
02934
02935 function &embeddedContentObjectList( $fromObjectVersion = false, $fromObjectID = false )
02936 {
02937 $embeddedList =& $this->relatedObjects( $fromObjectVersion, $fromObjectID, 0, false, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_EMBED ) );
02938 return $embeddedList;
02939 }
02940
02941
02942
02943
02944 function &reverseLinkedObjectList( $fromObjectVersion = false, $fromObjectID = false )
02945 {
02946 $linkedList =& $this->relatedObjects( $fromObjectVersion, $fromObjectID, 0, false, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_LINK ), true );
02947 return $linkedList;
02948 }
02949
02950
02951
02952
02953 function &reverseEmbeddedObjectList( $fromObjectVersion = false, $fromObjectID = false )
02954 {
02955 $embeddedList =& $this->relatedObjects( $fromObjectVersion, $fromObjectID, 0, false, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_EMBED ), true );
02956 return $embeddedList;
02957 }
02958
02959
02960 function &relatedContentObjectArray( $fromObjectVersion = false, $fromObjectID = false, $attributeID = 0, $params = false )
02961 {
02962 $relatedList =& eZContentObject::relatedContentObjectList( $fromObjectVersion, $fromObjectID, $attributeID, false, $params );
02963 return $relatedList;
02964 }
02965
02966
02967
02968
02969
02970
02971
02972
02973
02974
02975
02976
02977
02978
02979
02980
02981
02982
02983 function &relatedContentObjectCount( $fromObjectVersion = false, $fromObjectID = false, $attributeID = 0, $params = false )
02984 {
02985 eZDebugSetting::writeDebug( 'kernel-content-object-related-objects', $fromObjectID, "relatedContentObjectCount::objectID" );
02986 $result = get_class( $this ) == 'ezcontentobject' ? $this->relatedObjectCount( $fromObjectVersion, $fromObjectID, $attributeID, false, $params )
02987 : eZContentObject::relatedObjectCount( $fromObjectVersion, $fromObjectID, $attributeID, false, $params );
02988 return $result;
02989 }
02990
02991
02992
02993
02994
02995
02996
02997
02998
02999
03000
03001
03002
03003
03004
03005
03006
03007
03008
03009
03010
03011 function &reverseRelatedObjectList( $version = false,
03012 $toObjectID = false,
03013 $attributeID = 0,
03014 $groupByAttribute = false,
03015 $params = false )
03016 {
03017 $result = get_class( $this ) == 'ezcontentobject' ? $this->relatedObjects( $version, $toObjectID, $attributeID, $groupByAttribute, $params, true )
03018 : eZContentObject::relatedObjects( $version, $toObjectID, $attributeID, $groupByAttribute, $params, true );
03019 return $result;
03020 }
03021
03022
03023
03024
03025 function &linkedContentObjectCount( $fromObjectVersion = false, $fromObjectID = false )
03026 {
03027 $result =& $this->relatedObjectCount( $fromObjectVersion, $fromObjectID, 0, false, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_LINK ) );
03028 return $result;
03029 }
03030
03031
03032
03033
03034 function &embeddedContentObjectCount( $fromObjectVersion = false, $fromObjectID = false )
03035 {
03036 $result =& $this->relatedObjectCount( $fromObjectVersion, $fromObjectID, 0, false, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_EMBED ) );
03037 return $result;
03038 }
03039
03040
03041
03042
03043 function &reverseLinkedObjectCount( $fromObjectVersion = false, $fromObjectID = false )
03044 {
03045 $result =& $this->relatedObjectCount( $fromObjectVersion, $fromObjectID, 0, true, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_LINK ) );
03046 return $result;
03047 }
03048
03049
03050
03051
03052 function &reverseEmbeddedObjectCount( $fromObjectVersion = false, $fromObjectID = false )
03053 {
03054 $result =& $this->relatedObjectCount( $fromObjectVersion, $fromObjectID, 0, true, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_EMBED ) );
03055 return $result;
03056 }
03057
03058
03059
03060
03061
03062
03063
03064
03065
03066
03067
03068
03069
03070
03071
03072
03073
03074
03075
03076
03077 function &relatedObjectCount( $version = false, $objectID = false, $attributeID = 0, $reverseRelatedObjects = false, $params = false )
03078 {
03079 if ( !$objectID )
03080 $objectID = $this->ID;
03081 if ( $version == false )
03082 $version = isset( $this->CurrentVersion ) ? $this->CurrentVersion : false;
03083 $version == (int) $version;
03084
03085 $db =& eZDB::instance();
03086 $showInvisibleNodesCond = '';
03087 $showInvisibleNodesTable = '';
03088
03089
03090 if ( is_array( $params ) )
03091 {
03092 if ( isset( $params['IgnoreVisibility'] ) )
03093 {
03094 $ignoreVisibility = $params['IgnoreVisibility'];
03095 if ( !$ignoreVisibility )
03096 {
03097 $showInvisibleNodesCond = 'AND ezcontentobject_tree.contentobject_id = ezcontentobject.id
03098 AND ezcontentobject_tree.is_invisible = 0';
03099 $showInvisibleNodesTable = ', ezcontentobject_tree';
03100 }
03101 }
03102 }
03103
03104 $relationTypeMasking = '';
03105 $relationTypeMask = isset( $params['AllRelations'] ) ? $params['AllRelations'] : ( $attributeID === false );
03106 if ( $attributeID && ( $relationTypeMask === false || $relationTypeMask === EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE ) )
03107 {
03108 $attributeID =(int) $attributeID;
03109 $relationTypeMasking .= " AND contentclassattribute_id=$attributeID ";
03110 $relationTypeMask = EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE;
03111 }
03112 elseif ( is_bool( $relationTypeMask ) )
03113 {
03114 $relationTypeMask = eZContentObject::relationTypeMask( $relationTypeMask );
03115 }
03116
03117 if ( $db->databaseName() == 'oracle' )
03118 {
03119 $relationTypeMasking .= " AND bitand( relation_type, $relationTypeMask ) <> 0 ";
03120 }
03121 else
03122 {
03123 $relationTypeMasking .= " AND ( relation_type & $relationTypeMask ) <> 0 ";
03124 }
03125
03126 if ( $reverseRelatedObjects )
03127 {
03128 if ( is_array( $objectID ) )
03129 {
03130 $objectIDSQL = ' AND ezcontentobject_link.to_contentobject_id in (' . $db->implodeWithTypeCast( ', ', $objectID, 'int' ) . ') AND
03131 ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version';
03132 }
03133 else
03134 {
03135 $objectID = (int) $objectID;
03136 $objectIDSQL = ' AND ezcontentobject_link.to_contentobject_id = ' . $objectID . ' AND
03137 ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version';
03138 }
03139 $select = " count( DISTINCT ezcontentobject.id ) AS count";
03140 }
03141 else
03142 {
03143 $select = " count( ezcontentobject_link.from_contentobject_id ) as count ";
03144 $objectIDSQL = " AND ezcontentobject_link.from_contentobject_id='$objectID'
03145 AND ezcontentobject_link.from_contentobject_version='$version'";
03146 }
03147 $query = "SELECT $select
03148 FROM
03149 ezcontentobject, ezcontentobject_link $showInvisibleNodesTable
03150 WHERE
03151 ezcontentobject.id=ezcontentobject_link.from_contentobject_id AND
03152 ezcontentobject.status=" . EZ_CONTENT_OBJECT_STATUS_PUBLISHED . " AND
03153 ezcontentobject_link.op_code='0'
03154 $objectIDSQL
03155 $relationTypeMasking
03156 $showInvisibleNodesCond";
03157
03158 $rows = $db->arrayQuery( $query );
03159 return $rows[0]['count'];
03160 }
03161
03162
03163
03164
03165
03166
03167
03168
03169
03170
03171
03172
03173
03174
03175
03176 function &reverseRelatedObjectCount( $version = false, $toObjectID = false, $attributeID = 0, $params = false )
03177 {
03178 $result = get_class( $this ) == 'ezcontentobject' ? $this->relatedObjectCount( $version, $toObjectID, $attributeID, true, $params )
03179 : eZContentObject::relatedObjectCount( $version, $toObjectID, $attributeID, true, $params );
03180 return $result;
03181 }
03182
03183
03184
03185
03186
03187 function &contentObjectListRelatingThis( $version = false, $objectID = false )
03188 {
03189 $reverseRelatedObjectList =& $this->reverseRelatedObjectList( $version, $objectID );
03190 return $reverseRelatedObjectList;
03191 }
03192
03193 function publishContentObjectRelations( $version )
03194 {
03195 $objectID = $this->ID;
03196 $currentVersion = $this->CurrentVersion;
03197 $version =(int) $version;
03198 $db = eZDB::instance();
03199 $db->begin();
03200
03201 $toContentObjectIDs = array();
03202 $relationTypesArray = array();
03203 $publishedRelations = $db->arrayQuery( "SELECT to_contentobject_id, relation_type FROM ezcontentobject_link
03204 WHERE contentclassattribute_id='0'
03205 AND from_contentobject_id='$objectID'
03206 AND from_contentobject_version='$currentVersion'
03207 AND op_code='0'" );
03208
03209 foreach ( $publishedRelations as $relation )
03210 {
03211 $toContentObjectIDs[] = $relation['to_contentobject_id'];
03212 $relationTypesArray[$relation['to_contentobject_id']] = (int) $relation['relation_type'];
03213 }
03214 $toContentObjectIDs = array_unique( $toContentObjectIDs );
03215
03216 $addedOrRemovedRelations = $db->arrayQuery( "SELECT to_contentobject_id, op_code, relation_type FROM ezcontentobject_link
03217 WHERE contentclassattribute_id='0'
03218 AND from_contentobject_id='$objectID'
03219 AND from_contentobject_version='$version'
03220 AND op_code!='0'
03221 ORDER BY id ASC" );
03222
03223 foreach ( $addedOrRemovedRelations as $relation )
03224 {
03225 $relationType = (int) $relation['relation_type'];
03226 if ( !isset( $relationTypesArray[$relation['to_contentobject_id']] ) )
03227 {
03228 $relationTypesArray[$relation['to_contentobject_id']] = 0;
03229 }
03230 if ( $relation['op_code'] == 1 )
03231 {
03232 if ( !in_array( $relation['to_contentobject_id'], $toContentObjectIDs ) )
03233 {
03234 $toContentObjectIDs[] = $relation['to_contentobject_id'];
03235 }
03236 $relationTypesArray[$relation['to_contentobject_id']] |= $relationType;
03237 }
03238 else
03239 {
03240 $relationTypesArray[$relation['to_contentobject_id']] &= ~$relationType;
03241 if ( 0 === $relationTypesArray[$relation['to_contentobject_id']] )
03242 {
03243 $toContentObjectIDs = array_diff( $toContentObjectIDs, array( $relation['to_contentobject_id'] ) );
03244 }
03245 }
03246 }
03247
03248 $db->query( "DELETE FROM ezcontentobject_link
03249 WHERE contentclassattribute_id='0'
03250 AND from_contentobject_id='$objectID'
03251 AND from_contentobject_version='$version'" );
03252
03253 foreach( $toContentObjectIDs as $toContentObjectID )
03254 {
03255 $db->query( "INSERT INTO ezcontentobject_link( contentclassattribute_id,
03256 from_contentobject_id,
03257 from_contentobject_version,
03258 to_contentobject_id,
03259 op_code,
03260 relation_type )
03261 VALUES ( '0', '$objectID', '$version', '$toContentObjectID', '0', '{$relationTypesArray[$toContentObjectID]}' )" );
03262 }
03263
03264 $db->commit();
03265 }
03266
03267
03268
03269
03270 function &parentNodeIDArray()
03271 {
03272 $nodeIDArray = $this->parentNodes( true, false );
03273 return $nodeIDArray;
03274 }
03275
03276
03277
03278
03279
03280
03281 function &parentNodes( $version = false, $asObject = true )
03282 {
03283
03284
03285 $retNodes = array();
03286
03287 $nodes = & $this->assignedNodes();
03288 if ( $asObject )
03289 {
03290 foreach ( $nodes as $node )
03291 {
03292 $retNodes[] = $node->fetchParent();
03293 }
03294 }
03295 else
03296 {
03297 foreach ( $nodes as $node )
03298 {
03299 $parentNode = $node->fetchParent();
03300 $retNodes[] = $parentNode->attribute( 'node_id' );
03301 }
03302 }
03303
03304 return $retNodes;
03305 }
03306
03307
03308
03309
03310
03311
03312
03313
03314
03315
03316
03317 function createNodeAssignment( $parentNodeID, $isMain, $remoteID = false, $sortField = 2 , $sortOrder = 0 )
03318 {
03319 $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $this->attribute( 'id' ),
03320 'contentobject_version' => $this->attribute( 'current_version' ),
03321 'parent_node' => $parentNodeID,
03322 'is_main' => ( $isMain ? 1 : 0 ),
03323 'sort_field' => $sortField,
03324 'sort_order' => $sortOrder ) );
03325 if ( $remoteID !== false )
03326 {
03327 $nodeAssignment->setAttribute( 'remote_id', $remoteID );
03328 }
03329 $nodeAssignment->store();
03330 return $nodeAssignment;
03331 }
03332
03333
03334
03335
03336 function createWithNodeAssignment( $parentNode, $contentClassID, $languageCode, $remoteID = false )
03337 {
03338
03339 $class = eZContentClass::fetch( $contentClassID );
03340 $parentObject = $parentNode->attribute( 'object' );
03341
03342
03343 if ( strtolower( get_class( $class ) ) == "ezcontentclass" and
03344 $parentObject->checkAccess( 'create', $contentClassID, false, false, $languageCode ) == '1' )
03345 {
03346
03347 $sectionID = $parentObject->attribute( 'section_id' );
03348
03349 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
03350 $userID = eZUser::currentUserID();
03351
03352 $db =& eZDB::instance();
03353 $db->begin();
03354 $contentObject = $class->instantiateIn( $languageCode, $userID, $sectionID, false, EZ_VERSION_STATUS_INTERNAL_DRAFT );
03355 $nodeAssignment = $contentObject->createNodeAssignment( $parentNode->attribute( 'node_id' ),
03356 true, $remoteID,
03357 $class->attribute( 'sort_field' ),
03358 $class->attribute( 'sort_order' ) );
03359 $db->commit();
03360 return $contentObject;
03361 }
03362 return null;
03363 }
03364
03365
03366
03367
03368
03369 function &assignedNodes( $asObject = true )
03370 {
03371 $contentobjectID = $this->attribute( 'id' );
03372 if ( $contentobjectID == null )
03373 {
03374 $retValue = array();
03375 return $retValue;
03376 }
03377 $query = "SELECT ezcontentobject.*,
03378 ezcontentobject_tree.*,
03379 ezcontentclass.serialized_name_list as class_serialized_name_list
03380 FROM ezcontentobject_tree,
03381 ezcontentobject,
03382 ezcontentclass
03383 WHERE contentobject_id=$contentobjectID AND
03384 ezcontentobject_tree.contentobject_id=ezcontentobject.id AND
03385 ezcontentclass.version=0 AND
03386 ezcontentclass.id = ezcontentobject.contentclass_id
03387 ORDER BY path_string";
03388 $db =& eZDB::instance();
03389 $nodesListArray = $db->arrayQuery( $query );
03390 if ( $asObject == true )
03391 {
03392 $nodes = eZContentObjectTreeNode::makeObjectsArray( $nodesListArray );
03393 return $nodes;
03394 }
03395 else
03396 return $nodesListArray;
03397 }
03398
03399
03400
03401
03402 function &mainNodeID()
03403 {
03404 if ( !is_numeric( $this->MainNodeID ) )
03405 {
03406 $mainNodeID = eZContentObjectTreeNode::findMainNode( $this->attribute( 'id' ) );
03407 $this->MainNodeID = $mainNodeID;
03408 }
03409 return $this->MainNodeID;
03410 }
03411
03412 function &mainNode()
03413 {
03414 $mainNode =& eZContentObjectTreeNode::findMainNode( $this->attribute( 'id' ), true );
03415 return $mainNode;
03416 }
03417
03418
03419
03420
03421 function setPermissions( $permissionArray )
03422 {
03423 $this->Permissions =& $permissionArray;
03424 }
03425
03426
03427
03428
03429 function permissions( )
03430 {
03431 return $this->Permissions;
03432 }
03433
03434 function &canEditLanguages()
03435 {
03436 $availableLanguages =& $this->availableLanguages();
03437 $languages = array();
03438
03439 foreach ( eZContentLanguage::prioritizedLanguages() as $language )
03440 {
03441 $languageCode = $language->attribute( 'locale' );
03442 if ( in_array( $languageCode, $availableLanguages ) &&
03443 $this->canEdit( false, false, false, $languageCode ) )
03444 {
03445 $languages[] = $language;
03446 }
03447 }
03448
03449 return $languages;
03450 }
03451
03452 function &canCreateLanguages()
03453 {
03454 $availableLanguages =& $this->availableLanguages();
03455 $languages = array();
03456 foreach ( eZContentLanguage::prioritizedLanguages() as $language )
03457 {
03458 $languageCode = $language->attribute( 'locale' );
03459 if ( !in_array( $languageCode, $availableLanguages ) &&
03460 $this->checkAccess( 'edit', false, false, false, $languageCode ) )
03461 {
03462 $languages[] = $language;
03463 }
03464 }
03465
03466 return $languages;
03467 }
03468
03469
03470
03471 function checkGroupLimitationAccess( $limitationValueList, $userID, $contentObjectID = false )
03472 {
03473 $access = 'denied';
03474
03475 if ( is_array( $limitationValueList ) && is_numeric( $userID ) )
03476 {
03477 if ( $contentObjectID !== false )
03478 {
03479 $contentObject =& eZContentObject::fetch( $contentObjectID );
03480 }
03481 else
03482 {
03483 $contentObject =& $this;
03484 }
03485
03486 if ( is_object( $contentObject ) )
03487 {
03488
03489 if ( in_array( 1, $limitationValueList ) )
03490 {
03491
03492 $ownerID = $contentObject->attribute( 'owner_id' );
03493 if ( $ownerID == $userID || $contentObject->attribute( 'id' ) == $userID )
03494 {
03495 $access = 'allowed';
03496 }
03497 else
03498 {
03499
03500 $userList =& eZContentObject::fetchIDArray( array( $userID, $ownerID ) );
03501
03502
03503 $groupList = array();
03504 foreach ( array_keys( $userList ) as $key )
03505 {
03506 $groupList[] =& $userList[$key]->attribute( 'parent_nodes' );
03507 }
03508
03509
03510
03511 $commonGroup = array_intersect( $groupList[0], $groupList[1] );
03512
03513 if ( count( $commonGroup ) > 0 )
03514 {
03515
03516 $access = 'allowed';
03517 }
03518 }
03519 }
03520 }
03521 }
03522
03523 return $access;
03524 }
03525
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535
03536
03537 function checkAccess( $functionName, $originalClassID = false, $parentClassID = false, $returnAccessList = false, $language = false )
03538 {
03539 $classID = $originalClassID;
03540 $user =& eZUser::currentUser();
03541 $userID = $user->attribute( 'contentobject_id' );
03542 $origFunctionName = $functionName;
03543
03544 include_once( 'kernel/classes/ezcontentlanguage.php' );
03545
03546
03547 $originalLanguage = $language;
03548 if ( is_string( $language ) && strlen( $language ) > 0 )
03549 {
03550 $language = eZContentLanguage::idByLocale( $language );
03551 }
03552 else
03553 {
03554 $language = false;
03555 }
03556
03557
03558
03559 $languageList = false;
03560
03561
03562
03563
03564 if ( $functionName == 'move' )
03565 $functionName = 'edit';
03566
03567 $accessResult = $user->hasAccessTo( 'content' , $functionName );
03568 $accessWord = $accessResult['accessWord'];
03569
03570
03571
03572
03573
03574
03575
03576
03577
03578
03579
03580
03581
03582
03583
03584
03585
03586
03587
03588
03589
03590
03591
03592
03593
03594
03595 if ( $origFunctionName == 'remove' or
03596 $origFunctionName == 'move' )
03597 {
03598 $mainNode =& $this->attribute( 'main_node' );
03599
03600
03601
03602 if ( $mainNode and $mainNode->attribute( 'parent_node_id' ) <= 1 )
03603 {
03604 return 0;
03605 }
03606 }
03607
03608 if ( $classID === false )
03609 {
03610 $classID = $this->attribute( 'contentclass_id' );
03611 }
03612 if ( $accessWord == 'yes' )
03613 {
03614 return 1;
03615 }
03616 else if ( $accessWord == 'no' )
03617 {
03618 if ( $functionName == 'edit' )
03619 {
03620
03621 if ( $this->attribute( 'current_version' ) == 1 && !$this->attribute( 'status' ) )
03622 {
03623 $mainNode = eZNodeAssignment::fetchForObject( $this->attribute( 'id' ), $this->attribute( 'current_version' ) );
03624 $parentObj = $mainNode[0]->attribute( 'parent_contentobject' );
03625 $result = $parentObj->checkAccess( 'create', $this->attribute( 'contentclass_id' ),
03626 $parentObj->attribute( 'contentclass_id' ), false, $originalLanguage );
03627 return $result;
03628 }
03629 else
03630 {
03631 return 0;
03632 }
03633 }
03634
03635 if ( $returnAccessList === false )
03636 {
03637 return 0;
03638 }
03639 else
03640 {
03641 return $accessResult['accessList'];
03642 }
03643 }
03644 else
03645 {
03646 $policies =& $accessResult['policies'];
03647 $access = 'denied';
03648 foreach ( array_keys( $policies ) as $pkey )
03649 {
03650 $limitationArray =& $policies[ $pkey ];
03651 if ( $access == 'allowed' )
03652 {
03653 break;
03654 }
03655
03656 $limitationList = array();
03657 if ( isset( $limitationArray['Subtree' ] ) )
03658 {
03659 $checkedSubtree = false;
03660 }
03661 else
03662 {
03663 $checkedSubtree = true;
03664 $accessSubtree = false;
03665 }
03666 if ( isset( $limitationArray['Node'] ) )
03667 {
03668 $checkedNode = false;
03669 }
03670 else
03671 {
03672 $checkedNode = true;
03673 $accessNode = false;
03674 }
03675 foreach ( array_keys( $limitationArray ) as $key )
03676 {
03677 $access = 'denied';
03678 switch( $key )
03679 {
03680 case 'Class':
03681 {
03682 if ( $functionName == 'create' and
03683 !$originalClassID )
03684 {
03685 $access = 'allowed';
03686 }
03687 else if ( $functionName == 'create' and
03688 in_array( $classID, $limitationArray[$key] ) )
03689 {
03690 $access = 'allowed';
03691 }
03692 else if ( $functionName != 'create' and
03693 in_array( $this->attribute( 'contentclass_id' ), $limitationArray[$key] ) )
03694 {
03695 $access = 'allowed';
03696 }
03697 else
03698 {
03699 $access = 'denied';
03700 $limitationList = array( 'Limitation' => $key,
03701 'Required' => $limitationArray[$key] );
03702 }
03703 } break;
03704
03705 case 'ParentClass':
03706 {
03707
03708 if ( in_array( $this->attribute( 'contentclass_id' ), $limitationArray[$key] ) )
03709 {
03710 $access = 'allowed';
03711 }
03712 else
03713 {
03714 $access = 'denied';
03715 $limitationList = array( 'Limitation' => $key,
03716 'Required' => $limitationArray[$key] );
03717 }
03718 } break;
03719
03720 case 'ParentDepth':
03721 {
03722 $assignedNodes =& $this->attribute( 'assigned_nodes' );
03723 if ( count( $assignedNodes ) > 0 )
03724 {
03725 foreach ( $assignedNodes as $assignedNode )
03726 {
03727 $depth =& $assignedNode->attribute( 'depth' );
03728 if ( in_array( $depth, $limitationArray[$key] ) )
03729 {
03730 $access = 'allowed';
03731 break;
03732 }
03733 }
03734 }
03735
03736 if ( $access != 'allowed' )
03737 {
03738 $access = 'denied';
03739 $limitationList = array( 'Limitation' => $key,
03740 'Required' => $limitationArray[$key] );
03741 }
03742 } break;
03743
03744 case 'Section':
03745 case 'User_Section':
03746 {
03747 if ( in_array( $this->attribute( 'section_id' ), $limitationArray[$key] ) )
03748 {
03749 $access = 'allowed';
03750 }
03751 else
03752 {
03753 $access = 'denied';
03754 $limitationList = array( 'Limitation' => $key,
03755 'Required' => $limitationArray[$key] );
03756 }
03757 } break;
03758
03759 case 'Language':
03760 {
03761 $languageMask = 0;
03762
03763
03764
03765 if ( $functionName == 'create' )
03766 {
03767
03768 if ( $language !== false )
03769 {
03770 $languageMask = $language;
03771 }
03772 else
03773 {
03774
03775
03776
03777 $languageMask = -1;
03778 }
03779 }
03780 else
03781 {
03782 if ( $language !== false )
03783 {
03784 if ( $languageList === false )
03785 {
03786 $languageMask = (int)$this->attribute( 'language_mask' );
03787
03788 $languageMask &= (int)$language;
03789
03790
03791
03792 if ( $languageMask == 0 )
03793 {
03794 $languageMask = $language;
03795 }
03796 }
03797 }
03798 else
03799 {
03800 $languageMask = -1;
03801 }
03802 }
03803
03804 $limitMask = eZContentLanguage::maskByLocale( $limitationArray[$key] );
03805 if ( ( $languageMask & $limitMask ) != 0 )
03806 {
03807 $access = 'allowed';
03808 }
03809 else
03810 {
03811 $access = 'denied';
03812 $limitationList = array( 'Limitation' => $key,
03813 'Required' => $limitationArray[$key] );
03814 }
03815 } break;
03816
03817 case 'Owner':
03818 {
03819
03820 if ( in_array( 2, $limitationArray[$key] ) &&
03821 $user->isAnonymous() )
03822 {
03823 include_once( 'kernel/classes/ezpreferences.php' );
03824 $createdObjectIDList = eZPreferences::value( 'ObjectCreationIDList' );
03825 if ( $createdObjectIDList &&
03826 in_array( $this->ID, unserialize( $createdObjectIDList ) ) )
03827 {
03828 $access = 'allowed';
03829 }
03830 }
03831 else if ( $this->attribute( 'owner_id' ) == $userID || $this->ID == $userID )
03832 {
03833 $access = 'allowed';
03834 }
03835 if ( $access != 'allowed' )
03836 {
03837 $access = 'denied';
03838 $limitationList = array ( 'Limitation' => $key, 'Required' => $limitationArray[$key] );
03839 }
03840 } break;
03841
03842 case 'Group':
03843 {
03844 $access = $this->checkGroupLimitationAccess( $limitationArray[$key], $userID );
03845
03846 if ( $access != 'allowed' )
03847 {
03848 $access = 'denied';
03849 $limitationList = array ( 'Limitation' => $key,
03850 'Required' => $limitationArray[$key] );
03851 }
03852 } break;
03853
03854 case 'Node':
03855 {
03856 $accessNode = false;
03857 $mainNodeID = $this->attribute( 'main_node_id' );
03858 foreach ( $limitationArray[$key] as $nodeID )
03859 {
03860 $node = eZContentObjectTreeNode::fetch( $nodeID, false, false );
03861 $limitationNodeID = $node['main_node_id'];
03862 if ( $mainNodeID == $limitationNodeID )
03863 {
03864 $access = 'allowed';
03865 $accessNode = true;
03866 break;
03867 }
03868 }
03869 if ( $access != 'allowed' && $checkedSubtree && !$accessSubtree )
03870 {
03871 $access = 'denied';
03872
03873 $limitationList = array( 'Limitation' => $key,
03874 'Required' => $limitationArray[$key] );
03875 }
03876 else
03877 {
03878 $access = 'allowed';
03879 }
03880 $checkedNode = true;
03881 } break;
03882
03883 case 'Subtree':
03884 {
03885 $accessSubtree = false;
03886 $assignedNodes = $this->attribute( 'assigned_nodes' );
03887 if ( count( $assignedNodes ) != 0 )
03888 {
03889 foreach ( $assignedNodes as $assignedNode )
03890 {
03891 $path = $assignedNode->attribute( 'path_string' );
03892 $subtreeArray = $limitationArray[$key];
03893 foreach ( $subtreeArray as $subtreeString )
03894 {
03895 if ( strstr( $path, $subtreeString ) )
03896 {
03897 $access = 'allowed';
03898 $accessSubtree = true;
03899 break;
03900 }
03901 }
03902 }
03903 }
03904 else
03905 {
03906 $parentNodes = $this->attribute( 'parent_nodes' );
03907 if ( count( $parentNodes ) == 0 )
03908 {
03909 if ( $this->attribute( 'owner_id' ) == $userID || $this->ID == $userID )
03910 {
03911 $access = 'allowed';
03912 $accessSubtree = true;
03913 }
03914 }
03915 else
03916 {
03917 foreach ( $parentNodes as $parentNode )
03918 {
03919 $parentNode = eZContentObjectTreeNode::fetch( $parentNode, false, false );
03920 $path = $parentNode['path_string'];
03921
03922 $subtreeArray = $limitationArray[$key];
03923 foreach ( $subtreeArray as $subtreeString )
03924 {
03925 if ( strstr( $path, $subtreeString ) )
03926 {
03927 $access = 'allowed';
03928 $accessSubtree = true;
03929 break;
03930 }
03931 }
03932 }
03933 }
03934 }
03935 if ( $access != 'allowed' && $checkedNode && !$accessNode )
03936 {
03937 $access = 'denied';
03938
03939 $limitationList = array( 'Limitation' => $key,
03940 'Required' => $limitationArray[$key] );
03941 }
03942 else
03943 {
03944 $access = 'allowed';
03945 }
03946 $checkedSubtree = true;
03947 } break;
03948
03949 case 'User_Subtree':
03950 {
03951 $assignedNodes = $this->attribute( 'assigned_nodes' );
03952 if ( count( $assignedNodes ) != 0 )
03953 {
03954 foreach ( $assignedNodes as $assignedNode )
03955 {
03956 $path = $assignedNode->attribute( 'path_string' );
03957 $subtreeArray = $limitationArray[$key];
03958 foreach ( $subtreeArray as $subtreeString )
03959 {
03960 if ( strstr( $path, $subtreeString ) )
03961 {
03962 $access = 'allowed';
03963 }
03964 }
03965 }
03966 }
03967 else
03968 {
03969 $parentNodes = $this->attribute( 'parent_nodes' );
03970 if ( count( $parentNodes ) == 0 )
03971 {
03972 if ( $this->attribute( 'owner_id' ) == $userID || $this->ID == $userID )
03973 {
03974 $access = 'allowed';
03975 }
03976 }
03977 else
03978 {
03979 foreach ( $parentNodes as $parentNode )
03980 {
03981 $parentNode = eZContentObjectTreeNode::fetch( $parentNode, false, false );
03982 $path = $parentNode['path_string'];
03983
03984 $subtreeArray = $limitationArray[$key];
03985 foreach ( $subtreeArray as $subtreeString )
03986 {
03987 if ( strstr( $path, $subtreeString ) )
03988 {
03989 $access = 'allowed';
03990 break;
03991 }
03992 }
03993 }
03994 }
03995 }
03996 if ( $access != 'allowed' )
03997 {
03998 $access = 'denied';
03999 $limitationList = array( 'Limitation' => $key,
04000 'Required' => $limitationArray[$key] );
04001 }
04002 } break;
04003 }
04004 if ( $access == 'denied' )
04005 {
04006 break;
04007 }
04008 }
04009
04010 $policyList[] = array( 'PolicyID' => $pkey,
04011 'LimitationList' => $limitationList );
04012 }
04013
04014 if ( $access == 'denied' )
04015 {
04016 if ( $functionName == 'edit' )
04017 {
04018
04019 if ( $this->attribute( 'current_version' ) == 1 && !$this->attribute( 'status' ) )
04020 {
04021 $mainNode = eZNodeAssignment::fetchForObject( $this->attribute( 'id' ), $this->attribute( 'current_version' ) );
04022 $parentObj = $mainNode[0]->attribute( 'parent_contentobject' );
04023 $result = $parentObj->checkAccess( 'create', $this->attribute( 'contentclass_id' ),
04024 $parentObj->attribute( 'contentclass_id' ), false, $originalLanguage );
04025 if ( $result )
04026 {
04027 $access = 'allowed';
04028 }
04029 return $result;
04030 }
04031 }
04032 }
04033
04034 if ( $access == 'denied' )
04035 {
04036 if ( $returnAccessList === false )
04037 {
04038 return 0;
04039 }
04040 else
04041 {
04042 return array( 'FunctionRequired' => array ( 'Module' => 'content',
04043 'Function' => $origFunctionName,
04044 'ClassID' => $classID,
04045 'MainNodeID' => $this->attribute( 'main_node_id' ) ),
04046 'PolicyList' => $policyList );
04047 }
04048 }
04049 else
04050 {
04051 return 1;
04052 }
04053 }
04054 }
04055
04056
04057
04058
04059
04060
04061 function classListFromPolicy( $policy, $allowedLanguageCodes = false )
04062 {
04063 $canCreateClassIDListPart = array();
04064 $hasClassIDLimitation = false;
04065 if ( isset( $policy['Class'] ) )
04066 {
04067 $canCreateClassIDListPart = $policy['Class'];
04068 $hasClassIDLimitation = true;
04069 }
04070
04071 if ( isset( $policy['User_Section'] ) )
04072 {
04073 if ( !in_array( $this->attribute( 'section_id' ), $policy['User_Section'] ) )
04074 {
04075 return array();
04076 }
04077 }
04078
04079 if ( isset( $policy['User_Subtree'] ) )
04080 {
04081 $allowed = false;
04082 $assignedNodes = $this->attribute( 'assigned_nodes' );
04083 foreach ( $assignedNodes as $assignedNode )
04084 {
04085 $path = $assignedNode->attribute( 'path_string' );
04086 foreach ( $policy['User_Subtree'] as $subtreeString )
04087 {
04088 if ( strstr( $path, $subtreeString ) )
04089 {
04090 $allowed = true;
04091 break;
04092 }
04093 }
04094 }
04095 if( !$allowed )
04096 {
04097 return array();
04098 }
04099 }
04100
04101 if ( isset( $policy['Section'] ) )
04102 {
04103 if ( !in_array( $this->attribute( 'section_id' ), $policy['Section'] ) )
04104 {
04105 return array();
04106 }
04107 }
04108
04109 if ( isset( $policy['ParentClass'] ) )
04110 {
04111 if ( !in_array( $this->attribute( 'contentclass_id' ), $policy['ParentClass'] ) )
04112 {
04113 return array();
04114 }
04115 }
04116
04117 if ( isset( $policy['Assigned'] ) )
04118 {
04119 if ( $this->attribute( 'owner_id' ) != $user->attribute( 'contentobject_id' ) )
04120 {
04121 return array();
04122 }
04123 }
04124
04125 $allowedNode = false;
04126 if ( isset( $policy['Node'] ) )
04127 {
04128 $allowed = false;
04129 foreach( $policy['Node'] as $nodeID )
04130 {
04131 $mainNodeID = $this->attribute( 'main_node_id' );
04132 $node = eZContentObjectTreeNode::fetch( $nodeID, false, false );
04133 if ( $mainNodeID == $node['main_node_id'] )
04134 {
04135 $allowed = true;
04136 $allowedNode = true;
04137 break;
04138 }
04139 }
04140 if ( !$allowed && !isset( $policy['Subtree'] ) )
04141 {
04142 return array();
04143 }
04144 }
04145
04146 if ( isset( $policy['Subtree'] ) )
04147 {
04148 $allowed = false;
04149 $assignedNodes = $this->attribute( 'assigned_nodes' );
04150 foreach ( $assignedNodes as $assignedNode )
04151 {
04152 $path = $assignedNode->attribute( 'path_string' );
04153 foreach ( $policy['Subtree'] as $subtreeString )
04154 {
04155 if ( strstr( $path, $subtreeString ) )
04156 {
04157 $allowed = true;
04158 break;
04159 }
04160 }
04161 }
04162 if ( !$allowed && !$allowedNode )
04163 {
04164 return array();
04165 }
04166 }
04167
04168 if ( isset( $policy['Language'] ) )
04169 {
04170 if ( $allowedLanguageCodes )
04171 {
04172 $allowedLanguageCodes = array_intersect( $allowedLanguageCodes, $policy['Language'] );
04173 }
04174 else
04175 {
04176 $allowedLanguageCodes = $policy['Language'];
04177 }
04178 }
04179
04180 if ( $hasClassIDLimitation )
04181 {
04182 return array( 'classes' => $canCreateClassIDListPart, 'language_codes' => $allowedLanguageCodes );
04183 }
04184 return array( 'classes' => '*', 'language_codes' => $allowedLanguageCodes );
04185 }
04186
04187
04188
04189
04190
04191
04192
04193
04194
04195
04196
04197
04198
04199
04200
04201
04202
04203
04204
04205
04206
04207
04208 function &canCreateClassList( $asObject = false, $includeFilter = true, $groupList = false, $fetchID = false )
04209 {
04210 $ini =& eZINI::instance();
04211 $groupArray = array();
04212 $languageCodeList = eZContentLanguage::fetchLocaleList();
04213 $allowedLanguages = array( '*' => array() );
04214
04215 $user =& eZUser::currentUser();
04216 $accessResult = $user->hasAccessTo( 'content' , 'create' );
04217 $accessWord = $accessResult['accessWord'];
04218
04219 $classIDArray = array();
04220 $classList = array();
04221 $fetchAll = false;
04222 if ( $accessWord == 'yes' )
04223 {
04224 $fetchAll = true;
04225 $allowedLanguages['*'] = $languageCodeList;
04226 }
04227 else if ( $accessWord == 'no' )
04228 {
04229
04230 return $classList;
04231 }
04232 else
04233 {
04234 $policies = $accessResult['policies'];
04235 foreach ( $policies as $policyKey => $policy )
04236 {
04237 $policyArray = $this->classListFromPolicy( $policy, $languageCodeList );
04238 if ( count( $policyArray ) == 0 )
04239 {
04240 continue;
04241 }
04242 $classIDArrayPart = $policyArray['classes'];
04243 $languageCodeArrayPart = $policyArray['language_codes'];
04244 if ( $classIDArrayPart == '*' )
04245 {
04246 $fetchAll = true;
04247 $allowedLanguages['*'] = array_unique( array_merge( $allowedLanguages['*'], $languageCodeArrayPart ) );
04248 }
04249 else
04250 {
04251 foreach( $classIDArrayPart as $class )
04252 {
04253 if ( isset( $allowedLanguages[$class] ) )
04254 {
04255 $allowedLanguages[$class] = array_unique( array_merge( $allowedLanguages[$class], $languageCodeArrayPart ) );
04256 }
04257 else
04258 {
04259 $allowedLanguages[$class] = $languageCodeArrayPart;
04260 }
04261 }
04262 $classIDArray = array_merge( $classIDArray, array_diff( $classIDArrayPart, $classIDArray ) );
04263 }
04264 }
04265 }
04266
04267 $filterTableSQL = '';
04268 $filterSQL = '';
04269
04270 if ( is_array( $groupList ) )
04271 {
04272 $filterTableSQL = ', ezcontentclass_classgroup ccg';
04273 $filterSQL = ( " AND\n" .
04274 " cc.id = ccg.contentclass_id AND\n" .
04275 " ccg.group_id " );
04276 $groupText = implode( ', ', $groupList );
04277 if ( $includeFilter )
04278 $filterSQL .= "IN ( $groupText )";
04279 else
04280 $filterSQL .= "NOT IN ( $groupText )";
04281 }
04282
04283 $classNameFilter = eZContentClassName::sqlFilter( 'cc' );
04284
04285 if ( $fetchAll )
04286 {
04287 $classList = array();
04288 $db =& eZDb::instance();
04289
04290 $fields = $asObject ? "cc.*, $classNameFilter[nameField]" : "cc.id, $classNameFilter[nameField]";
04291 $rows = $db->arrayQuery( "SELECT DISTINCT $fields\n" .
04292 "FROM ezcontentclass cc$filterTableSQL, $classNameFilter[from]\n" .
04293 "WHERE cc.version = " . EZ_CLASS_VERSION_STATUS_DEFINED . " $filterSQL AND $classNameFilter[where]\n" .
04294 "ORDER BY $classNameFilter[nameField] ASC" );
04295 $classList = eZPersistentObject::handleRows( $rows, 'ezcontentclass', $asObject );
04296 }
04297 else
04298 {
04299
04300 if ( count( $classIDArray ) == 0 )
04301 {
04302 $classList = array();
04303 return $classList;
04304 }
04305
04306 $classList = array();
04307 $db =& eZDb::instance();
04308 $classString = implode( ',', $classIDArray );
04309
04310 $fields = $asObject ? "cc.*, $classNameFilter[nameField]" : "cc.id, $classNameFilter[nameField]";
04311 $rows = $db->arrayQuery( "SELECT DISTINCT $fields\n" .
04312 "FROM ezcontentclass cc$filterTableSQL, $classNameFilter[from]\n" .
04313 "WHERE cc.id IN ( $classString ) AND\n" .
04314 " cc.version = " . EZ_CLASS_VERSION_STATUS_DEFINED . " $filterSQL AND $classNameFilter[where]\n" .
04315 "ORDER BY $classNameFilter[nameField] ASC" );
04316 $classList = eZPersistentObject::handleRows( $rows, 'ezcontentclass', $asObject );
04317 }
04318
04319 if ( $asObject )
04320 {
04321 foreach ( $classList as $key => $class )
04322 {
04323 $id = $class->attribute( 'id' );
04324 if ( isset( $allowedLanguages[$id] ) )
04325 {
04326 $languageCodes = array_unique( array_merge( $allowedLanguages['*'], $allowedLanguages[$id] ) );
04327 }
04328 else
04329 {
04330 $languageCodes = $allowedLanguages['*'];
04331 }
04332 $classList[$key]->setCanInstantiateLanguages( $languageCodes );
04333 }
04334 }
04335
04336 eZDebugSetting::writeDebug( 'kernel-content-class', $classList, "class list fetched from db" );
04337 return $classList;
04338 }
04339
04340
04341
04342
04343
04344
04345
04346
04347
04348
04349
04350 function accessList( $function )
04351 {
04352 switch( $function )
04353 {
04354 case 'read':
04355 {
04356 return $this->checkAccess( 'read', false, false, true );
04357 } break;
04358
04359 case 'edit':
04360 {
04361 return $this->checkAccess( 'edit', false, false, true );
04362 } break;
04363 }
04364 return 0;
04365 }
04366
04367
04368
04369
04370
04371
04372 function &canRead( )
04373 {
04374 if ( !isset( $this->Permissions["can_read"] ) )
04375 {
04376 $this->Permissions["can_read"] = $this->checkAccess( 'read' );
04377 }
04378 $p = ( $this->Permissions["can_read"] == 1 );
04379 return $p;
04380 }
04381
04382
04383
04384
04385
04386
04387 function &canPdf( )
04388 {
04389 if ( !isset( $this->Permissions["can_pdf"] ) )
04390 {
04391 $this->Permissions["can_pdf"] = $this->checkAccess( 'pdf' );
04392 }
04393 $p = ( $this->Permissions["can_pdf"] == 1 );
04394 return $p;
04395 }
04396
04397
04398
04399
04400
04401
04402
04403 function &canViewEmbed( )
04404 {
04405 if ( !isset( $this->Permissions["can_view_embed"] ) )
04406 {
04407 $this->Permissions["can_view_embed"] = $this->checkAccess( 'view_embed' );
04408 }
04409 $p = ( $this->Permissions["can_view_embed"] == 1 );
04410 return $p;
04411 }
04412
04413
04414
04415
04416
04417
04418 function &canDiff( )
04419 {
04420 if ( !isset( $this->Permissions["can_diff"] ) )
04421 {
04422 $this->Permissions["can_diff"] = $this->checkAccess( 'diff' );
04423 }
04424 $p = ( $this->Permissions["can_diff"] == 1 );
04425 return $p;
04426 }
04427
04428
04429
04430
04431
04432 function &canCreate( )
04433 {
04434 if ( !isset( $this->Permissions["can_create"] ) )
04435 {
04436 $this->Permissions["can_create"] = $this->checkAccess( 'create' );
04437 }
04438 $p = ( $this->Permissions["can_create"] == 1 );
04439 return $p;
04440 }
04441
04442
04443
04444
04445
04446 function &canEdit( $originalClassID = false, $parentClassID = false, $returnAccessList = false, $language = false )
04447 {
04448 $isCalledClean = ( func_num_args() == 0 );
04449 if ( isset( $this->Permissions["can_edit"] ) && $isCalledClean )
04450 {
04451 $canEdit = $this->Permissions["can_edit"];
04452 }
04453 else
04454 {
04455 $canEdit = $this->checkAccess( 'edit', $originalClassID, $parentClassID, $returnAccessList, $language );
04456 if ( $canEdit != 1 )
04457 {
04458 $user =& eZUser::currentUser();
04459 if ( $user->attribute( 'contentobject_id' ) === $this->attribute( 'id' ) )
04460 {
04461 $access = $user->hasAccessTo( 'user', 'selfedit' );
04462 if ( $access['accessWord'] == 'yes' )
04463 {
04464 $canEdit = 1;
04465 }
04466 }
04467 }
04468
04469 if ( $isCalledClean )
04470 {
04471 $this->Permissions["can_edit"] = $canEdit;
04472 }
04473 }
04474 $p = ( $canEdit == 1 );
04475 return $p;
04476 }
04477
04478
04479
04480
04481
04482 function &canTranslate( )
04483 {
04484 if ( !isset( $this->Permissions["can_translate"] ) )
04485 {
04486 $this->Permissions["can_translate"] = $this->checkAccess( 'translate' );
04487 if ( $this->Permissions["can_translate"] != 1 )
04488 {
04489 $user =& eZUser::currentUser();
04490 if ( $user->id() == $this->attribute( 'id' ) )
04491 {
04492 $access = $user->hasAccessTo( 'user', 'selfedit' );
04493 if ( $access['accessWord'] == 'yes' )
04494 {
04495 $this->Permissions["can_translate"] = 1;
04496 }
04497 }
04498 }
04499 }
04500 $p = ( $this->Permissions["can_translate"] == 1 );
04501 return $p;
04502 }
04503
04504
04505
04506
04507
04508 function &canRemove( )
04509 {
04510
04511 if ( !isset( $this->Permissions["can_remove"] ) )
04512 {
04513 $this->Permissions["can_remove"] = $this->checkAccess( 'remove' );
04514 }
04515 $p = ( $this->Permissions["can_remove"] == 1 );
04516 return $p;
04517 }
04518
04519
04520
04521
04522
04523
04524
04525
04526
04527 function &canMove( )
04528 {
04529 return $this->canMoveFrom();
04530 }
04531
04532
04533
04534
04535
04536
04537
04538
04539 function &canMoveFrom( )
04540 {
04541
04542 if ( !isset( $this->Permissions['can_move_from'] ) )
04543 {
04544 $this->Permissions['can_move_from'] = $this->checkAccess( 'edit' ) && $this->checkAccess( 'remove' );
04545 }
04546 $p = ( $this->Permissions['can_move_from'] == 1 );
04547 return $p;
04548 }
04549
04550
04551
04552
04553
04554
04555 function &className()
04556 {
04557 if ( !is_numeric( $this->ClassID ) )
04558 {
04559 $retValue = null;
04560 return $retValue;
04561 }
04562
04563 if ( $this->ClassName !== false )
04564 return $this->ClassName;
04565
04566 $db =& eZDB::instance();
04567 $id = (int)$this->ClassID;
04568 $sql = "SELECT serialized_name_list FROM ezcontentclass WHERE id=$id and version=0";
04569 $rows = $db->arrayQuery( $sql );
04570 if ( count( $rows ) > 0 )
04571 {
04572 $this->ClassName = eZContentClass::nameFromSerializedString( $rows[0]['serialized_name_list'] );
04573 }
04574 return $this->ClassName;
04575 }
04576
04577
04578
04579
04580
04581 function &contentActionList()
04582 {
04583 $version = $this->attribute( 'current_version' );
04584 $language = $this->initialLanguageCode();
04585 if ( !isset( $this->ContentObjectAttributeArray[$version][$language] ) )
04586 {
04587 $attributeList =& $this->contentObjectAttributes();
04588 $this->ContentObjectAttributeArray[$version][$language] =& $attributeList;
04589 }
04590 else
04591 $attributeList =& $this->ContentObjectAttributeArray[$version][$language];
04592
04593
04594 if ( $this->ContentActionList === false )
04595 {
04596
04597 $contentActionList = array();
04598 foreach ( $attributeList as $attribute )
04599 {
04600 $contentActions =& $attribute->contentActionList();
04601 if ( count( $contentActions ) > 0 )
04602 {
04603 $contentActionList = $attribute->contentActionList();
04604
04605 if ( is_array( $contentActionList ) )
04606 {
04607 foreach ( $contentActionList as $action )
04608 {
04609 if ( !$this->hasContentAction( $action['action'] ) )
04610 {
04611 $this->ContentActionList[] = $action;
04612 }
04613 }
04614 }
04615 }
04616 }
04617 }
04618 return $this->ContentActionList;
04619 }
04620
04621
04622
04623
04624 function hasContentAction( $name )
04625 {
04626 $return = false;
04627 if ( is_array ( $this->ContentActionList ) )
04628 {
04629 foreach ( $this->ContentActionList as $action )
04630 {
04631 if ( $action['action'] == $name )
04632 {
04633 $return = true;
04634 }
04635 }
04636 }
04637 return $return;
04638 }
04639
04640
04641
04642
04643
04644
04645
04646
04647 function &availableLanguages()
04648 {
04649 $languages = array();
04650 $languageObjects = $this->languages();
04651
04652 foreach ( $languageObjects as $languageObject )
04653 {
04654 $languages[] = $languageObject->attribute( 'locale' );
04655 }
04656
04657 return $languages;
04658 }
04659
04660 function &availableLanguagesJsArray()
04661 {
04662 $jsArray = eZContentLanguage::jsArrayByMask( $this->LanguageMask );
04663 return $jsArray;
04664 }
04665
04666 function &languages()
04667 {
04668 $languages = isset( $this->LanguageMask ) ? eZContentLanguage::prioritizedLanguagesByMask( $this->LanguageMask ) : array();
04669
04670 return $languages;
04671 }
04672
04673 function &allLanguages()
04674 {
04675 $languages = isset( $this->LanguageMask ) ? eZContentLanguage::languagesByMask( $this->LanguageMask ) : array();
04676 return $languages;
04677 }
04678
04679 function &defaultLanguage()
04680 {
04681 if ( ! isset( $GLOBALS['eZContentObjectDefaultLanguage'] ) )
04682 {
04683 $defaultLanguage = false;
04684 $language = eZContentLanguage::topPriorityLanguage();
04685 if ( $language )
04686 {
04687 $defaultLanguage = $language->attribute( 'locale' );
04688 }
04689 else
04690 {
04691 $ini =& eZINI::instance();
04692 if ( $ini->hasVariable( 'RegionalSettings', 'ContentObjectLocale' ) )
04693 {
04694 $defaultLanguage = $ini->variable( 'RegionalSettings', 'ContentObjectLocale' );
04695 eZContentLanguage::fetchByLocale( $defaultLanguage, true );
04696 }
04697 }
04698 $GLOBALS['eZContentObjectDefaultLanguage'] = $defaultLanguage;
04699 }
04700
04701 return $GLOBALS['eZContentObjectDefaultLanguage'];
04702 }
04703
04704
04705
04706
04707
04708
04709
04710
04711 function setDefaultLanguage( $lang )
04712 {
04713 return false;
04714 }
04715
04716
04717
04718
04719 function setClassName( $name )
04720 {
04721 $this->ClassName = $name;
04722 }
04723
04724
04725
04726
04727
04728
04729 function translationStringList()
04730 {
04731 $translationList = array();
04732 $languageList = eZContentLanguage::fetchList();
04733
04734 foreach ( $languageList as $language )
04735 {
04736 $translationList[] = $language->attribute( 'locale' );
04737 }
04738
04739 return $translationList;
04740 }
04741
04742
04743
04744
04745
04746
04747 function translationList()
04748 {
04749 $translationList = array();
04750 $languageList = eZContentLanguage::fetchList();
04751
04752 foreach ( $languageList as $language )
04753 {
04754 $translationList[] = $language->localeObject();
04755 }
04756
04757 return $translationList;
04758 }
04759
04760
04761
04762
04763
04764
04765 function &fetchClassAttributes( $version = 0, $asObject = true )
04766 {
04767 $classAttributesList =& eZContentClassAttribute::fetchListByClassID( $this->attribute( 'contentclass_id' ), $version, $asObject );
04768 return $classAttributesList;
04769 }
04770
04771
04772
04773
04774
04775
04776
04777 function mapLanguage( $language, $options )
04778 {
04779 if ( isset( $options['language_map'][$language] ) )
04780 {
04781 return $options['language_map'][$language];
04782 }
04783 return $language;
04784 }
04785
04786
04787
04788
04789
04790
04791
04792
04793
04794
04795
04796
04797
04798
04799
04800 function &unserialize( &$package, &$domNode, &$options, $ownerID = false, $handlerType = 'ezcontentobject' )
04801 {
04802 if ( $domNode->name() != 'object' )
04803 {
04804 $retValue = false;
04805 return $retValue;
04806 }
04807
04808 $sectionID = $domNode->attributeValue( 'section_id' );
04809 if ( $ownerID === false )
04810 {
04811 $ownerID = $domNode->attributeValue( 'owner_id' );
04812 }
04813 $remoteID = $domNode->attributeValue( 'remote_id' );
04814 $name = $domNode->attributeValue( 'name' );
04815 $classRemoteID = $domNode->attributeValue( 'class_remote_id' );
04816 $classIdentifier = $domNode->attributeValue( 'class_identifier' );
04817 $initialLanguage = eZContentObject::mapLanguage( $domNode->attributeValue( 'initial_language' ), $options );
04818 $alwaysAvailable = ( $domNode->attributeValue( 'always_available' ) == '1' );
04819
04820 $contentClass = eZContentClass::fetchByRemoteID( $classRemoteID );
04821 if ( !$contentClass )
04822 {
04823 $contentClass = eZContentClass::fetchByIdentifier( $classIdentifier );
04824 }
04825
04826 if ( !$contentClass )
04827 {
04828 $options['error'] = array( 'error_code' => EZ_PACKAGE_CONTENTOBJECT_ERROR_NO_CLASS,
04829 'element_id' => $remoteID,
04830 'description' => "Can't install object '$name': Unable to fetch class with remoteID: $classRemoteID." );
04831 $retValue = false;
04832 return $retValue;
04833 }
04834
04835 $versionListNode =& $domNode->elementByName( 'version-list' );
04836
04837 $importedLanguages = array();
04838 foreach( $versionListNode->elementsByName( 'version' ) as $versionDOMNode )
04839 {
04840 foreach ( $versionDOMNode->children() as $versionDOMNodeChild )
04841 {
04842 if ( $versionDOMNodeChild->name() != 'object-translation' )
04843 {
04844 continue;
04845 }
04846 $importedLanguage = eZContentObject::mapLanguage( $versionDOMNodeChild->attributeValue( 'language' ), $options );
04847 $language = eZContentLanguage::fetchByLocale( $importedLanguage );
04848
04849 if ( $language )
04850 {
04851 $hasTranslation = true;
04852 }
04853 else
04854 {
04855
04856 $locale =& eZLocale::instance( $importedLanguage );
04857 $translationName = $locale->internationalLanguageName();
04858 $translationLocale = $locale->localeCode();
04859
04860 if ( $locale->isValid() )
04861 {
04862 eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() );
04863 $hasTranslation = true;
04864 }
04865 else
04866 $hasTranslation = false;
04867 }
04868 if ( $hasTranslation )
04869 {
04870 $importedLanguages[] = $importedLanguage;
04871 $importedLanguages = array_unique( $importedLanguages );
04872 }
04873 }
04874 }
04875
04876
04877
04878
04879 $contentObject =& eZContentObject::fetchByRemoteID( $remoteID );
04880
04881 if ( !$initialLanguage ||
04882 !in_array( $initialLanguage, $importedLanguages ) )
04883 {
04884 $initialLanguage = false;
04885 foreach ( eZContentLanguage::prioritizedLanguages() as $language )
04886 {
04887 if ( in_array( $language->attribute( 'locale' ), $importedLanguages ) )
04888 {
04889 $initialLanguage = $language->attribute( 'locale' );
04890 break;
04891 }
04892 }
04893 }
04894 if ( !$contentObject )
04895 {
04896 $firstVersion = true;
04897 $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID );
04898 }
04899 else
04900 {
04901 $firstVersion = false;
04902 $description = "Object '$name' already exists.";
04903
04904 include_once( 'kernel/classes/ezpackagehandler.php' );
04905 $choosenAction = eZPackageHandler::errorChoosenAction( EZ_PACKAGE_CONTENTOBJECT_ERROR_EXISTS,
04906 $options, $description, $handlerType, false );
04907
04908 switch( $choosenAction )
04909 {
04910 case EZ_PACKAGE_NON_INTERACTIVE:
04911 {
04912
04913 } break;
04914
04915 case EZ_PACKAGE_CONTENTOBJECT_REPLACE:
04916 {
04917 include_once( 'kernel/classes/ezcontentobjectoperations.php' );
04918 eZContentObjectOperations::remove( $contentObject->attribute( 'id' ) );
04919
04920 unset( $contentObject );
04921 $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID );
04922 $firstVersion = true;
04923 } break;
04924
04925 case EZ_PACKAGE_CONTENTOBJECT_SKIP:
04926 {
04927 $retValue = true;
04928 return $retValue;
04929 } break;
04930
04931 case EZ_PACKAGE_CONTENTOBJECT_NEW:
04932 {
04933 $contentObject->setAttribute( 'remote_id', md5( (string)mt_rand() . (string)mktime() ) );
04934 $contentObject->store();
04935 unset( $contentObject );
04936 $contentObject = $contentClass->instantiate( $ownerID, $sectionID );
04937 $firstVersion = true;
04938 } break;
04939
04940 default:
04941 {
04942 $options['error'] = array( 'error_code' => EZ_PACKAGE_CONTENTOBJECT_ERROR_EXISTS,
04943 'element_id' => $remoteID,
04944 'description' => $description,
04945 'actions' => array( EZ_PACKAGE_CONTENTOBJECT_REPLACE => 'Replace existing object',
04946 EZ_PACKAGE_CONTENTOBJECT_SKIP => 'Skip object',
04947 EZ_PACKAGE_CONTENTOBJECT_NEW => 'Keep existing and create a new one' ) );
04948 $retValue = false;
04949 return $retValue;
04950 } break;
04951 }
04952 }
04953
04954 $db =& eZDB::instance();
04955 $db->begin();
04956
04957 if ( $alwaysAvailable )
04958 {
04959
04960 $contentObject->setAttribute( 'language_mask', (int)$contentObject->attribute( 'language_mask' ) | 1 );
04961 }
04962 $contentObject->store();
04963 $activeVersion = false;
04964 $lastVersion = false;
04965 $versionListActiveVersion = $versionListNode->attributeValue( 'active_version' );
04966
04967 $contentObject->setAttribute( 'remote_id', $remoteID );
04968 $contentObject->setAttribute( 'contentclass_id', $contentClass->attribute( 'id' ) );
04969 $contentObject->store();
04970
04971 $options['language_array'] = $importedLanguages;
04972 $versionList = array();
04973 foreach( $versionListNode->elementsByName( 'version' ) as $versionDOMNode )
04974 {
04975 unset( $nodeList );
04976 $nodeList = array();
04977 $contentObjectVersion = eZContentObjectVersion::unserialize( $versionDOMNode,
04978 $contentObject,
04979 $ownerID,
04980 $sectionID,
04981 $versionListActiveVersion,
04982 $firstVersion,
04983 $nodeList,
04984 $options,
04985 $package );
04986
04987 if ( !$contentObjectVersion )
04988 {
04989 $db->commit();
04990
04991 $retValue = false;
04992 return $retValue;
04993 }
04994
04995 $versionStatus = $versionDOMNode->attributeValue( 'status' );
04996 $versionList[$versionDOMNode->attributeValue( 'version' )] = array( 'node_list' => $nodeList,
04997 'status' => $versionStatus );
04998 unset( $versionStatus );
04999
05000 $firstVersion = false;
05001 $lastVersion = $contentObjectVersion->attribute( 'version' );
05002 if ( $versionDOMNode->attributeValue( 'version' ) == $versionListActiveVersion )
05003 {
05004 $activeVersion = $contentObjectVersion->attribute( 'version' );
05005 }
05006 eZNodeAssignment::setNewMainAssignment( $contentObject->attribute( 'id' ), $lastVersion );
05007
05008 include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
05009 eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ),
05010 'version' => $lastVersion ) );
05011
05012 $mainNodeInfo = null;
05013 foreach ( $nodeList as $nodeInfo )
05014 {
05015 if ( $nodeInfo['is_main'] )
05016 {
05017 $mainNodeInfo =& $nodeInfo;
05018 break;
05019 }
05020 }
05021 if ( $mainNodeInfo )
05022 {
05023 $existingMainNode = eZContentObjectTreeNode::fetchByRemoteID( $mainNodeInfo['parent_remote_id'], false );
05024 if ( $existingMainNode )
05025 {
05026 eZContentObjectTreeNode::updateMainNodeID( $existingMainNode['node_id'],
05027 $mainNodeInfo['contentobject_id'],
05028 $mainNodeInfo['contentobject_version'],
05029 $mainNodeInfo['parent_node'] );
05030 }
05031 }
05032 unset( $mainNodeInfo );
05033
05034 $contentObject =& eZContentObject::fetch( $contentObject->attribute( 'id' ) );
05035 }
05036 if ( !$activeVersion )
05037 {
05038 $activeVersion = $lastVersion;
05039 }
05040
05041
05042
05043
05044 $contentObject->setAttribute( 'name', $name );
05045 $contentObject->store();
05046
05047 $versions =& $contentObject->versions();
05048 $objectName =& $contentObject->name();
05049 $objectID =& $contentObject->attribute( 'id' );
05050 foreach ( $versions as $version )
05051 {
05052 $versionNum = $version->attribute( 'version' );
05053 $oldVersionStatus = $version->attribute( 'status' );
05054 $newVersionStatus = isset( $versionList[$versionNum] ) ? $versionList[$versionNum]['status'] : null;
05055
05056
05057 if ( isset( $newVersionStatus ) && $oldVersionStatus != $newVersionStatus && $newVersionStatus != EZ_VERSION_STATUS_PUBLISHED )
05058 {
05059 $version->setAttribute( 'status', $newVersionStatus );
05060 $version->store( array( 'status' ) );
05061 }
05062
05063
05064 $translations =& $version->translations( false );
05065 if ( !$translations )
05066 continue;
05067 foreach ( $translations as $translation )
05068 {
05069 if ( ! $contentObject->name( $versionNum, $translation ) )
05070 {
05071 eZDebug::writeNotice( "Setting name '$objectName' for version ($versionNum) of the content object ($objectID) in language($translation)" );
05072 $contentObject->setName( $objectName, $versionNum, $translation );
05073 }
05074 }
05075 }
05076
05077 foreach ( $versionList[$versionListActiveVersion]['node_list'] as $nodeInfo )
05078 {
05079 unset( $parentNode );
05080 $parentNode = eZContentObjectTreeNode::fetchNode( $contentObject->attribute( 'id' ),
05081 $nodeInfo['parent_node'] );
05082 if ( is_object( $parentNode ) )
05083 {
05084 $parentNode->setAttribute( 'priority', $nodeInfo['priority'] );
05085 $parentNode->store( array( 'priority' ) );
05086 }
05087 }
05088
05089
05090
05091
05092
05093
05094
05095
05096
05097
05098
05099
05100
05101
05102
05103
05104
05105
05106
05107 $db->commit();
05108
05109 return $contentObject;
05110 }
05111
05112
05113
05114
05115
05116
05117 function postUnserialize( &$package )
05118 {
05119 $versions =& $this->versions();
05120 foreach( array_keys( $versions ) as $key )
05121 {
05122 $version = &$versions[$key];
05123 $version->postUnserialize( $package );
05124 }
05125 }
05126
05127
05128
05129
05130
05131
05132
05133
05134
05135
05136
05137
05138
05139 function serialize( &$package, $specificVersion = false, $options = false, $contentNodeIDArray = false, $topNodeIDArray = false )
05140 {
05141 if ( $options &&
05142 $options['node_assignment'] == 'main' )
05143 {
05144 if ( !isset( $contentNodeIDArray[$this->attribute( 'main_node_id' )] ) )
05145 {
05146 return false;
05147 }
05148 }
05149
05150 include_once( 'lib/ezlocale/classes/ezdateutils.php' );
05151 include_once( 'lib/ezxml/classes/ezdomdocument.php' );
05152 include_once( 'lib/ezxml/classes/ezdomnode.php' );
05153 $objectNode = new eZDOMNode();
05154
05155 $objectNode->setName( 'object' );
05156 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'ezremote', 'http://ez.no/ezobject', 'xmlns' ) );
05157 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'id', $this->ID, 'ezremote' ) );
05158 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'name', $this->Name ) );
05159 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'section_id', $this->SectionID, 'ezremote' ) );
05160 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'owner_id', $this->OwnerID, 'ezremote' ) );
05161 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'class_id', $this->ClassID, 'ezremote' ) );
05162 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'published', eZDateUtils::rfc1123Date( $this->attribute( 'published' ) ), 'ezremote' ) );
05163 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'modified', eZDateUtils::rfc1123Date( $this->attribute( 'modified' ) ), 'ezremote' ) );
05164 if ( !$this->attribute( 'remote_id' ) )
05165 {
05166 $this->setAttribute( 'remote_id', md5( (string)mt_rand() ) . (string)mktime() );
05167 $this->store();
05168 }
05169 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'remote_id', $this->attribute( 'remote_id' ) ) );
05170 $contentClass =& $this->attribute( 'content_class' );
05171 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'class_remote_id', $contentClass->attribute( 'remote_id' ) ) );
05172 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'class_identifier', $contentClass->attribute( 'identifier' ), 'ezremote' ) );
05173 $alwaysAvailableText = '0';
05174 if ( (int)$this->attribute( 'language_mask' ) & 1 )
05175 {
05176 $alwaysAvailableText = '1';
05177 }
05178 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'always_available', $alwaysAvailableText, 'ezremote' ) );
05179
05180 $versions = array();
05181 $oneLanguagePerVersion = false;
05182 if ( $specificVersion === false )
05183 {
05184 $versions =& $this->versions();
05185
05186
05187
05188 }
05189 else if ( $specificVersion === true )
05190 {
05191 $versions[] = $this->currentVersion();
05192 }
05193 else
05194 {
05195 $versions[] = $this->version( $specificVersion );
05196
05197
05198 $oneLanguagePerVersion = true;
05199 }
05200
05201 $this->fetchClassAttributes();
05202
05203 $exportedLanguages = array();
05204
05205 $versionsNode = new eZDOMNode();
05206 $versionsNode->setName( 'version-list' );
05207 $versionsNode->appendAttribute( eZDOMDocument::createAttributeNode( 'active_version', $this->CurrentVersion ) );
05208 $versionsNode->appendAttribute( eZDOMDocument::createAttributeNamespaceDefNode( "ezobject", "http://ez.no/object/" ) );
05209 foreach ( $versions as $version )
05210 {
05211 if ( !$version )
05212 {
05213 continue;
05214 }
05215 $options['only_initial_language'] = $oneLanguagePerVersion;
05216 $versionNode = $version->serialize( $package, $options, $contentNodeIDArray, $topNodeIDArray );
05217 if ( $versionNode )
05218 {
05219 $versionsNode->appendChild( $versionNode );
05220 foreach ( $versionNode->children() as $versionNodeChild )
05221 {
05222 if ( $versionNodeChild->name() != 'object-translation' )
05223 {
05224 continue;
05225 }
05226 $exportedLanguage = $versionNodeChild->attributeValue( 'language' );
05227 $exportedLanguages[] = $exportedLanguage;
05228 $exportedLanguages = array_unique( $exportedLanguages );
05229 }
05230 }
05231 unset( $versionNode );
05232 unset( $versionNode );
05233 }
05234 $initialLanguageCode = $this->attribute( 'initial_language_code' );
05235 if ( in_array( $initialLanguageCode, $exportedLanguages ) )
05236 {
05237 $objectNode->appendAttribute( eZDOMDocument::createAttributeNode( 'initial_language', $initialLanguageCode ) );
05238 }
05239 $objectNode->appendChild( $versionsNode );
05240 return $objectNode;
05241 }
05242
05243
05244
05245
05246 function cacheInfo( $Params )
05247 {
05248 $contentCacheInfo =& $GLOBALS['eZContentCacheInfo'];
05249 if ( !isset( $contentCacheInfo ) )
05250 {
05251 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
05252 include_once( 'kernel/classes/ezuserdiscountrule.php' );
05253 $user =& eZUser::currentUser();
05254 $language = false;
05255 if ( isset( $Params['Language'] ) )
05256 {
05257 $language = $Params['Language'];
05258 }
05259 $roleList = $user->roleIDList();
05260 $discountList = eZUserDiscountRule::fetchIDListByUserID( $user->attribute( 'contentobject_id' ) );
05261 $contentCacheInfo = array( 'language' => $language,
05262 'role_list' => $roleList,
05263 'discount_list' => $discountList );
05264 }
05265 return $contentCacheInfo;
05266 }
05267
05268
05269
05270
05271 function expireAllViewCache()
05272 {
05273 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
05274 $handler =& eZExpiryHandler::instance();
05275 $handler->setTimestamp( 'content-view-cache', mktime() );
05276 $handler->store();
05277 }
05278
05279
05280
05281
05282
05283
05284 function expireAllCache()
05285 {
05286 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
05287 $handler =& eZExpiryHandler::instance();
05288 $handler->setTimestamp( 'content-view-cache', mktime() );
05289 $handler->setTimestamp( 'template-block-cache', mktime() );
05290 $handler->store();
05291 }
05292
05293
05294
05295
05296
05297
05298
05299 function expireTemplateBlockCache()
05300 {
05301 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
05302 $handler =& eZExpiryHandler::instance();
05303 $handler->setTimestamp( 'template-block-cache', mktime() );
05304 $handler->store();
05305 }
05306
05307
05308
05309
05310
05311 function expireTemplateBlockCacheIfNeeded()
05312 {
05313 $ini =& eZIni::instance();
05314 if ( $ini->variable( 'TemplateSettings', 'TemplateCache' ) == 'enabled' )
05315 eZContentObject::expireTemplateBlockCache();
05316 }
05317
05318
05319
05320
05321
05322
05323 function expireComplexViewModeCache()
05324 {
05325 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
05326 $handler =& eZExpiryHandler::instance();
05327 $handler->setTimestamp( 'content-complex-viewmode-cache', mktime() );
05328 $handler->store();
05329 }
05330
05331
05332
05333
05334 function isCacheExpired( $timestamp )
05335 {
05336 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
05337 $handler =& eZExpiryHandler::instance();
05338 if ( !$handler->hasTimestamp( 'content-view-cache' ) )
05339 return false;
05340 $expiryTime = $handler->timestamp( 'content-view-cache' );
05341 if ( $expiryTime > $timestamp )
05342 return true;
05343 return false;
05344 }
05345
05346
05347
05348
05349 function isComplexViewMode( $viewMode )
05350 {
05351 $ini =& eZINI::instance();
05352 $viewModes = $ini->variableArray( 'ContentSettings', 'ComplexDisplayViewModes' );
05353 return in_array( $viewMode, $viewModes );
05354 }
05355
05356
05357
05358
05359 function isComplexViewModeCacheExpired( $viewMode, $timestamp )
05360 {
05361 if ( !eZContentObject::isComplexViewMode( $viewMode ) )
05362 return false;
05363 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
05364 $handler =& eZExpiryHandler::instance();
05365 if ( !$handler->hasTimestamp( 'content-complex-viewmode-cache' ) )
05366 return false;
05367 $expiryTime = $handler->timestamp( 'content-complex-viewmode-cache' );
05368 if ( $expiryTime > $timestamp )
05369 return true;
05370 return false;
05371 }
05372
05373
05374
05375
05376
05377 function &authorArray()
05378 {
05379 $db =& eZDB::instance();
05380
05381 $userArray = $db->arrayQuery( "SELECT DISTINCT ezuser.contentobject_id, ezuser.login, ezuser.email, ezuser.password_hash, ezuser.password_hash_type
05382 FROM ezcontentobject_version, ezuser where ezcontentobject_version.contentobject_id='$this->ID'
05383 AND ezcontentobject_version.creator_id=ezuser.contentobject_id" );
05384
05385 $return = array();
05386
05387 foreach ( $userArray as $userRow )
05388 {
05389 $return[] = new eZUser( $userRow );
05390 }
05391 return $return;
05392 }
05393
05394
05395
05396
05397 function fetchObjectCountByUserID( $classID, $userID )
05398 {
05399 $count = 0;
05400 if ( is_numeric( $classID ) and is_numeric( $userID ) )
05401 {
05402 $db =& eZDB::instance();
05403 $classID =(int) $classID;
05404 $userID =(int) $userID;
05405 $countArray = $db->arrayQuery( "SELECT count(*) AS count FROM ezcontentobject WHERE contentclass_id=$classID AND owner_id=$userID" );
05406 $count = $countArray[0]['count'];
05407 }
05408 return $count;
05409 }
05410
05411
05412
05413
05414
05415
05416 function removeVersions( $versionStatus = false )
05417 {
05418 eZContentObjectVersion::removeVersions( $versionStatus );
05419 }
05420
05421
05422
05423
05424
05425
05426 function rename( $newName )
05427 {
05428
05429 $objectNamePattern = '';
05430 $contentClass =& $this->contentClass();
05431 if ( is_object( $contentClass ) )
05432 $objectNamePattern = $contentClass->ContentObjectName;
05433
05434 if ( $objectNamePattern == '' )
05435 return false;
05436
05437
05438 $objectNamePatternPartsPattern = '/<([^>]+)>/U';
05439 preg_match_all( $objectNamePatternPartsPattern, $objectNamePattern, $objectNamePatternParts );
05440
05441 if( count( $objectNamePatternParts ) === 0 || count( $objectNamePatternParts[1] ) == 0 )
05442 return false;
05443
05444 $objectNamePatternParts = $objectNamePatternParts[1];
05445
05446
05447 $newNamePattern = preg_replace( $objectNamePatternPartsPattern, '(.*)', $objectNamePattern );
05448
05449 $newNamePattern = '/' . $newNamePattern . '/';
05450
05451
05452 preg_match_all( $newNamePattern, $newName, $newNameParts );
05453
05454
05455 $contentObjectVersion = $this->createNewVersion();
05456
05457 $dataMap =& $contentObjectVersion->attribute( 'data_map' );
05458 if ( count( $dataMap ) === 0 )
05459 return false;
05460
05461
05462 $pos = 0;
05463 while( $pos < count( $objectNamePatternParts ) )
05464 {
05465 $attributes = $objectNamePatternParts[$pos];
05466
05467
05468
05469 $attributes = explode( '|', $attributes );
05470 $attribute = $attributes[0];
05471
05472 $newNamePart = $newNameParts[$pos+1];
05473 if ( count( $newNamePart ) === 0 )
05474 {
05475 if( $pos === 0 )
05476 {
05477
05478 $attributeValue = $newName;
05479 }
05480 else
05481 {
05482
05483 $attributeValue = '';
05484 }
05485 }
05486 else
05487 {
05488 $attributeValue = $newNamePart[0];
05489 }
05490
05491 $contentAttribute =& $dataMap[$attribute];
05492 $dataType = $contentAttribute->dataType();
05493 if( is_object( $dataType ) && $dataType->isSimpleStringInsertionSupported() )
05494 {
05495 $result = '';
05496 $dataType->insertSimpleString( $this, $contentObjectVersion, false, $contentAttribute, $attributeValue, $result );
05497 $contentAttribute->store();
05498 }
05499
05500 ++$pos;
05501 }
05502
05503 include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
05504 $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $this->attribute( 'id' ),
05505 'version' => $contentObjectVersion->attribute( 'version') ) );
05506 return ($operationResult != null ? true : false);
05507 }
05508
05509 function removeTranslation( $languageID )
05510 {
05511 $language = eZContentLanguage::fetch( $languageID );
05512
05513 if ( !$language )
05514 {
05515 return false;
05516 }
05517
05518
05519 if ( !$this->checkAccess( 'edit', false, false, false, $languageID ) )
05520 {
05521 return false;
05522 }
05523
05524
05525 $objectInitialLanguageID = $this->attribute( 'initial_language_id' );
05526 if ( $objectInitialLanguageID == $languageID )
05527 {
05528 return false;
05529 }
05530
05531
05532 $languageMask = (int) $this->attribute( 'language_mask' );
05533 $languageMask = (int) $languageMask & ~ (int) $languageID;
05534 $this->setAttribute( 'language_mask', $languageMask );
05535
05536 $db =& eZDB::instance();
05537 $db->begin();
05538
05539 $this->store();
05540
05541 $objectID = $this->ID;
05542
05543
05544 $currentVersion = $this->currentVersion();
05545 if ( $currentVersion->attribute( 'initial_language_id' ) == $languageID )
05546 {
05547 $currentVersion->setAttribute( 'initial_language_id', $objectInitialLanguageID );
05548 $currentVersion->store();
05549 }
05550
05551
05552 $versionsToRemove = $this->versions( true, array( 'conditions' => array( 'initial_language_id' => $languageID ) ) );
05553 foreach ( $versionsToRemove as $version )
05554 {
05555 $version->remove();
05556 }
05557
05558 $altLanguageID = $languageID++;
05559
05560
05561 $attributes = $db->arrayQuery( "SELECT * FROM ezcontentobject_attribute
05562 WHERE contentobject_id='$objectID'
05563 AND ( language_id='$languageID' OR language_id='$altLanguageID' )" );
05564 foreach ( $attributes as $attribute )
05565 {
05566 $attributeObject = new eZContentObjectAttribute( $attribute );
05567 $attributeObject->remove( $attributeObject->attribute( 'id' ), $attributeObject->attribute( 'version' ) );
05568 unset( $attributeObject );
05569 }
05570
05571
05572 $db->query( "DELETE FROM ezcontentobject_name
05573 WHERE contentobject_id='$objectID'
05574 AND ( language_id='$languageID' OR language_id='$altLanguageID' )" );
05575
05576
05577 $mask = eZContentLanguage::maskForRealLanguages() - (int) $languageID;
05578
05579 if ( $db->databaseName() == 'oracle' )
05580 {
05581 $db->query( "UPDATE ezcontentobject_version SET language_mask = bitand( language_mask, $mask )
05582 WHERE contentobject_id='$objectID'" );
05583 }
05584 else
05585 {
05586 $db->query( "UPDATE ezcontentobject_version SET language_mask = language_mask & $mask
05587 WHERE contentobject_id='$objectID'" );
05588 }
05589
05590 $db->commit();
05591
05592 return true;
05593 }
05594
05595 function &isAlwaysAvailable()
05596 {
05597 $result = false;
05598 if ( $this->attribute( 'language_mask' ) & 1 )
05599 {
05600 $result = true;
05601 }
05602
05603 return $result;
05604 }
05605
05606 function setAlwaysAvailableLanguageID( $languageID, $version = false )
05607 {
05608 $db =& eZDB::instance();
05609 $db->begin();
05610
05611 if ( $version == false )
05612 {
05613 $version = $this->currentVersion();
05614 if ( $languageID )
05615 {
05616 $this->setAttribute( 'language_mask', (int)$this->attribute( 'language_mask' ) | 1 );
05617 }
05618 else
05619 {
05620 $this->setAttribute( 'language_mask', (int)$this->attribute( 'language_mask' ) & ~1 );
05621 }
05622 $this->store();
05623 }
05624
05625 $objectID = $this->attribute( 'id' );
05626 $versionID = $version->attribute( 'version' );
05627
05628
05629 $sql = "UPDATE ezcontentobject_name SET language_id=";
05630 if ( $db->databaseName() == 'oracle' )
05631 {
05632 $sql .= "bitand( language_id, -2 )";
05633 }
05634 else
05635 {
05636 $sql .= "language_id & ~1";
05637 }
05638 $sql .= " WHERE contentobject_id = '$objectID' AND content_version = '$versionID'";
05639 $db->query( $sql );
05640
05641 if ( $languageID != false )
05642 {
05643 $newLanguageID = $languageID | 1;
05644 $sql = "UPDATE ezcontentobject_name
05645 SET language_id='$newLanguageID'
05646 WHERE language_id='$languageID' AND contentobject_id = '$objectID' AND content_version = '$versionID'";
05647 $db->query( $sql );
05648 }
05649
05650 $version->setAlwaysAvailableLanguageID( $languageID );
05651
05652 $db->commit();
05653 }
05654
05655 var $ID;
05656 var $Name;
05657
05658
05659 var $CurrentLanguage;
05660
05661
05662 var $ClassName;
05663
05664
05665 var $ClassIdentifier;
05666
05667
05668 var $DataMap = array();
05669
05670
05671 var $ContentActionList = false;
05672
05673
05674 var $ContentObjectAttributes = array();
05675
05676
05677 var $MainNodeID = false;
05678
05679
05680 var $InputRelationList = array();
05681 }
05682
05683 ?>