baseline
[omp.pkp.sfu.ca.git] / lib / pkp / pages / help / HelpHandler.inc.php
blob8ff775c82668a5f9edae0ffa5c47e2cf6f540f79
1 <?php
3 /**
4 * @file HelpHandler.inc.php
6 * Copyright (c) 2000-2009 John Willinsky
7 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
9 * @class HelpHandler
10 * @ingroup pages_help
12 * @brief Handle requests for viewing help pages.
17 define('HELP_DEFAULT_TOPIC', 'index/topic/000000');
18 define('HELP_DEFAULT_TOC', 'index/toc/000000');
20 import('help.HelpToc');
21 import('help.HelpTocDAO');
22 import('help.HelpTopic');
23 import('help.HelpTopicDAO');
24 import('help.HelpTopicSection');
25 import('handler.Handler');
27 class HelpHandler extends Handler {
29 /**
30 * Display help table of contents.
32 function index() {
33 $this->view(array('index', 'topic', '000000'));
36 function toc() {
37 $this->validate();
38 $this->setupTemplate();
40 $templateMgr =& TemplateManager::getManager();
41 import('help.Help');
42 $help =& Help::getHelp();
43 $templateMgr->assign_by_ref('helpToc', $help->getTableOfContents());
44 $templateMgr->display('help/helpToc.tpl');
47 /**
48 * Display the selected help topic.
49 * @param $args array first parameter is the ID of the topic to display
51 function view($args) {
52 $this->validate();
53 $this->setupTemplate();
55 $topicId = implode("/",$args);
56 $keyword = trim(String::regexp_replace('/[^\w\s\.\-]/', '', strip_tags(Request::getUserVar('keyword'))));
57 $result = (int) Request::getUserVar('result');
59 $topicDao =& DAORegistry::getDAO('HelpTopicDAO');
60 $topic = $topicDao->getTopic($topicId);
62 if ($topic === false) {
63 // Invalid topic, use default instead
64 $topicId = HELP_DEFAULT_TOPIC;
65 $topic = $topicDao->getTopic($topicId);
68 $tocDao =& DAORegistry::getDAO('HelpTocDAO');
69 $toc = $tocDao->getToc($topic->getTocId());
71 if ($toc === false) {
72 // Invalid toc, use default instead
73 $toc = $tocDao->getToc(HELP_DEFAULT_TOC);
76 if ($topic->getSubTocId() != null) {
77 $subToc = $tocDao->getToc($topic->getSubTocId());
78 } else {
79 $subToc = null;
82 $relatedTopics = $topic->getRelatedTopics();
84 $topics = $toc->getTopics();
86 $templateMgr =& TemplateManager::getManager();
87 $templateMgr->assign('currentTopicId', $topic->getId());
88 $templateMgr->assign_by_ref('topic', $topic);
89 $templateMgr->assign('toc', $toc);
90 $templateMgr->assign('subToc', $subToc);
91 $templateMgr->assign('relatedTopics', $relatedTopics);
92 $templateMgr->assign('locale', Locale::getLocale());
93 $templateMgr->assign('breadcrumbs', $toc->getBreadcrumbs());
94 if (!empty($keyword)) {
95 $templateMgr->assign('helpSearchKeyword', $keyword);
97 if (!empty($result)) {
98 $templateMgr->assign('helpSearchResult', $result);
100 $templateMgr->display('help/view.tpl');
104 * Display search results for a topic search by keyword.
106 function search() {
107 $this->validate();
108 $this->setupTemplate();
110 $searchResults = array();
112 $keyword = trim(String::regexp_replace('/[^\w\s\.\-]/', '', strip_tags(Request::getUserVar('keyword'))));
114 if (!empty($keyword)) {
115 $topicDao =& DAORegistry::getDAO('HelpTopicDAO');
116 $topics = $topicDao->getTopicsByKeyword($keyword);
118 $tocDao =& DAORegistry::getDAO('HelpTocDAO');
119 foreach ($topics as $topic) {
120 $searchResults[] = array('topic' => $topic, 'toc' => $tocDao->getToc($topic->getTocId()));
124 $templateMgr =& TemplateManager::getManager();
125 $templateMgr->assign('showSearch', true);
126 $templateMgr->assign('pageTitle', Locale::translate('help.searchResults'));
127 $templateMgr->assign('helpSearchKeyword', $keyword);
128 $templateMgr->assign('searchResults', $searchResults);
129 $templateMgr->display('help/searchResults.tpl');
133 * Initialize the template
135 function setupTemplate() {
136 parent::setupTemplate();
138 $templateMgr =& TemplateManager::getManager();
139 $templateMgr->setCacheability(CACHEABILITY_PUBLIC);