00001 <?php
00002
00016
00017
00018
00019 import('help.HelpToc');
00020
00021 class HelpTocDAO extends XMLDAO {
00022 function &_getCache($tocId) {
00023 static $cache;
00024 $locale = Help::getLocale();
00025
00026 if (!isset($cache[$locale][$tocId])) {
00027 import('cache.CacheManager');
00028 $help =& Help::getHelp();
00029 $cacheManager =& CacheManager::getManager();
00030 $cache[$locale][$tocId] = $cacheManager->getFileCache('help-toc-' . $help->getLocale(), $tocId, array($this, '_cacheMiss'));
00031
00032
00033 $cacheTime = $cache[$locale][$tocId]->getCacheTime();
00034 if ($cacheTime !== null && $cacheTime < filemtime($this->getFilename($tocId))) {
00035
00036 $cache[$locale][$tocId]->flush();
00037 }
00038 }
00039 return $cache[$locale][$tocId];
00040 }
00041
00042 function _cacheMiss(&$cache, $id) {
00043 static $data;
00044
00045 if (!isset($data)) {
00046 $helpFile = $this->getFilename($cache->getCacheId());
00047 $data = &$this->parseStruct($helpFile);
00048
00049
00050 if ($data === false) {
00051 $returner = false;
00052 return $returner;
00053 }
00054 $cache->setEntireCache($data);
00055 }
00056 return null;
00057 }
00058
00059 function &getMappingFile($tocId) {
00060 $help =& Help::getHelp();
00061 $mappingFiles =& $help->getMappingFiles();
00062
00063 for ($i=0; $i < count($mappingFiles); $i++) {
00064
00065 $mappingFile =& $mappingFiles[$i];
00066 if ($mappingFile->containsToc($tocId)) return $mappingFile;
00067 unset($mappingFile);
00068 }
00069 $returner = null;
00070 return $returner;
00071 }
00072
00073 function getFilename($tocId) {
00074 $mappingFile =& $this->getMappingFile($tocId);
00075 return $mappingFile?$mappingFile->getTocFilename($tocId):null;
00076 }
00077
00083 function &getToc($tocId) {
00084 $cache =& $this->_getCache($tocId);
00085 $data = $cache->getContents();
00086
00087
00088 if (!is_array($data)) {
00089 $returner = false;
00090 return $returner;
00091 }
00092
00093 $toc = &new HelpToc();
00094
00095 $toc->setId($data['toc'][0]['attributes']['id']);
00096 $toc->setTitle($data['toc'][0]['attributes']['title']);
00097 if (isset($data['toc'][0]['attributes']['parent_topic'])) {
00098 $toc->setParentTopicId($data['toc'][0]['attributes']['parent_topic']);
00099 }
00100
00101 if (isset($data['topic'])) {
00102 foreach ($data['topic'] as $topicData) {
00103 $topic = &new HelpTopic();
00104 $topic->setId($topicData['attributes']['id']);
00105 $topic->setTitle($topicData['attributes']['title']);
00106 $toc->addTopic($topic);
00107 }
00108 }
00109
00110 if (isset($data['breadcrumb'])) {
00111 foreach ($data['breadcrumb'] as $breadcrumbData) {
00112 $toc->addBreadcrumb($breadcrumbData['attributes']['title'], $breadcrumbData['attributes']['url']);
00113 }
00114 }
00115
00116 return $toc;
00117 }
00118 }
00119
00120 ?>