Exemplo n.º 1
0
 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 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);
     // }
 }