private function getDocumentations($sPreferredLanguageId) { $aMetaData = DocumentationProviderTypeModule::completeMetaData(); $aPreferredDocumentationLanguages = array_unique(array($sPreferredLanguageId, 'de', 'en')); $cFormat = function ($aLanguageData) use($aPreferredDocumentationLanguages) { $oResult = new stdClass(); foreach ($aPreferredDocumentationLanguages as $sLanguageId) { if (isset($aLanguageData[$sLanguageId])) { $oResult->title = $aLanguageData[$sLanguageId]['title']; $oResult->url = $aLanguageData[$sLanguageId]['url']; } } return $oResult; }; // A list of all documentation heads, by key. Documentation heads are all the documentations whose keys do not contain a slash $aDocumentations = array(); // Try to figure out how many documentations (and which ones) there are foreach ($aMetaData as $sKey => $aLanguageData) { if (strpos($sKey, '/') !== false) { continue; } $aDocumentations[$sKey] = $cFormat($aLanguageData); $aDocumentations[$sKey]->parts = array(); } // Add keys to documentations foreach ($aMetaData as $sKey => $aLanguageData) { if (strpos($sKey, '/') === false) { continue; } $sDocumentationKey = explode('/', $sKey); $sPartKey = implode('/', array_slice($sDocumentationKey, 1)); $sDocumentationKey = $sDocumentationKey[0]; if (isset($aDocumentations[$sDocumentationKey])) { $aDocumentations[$sDocumentationKey]->parts[$sPartKey] = $cFormat($aLanguageData); } else { // If there are no documentations with this key, just pretend it’s a documentation in itself $aDocumentations[$sKey] = $cFormat($aLanguageData); $aDocumentations[$sKey]->parts = array(); } } $aEmptyDocumentations = array(); foreach ($aDocumentations as $sKey => $oDocumentation) { if (count($oDocumentation->parts) === 0) { $aEmptyDocumentations[$sKey] = $oDocumentation; unset($aDocumentations[$sKey]); } } usort($aDocumentations, function ($a, $b) { return strnatcasecmp($a->title, $b->title); }); if (count($aEmptyDocumentations) > 0) { $oOthers = new stdClass(); $oOthers->title = TranslationPeer::getString('wns.others', $sPreferredLanguageId, 'Weiteres'); $oOthers->url = null; $oOthers->parts = $aEmptyDocumentations; $aDocumentations[] = $oOthers; } return $aDocumentations; }
public function partFor($sDocumentationPartKey) { $oResult = new stdClass(); $aData = DocumentationProviderTypeModule::dataForPart($sDocumentationPartKey, Session::language()); if (!$aData) { throw new LocalizedException("wns.documentation.unknown", array('key' => $sDocumentationPartKey, 'language' => Session::language())); } $oResult->title = $aData['title']; $oResult->content = $aData['content']; $oResult->url = $aData['url']; return $oResult; }
public function onNavigationItemChildrenRequested(NavigationItem $oNavigationItem) { if (!($oNavigationItem instanceof PageNavigationItem && $oNavigationItem->getIdentifier() === self::PARENT_PAGE_IDENTIFIER)) { return; } $aDocumentationPartKeys = array(); foreach (DocumentationProviderTypeModule::completeMetaData() as $sPart => $aLanguages) { if (isset($aLanguages[Session::language()])) { $aDocumentationPartKeys[$sPart] = false; } } foreach (DocumentationPartQuery::create()->filterByLanguageId(Session::language())->select('Key')->find() as $sPart) { $aDocumentationPartKeys[$sPart] = true; } ksort($aDocumentationPartKeys); $aDocumentations = DocumentationsFrontendModule::listQuery()->select(array('Key', 'Name', 'Title', 'NameSpace'))->find(); foreach ($aDocumentations as $aParams) { $aConfiguredParts = array(); foreach ($aDocumentationPartKeys as $sKey => $bIsInternal) { if (StringUtil::startsWith($sKey, $aParams['NameSpace'] . '.')) { $aConfiguredParts[$sKey] = $bIsInternal; unset($aDocumentationPartKeys[$sKey]); } else { if ($sKey > $aParams['NameSpace'] . '.') { break; } } } $sTitle = $aParams['Title'] != null ? $aParams['Title'] : $aParams['Name']; $oNavItem = new VirtualNavigationItem(self::ITEM_TYPE, $aParams['Key'], 'Dokumentation ' . $sTitle, $aParams['Name'], $aConfiguredParts); $oNavigationItem->addChild($oNavItem); } // if(count($aDocumentationPartKeys) > 0) { // $oNavItem = new VirtualNavigationItem(self::ITEM_TYPE_UNCATEGORIZED, 'uncategorized', TranslationPeer::getString('documentations.uncategorized'), null, $aDocumentationPartKeys); // $oNavigationItem->addChild($oNavItem); // } }
public function documentationData($sDocumentationName) { return DocumentationProviderTypeModule::dataForPart($sDocumentationName, Session::language()); }
public function renderDetail(Documentation $oDocumentation = null) { if (self::$DOCUMENTATION_PARTS == null) { self::$DOCUMENTATION_PARTS = DocumentationPartQuery::create()->filterByDocumentationId($oDocumentation->getId())->filterByIsPublished(true)->orderBySort()->find(); } if ($oDocumentation) { $sName = $oDocumentation->getName(); $sEmbedUrl = $oDocumentation->getYoutubeUrl(); $sDescription = RichtextUtil::parseStorageForFrontendOutput(stream_get_contents($oDocumentation->getDescription())); } else { $sName = TranslationPeer::getString('documentations.uncategorized'); $sEmbedUrl = null; $sDescription = null; } $oTemplate = $this->constructTemplate('documentation'); // render video if exists if ($sEmbedUrl != null) { $this->embedVideo($oTemplate, $sEmbedUrl); } $oTemplate->replaceIdentifier('documentation_name', $sName); $oTemplate->replaceIdentifier('description', $sDescription); // render parts $oPartTmpl = $this->constructTemplate('part'); $sLinkToSelf = LinkUtil::linkToSelf(); $bRequiresQuicklinks = count(self::$DOCUMENTATION_PARTS) > 1; $oPartLinkPrototype = $this->constructTemplate('part_link'); foreach (self::$DOCUMENTATION_PARTS as $sKey => $mPart) { if ($mPart === true) { $mPart = DocumentationPartQuery::create()->filterByKey($sKey)->findOne(); } $bIsOverview = false; if ($mPart instanceof DocumentationPart) { //Internal documentation $sBody = RichtextUtil::parseStorageForFrontendOutput(stream_get_contents($mPart->getBody())); $sLinkText = $mPart->getName(); $sTitle = $mPart->getTitle(); $sImageUrl = null; if ($mPart->getDocument()) { $sImageUrl = $mPart->getDocument()->getDisplayUrl(); if (RichtextUtil::$USE_ABSOLUTE_LINKS) { $sImageUrl = LinkUtil::absoluteLink($sImageUrl); } } $sKey = $mPart->getKey(); $bIsOverview = $mPart->getIsOverview(); $sExternalLink = null; } else { //External documentation $aData = DocumentationProviderTypeModule::dataForPart($sKey, Session::language()); $sBody = new Template($aData['content'], null, true); $sLinkText = $aData['title']; $sTitle = null; $sImageUrl = null; $sExternalLink = $aData['url']; } // Add quick links if ($bRequiresQuicklinks) { $oPartLink = clone $oPartLinkPrototype; $oPartLink->replaceIdentifier('href', $sLinkToSelf . '#' . $sKey); $oPartLink->replaceIdentifier('link_text', $sLinkText); if ($sTitle != null) { $oPartLink->replaceIdentifier('title', $sTitle); } $oTemplate->replaceIdentifierMultiple('part_links', $oPartLink, null, Template::NO_NEW_CONTEXT); } // Add documentation part $oPartTemplate = clone $oPartTmpl; $oPartTemplate->replaceIdentifier('name', $sLinkText); $oPartTemplate->replaceIdentifier('anchor', $sKey); $oPartTemplate->replaceIdentifier('href_top', $sLinkToSelf . "#top_of_page"); $oPartTemplate->replaceIdentifier('external_link', $sExternalLink); if ($sImageUrl) { $oPartTemplate->replaceIdentifier('image', TagWriter::quickTag('img', array('class' => !$bIsOverview ? 'image_float' : "image_fullwidth", 'src' => $sImageUrl, 'alt' => 'Bildschirmfoto von ' . $sLinkText))); $oPartTemplate->replaceIdentifier('margin_left_class', $bIsOverview ? '' : ' margin_left_class'); } $oPartTemplate->replaceIdentifier('content', $sBody); $oTemplate->replaceIdentifierMultiple('part', $oPartTemplate); } return $oTemplate; }