From a00fdab37fd36faba30b50cbc0f755ee43750fbe Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sat, 26 Nov 2016 21:18:18 +0100 Subject: [PATCH] Cleanup, Url handling improvements, some helpers --- library/Businessprocess/BpNode.php | 2 +- library/Businessprocess/BusinessProcess.php | 3 ++ library/Businessprocess/Controller.php | 37 +++++++++++++++++-- library/Businessprocess/Node.php | 5 +++ library/Businessprocess/Simulation.php | 6 ++- .../Businessprocess/Storage/LegacyStorage.php | 2 + library/Businessprocess/Web/FakeRequest.php | 2 +- library/Businessprocess/Web/Url.php | 20 ++++++++-- 8 files changed, 68 insertions(+), 9 deletions(-) diff --git a/library/Businessprocess/BpNode.php b/library/Businessprocess/BpNode.php index 374c304..52086e6 100644 --- a/library/Businessprocess/BpNode.php +++ b/library/Businessprocess/BpNode.php @@ -63,7 +63,7 @@ class BpNode extends Node $this->getState(); $this->counters = self::$emptyStateSummary; - foreach ($this->children as $child) { + foreach ($this->getChildren() as $child) { if ($child instanceof BpNode) { $counters = $child->getStateSummary(); foreach ($counters as $k => $v) { diff --git a/library/Businessprocess/BusinessProcess.php b/library/Businessprocess/BusinessProcess.php index e1b0005..526c135 100644 --- a/library/Businessprocess/BusinessProcess.php +++ b/library/Businessprocess/BusinessProcess.php @@ -425,6 +425,9 @@ class BusinessProcess } } + /** + * @return BpNode[] + */ public function getChildren() { return $this->getRootNodes(); diff --git a/library/Businessprocess/Controller.php b/library/Businessprocess/Controller.php index fa4499f..1161806 100644 --- a/library/Businessprocess/Controller.php +++ b/library/Businessprocess/Controller.php @@ -5,22 +5,33 @@ namespace Icinga\Module\Businessprocess; use Icinga\Application\Icinga; use Icinga\Module\Businessprocess\Modification\ProcessChanges; use Icinga\Module\Businessprocess\Storage\LegacyStorage; +use Icinga\Module\Businessprocess\Storage\Storage; use Icinga\Module\Businessprocess\Web\Component\ActionBar; use Icinga\Module\Businessprocess\Web\Form\FormLoader; +use Icinga\Module\Businessprocess\Web\Url; use Icinga\Web\Controller as ModuleController; use Icinga\Web\Notification; +use Icinga\Web\View; use Icinga\Web\Widget; class Controller extends ModuleController { - protected $config; - + /** @deprecated, obsolete */ protected $backend; + /** @var BusinessProcess */ protected $bp; + /** @var View */ + public $view; + + /** @var Storage */ private $storage; + /** @var bool */ + private $showFullscreen; + + /** @var Url */ private $url; public function init() @@ -31,17 +42,31 @@ class Controller extends ModuleController } $this->view->errors = array(); + $this->url(); + $this->view->showFullscreen + = $this->showFullscreen + = (bool) $this->_helper->layout()->showFullscreen; + $this->view->compact = $this->params->get('view') === 'compact'; } + /** + * @return Url + */ protected function url() { if ($this->url === null) { - $this->url = clone $this->getRequest()->getUrl(); + $this->url = Url::fromPath( + $this->getRequest()->getUrl()->getPath() + )->setParams($this->params); } + return $this->url; } + /** + * @return ActionBar + */ protected function actions() { if ($this->view->actions === null) { @@ -64,6 +89,12 @@ class Controller extends ModuleController return $this->Window()->getSessionNamespace('businessprocess'); } + protected function setViewScript($name) + { + $this->_helper->viewRenderer->setNoController(true); + $this->_helper->viewRenderer->setScriptAction($name); + } + protected function setTitle($title) { $args = func_get_args(); diff --git a/library/Businessprocess/Node.php b/library/Businessprocess/Node.php index 96fdfef..693b6e8 100644 --- a/library/Businessprocess/Node.php +++ b/library/Businessprocess/Node.php @@ -298,6 +298,11 @@ abstract class Node return count($this->parents) > 0; } + public function getParents() + { + return $this->parents; + } + protected function stateToSortState($state) { if (array_key_exists($state, static::$stateToSortStateMap)) { diff --git a/library/Businessprocess/Simulation.php b/library/Businessprocess/Simulation.php index 4babc48..2d47470 100644 --- a/library/Businessprocess/Simulation.php +++ b/library/Businessprocess/Simulation.php @@ -2,12 +2,13 @@ namespace Icinga\Module\Businessprocess; +use Icinga\Exception\ProgrammingError; use Icinga\Web\Session\SessionNamespace; class Simulation { /** - * @var Session + * @var SessionNamespace */ protected $session; @@ -21,6 +22,9 @@ class Simulation */ protected $key; + /** + * @var + */ protected $simulations; public function __construct(BusinessProcess $bp, SessionNamespace $session) diff --git a/library/Businessprocess/Storage/LegacyStorage.php b/library/Businessprocess/Storage/LegacyStorage.php index 4d4ea8c..3d50ce3 100644 --- a/library/Businessprocess/Storage/LegacyStorage.php +++ b/library/Businessprocess/Storage/LegacyStorage.php @@ -196,6 +196,8 @@ class LegacyStorage extends Storage /** * @param BusinessProcess $process + * + * @return void */ public function storeProcess(BusinessProcess $process) { diff --git a/library/Businessprocess/Web/FakeRequest.php b/library/Businessprocess/Web/FakeRequest.php index 6735e81..4e54117 100644 --- a/library/Businessprocess/Web/FakeRequest.php +++ b/library/Businessprocess/Web/FakeRequest.php @@ -23,4 +23,4 @@ class FakeRequest extends Request return self::$baseUrl; } } -} \ No newline at end of file +} diff --git a/library/Businessprocess/Web/Url.php b/library/Businessprocess/Web/Url.php index a466d30..4f508e6 100644 --- a/library/Businessprocess/Web/Url.php +++ b/library/Businessprocess/Web/Url.php @@ -5,7 +5,18 @@ namespace Icinga\Module\Businessprocess\Web; use Icinga\Application\Icinga; use Icinga\Exception\ProgrammingError; use Icinga\Web\Url as WebUrl; +use Icinga\Web\UrlParams; +/** + * Class Url + * + * The main purpose of this class is to get unit tests running on CLI + * Little code from Icinga\Web\Url has been duplicated, as neither fromPath() + * nor getRequest() can be extended in a meaningful way at the time of this + * writing + * + * @package Icinga\Module\Businessprocess\Web + */ class Url extends WebUrl { public static function fromPath($url, array $params = array(), $request = null) @@ -33,7 +44,11 @@ class Url extends WebUrl if (isset($parts['path'])) { $self->setPath($parts['path']); } - + + if (isset($urlParts['query'])) { + $params = UrlParams::fromQueryString($urlParts['query'])->mergeValues($params); + } + if (isset($parts['fragment'])) { $self->setAnchor($parts['fragment']); } @@ -51,5 +66,4 @@ class Url extends WebUrl return $app->getRequest(); } } - -} \ No newline at end of file +}