/** * recursive chapter output * * ... yeah :( * * @param Chapter $chapter * @return string */ function outputChapter(Chapter $chapter, View $view) { ?> <li class="chapter"> <h2><?php echo $chapter->getName(); ?> </h2> <?php if (count($chapter->getChapters()) > 0) { ?> <ul class="chapters"> <?php foreach ($chapter->getChapters() as $subChapter) { ?> <?php outputChapter($subChapter, $view); ?> <?php } ?> </ul> <?php } ?> <?php if (count($chapter->getPages()) > 0) { ?> <ul class="pages"> <?php foreach ($chapter->getPages() as $page) { ?> <li> <a href="<?php echo $view['router']->generate('book_page', array('path' => $page->getPath())); ?> "> <?php echo $page->getTitle(); ?> </a> </li> <?php } ?> </ul> <?php } ?> </li> <?php }
/** * recursive chapter output * * ... yeah :( * * @param Chapter $chapter * @return string */ function outputChapter(Chapter $chapter) { ?> <h1><?php echo $chapter->getName(); ?> </h1> <?php if (count($chapter->getChapters()) > 0) { ?> <ul class="chapters"> <?php foreach ($chapter->getChapters() as $subChapter) { ?> <?php outputChapter($subChapter); ?> <?php } ?> </ul> <?php } ?> <?php if (count($chapter->getPages()) > 0) { ?> <ul class="pages"> <h2>Pagina's</h2> <?php foreach ($chapter->getPages() as $page) { ?> <?php echo $page->getParsedText(); ?> <?php } ?> </ul> <?php } }
/** * add a chapter * * @param Chapter $chapter * @return void */ public function addChapter(Chapter $chapter) { $chapter->setParent($this); $this->chapters[] = $chapter; }
/** * find chapter from path recursively * * @param Chapter $chapter * @param string $path * @return bool|Chapter */ private function findPageFromPath(Chapter $chapter, $path) { foreach ($chapter->getPages() as $page) { if ($page->getPath() == $path) { return $page; } } foreach ($chapter->getChapters() as $subChapter) { $found = $this->findPageFromPath($subChapter, $path); if ($found !== false) { return $found; } } return false; }
/** * create chapter from directory name * * @param string $name * @return Chapter */ private function createChapterFromFileInfo(\SplFileInfo $fileInfo) { $chapter = new Chapter(); $chapter->setName($this->stripNumberFromString($fileInfo->getFilename())); $chapter->setPath($this->parsePath($fileInfo)); //set "path" like identifier return $chapter; }