User: Add method getNavigation()

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-07 12:19:54 +02:00
parent 411c6e0546
commit a012595e3d
1 changed files with 46 additions and 0 deletions

View File

@ -5,7 +5,9 @@ namespace Icinga;
use DateTimeZone;
use InvalidArgumentException;
use Icinga\Application\Config;
use Icinga\User\Preferences;
use Icinga\Web\Navigation\Navigation;
/**
* This class represents an authorized user
@ -476,4 +478,48 @@ class User
return false;
}
/**
* Load and return this user's configured navigation of the given type
*
* @param string $type
*
* @return Navigation
*/
public function getNavigation($type)
{
$config = Config::fromIni(
Config::resolvePath('preferences')
. DIRECTORY_SEPARATOR
. $this->getUsername()
. DIRECTORY_SEPARATOR
. 'navigation.ini'
)->getConfigObject();
$config->setKeyColumn('name');
$navigation = new Navigation();
if ($type === 'dashboard-pane') {
$panes = array();
foreach ($config->select()->where('type', 'dashlet') as $dashletName => $dashletConfig) {
// TODO: Throw ConfigurationError if pane or url is missing
$panes[$dashletConfig->pane][$dashletName] = $dashletConfig->url;
}
foreach ($panes as $paneName => $dashlets) {
$navigation->addItem(
$paneName,
array(
'type' => 'dashboard-pane',
'dashlets' => $dashlets
)
);
}
} else {
foreach ($config->select()->where('type', $type) as $name => $typeConfig) {
$navigation->addItem($name, $typeConfig->toArray());
}
}
return $navigation;
}
}