Example #1
0
 function manual($params)
 {
     // View
     $view = new View();
     // TOC
     $toc = array('introduction' => array('title' => 'Introduction', 'chapters' => array('requirements' => array('title' => 'System requirements', 'chapters' => array('phpext' => array('title' => 'PHP extensions'))), 'installation' => array('title' => 'Installation'), 'post-installation' => array('title' => 'Post-installation tasks', 'chapters' => array('#app-config' => array('title' => 'Application configuration variables'), '#db-connection' => array('title' => 'Database connections'), '#model-relations' => array('title' => 'Define Model relationships'), '#bootstrap' => array('title' => 'Bootstrap script'))), 'conventions' => array('title' => 'Conventions'), 'autoloading' => array('title' => 'Class autoloading'))), 'how-it-works' => array('title' => 'How it works', 'chapters' => array('#urlcommand' => array('title' => 'The UrlCommand', 'chapters' => array('#global-view' => array('title' => "The '/global-view' command"))), '#rendering' => array('title' => 'Rendering a View to output'), 'global-config' => array('title' => 'Global configuration'))), 'environment' => array('title' => 'The Buan environment', 'chapters' => array('#global-config' => array('title' => 'Global configuration variables'))), 'controller' => array('title' => 'The Controller'), 'model' => array('title' => 'The Model', 'chapters' => array('#model-manager' => array('title' => 'ModelManager'), 'relationships' => array('title' => 'Model relationships'), 'example' => array('title' => 'Basic example'))), 'view' => array('title' => 'The View', 'chapters' => array('#global-view' => array('title' => 'The GlobalView'))), 'extensions' => array('title' => 'Buan Extensions'), 'example-app' => array('title' => 'Example application'));
     $view->toc = $toc;
     // Determine requested page
     $chapter = $chapterPath = $previousChapterPath = $nextChapterPath = NULL;
     if (isset($params[0])) {
         $chapters = strpos($params[0], '.') > 0 ? explode(".", $params[0]) : array($params[0]);
         $c = array_shift($chapters);
         $chapterPath = $c;
         $chapterChain = array();
         if (isset($toc[$c])) {
             // Find position of chapter within tree
             $chapterIndex = '';
             $count = 1;
             foreach ($toc as $k => $v) {
                 if ($k == $c) {
                     break;
                 }
                 $count++;
             }
             $chapter = $toc[$c];
             $chapter['__key'] = $c;
             $chapterChain[] = $chapter;
             $chapterIndex = $count;
             // Search through sub-chapters to find target chapter
             while (count($chapters) > 0 && $chapter !== NULL) {
                 $c = array_shift($chapters);
                 $chapterPath .= ".{$c}";
                 if (isset($chapter['chapters'][$c])) {
                     $count = 1;
                     foreach ($chapter['chapters'] as $k => $v) {
                         if ($k == $c) {
                             break;
                         }
                         $count++;
                     }
                     $chapter = $chapter['chapters'][$c];
                     $chapter['__key'] = $c;
                     $chapterChain[] = $chapter;
                     $chapterIndex .= ".{$count}";
                 } else {
                     $chapter = NULL;
                 }
             }
             // Work out previous and next chapters
         }
     }
     $templateFile = $chapter === NULL ? 'toc.tpl' : 'chapter.' . $chapterPath . '.tpl';
     $view->setSource(Config::get('core.dir.views') . '/core/manual/' . $templateFile);
     // Manual wrapper
     $wrapper = new View();
     $wrapper->setSource(Config::get('core.dir.views') . '/core/manual/wrapper.tpl');
     $wrapper->attachViewToSlot($view, 'chapter');
     $wrapper->footer = array('previous' => $chapter === NULL ? NULL : ($previousChapterPath === NULL ? NULL : UrlCommand::createUrl('core', 'manual', $previousChapterPath)), 'next' => $chapter === NULL ? NULL : ($nextChapterPath === NULL ? NULL : UrlCommand::createUrl('core', 'manual', $nextChapterPath)));
     $wrapper->chapterH1 = $chapter === NULL ? 'Table of Contents' : "{$chapterIndex}. {$chapter['title']}";
     // Result
     return $this->wrapper($wrapper);
 }