2014-02-03 15:39:53 +01:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-02-03 15:39:53 +01:00
|
|
|
|
|
|
|
namespace Icinga\Module\Doc;
|
|
|
|
|
2015-02-11 14:10:12 +01:00
|
|
|
use Icinga\Module\Doc\Renderer\DocSectionRenderer;
|
|
|
|
use Icinga\Module\Doc\Renderer\DocTocRenderer;
|
2015-04-08 15:08:14 +02:00
|
|
|
use Icinga\Web\Controller;
|
2014-02-03 15:39:53 +01:00
|
|
|
|
2015-04-08 15:08:14 +02:00
|
|
|
class DocController extends Controller
|
2014-02-03 15:39:53 +01:00
|
|
|
{
|
2015-08-04 12:48:53 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function moduleInit()
|
|
|
|
{
|
|
|
|
// Our UrlParams object does not take parameters from custom routes into account which is why we have to set
|
|
|
|
// them explicitly
|
|
|
|
if ($this->hasParam('chapter')) {
|
|
|
|
$this->params->set('chapter', $this->getParam('chapter'));
|
|
|
|
}
|
|
|
|
if ($this->hasParam('moduleName')) {
|
|
|
|
$this->params->set('moduleName', $this->getParam('moduleName'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-03 15:39:53 +01:00
|
|
|
/**
|
2014-07-28 19:17:03 +02:00
|
|
|
* Render a chapter
|
2014-02-03 15:39:53 +01:00
|
|
|
*
|
2015-02-10 17:09:56 +01:00
|
|
|
* @param string $path Path to the documentation
|
|
|
|
* @param string $chapter ID of the chapter
|
|
|
|
* @param string $url URL to replace links with
|
|
|
|
* @param array $urlParams Additional URL parameters
|
2014-02-03 15:39:53 +01:00
|
|
|
*/
|
2015-02-10 17:09:56 +01:00
|
|
|
protected function renderChapter($path, $chapter, $url, array $urlParams = array())
|
2014-02-03 15:39:53 +01:00
|
|
|
{
|
2014-05-27 15:06:48 +02:00
|
|
|
$parser = new DocParser($path);
|
2015-02-11 14:01:19 +01:00
|
|
|
$section = new DocSectionRenderer($parser->getDocTree(), DocSectionRenderer::decodeUrlParam($chapter));
|
2015-02-10 17:09:56 +01:00
|
|
|
$this->view->section = $section
|
|
|
|
->setUrl($url)
|
2015-02-11 13:21:01 +01:00
|
|
|
->setUrlParams($urlParams)
|
|
|
|
->setHighlightSearch($this->params->get('highlight-search'));
|
2015-02-10 17:09:56 +01:00
|
|
|
$this->view->title = $chapter;
|
2014-12-09 14:24:45 +01:00
|
|
|
$this->render('chapter', null, true);
|
2014-02-03 15:39:53 +01:00
|
|
|
}
|
2014-05-27 14:49:32 +02:00
|
|
|
|
|
|
|
/**
|
2014-07-28 19:17:03 +02:00
|
|
|
* Render a toc
|
2014-05-27 14:49:32 +02:00
|
|
|
*
|
2015-02-10 17:09:56 +01:00
|
|
|
* @param string $path Path to the documentation
|
|
|
|
* @param string $name Name of the documentation
|
|
|
|
* @param string $url URL to replace links with
|
|
|
|
* @param array $urlParams Additional URL parameters
|
2014-05-27 14:49:32 +02:00
|
|
|
*/
|
2014-07-28 19:17:03 +02:00
|
|
|
protected function renderToc($path, $name, $url, array $urlParams = array())
|
2014-05-27 14:49:32 +02:00
|
|
|
{
|
|
|
|
$parser = new DocParser($path);
|
2015-02-11 14:02:12 +01:00
|
|
|
$toc = new DocTocRenderer($parser->getDocTree()->getIterator());
|
2015-02-10 17:09:56 +01:00
|
|
|
$this->view->toc = $toc
|
|
|
|
->setUrl($url)
|
|
|
|
->setUrlParams($urlParams);
|
2014-08-19 13:38:18 +02:00
|
|
|
$name = ucfirst($name);
|
2014-08-19 16:22:22 +02:00
|
|
|
$this->view->title = sprintf($this->translate('%s Documentation'), $name);
|
2014-12-09 14:24:45 +01:00
|
|
|
$this->render('toc', null, true);
|
2014-07-28 19:17:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a pdf
|
|
|
|
*
|
|
|
|
* @param string $path Path to the documentation
|
|
|
|
* @param string $name Name of the documentation
|
|
|
|
* @param string $url
|
|
|
|
* @param array $urlParams
|
|
|
|
*/
|
|
|
|
protected function renderPdf($path, $name, $url, array $urlParams = array())
|
|
|
|
{
|
|
|
|
$parser = new DocParser($path);
|
2015-02-11 15:15:37 +01:00
|
|
|
$toc = new DocTocRenderer($parser->getDocTree()->getIterator());
|
|
|
|
$this->view->toc = $toc
|
|
|
|
->setUrl($url)
|
|
|
|
->setUrlParams($urlParams);
|
|
|
|
$section = new DocSectionRenderer($parser->getDocTree());
|
|
|
|
$this->view->section = $section
|
|
|
|
->setUrl($url)
|
|
|
|
->setUrlParams($urlParams);
|
|
|
|
$this->view->title = sprintf($this->translate('%s Documentation'), $name);
|
2014-07-28 19:17:03 +02:00
|
|
|
$this->_request->setParam('format', 'pdf');
|
2015-02-11 15:15:37 +01:00
|
|
|
$this->_helper->viewRenderer->setRender('pdf', null, true);
|
2014-05-27 14:49:32 +02:00
|
|
|
}
|
2014-05-23 09:36:14 +02:00
|
|
|
}
|