|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZContentFunctionCollection class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZContentFunctionCollection ezcontentfunctioncollection.php 00013 \brief The class eZContentFunctionCollection does 00014 00015 */ 00016 00017 class eZContentFunctionCollection 00018 { 00019 /*! 00020 Constructor 00021 */ 00022 function eZContentFunctionCollection() 00023 { 00024 } 00025 00026 static public function fetchContentObject( $objectID, $remoteID = false ) 00027 { 00028 if ( $objectID === false && $remoteID !== false ) 00029 { 00030 $contentObject = eZContentObject::fetchByRemoteID( $remoteID ); 00031 } 00032 else 00033 { 00034 $contentObject = eZContentObject::fetch( $objectID ); 00035 } 00036 00037 if ( $contentObject === null ) 00038 { 00039 $result = array( 'error' => array( 'error_type' => 'kernel', 00040 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00041 } 00042 else 00043 { 00044 $result = array( 'result' => $contentObject ); 00045 } 00046 00047 return $result; 00048 } 00049 00050 static public function fetchContentVersion( $objectID, $versionID ) 00051 { 00052 $contentVersion = eZContentObjectVersion::fetchVersion( $versionID, $objectID ); 00053 if ( !$contentVersion ) 00054 { 00055 $result = array( 'error' => array( 'error_type' => 'kernel', 00056 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00057 } 00058 else 00059 { 00060 $result = array( 'result' => $contentVersion ); 00061 } 00062 00063 return $result; 00064 } 00065 00066 static public function fetchContentNode( $nodeID, $nodePath, $languageCode, $remoteID = false ) 00067 { 00068 $contentNode = null; 00069 if ( $nodeID ) 00070 { 00071 if ( !isset( $languageCode ) ) 00072 $languageCode = false; 00073 00074 $contentNode = eZContentObjectTreeNode::fetch( $nodeID, $languageCode ); 00075 } 00076 else if ( $nodePath ) 00077 { 00078 $nodeID = eZURLAliasML::fetchNodeIDByPath( $nodePath ); 00079 00080 if ( $nodeID ) 00081 { 00082 $contentNode = eZContentObjectTreeNode::fetch( $nodeID ); 00083 } 00084 } 00085 else if ( $remoteID ) 00086 { 00087 $contentNode = eZContentObjectTreeNode::fetchByRemoteID( $remoteID ); 00088 } 00089 if ( $contentNode === null ) 00090 { 00091 $retVal = array( 'error' => array( 'error_type' => 'kernel', 00092 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00093 } 00094 else 00095 { 00096 $retVal = array( 'result' => $contentNode ); 00097 } 00098 00099 return $retVal; 00100 } 00101 00102 static public function fetchNonTranslationList( $objectID, $version ) 00103 { 00104 $version = eZContentObjectVersion::fetchVersion( $version, $objectID ); 00105 if ( !$version ) 00106 return array( 'error' => array( 'error_type' => 'kernel', 00107 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00108 00109 $nonTranslationList = $version->nonTranslationList(); 00110 if ( $nonTranslationList === null ) 00111 return array( 'error' => array( 'error_type' => 'kernel', 00112 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00113 return array( 'result' => $nonTranslationList ); 00114 } 00115 00116 static public function fetchTranslationList() 00117 { 00118 $translationList = eZContentObject::translationList(); 00119 if ( $translationList === null ) 00120 { 00121 $result = array( 'error' => array( 'error_type' => 'kernel', 00122 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00123 } 00124 else 00125 { 00126 $result = array( 'result' => $translationList ); 00127 } 00128 00129 return $result; 00130 } 00131 00132 static public function fetchPrioritizedLanguages() 00133 { 00134 $languages = eZContentLanguage::prioritizedLanguages(); 00135 if ( $languages === null ) 00136 { 00137 $result = array( 'error' => array( 'error_type' => 'kernel', 00138 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00139 } 00140 else 00141 { 00142 $result = array( 'result' => $languages ); 00143 } 00144 00145 return $result; 00146 } 00147 00148 static public function fetchPrioritizedLanguageCodes() 00149 { 00150 $languageCodes = eZContentLanguage::prioritizedLanguageCodes(); 00151 if ( $languageCodes === null ) 00152 { 00153 $result = array( 'error' => array( 'error_type' => 'kernel', 00154 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00155 } 00156 else 00157 { 00158 $result = array( 'result' => $languageCodes ); 00159 } 00160 00161 return $result; 00162 } 00163 00164 static public function fetchLocaleList( $withVariations ) 00165 { 00166 $localeList = eZLocale::localeList( true, $withVariations ); 00167 if ( $localeList === null ) 00168 { 00169 $result = array( 'error' => array( 'error_type' => 'kernel', 00170 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00171 } 00172 else 00173 { 00174 $result = array( 'result' => $localeList ); 00175 } 00176 00177 return $result; 00178 } 00179 00180 static public function fetchLocale( $localeCode ) 00181 { 00182 // Fetch locale list 00183 $localeList = eZLocale::localeList( false, true ); 00184 $localeObj = eZLocale::instance( $localeCode ); 00185 // Check if $localeName exists 00186 if ( $localeObj === null or ( is_object( $localeObj ) and !in_array( $localeObj->localeFullCode(), $localeList ) ) ) 00187 { 00188 $result = array( 'error' => array( 'error_type' => 'kernel', 00189 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00190 } 00191 else 00192 { 00193 $result = array( 'result' => $localeObj ); 00194 } 00195 00196 return $result; 00197 } 00198 00199 static public function fetchObject( $objectID ) 00200 { 00201 $object = eZContentObject::fetch( $objectID ); 00202 if ( $object === null ) 00203 { 00204 $result = array( 'error' => array( 'error_type' => 'kernel', 00205 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00206 } 00207 else 00208 { 00209 $result = array( 'result' => $object ); 00210 } 00211 00212 return $result; 00213 } 00214 00215 static public function fetchClass( $classID ) 00216 { 00217 if ( !is_numeric( $classID ) ) 00218 $object = eZContentClass::fetchByIdentifier( $classID ); 00219 else 00220 $object = eZContentClass::fetch( $classID ); 00221 if ( $object === null ) 00222 { 00223 $result = array( 'error' => array( 'error_type' => 'kernel', 00224 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00225 } 00226 else 00227 { 00228 $result = array( 'result' => $object ); 00229 } 00230 00231 return $result; 00232 } 00233 00234 static public function fetchClassAttributeList( $classID, $versionID ) 00235 { 00236 $objectList = eZContentClass::fetch( $classID )->fetchAttributes( false, true, $versionID ); 00237 if ( $objectList === null ) 00238 { 00239 $result = array( 'error' => array( 'error_type' => 'kernel', 00240 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00241 } 00242 else 00243 { 00244 $result = array( 'result' => $objectList ); 00245 } 00246 00247 return $result; 00248 } 00249 00250 static public function fetchClassAttribute( $attributeID, $versionID ) 00251 { 00252 $attribute = eZContentClassAttribute::fetch( $attributeID, true, $versionID ); 00253 if ( $attribute === null ) 00254 { 00255 $result = array( 'error' => array( 'error_type' => 'kernel', 00256 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00257 } 00258 else 00259 { 00260 $result = array( 'result' => $attribute ); 00261 } 00262 00263 return $result; 00264 } 00265 00266 static public function calendar( $parentNodeID, $offset, $limit, $depth, $depthOperator, 00267 $classID, $attribute_filter, $extended_attribute_filter, $class_filter_type, $class_filter_array, 00268 $groupBy, $mainNodeOnly, $ignoreVisibility, $limitation ) 00269 { 00270 $treeParameters = array( 'Offset' => $offset, 00271 'Limit' => $limit, 00272 'Limitation' => $limitation, 00273 'class_id' => $classID, 00274 'AttributeFilter' => $attribute_filter, 00275 'ExtendedAttributeFilter' => $extended_attribute_filter, 00276 'ClassFilterType' => $class_filter_type, 00277 'ClassFilterArray' => $class_filter_array, 00278 'IgnoreVisibility' => $ignoreVisibility, 00279 'MainNodeOnly' => $mainNodeOnly ); 00280 if ( is_array( $groupBy ) ) 00281 { 00282 $groupByHash = array( 'field' => $groupBy[0], 00283 'type' => false ); 00284 if ( isset( $groupBy[1] ) ) 00285 $groupByHash['type'] = $groupBy[1]; 00286 $treeParameters['GroupBy'] = $groupByHash; 00287 } 00288 00289 if ( $depth !== false ) 00290 { 00291 $treeParameters['Depth'] = $depth; 00292 $treeParameters['DepthOperator'] = $depthOperator; 00293 } 00294 00295 $children = null; 00296 if ( is_numeric( $parentNodeID ) ) 00297 { 00298 $children = eZContentObjectTreeNode::calendar( $treeParameters, 00299 $parentNodeID ); 00300 } 00301 00302 if ( $children === null ) 00303 { 00304 $result = array( 'error' => array( 'error_type' => 'kernel', 00305 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00306 } 00307 else 00308 { 00309 $result = array( 'result' => $children ); 00310 } 00311 return $result; 00312 } 00313 00314 static public function fetchObjectTree( $parentNodeID, $sortBy, $onlyTranslated, $language, $offset, $limit, $depth, $depthOperator, 00315 $classID, $attribute_filter, $extended_attribute_filter, $class_filter_type, $class_filter_array, 00316 $groupBy, $mainNodeOnly, $ignoreVisibility, $limitation, $asObject, $objectNameFilter, $loadDataMap = null ) 00317 { 00318 $treeParameters = array( 'Offset' => $offset, 00319 'OnlyTranslated' => $onlyTranslated, 00320 'Language' => $language, 00321 'Limit' => $limit, 00322 'Limitation' => $limitation, 00323 'SortBy' => $sortBy, 00324 'class_id' => $classID, 00325 'AttributeFilter' => $attribute_filter, 00326 'ExtendedAttributeFilter' => $extended_attribute_filter, 00327 'ClassFilterType' => $class_filter_type, 00328 'ClassFilterArray' => $class_filter_array, 00329 'IgnoreVisibility' => $ignoreVisibility, 00330 'ObjectNameFilter' => $objectNameFilter, 00331 'MainNodeOnly' => $mainNodeOnly ); 00332 if ( is_array( $groupBy ) ) 00333 { 00334 $groupByHash = array( 'field' => $groupBy[0], 00335 'type' => false ); 00336 if ( isset( $groupBy[1] ) ) 00337 $groupByHash['type'] = $groupBy[1]; 00338 $treeParameters['GroupBy'] = $groupByHash; 00339 } 00340 if ( $asObject !== null ) 00341 $treeParameters['AsObject'] = $asObject; 00342 if ( $loadDataMap ) 00343 $treeParameters['LoadDataMap'] = true; 00344 else if ( $loadDataMap === null ) 00345 $treeParameters['LoadDataMap'] = 15; 00346 if ( $depth !== false ) 00347 { 00348 $treeParameters['Depth'] = $depth; 00349 $treeParameters['DepthOperator'] = $depthOperator; 00350 } 00351 00352 $children = null; 00353 if ( is_numeric( $parentNodeID ) or is_array( $parentNodeID ) ) 00354 { 00355 $children = eZContentObjectTreeNode::subTreeByNodeID( $treeParameters, 00356 $parentNodeID ); 00357 } 00358 00359 if ( $children === null ) 00360 { 00361 return array( 'error' => array( 'error_type' => 'kernel', 00362 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00363 } 00364 else 00365 { 00366 return array( 'result' => $children ); 00367 } 00368 } 00369 00370 static public function fetchObjectTreeCount( $parentNodeID, $onlyTranslated, $language, $class_filter_type, $class_filter_array, 00371 $attributeFilter, $depth, $depthOperator, 00372 $ignoreVisibility, $limitation, $mainNodeOnly, $extendedAttributeFilter, $objectNameFilter ) 00373 { 00374 $childrenCount = null; 00375 00376 if ( is_numeric( $parentNodeID ) or is_array( $parentNodeID ) ) 00377 { 00378 $childrenCount = eZContentObjectTreeNode::subTreeCountByNodeID( array( 'Limitation' => $limitation, 00379 'ClassFilterType' => $class_filter_type, 00380 'ClassFilterArray' => $class_filter_array, 00381 'AttributeFilter' => $attributeFilter, 00382 'DepthOperator' => $depthOperator, 00383 'Depth' => $depth, 00384 'IgnoreVisibility' => $ignoreVisibility, 00385 'OnlyTranslated' => $onlyTranslated, 00386 'Language' => $language, 00387 'ObjectNameFilter' => $objectNameFilter, 00388 'ExtendedAttributeFilter' => $extendedAttributeFilter, 00389 'MainNodeOnly' => $mainNodeOnly ), 00390 $parentNodeID ); 00391 } 00392 00393 if ( $childrenCount === null ) 00394 { 00395 $result = array( 'error' => array( 'error_type' => 'kernel', 00396 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00397 } 00398 else 00399 { 00400 $result = array( 'result' => $childrenCount ); 00401 } 00402 return $result; 00403 } 00404 00405 static public function fetchContentSearch( $searchText, $subTreeArray, $offset, $limit, $searchTimestamp, $publishDate, $sectionID, 00406 $classID, $classAttributeID, $ignoreVisibility, $limitation, $sortArray ) 00407 { 00408 $searchArray = eZSearch::buildSearchArray(); 00409 $parameters = array(); 00410 if ( $classID !== false ) 00411 $parameters['SearchContentClassID'] = $classID; 00412 if ( $classAttributeID !== false ) 00413 $parameters['SearchContentClassAttributeID'] = $classAttributeID; 00414 if ( $sectionID !== false ) 00415 $parameters['SearchSectionID'] = $sectionID; 00416 if ( $publishDate !== false ) 00417 $parameters['SearchDate'] = $publishDate; 00418 if ( $sortArray !== false ) 00419 $parameters['SortArray'] = $sortArray; 00420 $parameters['SearchLimit'] = $limit; 00421 $parameters['SearchOffset'] = $offset; 00422 $parameters['IgnoreVisibility'] = $ignoreVisibility; 00423 $parameters['Limitation'] = $limitation; 00424 00425 if ( $subTreeArray !== false ) 00426 $parameters['SearchSubTreeArray'] = $subTreeArray; 00427 if ( $searchTimestamp ) 00428 $parameters['SearchTimestamp'] = $searchTimestamp; 00429 $searchResult = eZSearch::search( $searchText, 00430 $parameters, 00431 $searchArray ); 00432 return array( 'result' => $searchResult ); 00433 } 00434 00435 static public function fetchTrashObjectCount( $objectNameFilter, $attributeFilter = false ) 00436 { 00437 $params = array(); 00438 if ( $objectNameFilter !== false ) 00439 { 00440 $params['ObjectNameFilter'] = $objectNameFilter; 00441 } 00442 00443 $params[ 'AttributeFilter' ] = $attributeFilter; 00444 00445 $trashCount = eZContentObjectTrashNode::trashListCount( $params ); 00446 return array( 'result' => $trashCount ); 00447 } 00448 00449 static public function fetchTrashObjectList( $offset, $limit, $objectNameFilter, $attributeFilter = false, $sortBy = false, $asObject = true ) 00450 { 00451 $params = array(); 00452 if ( $objectNameFilter !== false ) 00453 { 00454 $params['ObjectNameFilter'] = $objectNameFilter; 00455 } 00456 $params[ 'Limit' ] = $limit; 00457 $params[ 'Offset' ] = $offset; 00458 $params[ 'AttributeFilter' ] = $attributeFilter; 00459 $params[ 'SortBy' ] = $sortBy; 00460 $params[ 'AsObject' ] = $asObject; 00461 00462 $trashNodesList = eZContentObjectTrashNode::trashList( $params, false ); 00463 return array( 'result' => $trashNodesList ); 00464 } 00465 00466 static public function fetchDraftVersionList( $offset, $limit ) 00467 { 00468 $userID = eZUser::currentUserID(); 00469 $draftVersionList = eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(), 00470 null, array( 'creator_id' => $userID, 00471 'status' => eZContentObjectVersion::STATUS_DRAFT ), 00472 array( 'modified' => true, 00473 'initial_language_id' => true ), 00474 array( 'length' => $limit, 'offset' => $offset ), 00475 true ); 00476 return array( 'result' => $draftVersionList ); 00477 } 00478 00479 static public function fetchDraftVersionCount() 00480 { 00481 $userID = eZUser::currentUserID(); 00482 $draftVersionList = eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(), 00483 array(), 00484 array( 'creator_id' => $userID, 00485 'status' => eZContentObjectVersion::STATUS_DRAFT ), 00486 false, 00487 null, 00488 false, 00489 false, 00490 array( array( 'operation' => 'count( * )', 00491 'name' => 'count' ) ) ); 00492 return array( 'result' => $draftVersionList[0]['count'] ); 00493 } 00494 00495 static public function fetchPendingList( $offset, $limit ) 00496 { 00497 $userID = eZUser::currentUserID(); 00498 $pendingList = eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(), 00499 null, array( 'creator_id' => $userID, 00500 'status' => eZContentObjectVersion::STATUS_PENDING ), 00501 null, array( 'length' => $limit, 'offset' => $offset ), 00502 true ); 00503 return array( 'result' => $pendingList ); 00504 00505 } 00506 00507 static public function fetchPendingCount() 00508 { 00509 $userID = eZUser::currentUserID(); 00510 $pendingList = eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(), 00511 array(), 00512 array( 'creator_id' => $userID, 00513 'status' => eZContentObjectVersion::STATUS_PENDING ), 00514 false, 00515 null, 00516 false, 00517 false, 00518 array( array( 'operation' => 'count( * )', 00519 'name' => 'count' ) ) ); 00520 return array( 'result' => $pendingList[0]['count'] ); 00521 } 00522 00523 00524 static public function fetchVersionList( $contentObject, $offset, $limit, $sorts = null ) 00525 { 00526 if ( !is_object( $contentObject ) ) 00527 return array( 'result' => null ); 00528 $versionList = eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(), 00529 null, array( 'contentobject_id' => $contentObject->attribute("id") ), 00530 $sorts, array( 'length' => $limit, 'offset' => $offset ), 00531 true ); 00532 return array( 'result' => $versionList ); 00533 00534 } 00535 00536 static public function fetchVersionCount( $contentObject ) 00537 { 00538 if ( !is_object( $contentObject ) ) 00539 return array( 'result' => 0 ); 00540 $versionList = eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(), 00541 array(), 00542 array( 'contentobject_id' => $contentObject->attribute( 'id' ) ), 00543 false, 00544 null, 00545 false, 00546 false, 00547 array( array( 'operation' => 'count( * )', 00548 'name' => 'count' ) ) ); 00549 return array( 'result' => $versionList[0]['count'] ); 00550 } 00551 00552 static public function canInstantiateClassList( $groupID, $parentNode, $filterType = 'include', $fetchID, $asObject, $groupByClassGroup = false ) 00553 { 00554 $ClassGroupIDs = false; 00555 00556 if ( is_numeric( $groupID ) && ( $groupID > 0 ) ) 00557 { 00558 $ClassGroupIDs = array( $groupID ); 00559 } 00560 else if( is_array( $groupID ) ) 00561 { 00562 $ClassGroupIDs = $groupID; 00563 } 00564 00565 if ( is_numeric( $parentNode ) ) 00566 $parentNode = eZContentObjectTreeNode::fetch( $parentNode ); 00567 00568 if ( is_object( $parentNode ) ) 00569 { 00570 $classList = $parentNode->canCreateClassList( $asObject, $filterType == 'include', $ClassGroupIDs, $fetchID ); 00571 } 00572 else 00573 { 00574 $classList = eZContentClass::canInstantiateClassList( $asObject, $filterType == 'include', $ClassGroupIDs, $fetchID ); 00575 } 00576 00577 if ( $groupByClassGroup && $asObject ) 00578 { 00579 $tmpClassList = array(); 00580 00581 $ini = eZINI::instance( 'content.ini' ); 00582 00583 foreach ( $classList as $class ) 00584 { 00585 foreach ( $class->fetchGroupList() as $group ) 00586 { 00587 $groupID = $group->attribute( 'group_id' ); 00588 00589 if ( !in_array( $class->attribute('identifier'), $ini->variable( 'FetchFunctionSettings', 'InstClassListFilter' ) ) ) 00590 { 00591 if ( isset( $tmpClassList[$groupID] ) ) 00592 { 00593 $tmpClassList[$groupID]['items'][] = $class; 00594 } 00595 else 00596 { 00597 $tmpClassList[$groupID]['items'] = array( $class ); 00598 $tmpClassList[$groupID]['group_name'] = $group->attribute( 'group_name' ); 00599 } 00600 } 00601 } 00602 } 00603 00604 $classList = $tmpClassList; 00605 } 00606 00607 return array( 'result' => $classList ); 00608 } 00609 00610 static public function canInstantiateClasses( $parentNode ) 00611 { 00612 if ( is_object( $parentNode ) ) 00613 { 00614 $contentObject = $parentNode->attribute( 'object' ); 00615 return array( 'result' => $contentObject->attribute( 'can_create' ) ); 00616 } 00617 return array( 'result' => eZContentClass::canInstantiateClasses() ); 00618 } 00619 00620 static public function contentobjectAttributes( $version, $languageCode ) 00621 { 00622 if ( $languageCode == '' ) 00623 { 00624 return array( 'result' => $version->contentObjectAttributes( ) ); 00625 } 00626 else 00627 { 00628 return array( 'result' => $version->contentObjectAttributes( $languageCode ) ); 00629 } 00630 } 00631 00632 static public function fetchBookmarks( $offset, $limit ) 00633 { 00634 $user = eZUser::currentUser(); 00635 return array( 'result' => eZContentBrowseBookmark::fetchListForUser( $user->id(), $offset, $limit ) ); 00636 } 00637 00638 static public function fetchRecent() 00639 { 00640 $user = eZUser::currentUser(); 00641 return array( 'result' => eZContentBrowseRecent::fetchListForUser( $user->id() ) ); 00642 } 00643 00644 static public function fetchSectionList() 00645 { 00646 return array( 'result' => eZSection::fetchList() ); 00647 } 00648 00649 static public function fetchTipafriendTopList( $offset, $limit, $start_time, $end_time, $duration, $ascending, $extended ) 00650 { 00651 $currentTime = time(); 00652 $conds = array(); 00653 00654 if ( is_numeric( $start_time ) and is_numeric( $end_time ) ) 00655 { 00656 $conds = array( 'requested' => array( false, array( $start_time, $end_time ) ) ); 00657 } 00658 else if ( is_numeric( $start_time ) and is_numeric( $duration ) ) 00659 { 00660 $conds = array( 'requested' => array( false, array( $start_time, $start_time + $duration ) ) ); 00661 } 00662 else if ( is_numeric( $end_time ) and is_numeric( $duration ) ) 00663 { 00664 $conds = array( 'requested' => array( false, array( $end_time - $duration, $end_time ) ) ); 00665 } 00666 else if ( is_numeric( $start_time ) ) 00667 { 00668 $conds = array( 'requested' => array( '>', $start_time ) ); 00669 } 00670 else if ( is_numeric( $end_time ) ) 00671 { 00672 $conds = array( 'requested' => array( '<', $end_time ) ); 00673 } 00674 else if ( is_numeric( $duration ) ) 00675 { 00676 // substract passed duration from current time timestamp to get start_time stamp 00677 // end_timestamp is equal to current time in this case 00678 $conds = array( 'requested' => array( '>', $currentTime - $duration ) ); 00679 } 00680 00681 $topList = eZPersistentObject::fetchObjectList( eZTipafriendCounter::definition(), 00682 array( 'node_id' ), 00683 $conds, 00684 array( 'count' => ( $ascending ? 'asc' : 'desc' ) ), 00685 array( 'length' => $limit, 'offset' => $offset ), 00686 false, 00687 array( 'node_id' ), 00688 array( array( 'operation' => 'count( * )', 00689 'name' => 'count' ) ) ); 00690 if ( $extended ) 00691 { 00692 foreach ( array_keys( $topList ) as $key ) 00693 { 00694 $contentNode = eZContentObjectTreeNode::fetch( $topList[ $key ][ 'node_id' ] ); 00695 if ( !is_object( $contentNode ) ) 00696 return array( 'error' => array( 'error_type' => 'kernel', 00697 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00698 $topList[ $key ][ 'node' ] = $contentNode; 00699 } 00700 return array( 'result' => $topList ); 00701 } 00702 else 00703 { 00704 $retList = array(); 00705 foreach ( $topList as $entry ) 00706 { 00707 $contentNode = eZContentObjectTreeNode::fetch( $entry[ 'node_id' ] ); 00708 if ( !is_object( $contentNode ) ) 00709 return array( 'error' => array( 'error_type' => 'kernel', 00710 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00711 $retList[] = $contentNode; 00712 } 00713 return array( 'result' => $retList ); 00714 } 00715 00716 } 00717 00718 static public function fetchMostViewedTopList( $classID, $sectionID, $offset, $limit ) 00719 { 00720 $topList = eZViewCounter::fetchTopList( $classID, $sectionID, $offset, $limit ); 00721 $contentNodeList = array(); 00722 foreach ( array_keys ( $topList ) as $key ) 00723 { 00724 $nodeID = $topList[$key]['node_id']; 00725 $contentNode = eZContentObjectTreeNode::fetch( $nodeID ); 00726 if ( $contentNode === null ) 00727 return array( 'error' => array( 'error_type' => 'kernel', 00728 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00729 $contentNodeList[] = $contentNode; 00730 } 00731 return array( 'result' => $contentNodeList ); 00732 } 00733 00734 static public function fetchCollectedInfoCount( $objectAttributeID, $objectID, $value, $creatorID = false, $userIdentifier = false ) 00735 { 00736 return eZInfocollectorFunctionCollection::fetchCollectedInfoCount( $objectAttributeID, $objectID, $value, $creatorID, $userIdentifier ); 00737 } 00738 00739 static public function fetchCollectedInfoCountList( $objectAttributeID ) 00740 { 00741 return eZInfocollectorFunctionCollection::fetchCollectedInfoCountList( $objectAttributeID ); 00742 } 00743 00744 static public function fetchCollectedInfoCollection( $collectionID, $contentObjectID ) 00745 { 00746 return eZInfocollectorFunctionCollection::fetchCollectedInfoCollection( $collectionID, $contentObjectID ); 00747 } 00748 00749 static public function fetchCollectionsList( $objectID = false, $creatorID = false, $userIdentifier = false, $limit = false, $offset = false, $sortBy = false ) 00750 { 00751 return eZInfocollectorFunctionCollection::fetchCollectionsList( $objectID, 00752 $creatorID, 00753 $userIdentifier, 00754 $limit, 00755 $offset, 00756 $sortBy ); 00757 } 00758 00759 static public function fetchObjectByAttribute( $identifier ) 00760 { 00761 $contentObjectAttribute = eZContentObjectAttribute::fetchByIdentifier( $identifier ); 00762 if ( $contentObjectAttribute === null ) 00763 { 00764 $result = array( 'error' => array( 'error_type' => 'kernel', 00765 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 00766 } 00767 else 00768 { 00769 $result = array( 'result' => $contentObjectAttribute->attribute( 'object' ) ); 00770 } 00771 return $result; 00772 } 00773 00774 static public function fetchObjectCountByUserID( $classID, $userID, $status = false ) 00775 { 00776 $objectCount = eZContentObject::fetchObjectCountByUserID( $classID, $userID, $status ); 00777 return array( 'result' => $objectCount ); 00778 } 00779 00780 static public function fetchKeywordCount( $alphabet, 00781 $classid, 00782 $owner = false, 00783 $parentNodeID = false, 00784 $includeDuplicates = true, 00785 $strictMatching = false ) 00786 { 00787 $classIDArray = array(); 00788 if ( is_numeric( $classid ) ) 00789 { 00790 $classIDArray = array( $classid ); 00791 } 00792 else if ( is_array( $classid ) ) 00793 { 00794 $classIDArray = $classid; 00795 } 00796 00797 $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( true, false ); 00798 $limitation = false; 00799 $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation ); 00800 $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList ); 00801 00802 $db = eZDB::instance(); 00803 00804 $alphabet = $db->escapeString( $alphabet ); 00805 00806 $sqlOwnerString = is_numeric( $owner ) ? "AND ezcontentobject.owner_id = '$owner'" : ''; 00807 $parentNodeIDString = is_numeric( $parentNodeID ) ? "AND ezcontentobject_tree.parent_node_id = '$parentNodeID'" : ''; 00808 00809 $sqlClassIDs = ''; 00810 if ( $classIDArray != null ) 00811 { 00812 $sqlClassIDs = 'AND ' . $db->generateSQLINStatement( $classIDArray, 'ezkeyword.class_id', false, false, 'int' ) . ' '; 00813 } 00814 00815 $sqlToExcludeDuplicates = ''; 00816 if ( !$includeDuplicates ) 00817 { 00818 //will use SELECT COUNT( DISTINCT ezcontentobject.id ) to count object only once even if it has 00819 //several keywords started with $alphabet. 00820 //COUNT( DISTINCT fieldName ) is SQL92 compliant syntax. 00821 $sqlToExcludeDuplicates = ' DISTINCT'; 00822 } 00823 // composing sql for matching tag word, it could be strict equiality or LIKE clause dependent of $strictMatching parameter. 00824 $sqlMatching = "ezkeyword.keyword LIKE '$alphabet%'"; 00825 if ( $strictMatching ) 00826 { 00827 $sqlMatching = "ezkeyword.keyword = '$alphabet'"; 00828 } 00829 00830 $query = "SELECT COUNT($sqlToExcludeDuplicates ezcontentobject.id) AS count 00831 FROM ezkeyword INNER JOIN ezkeyword_attribute_link INNER JOIN ezcontentobject_tree INNER JOIN ezcontentobject INNER JOIN ezcontentclass INNER JOIN ezcontentobject_attribute 00832 $sqlPermissionChecking[from] 00833 WHERE $sqlMatching 00834 $showInvisibleNodesCond 00835 $sqlPermissionChecking[where] 00836 $sqlClassIDs 00837 $sqlOwnerString 00838 $parentNodeIDString 00839 AND ezcontentclass.version=0 00840 AND ezcontentobject.status=".eZContentObject::STATUS_PUBLISHED." 00841 AND ezcontentobject_attribute.version=ezcontentobject.current_version 00842 AND ezcontentobject_tree.main_node_id=ezcontentobject_tree.node_id 00843 AND ezcontentobject_attribute.contentobject_id=ezcontentobject.id 00844 AND ezcontentobject_tree.contentobject_id = ezcontentobject.id 00845 AND ezcontentclass.id = ezcontentobject.contentclass_id 00846 AND ezcontentobject_attribute.id=ezkeyword_attribute_link.objectattribute_id 00847 AND ezkeyword_attribute_link.keyword_id = ezkeyword.id"; 00848 00849 $keyWords = $db->arrayQuery( $query ); 00850 // cleanup temp tables 00851 $db->dropTempTableList( $sqlPermissionChecking['temp_tables'] ); 00852 00853 return array( 'result' => $keyWords[0]['count'] ); 00854 } 00855 00856 // 00857 //Returns an array( 'result' => array( 'keyword' => keyword, 'link_object' => node_id ); 00858 //By default fetchKeyword gets a list of (not necessary unique) nodes and respective keyword strings 00859 //Search keyword provided in $alphabet parameter. 00860 //By default keyword matching implemented by LIKE so all keywords that starts with $alphabet 00861 //will successfully match. This means that if some object have attached keywords: 00862 //'Skien', 'Skien forests', 'Skien comunity' than fetchKeyword('Skien') will return tree entries 00863 //for this object. 00864 //Setting $includeDuplicates parameter to false makes fetchKeyword('Skien') to return just 00865 //one entry for such objects. 00866 static public function fetchKeyword( $alphabet, 00867 $classid, 00868 $offset, 00869 $limit, 00870 $owner = false, 00871 $sortBy = array(), 00872 $parentNodeID = false, 00873 $includeDuplicates = true, 00874 $strictMatching = false ) 00875 { 00876 $classIDArray = array(); 00877 if ( is_numeric( $classid ) ) 00878 { 00879 $classIDArray = array( $classid ); 00880 } 00881 else if ( is_array( $classid ) ) 00882 { 00883 $classIDArray = $classid; 00884 } 00885 00886 $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( true, false ); 00887 $limitation = false; 00888 $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation ); 00889 $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList ); 00890 00891 $db_params = array(); 00892 $db_params['offset'] = $offset; 00893 $db_params['limit'] = $limit; 00894 00895 $keywordNodeArray = array(); 00896 $lastKeyword = ''; 00897 00898 $db = eZDB::instance(); 00899 00900 //in SELECT clause below we will use a full keyword value 00901 //or just a part of ezkeyword.keyword matched to $alphabet respective to $includeDuplicates parameter. 00902 //In the case $includeDuplicates = ture we need only a part 00903 //of ezkeyword.keyword to be fetched in field to allow DISTINCT to remove rows with the same node id's 00904 $sqlKeyword = 'ezkeyword.keyword'; 00905 if ( !$includeDuplicates ) 00906 { 00907 $sqlKeyword = $db->subString('ezkeyword.keyword', 1, strlen( $alphabet ) ) . ' AS keyword '; 00908 } 00909 00910 $alphabet = $db->escapeString( $alphabet ); 00911 00912 $sortingInfo = array(); 00913 $sortingInfo['attributeFromSQL'] = ' INNER JOIN ezcontentobject_attribute a1'; 00914 $sortingInfo['attributeWhereSQL'] = ''; 00915 $sqlTarget = $sqlKeyword.',ezcontentobject_tree.node_id'; 00916 00917 if ( is_array( $sortBy ) && count ( $sortBy ) > 0 ) 00918 { 00919 switch ( $sortBy[0] ) 00920 { 00921 case 'keyword': 00922 case 'name': 00923 { 00924 $sortingString = ''; 00925 if ( $sortBy[0] == 'name' ) 00926 { 00927 $sortingString = 'ezcontentobject.name'; 00928 $sortingInfo['attributeTargetSQL'] = ', ' . $sortingString; 00929 } 00930 elseif ( $sortBy[0] == 'keyword' ) 00931 { 00932 if ( $includeDuplicates ) 00933 $sortingString = 'ezkeyword.keyword'; 00934 else 00935 $sortingString = 'keyword'; 00936 $sortingInfo['attributeTargetSQL'] = ''; 00937 } 00938 00939 $sortOrder = true; // true is ascending 00940 if ( isset( $sortBy[1] ) ) 00941 $sortOrder = $sortBy[1]; 00942 $sortingOrder = $sortOrder ? ' ASC' : ' DESC'; 00943 $sortingInfo['sortingFields'] = $sortingString . $sortingOrder; 00944 } break; 00945 default: 00946 { 00947 $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $sortBy ); 00948 00949 if ( $sortBy[0] == 'attribute' ) 00950 { 00951 // if sort_by is 'attribute' we should add ezcontentobject_name to "FromSQL" and link to ezcontentobject 00952 $sortingInfo['attributeFromSQL'] .= ' INNER JOIN ezcontentobject_name INNER JOIN ezcontentobject_attribute a1'; 00953 $sortingInfo['attributeWhereSQL'] .= ' ezcontentobject.id = ezcontentobject_name.contentobject_id AND'; 00954 $sqlTarget = 'DISTINCT ezcontentobject_tree.node_id, '.$sqlKeyword; 00955 } 00956 else // for unique declaration 00957 { 00958 $sortByArray = explode( ' ', $sortingInfo['sortingFields'] ); 00959 $sortingInfo['attributeTargetSQL'] .= ', ' . $sortByArray[0]; 00960 00961 $sortingInfo['attributeFromSQL'] .= ' INNER JOIN ezcontentobject_attribute a1'; 00962 } 00963 00964 } break; 00965 } 00966 00967 $sqlTarget .= $sortingInfo['attributeTargetSQL']; 00968 } 00969 else 00970 { 00971 $sortingInfo['sortingFields'] = 'ezkeyword.keyword ASC'; 00972 } 00973 $sortingInfo['attributeWhereSQL'] .= " a1.version=ezcontentobject.current_version 00974 AND a1.contentobject_id=ezcontentobject.id AND"; 00975 00976 //Adding DISTINCT to avoid duplicates, 00977 //check if DISTINCT keyword was added before providing clauses for sorting. 00978 if ( !$includeDuplicates && substr( $sqlTarget, 0, 9) != 'DISTINCT ' ) 00979 { 00980 $sqlTarget = 'DISTINCT ' . $sqlTarget; 00981 } 00982 00983 $sqlOwnerString = is_numeric( $owner ) ? "AND ezcontentobject.owner_id = '$owner'" : ''; 00984 $parentNodeIDString = is_numeric( $parentNodeID ) ? "AND ezcontentobject_tree.parent_node_id = '$parentNodeID'" : ''; 00985 00986 $sqlClassIDString = ''; 00987 if ( is_array( $classIDArray ) and count( $classIDArray ) ) 00988 { 00989 $sqlClassIDString = 'AND ' . $db->generateSQLINStatement( $classIDArray, 'ezkeyword.class_id', false, false, 'int' ) . ' '; 00990 } 00991 00992 // composing sql for matching tag word, it could be strict equiality or LIKE clause 00993 // dependent of $strictMatching parameter. 00994 $sqlMatching = "ezkeyword.keyword LIKE '$alphabet%'"; 00995 if ( $strictMatching ) 00996 { 00997 $sqlMatching = "ezkeyword.keyword = '$alphabet'"; 00998 } 00999 01000 $query = "SELECT $sqlTarget 01001 FROM ezkeyword INNER JOIN ezkeyword_attribute_link INNER JOIN ezcontentobject_tree INNER JOIN ezcontentobject INNER JOIN ezcontentclass 01002 $sortingInfo[attributeFromSQL] 01003 $sqlPermissionChecking[from] 01004 WHERE 01005 $sortingInfo[attributeWhereSQL] 01006 $sqlMatching 01007 $showInvisibleNodesCond 01008 $sqlPermissionChecking[where] 01009 $sqlClassIDString 01010 $sqlOwnerString 01011 $parentNodeIDString 01012 AND ezcontentclass.version=0 01013 AND ezcontentobject.status=".eZContentObject::STATUS_PUBLISHED." 01014 AND ezcontentobject_tree.main_node_id=ezcontentobject_tree.node_id 01015 AND ezcontentobject_tree.contentobject_id = ezcontentobject.id 01016 AND ezcontentclass.id = ezcontentobject.contentclass_id 01017 AND a1.id=ezkeyword_attribute_link.objectattribute_id 01018 AND ezkeyword_attribute_link.keyword_id = ezkeyword.id ORDER BY {$sortingInfo['sortingFields']}"; 01019 01020 $keyWords = $db->arrayQuery( $query, $db_params ); 01021 01022 $trans = eZCharTransform::instance(); 01023 01024 foreach ( $keyWords as $keywordArray ) 01025 { 01026 $keyword = $keywordArray['keyword']; 01027 $nodeID = $keywordArray['node_id']; 01028 $nodeObject = eZContentObjectTreeNode::fetch( $nodeID ); 01029 01030 if ( $nodeObject != null ) 01031 { 01032 $keywordLC = $trans->transformByGroup( $keyword, 'lowercase' ); 01033 if ( $lastKeyword == $keywordLC ) 01034 $keywordNodeArray[] = array( 'keyword' => '', 'link_object' => $nodeObject ); 01035 else 01036 $keywordNodeArray[] = array( 'keyword' => $keyword, 'link_object' => $nodeObject ); 01037 01038 $lastKeyword = $keywordLC; 01039 } 01040 else 01041 { 01042 $lastKeyword = $trans->transformByGroup( $keyword, 'lowercase' ); 01043 } 01044 } 01045 return array( 'result' => $keywordNodeArray ); 01046 } 01047 01048 static public function fetchSameClassAttributeNodeList( $contentclassattributeID, $value, $datatype ) 01049 { 01050 if ( $datatype == "int" ) 01051 $type = "data_int"; 01052 else if ( $datatype == "float" ) 01053 $type = "data_float"; 01054 else if ( $datatype == "text" ) 01055 $type = "data_text"; 01056 else 01057 { 01058 eZDebug::writeError( "DatatypeString not supported in fetch same_classattribute_node, use int, float or text" ); 01059 return false; 01060 } 01061 $db = eZDB::instance(); 01062 $contentclassattributeID =(int) $contentclassattributeID; 01063 $value = $db->escapeString( $value ); 01064 if ( $datatype != "text" ) 01065 settype( $value, $datatype ); 01066 $resultNodeArray = array(); 01067 $nodeList = $db->arrayQuery( "SELECT ezcontentobject_tree.node_id, ezcontentobject.name, ezcontentobject_tree.parent_node_id 01068 FROM ezcontentobject_tree, ezcontentobject, ezcontentobject_attribute 01069 WHERE ezcontentobject_attribute.$type='$value' 01070 AND ezcontentobject_attribute.contentclassattribute_id='$contentclassattributeID' 01071 AND ezcontentobject_attribute.contentobject_id=ezcontentobject.id 01072 AND ezcontentobject_attribute.version=ezcontentobject.current_version 01073 AND ezcontentobject_tree.contentobject_version=ezcontentobject.current_version 01074 AND ezcontentobject_tree.contentobject_id=ezcontentobject.id 01075 ORDER BY ezcontentobject.name"); 01076 01077 foreach ( $nodeList as $nodeObject ) 01078 { 01079 $nodeID = $nodeObject['node_id']; 01080 $node = eZContentObjectTreeNode::fetch( $nodeID ); 01081 $resultNodeArray[] = $node; 01082 } 01083 return array( 'result' => $resultNodeArray ); 01084 } 01085 01086 static public function checkAccess( $access, $contentObject, $contentClassID, $parentContentClassID, $languageCode = false ) 01087 { 01088 if ( $contentObject instanceof eZContentObjectTreeNode ) 01089 { 01090 $contentObject = $contentObject->attribute( 'object' ); 01091 } 01092 if ( $contentClassID !== false and !is_numeric( $contentClassID ) ) 01093 { 01094 $class = eZContentClass::fetchByIdentifier( $contentClassID ); 01095 if ( !$class ) 01096 return array( 'error' => array( 'error_type' => 'kernel', 01097 'error_code' => eZError::KERNEL_NOT_FOUND ) ); 01098 $contentClassID = $class->attribute( 'id' ); 01099 } 01100 if ( $access and $contentObject instanceof eZContentObject ) 01101 { 01102 $result = $contentObject->checkAccess( $access, $contentClassID, $parentContentClassID, false, $languageCode ); 01103 return array( 'result' => $result ); 01104 } 01105 } 01106 01107 // Fetches all navigation parts as an array 01108 static public function fetchNavigationParts() 01109 { 01110 return array( 'result' => eZNavigationPart::fetchList() ); 01111 } 01112 01113 // Fetches one navigation parts by identifier 01114 static public function fetchNavigationPart( $identifier ) 01115 { 01116 return array( 'result' => eZNavigationPart::fetchPartByIdentifier( $identifier ) ); 01117 } 01118 01119 static public function contentobjectRelationTypeMask( $contentObjectRelationTypes = false ) 01120 { 01121 $relationTypeMask = 0; 01122 if ( is_array( $contentObjectRelationTypes ) ) 01123 { 01124 $relationTypeMap = array( 'common' => eZContentObject::RELATION_COMMON, 01125 'xml_embed' => eZContentObject::RELATION_EMBED, 01126 'xml_link' => eZContentObject::RELATION_LINK, 01127 'attribute' => eZContentObject::RELATION_ATTRIBUTE ); 01128 foreach ( $contentObjectRelationTypes as $relationType ) 01129 { 01130 if ( isset( $relationTypeMap[$relationType] ) ) 01131 { 01132 $relationTypeMask |= $relationTypeMap[$relationType]; 01133 } 01134 else 01135 { 01136 eZDebug::writeWarning( "Unknown relation type: '$relationType'.", __METHOD__ ); 01137 } 01138 } 01139 } 01140 elseif ( !is_bool( $contentObjectRelationTypes ) ) 01141 { 01142 $contentObjectRelationTypes = false; 01143 } 01144 01145 if ( is_bool( $contentObjectRelationTypes ) ) 01146 { 01147 $relationTypeMask = eZContentObject::relationTypeMask( $contentObjectRelationTypes ); 01148 } 01149 01150 return $relationTypeMask; 01151 } 01152 01153 // Fetches related objects id grouped by relation types 01154 static public function fetchRelatedObjectsID( $objectID, $attributeID, $allRelations) 01155 { 01156 if ( !is_array( $allRelations ) || $allRelations === array() ) 01157 { 01158 $allRelations = array( 'common', 'xml_embed', 'attribute' ); 01159 if ( eZContentObject::isObjectRelationTyped() ) 01160 { 01161 $allRelations[] = 'xml_link'; 01162 } 01163 } 01164 01165 $relatedObjectsTyped = array(); 01166 foreach ( $allRelations as $relationType ) 01167 { 01168 $relatedObjectsTyped[$relationType] = 01169 eZContentFunctionCollection::fetchRelatedObjects( $objectID, $attributeID, array( $relationType ), false, array() ); 01170 } 01171 01172 $relatedObjectsTypedIDArray = array(); 01173 foreach ( $relatedObjectsTyped as $relationTypeName => $relatedObjectsByType ) 01174 { 01175 $relatedObjectsTypedIDArray[$relationTypeName] = array(); 01176 foreach ( $relatedObjectsByType['result'] as $relatedObjectByType ) 01177 { 01178 $relatedObjectsTypedIDArray[$relationTypeName][] = $relatedObjectByType->ID; 01179 } 01180 } 01181 01182 return array( 'result' => $relatedObjectsTypedIDArray ); 01183 } 01184 01185 // Fetches reverse related objects id grouped by relation types 01186 static public function fetchReverseRelatedObjectsID( $objectID, $attributeID, $allRelations ) 01187 { 01188 if ( !is_array( $allRelations ) || $allRelations === array() ) 01189 { 01190 $allRelations = array( 'common', 'xml_embed', 'attribute' ); 01191 if ( eZContentObject::isObjectRelationTyped() ) 01192 { 01193 $allRelations[] = 'xml_link'; 01194 } 01195 } 01196 01197 $relatedObjectsTyped = array(); 01198 foreach ( $allRelations as $relationType ) 01199 { 01200 $relatedObjectsTyped[$relationType] = 01201 eZContentFunctionCollection::fetchReverseRelatedObjects( $objectID, $attributeID, array( $relationType ), false, array(), null ); 01202 } 01203 01204 $relatedObjectsTypedIDArray = array(); 01205 foreach ( $relatedObjectsTyped as $relationTypeName => $relatedObjectsByType ) 01206 { 01207 $relatedObjectsTypedIDArray[$relationTypeName] = array(); 01208 foreach ( $relatedObjectsByType['result'] as $relatedObjectByType ) 01209 { 01210 $relatedObjectsTypedIDArray[$relationTypeName][] = $relatedObjectByType->ID; 01211 } 01212 } 01213 01214 return array( 'result' =>$relatedObjectsTypedIDArray ); 01215 } 01216 01217 01218 /** 01219 * Fetches related object for $objectID 01220 * 01221 * @param int $objectID 01222 * @param int $attributeID Relation attribute id 01223 * @param int $allRelations Accepted elation bitmask 01224 * @param mixed $groupByAttribute 01225 * @param array $sortBy 01226 * @param int $limit 01227 * @param int $offset 01228 * @param bool $asObject 01229 * @param bool $loadDataMap 01230 * @param bool $ignoreVisibility 01231 * @param array $relatedClassIdentifiers Array of related class identifiers that will be accepted 01232 * @return array ANn array of eZContentObject 01233 */ 01234 static public function fetchRelatedObjects( $objectID, $attributeID, $allRelations, $groupByAttribute, $sortBy, $limit = false, $offset = false, $asObject = true, $loadDataMap = false, $ignoreVisibility = null, array $relatedClassIdentifiers = null ) 01235 { 01236 if ( !is_numeric( $objectID ) ) 01237 { 01238 eZDebug::writeError( "ObjectID is missing or invalid", __METHOD__ ); 01239 return false; 01240 } 01241 01242 $object = eZContentObject::fetch( $objectID ); 01243 if ( !$object instanceof eZContentObject ) 01244 { 01245 eZDebug::writeError( "An error occured fetching object #$objectID", __METHOD__ ); 01246 return false; 01247 } 01248 01249 $params = array(); 01250 $params['Limit'] = $limit; 01251 $params['Offset'] = $offset; 01252 $params['AsObject'] = $asObject; 01253 $params['LoadDataMap'] = $loadDataMap; 01254 01255 if ( $sortBy ) 01256 { 01257 if ( is_array( $sortBy ) ) 01258 { 01259 $params['SortBy'] = $sortBy; 01260 } 01261 else 01262 { 01263 eZDebug::writeError( "Function parameter 'SortBy' should be an array.", 'content/fetchRelatedObjects' ); 01264 } 01265 } 01266 01267 if ( $ignoreVisibility !== null ) 01268 { 01269 $params['IgnoreVisibility'] = $ignoreVisibility; 01270 } 01271 01272 if ( !$attributeID ) 01273 { 01274 $attributeID = 0; 01275 } 01276 01277 if ( isset( $allRelations ) ) 01278 { 01279 if ( $attributeID && !$allRelations ) 01280 { 01281 $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask( array( 'attribute' ) ); 01282 } 01283 elseif( $allRelations === true ) 01284 { 01285 $attributeID = false; 01286 } 01287 else 01288 { 01289 $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask( $allRelations ); 01290 } 01291 } 01292 01293 if ( $relatedClassIdentifiers !== null ) 01294 { 01295 $params['RelatedClassIdentifiers'] = $relatedClassIdentifiers; 01296 } 01297 01298 if ( $attributeID && !is_numeric( $attributeID ) && !is_bool( $attributeID ) ) 01299 { 01300 $attributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier( $attributeID ); 01301 if ( !$attributeID ) 01302 { 01303 eZDebug::writeError( "Can't get class attribute ID by identifier" ); 01304 return false; 01305 } 01306 } 01307 01308 return array( 'result' => $object->relatedContentObjectList( false, $objectID, $attributeID, $groupByAttribute, $params ) ); 01309 } 01310 01311 // Fetches count of reverse related objects 01312 static public function fetchRelatedObjectsCount( $objectID, $attributeID, $allRelations ) 01313 { 01314 if ( !is_numeric( $objectID ) ) 01315 { 01316 eZDebug::writeError( "ObjectID is missing", __METHOD__ ); 01317 return false; 01318 } 01319 01320 $object = eZContentObject::fetch( $objectID ); 01321 if ( !$object instanceof eZContentObject ) 01322 { 01323 eZDebug::writeError( "An error occured fetching object #$objectID", __METHOD__ ); 01324 return false; 01325 } 01326 01327 $params=array(); 01328 if ( !$attributeID ) 01329 { 01330 $attributeID = 0; 01331 } 01332 01333 if ( isset( $allRelations ) ) 01334 { 01335 if ( $attributeID && !$allRelations ) 01336 { 01337 $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask( array( 'attribute' ) ); 01338 } 01339 elseif( $allRelations === true ) 01340 { 01341 $attributeID = false; 01342 } 01343 else 01344 { 01345 $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask( $allRelations ); 01346 } 01347 } 01348 01349 if ( $attributeID && !is_numeric( $attributeID ) && !is_bool( $attributeID ) ) 01350 { 01351 $attributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier( $attributeID ); 01352 if ( !$attributeID ) 01353 { 01354 eZDebug::writeError( "Can't get class attribute ID by identifier" ); 01355 return false; 01356 } 01357 } 01358 01359 return array( 'result' => $object->relatedContentObjectCount( false, $attributeID, $params ) ); 01360 } 01361 01362 static public function fetchReverseRelatedObjects( $objectID, $attributeID, $allRelations, $groupByAttribute, $sortBy, $ignoreVisibility, $limit = false, $offset = false, $asObject = true, $loadDataMap = false ) 01363 { 01364 if ( !$objectID or !is_numeric( $objectID ) ) 01365 { 01366 eZDebug::writeDebug( "Missing or incorrect \$objectID parameter", __METHOD__ ); 01367 return false; 01368 } 01369 01370 $object = eZContentObject::fetch( $objectID ); 01371 if ( !$object instanceof eZContentObject ) 01372 { 01373 eZDebug::writeError( "An error occured fetching object #$objectID", __METHOD__ ); 01374 return false; 01375 } 01376 01377 $params = array(); 01378 $params['Limit'] = $limit; 01379 $params['Offset'] = $offset; 01380 $params['AsObject'] = $asObject; 01381 $params['LoadDataMap'] = $loadDataMap; 01382 01383 if ( $sortBy ) 01384 { 01385 if ( is_array( $sortBy ) ) 01386 { 01387 $params['SortBy'] = $sortBy; 01388 } 01389 else 01390 { 01391 eZDebug::writeError( "Function parameter 'SortBy' should be an array.", 'content/fetchReverseRelatedObjects' ); 01392 } 01393 } 01394 if ( isset( $ignoreVisibility ) ) 01395 { 01396 $params['IgnoreVisibility'] = $ignoreVisibility; 01397 } 01398 if ( !$attributeID ) 01399 { 01400 $attributeID = 0; 01401 } 01402 01403 if ( isset( $allRelations ) ) 01404 { 01405 if ( $attributeID && !$allRelations ) 01406 { 01407 $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask( array( 'attribute' ) ); 01408 } 01409 elseif( $allRelations === true ) 01410 { 01411 $attributeID = false; 01412 } 01413 else 01414 { 01415 $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask( $allRelations ); 01416 } 01417 } 01418 01419 if ( $attributeID && !is_numeric( $attributeID ) && !is_bool( $attributeID ) ) 01420 { 01421 $attributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier( $attributeID ); 01422 if ( !$attributeID ) 01423 { 01424 eZDebug::writeError( "Can't get class attribute ID by identifier" ); 01425 return false; 01426 } 01427 } 01428 return array( 'result' => $object->reverseRelatedObjectList( false, $attributeID, $groupByAttribute, $params ) ); 01429 } 01430 01431 // Fetches count of reverse related objects 01432 static public function fetchReverseRelatedObjectsCount( $objectID, $attributeID, $allRelations, $ignoreVisibility ) 01433 { 01434 if ( !is_numeric( $objectID ) ) 01435 { 01436 eZDebug::writeError( "\$objectID is missing or invalid", __METHOD__ ); 01437 return false; 01438 } 01439 01440 $object = eZContentObject::fetch( $objectID ); 01441 if ( !$object instanceof eZContentObject ) 01442 { 01443 eZDebug::writeError( "An error occured fetching object #$objectID", __METHOD__ ); 01444 return false; 01445 } 01446 01447 $params = array(); 01448 if ( isset( $ignoreVisibility ) ) 01449 { 01450 $params['IgnoreVisibility'] = $ignoreVisibility; 01451 } 01452 01453 if ( !$attributeID ) 01454 { 01455 $attributeID = 0; 01456 } 01457 01458 if ( isset( $allRelations ) ) 01459 { 01460 if ( $attributeID && !$allRelations ) 01461 { 01462 $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask( array( 'attribute' ) ); 01463 } 01464 elseif( $allRelations === true ) 01465 { 01466 $attributeID = false; 01467 } 01468 else 01469 { 01470 $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask( $allRelations ); 01471 } 01472 } 01473 01474 if ( $attributeID && !is_numeric( $attributeID ) && !is_bool( $attributeID ) ) 01475 { 01476 $attributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier( $attributeID ); 01477 if ( !$attributeID ) 01478 { 01479 eZDebug::writeError( "Can't get class attribute ID by identifier" ); 01480 return false; 01481 } 01482 } 01483 return array( 'result' => $object->reverseRelatedObjectCount( false, $attributeID, $params ) ); 01484 } 01485 01486 static public function fetchAvailableSortFieldList() 01487 { 01488 return array( 'result' => array( '6' => ezpI18n::tr( 'kernel/content', 'Class identifier' ), 01489 '7' => ezpI18n::tr( 'kernel/content', 'Class name' ), 01490 '5' => ezpI18n::tr( 'kernel/content', 'Depth' ), 01491 '3' => ezpI18n::tr( 'kernel/content', 'Modified' ), 01492 '9' => ezpI18n::tr( 'kernel/content', 'Name' ), 01493 '1' => ezpI18n::tr( 'kernel/content', 'Path String' ), 01494 '8' => ezpI18n::tr( 'kernel/content', 'Priority' ), 01495 '2' => ezpI18n::tr( 'kernel/content', 'Published' ), 01496 '4' => ezpI18n::tr( 'kernel/content', 'Section' ) ) ); 01497 } 01498 01499 static public function fetchCountryList( $filter, $value ) 01500 { 01501 // Fetch country list 01502 if ( !$filter and !$value ) 01503 { 01504 $country = eZCountryType::fetchCountryList(); 01505 } 01506 else 01507 { 01508 $country = eZCountryType::fetchCountry( $value, $filter ); 01509 } 01510 01511 return array( 'result' => $country ); 01512 } 01513 01514 static public function fetchContentTreeMenuExpiry() 01515 { 01516 eZExpiryHandler::registerShutdownFunction(); 01517 01518 $expiryHandler = eZExpiryHandler::instance(); 01519 01520 if ( !$expiryHandler->hasTimestamp( 'content-tree-menu' ) ) 01521 { 01522 $expiryHandler->setTimestamp( 'content-tree-menu', time() ); 01523 $expiryHandler->store(); 01524 } 01525 01526 return array( 'result' => $expiryHandler->timestamp( 'content-tree-menu' ) ); 01527 } 01528 } 01529 01530 ?>