diff --git a/library/Icinga/Web/Widget/Dashboard.php b/library/Icinga/Web/Widget/Dashboard.php index 866dfe3ca..f8cc54625 100644 --- a/library/Icinga/Web/Widget/Dashboard.php +++ b/library/Icinga/Web/Widget/Dashboard.php @@ -8,6 +8,7 @@ use Icinga\Application\Icinga; use Icinga\Application\Config; use Icinga\Exception\ConfigurationError; use Icinga\Exception\ProgrammingError; +use Icinga\File\Ini\IniWriter; use Icinga\User; use Icinga\Web\Widget\Dashboard\Pane; use Icinga\Web\Widget\Dashboard\Component as DashboardComponent; @@ -80,6 +81,29 @@ class Dashboard extends AbstractWidget return $this; } + /** + * Write user specific dashboards to disk + */ + public function write() + { + $configFile = $this->getConfigFile(); + $output = array(); + foreach ($this->panes as $pane) { + if ($pane->isUserWidget() === true) { + $output[$pane->getName()] = $pane->toArray(); + } + foreach ($pane->getComponents() as $component) { + if ($component->isUserWidget() === true) { + $output[$pane->getName() . '.' . $component->getTitle()] = $component->toArray(); + } + } + } + + $config = new Config($output); + $writer = new IniWriter(array('config' => $config, 'filename' => $configFile)); + $writer->write(); + } + /** * @return bool */ @@ -316,21 +340,30 @@ class Dashboard extends AbstractWidget } /** - * @param \Icinga\User $user + * Setter for user object + * + * @param User $user */ - public function setUser($user) + public function setUser(User $user) { $this->user = $user; } /** - * @return \Icinga\User + * Getter for user object + * + * @return User */ public function getUser() { return $this->user; } + /** + * Get config file + * + * @return string + */ public function getConfigFile() { if ($this->user === null) { diff --git a/library/Icinga/Web/Widget/Dashboard/Component.php b/library/Icinga/Web/Widget/Dashboard/Component.php index 0017ce9e3..17734478c 100644 --- a/library/Icinga/Web/Widget/Dashboard/Component.php +++ b/library/Icinga/Web/Widget/Dashboard/Component.php @@ -147,7 +147,13 @@ EOD; */ public function toArray() { - $array = array('url' => $this->url->getPath()); + $array = array( + 'url' => $this->url->getPath(), + 'title' => $this->getTitle() + ); + if ($this->getDisabled() === true) { + $array['disabled'] = 1; + } foreach ($this->url->getParams()->toArray() as $param) { $array[$param[0]] = $param[1]; } diff --git a/library/Icinga/Web/Widget/Dashboard/Pane.php b/library/Icinga/Web/Widget/Dashboard/Pane.php index 04073411a..8119eaf66 100644 --- a/library/Icinga/Web/Widget/Dashboard/Pane.php +++ b/library/Icinga/Web/Widget/Dashboard/Pane.php @@ -247,12 +247,9 @@ class Pane extends UserWidget */ public function toArray() { - $array = array($this->getName() => array('title' => $this->getTitle())); - foreach ($this->components as $title => $component) { - $array[$this->getName() . ".$title"] = $component->toArray(); - } - - return $array; + return array( + 'title' => $this->getTitle() + ); } /**