Re-introduce the ModulePage

Now with pretty checkboxes :)

refs #8191
This commit is contained in:
Johannes Meyer 2015-01-21 13:57:59 +01:00
parent 64a8006973
commit 08e600a376
1 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,96 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Setup\Forms;
use Icinga\Application\Icinga;
use Icinga\Web\Form;
class ModulePage extends Form
{
protected $modules;
protected $modulePaths;
/**
* Initialize this page
*/
public function init()
{
$this->setName('setup_modules');
//$this->setViewScript('form/setup-modules.phtml');
$this->modulePaths = array();
if (($appModulePath = realpath(Icinga::app()->getApplicationDir() . '/../modules')) !== false) {
$this->modulePaths[] = $appModulePath;
}
}
public function createElements(array $formData)
{
foreach ($this->getModules() as $module) {
$this->addElement(
'checkbox',
$module->getName(),
array(
'label' => ucfirst($module->getName())
)
);
$this->addElement(
'note',
$module->getName() . '_desc',
array(
'value' => $module->getDescription()
)
);
}
}
protected function getModules()
{
if ($this->modules !== null) {
return $this->modules;
} else {
$this->modules = array();
}
$moduleManager = Icinga::app()->getModuleManager();
$moduleManager->detectInstalledModules($this->modulePaths);
foreach ($moduleManager->listInstalledModules() as $moduleName) {
if ($moduleName !== 'setup') {
$this->modules[$moduleName] = $moduleManager->loadModule($moduleName)->getModule($moduleName);
}
}
return $this->modules;
}
public function getCheckedModules()
{
$modules = $this->getModules();
$checked = array();
foreach ($this->getElements() as $name => $element) {
if (array_key_exists($name, $modules) && $element->isChecked()) {
$checked[$name] = $modules[$name];
}
}
return $checked;
}
public function getModuleWizards()
{
$checked = $this->getCheckedModules();
$wizards = array();
foreach ($checked as $name => $module) {
if ($module->providesSetupWizard()) {
$wizards[$name] = $module->getSetupWizard();
}
}
return $wizards;
}
}