2014-01-24 16:41:37 +01:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-06-30 15:48:43 +02:00
|
|
|
use \Zend_Controller_Action_Exception;
|
2014-01-24 16:41:37 +01:00
|
|
|
use Icinga\Application\Icinga;
|
2014-05-27 14:53:25 +02:00
|
|
|
use Icinga\Module\Doc\DocController;
|
2014-06-30 15:48:43 +02:00
|
|
|
use Icinga\Module\Doc\Exception\DocException;
|
2014-01-24 16:41:37 +01:00
|
|
|
|
2014-02-03 15:39:53 +01:00
|
|
|
class Doc_ModuleController extends DocController
|
2014-01-24 16:41:37 +01:00
|
|
|
{
|
|
|
|
/**
|
2014-06-30 11:43:25 +02:00
|
|
|
* List modules which are enabled and having the 'doc' directory
|
2014-01-24 16:41:37 +01:00
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2014-06-30 11:43:25 +02:00
|
|
|
$moduleManager = Icinga::app()->getModuleManager();
|
|
|
|
$modules = array();
|
|
|
|
foreach (Icinga::app()->getModuleManager()->listEnabledModules() as $enabledModule) {
|
|
|
|
$docDir = $moduleManager->getModuleDir($enabledModule, '/doc');
|
|
|
|
if (is_dir($docDir)) {
|
|
|
|
$modules[] = $enabledModule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->view->modules = $modules;
|
2014-01-24 16:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-27 14:53:25 +02:00
|
|
|
* Assert that the given module is enabled
|
2014-01-24 16:41:37 +01:00
|
|
|
*
|
2014-05-27 14:53:25 +02:00
|
|
|
* @param $moduleName
|
2014-01-24 16:41:37 +01:00
|
|
|
*
|
2014-07-28 19:17:03 +02:00
|
|
|
* @throws Zend_Controller_Action_Exception If the required parameter 'moduleName' is empty or either if the
|
|
|
|
* given module is neither installed nor enabled
|
2014-01-24 16:41:37 +01:00
|
|
|
*/
|
2014-05-27 14:53:25 +02:00
|
|
|
protected function assertModuleEnabled($moduleName)
|
2014-01-24 16:41:37 +01:00
|
|
|
{
|
2014-07-28 19:17:03 +02:00
|
|
|
if (empty($moduleName)) {
|
|
|
|
throw new Zend_Controller_Action_Exception(
|
|
|
|
$this->translate('Missing parameter \'moduleName\''),
|
|
|
|
404
|
|
|
|
);
|
2014-05-27 14:53:25 +02:00
|
|
|
}
|
2014-05-23 14:06:28 +02:00
|
|
|
$moduleManager = Icinga::app()->getModuleManager();
|
2014-05-27 14:53:25 +02:00
|
|
|
if (! $moduleManager->hasInstalled($moduleName)) {
|
2014-07-28 19:17:03 +02:00
|
|
|
throw new Zend_Controller_Action_Exception(
|
2014-08-19 13:20:46 +02:00
|
|
|
$this->translate(sprintf('Module \'%s\' is not installed', $moduleName)),
|
2014-07-28 19:17:03 +02:00
|
|
|
404
|
|
|
|
);
|
2014-05-27 14:53:25 +02:00
|
|
|
}
|
2014-05-23 14:06:28 +02:00
|
|
|
if (! $moduleManager->hasEnabled($moduleName)) {
|
2014-07-28 19:17:03 +02:00
|
|
|
throw new Zend_Controller_Action_Exception(
|
2014-08-19 13:20:46 +02:00
|
|
|
$this->translate(sprintf('Module \'%s\' is not enabled', $moduleName)),
|
2014-07-28 19:17:03 +02:00
|
|
|
404
|
|
|
|
);
|
2014-01-24 16:41:37 +01:00
|
|
|
}
|
2014-05-27 14:53:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-28 19:17:03 +02:00
|
|
|
* View the toc of a module's documentation
|
|
|
|
*
|
|
|
|
* @see assertModuleEnabled()
|
2014-05-27 14:53:25 +02:00
|
|
|
*/
|
|
|
|
public function tocAction()
|
|
|
|
{
|
|
|
|
$moduleName = $this->getParam('moduleName');
|
|
|
|
$this->assertModuleEnabled($moduleName);
|
|
|
|
$moduleManager = Icinga::app()->getModuleManager();
|
2014-06-30 15:48:43 +02:00
|
|
|
try {
|
2014-07-28 19:17:03 +02:00
|
|
|
$this->renderToc(
|
|
|
|
$moduleManager->getModuleDir($moduleName, '/doc'),
|
|
|
|
$moduleName,
|
|
|
|
'doc/module/chapter',
|
|
|
|
array('moduleName' => $moduleName)
|
|
|
|
);
|
2014-06-30 15:48:43 +02:00
|
|
|
} catch (DocException $e) {
|
|
|
|
throw new Zend_Controller_Action_Exception($e->getMessage(), 404);
|
|
|
|
}
|
2014-05-28 17:19:24 +02:00
|
|
|
$this->view->moduleName = $moduleName;
|
2014-01-24 16:41:37 +01:00
|
|
|
}
|
2014-05-27 15:09:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* View a chapter of a module's documentation
|
|
|
|
*
|
2014-08-19 09:45:53 +02:00
|
|
|
* @throws Zend_Controller_Action_Exception If the required parameter 'chapterId' is missing or if an error in
|
2014-07-28 19:17:03 +02:00
|
|
|
* the documentation module's library occurs
|
|
|
|
* @see assertModuleEnabled()
|
2014-05-27 15:09:01 +02:00
|
|
|
*/
|
|
|
|
public function chapterAction()
|
|
|
|
{
|
|
|
|
$moduleName = $this->getParam('moduleName');
|
|
|
|
$this->assertModuleEnabled($moduleName);
|
2014-08-19 09:45:53 +02:00
|
|
|
$chapterId = $this->getParam('chapterId');
|
|
|
|
if ($chapterId === null) {
|
2014-07-28 19:17:03 +02:00
|
|
|
throw new Zend_Controller_Action_Exception(
|
2014-08-19 09:45:53 +02:00
|
|
|
$this->translate('Missing parameter \'chapterId\''),
|
2014-07-28 19:17:03 +02:00
|
|
|
404
|
|
|
|
);
|
2014-05-27 15:09:01 +02:00
|
|
|
}
|
|
|
|
$moduleManager = Icinga::app()->getModuleManager();
|
2014-06-30 15:48:43 +02:00
|
|
|
try {
|
2014-07-28 19:17:03 +02:00
|
|
|
$this->renderChapter(
|
|
|
|
$moduleManager->getModuleDir($moduleName, '/doc'),
|
2014-08-19 09:45:53 +02:00
|
|
|
$chapterId,
|
2014-08-19 11:30:56 +02:00
|
|
|
$this->_helper->url->url(array('moduleName' => $moduleName), 'doc/module/toc'),
|
2014-07-28 19:17:03 +02:00
|
|
|
'doc/module/chapter',
|
|
|
|
array('moduleName' => $moduleName)
|
|
|
|
);
|
2014-06-30 15:48:43 +02:00
|
|
|
} catch (DocException $e) {
|
|
|
|
throw new Zend_Controller_Action_Exception($e->getMessage(), 404);
|
|
|
|
}
|
2014-06-06 14:10:35 +02:00
|
|
|
$this->view->moduleName = $moduleName;
|
2014-05-27 15:09:01 +02:00
|
|
|
}
|
2014-07-28 19:17:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* View a module's documentation as PDF
|
|
|
|
*
|
|
|
|
* @see assertModuleEnabled()
|
|
|
|
*/
|
|
|
|
public function pdfAction()
|
|
|
|
{
|
|
|
|
$moduleName = $this->getParam('moduleName');
|
|
|
|
$this->assertModuleEnabled($moduleName);
|
|
|
|
$moduleManager = Icinga::app()->getModuleManager();
|
|
|
|
$this->renderPdf(
|
|
|
|
$moduleManager->getModuleDir($moduleName, '/doc'),
|
|
|
|
$moduleName,
|
|
|
|
'doc/module/chapter',
|
|
|
|
array('moduleName' => $moduleName)
|
|
|
|
);
|
|
|
|
}
|
2014-01-24 16:41:37 +01:00
|
|
|
}
|