| // +---------------------------------------------------------------------------+ // $Id$ /** * Base class for navigation module. * * @package navigation * @author Demian Turner * @version $Revision: 1.12 $ */ class MenuBuilder { var $GUI = null; var $options = array(); var $_startId = 0; var $_options = array(); function MenuBuilder($type, $options = array()) { SGL::logMessage(null, PEAR_LOG_DEBUG); $this->_options = $options; $c = &SGL_Config::singleton(); $conf = $c->getAll(); $this->GUI = & $this->_factory($type, $conf, $options); $this->GUI->dbCatTableName = (isset($options['table'])) ? $options['table']: $conf['table']['category']; } function setStartId($startId = 0) { SGL::logMessage(null, PEAR_LOG_DEBUG); $this->_startId = $startId; } function &_factory($type, $conf, $options = array()) { SGL::logMessage(null, PEAR_LOG_DEBUG); $guiPath = SGL_MOD_DIR . "/navigation/classes/menu/$type.php"; require_once $guiPath; $guiClass = 'Menu_' . $type; if (!class_exists($guiClass)) { SGL::raiseError("$guiClass is not a valid classname", SGL_ERROR_NOCLASS); } @$obj = & new $guiClass($options, $conf); return $obj; } function toHtml() { SGL::logMessage(null, PEAR_LOG_DEBUG); $menuType = strtolower(get_class($this->GUI)); switch ($menuType) { case 'menu_explorer': // cannot cache at this level because output is sent to blocks // which are cacheable $ret = $this->GUI->render($this->_startId); // add closing js script tags $ret .= 'document.write(tree);}'; $ret .= ''; break; case 'menu_explorerbsd': $ret = $this->GUI->render($this->_startId); break; case 'menu_selectbox': $cache = & SGL_Cache::singleton(); $cacheId = 'categorySelect' . $this->_startId . serialize($this->_options); if ($data = $cache->get($cacheId, 'categorySelect')) { $ret = unserialize($data); SGL::logMessage('categorySelect from cache', PEAR_LOG_DEBUG); } else { SGL::logMessage('categorySelect from db', PEAR_LOG_DEBUG); $ret = $this->GUI->render($this->_startId); $data = serialize($ret); $cache->save($data, $cacheId, 'categorySelect'); } break; case 'menu_anchortoc': $ret = $this->GUI->render($this->_startId); break; default: $ret = 'incorrect menu type specified'; } return $ret; } function getBreadCrumbs($catID, $links = true) { return $this->GUI->getBreadCrumbs($catID, $links); } } ?>