root = new Chapter(); $this->chapter = &$this->root; //initial chapter is root $this->paths = array(); return true; } //init() /** * @brief handles the command * @param $command [String] command that rised this event * @param $params [String] params behind the keyword * @return [void/String] null or String which to put in place of command */ public function execute($command, $params) { $skip = Config::get('skipFirstChapter'); switch($command){ case 'kapitola': $index = $this->addChapter(0, $params); if (!$skip) { $index++; } $this->paths[0] = (string)$index; return 'Hlavní menu
' .'

'.(0 === $index?'':$index.'. ').$params.'

'; break; case 'nadpis': $index = $this->addChapter(1, $params); $index++; $this->paths[1] = $this->paths[0].'_'.$index; return '
Hlavní menu' .'

'.$index.'. '.$params.'

'; break; case 'úkol': $index = $this->addChapter(2, $params); $index++; $this->paths[2] = $this->paths[1].'_'.$index; return '
Hlavní menu' .'

'.$index.'. '.$params.'

'; break; } // switch } //execute() /** * @brief sets current level to requested one * @param [integer] requested level * @param [void] reserver * @return [mixed] integer for success (number of steps), false for error, null for root */ public function gotoLevel($level, $step = 0) { $currentLevel = $this->chapter->getLevel(); if ($level == $currentLevel) { //end of recurse return $step; } //end of recurse elseif ($level < $currentLevel) { //go to previous (parent) level if ($this->chapter->isRoot()) { //we are already in root - an error? return null; } else { $this->chapter = & $this->chapter->getParent(); return $this->gotoLevel($level, --$step); } //chapter is root } //go to previous level else { //go to next level $chapter = & $this->chapter->getChapter(); //get active sub-chapter if (null === $chapter) { //active chapter does not exist return false; } else { $this->chapter = & $chapter; return $this->gotoLevel($level, ++$step); } //chapter exists } //go to next level } //gotoLevel() /** * @brief returns current chapter * @return [Chapter] */ public function getPath() { $pointer = $this->chapter; } /** * @brief adds new chapter to the requested level * @param [integer] level for the chapter * @param [string] caption of the chapter * @return [integer] index of the new chapter in its level * @throws shows alert when chapter cannot be created in requested level */ public function addChapter($level, $caption) { if (false === $this->gotoLevel($level)) { echo (""); } $index = $this->chapter->addChapter($caption); //set active chapter to last on $this->chapter = & $this->chapter->getChapter(); return $index; } public function &getRoot() { return $this->root; } } //class Chapters //Register this class as Interpreter and Observer Plugins::register(Plugins::INTERPRETER, 'Chapters'); ?>