/** * @param string $sectionRemote * @param int|eZContentObjectTreeNode $chapterNode * @param int|eZContentObjectTreeNode $topicNode * @param string $linkType * @return array */ public static function fetchUnifiedUrl( $sectionRemote, $chapterNode, $topicNode, $linkType ) { $error = false; if ( !in_array($linkType, array('section', 'chapter', 'topic')) ) { $error = true; } else { if ( is_numeric($chapterNode) && $chapterNode ) $chapterNode = eZContentObjectTreeNode::fetch($chapterNode); if ( is_numeric($topicNode) && $topicNode ) $topicNode = eZContentObjectTreeNode::fetch($topicNode); switch ( true ) { case ( $topicNode instanceof eZContentObjectTreeNode ): $chapterNode = $topicNode->fetchParent(); case ( $chapterNode instanceof eZContentObjectTreeNode ): if ( !$sectionRemote ) { /* @type $chapterDM eZContentObjectAttribute[] */ $chapterDM = $chapterNode->dataMap(); if ( isset($chapterDM['serialized_taxonomies']) ) { $chapterSerial = $chapterDM['serialized_taxonomies']->content(); if ( isset($chapterSerial['section']) && count($chapterSerial['section']) > 0 ) $sectionRemote = $chapterSerial['section'][0]; } } case ( $sectionRemote != "" ): $sectionUrl = false; $section = self::fetchSection('remote', $sectionRemote); if ( $section['result'] ) { $sectionUrl = '/' . $section['result']['url']; } else { $error = true; } break; default: $error = true; break; } } if ( !$error ) { /* @type $sectionUrl string */ $applicationLocalized = CacheApplicationTool::buildLocalizedApplicationByIdentifier(MerckManualShowcase::mainApplicationIdentifier()); $publisherFolderNodeId = MerckManualShowcase::rootNodeId(); $publisherFolderNode = eZContentObjectTreeNode::fetch($publisherFolderNodeId); $publisherFolderInfo = PublisherFolderTool::getNodeIdToPathMapping( $publisherFolderNodeId ); $publisherFolderId = $publisherFolderInfo['pfid']; // Link in about page $AboutChapterNodeID = MerckManualAbout::rootNodeId(); if ( $topicNode && in_array($AboutChapterNodeID, $topicNode->pathArray()) ) { $topicUrl = end(explode('/', $topicNode->attribute('url_alias'))); return array('result' => CacheApplicationTool::buildLocalizedApplicationByIdentifier(MerckManualAbout::mainApplicationIdentifier())->url . '/' . $topicUrl); } $url = null; $applicationObject = $applicationLocalized->applicationObject(); $forceExternalLink = $applicationObject->hasExternalLinkHandler(); switch ( $linkType ) { case 'topic': if ( !( $topicNode instanceof eZContentObjectTreeNode ) ) { $error = true; break; } $urlParts = explode('/', $topicNode->attribute('url_alias')); $urlParts = array_slice($urlParts, $publisherFolderNode->attribute('depth') - $topicNode->attribute('depth')); $url = $applicationLocalized->applicationUrl($forceExternalLink) . '/' . $publisherFolderId . $sectionUrl . '/' . implode('/', $urlParts); break; case 'chapter': if ( !( $chapterNode instanceof eZContentObjectTreeNode ) ) { $error = true; break; } $urlParts = explode('/', $chapterNode->attribute('url_alias')); $urlParts = array_slice($urlParts, $publisherFolderNode->attribute('depth') - $chapterNode->attribute('depth')); $url = $applicationLocalized->applicationUrl( $forceExternalLink ) . '/' . $publisherFolderId . $sectionUrl . '/' . implode('/', $urlParts); break; case 'section': $url = $applicationLocalized->applicationUrl() . '/' . $publisherFolderId . $sectionUrl; break; default: $url = ''; $error = true; break; } } return array('result' => !$error ? $url : null); }
/** * @return int */ public static function rootNodeId() { if (self::$rootNodeID == null) { $aboutChapterPublisherInternalID = self::iniMerck()->variable( 'MerckManualAboutSettings', 'PublisherInternalID' ); $params = array( 'ClassFilterType' => 'include', 'ClassFilterArray' => array('article'), 'Limit' => 1, 'Offset' => 0, 'Depth' => 1, 'AttributeFilter' => array( array( 'article/publisher_internal_id', 'like', strtolower($aboutChapterPublisherInternalID) . '*' ) ), ); /* @type $nodes eZContentObjectTreeNode[] */ $nodes = eZContentObjectTreeNode::subTreeByNodeID( $params, MerckManualShowcase::rootNodeId() ); $node = $nodes[0]; if ( !empty( $nodes ) ) self::$rootNodeID = $node->attribute('node_id'); } return self::$rootNodeID; }