Fix PSR compliance of code

refs #4192
This commit is contained in:
Jannis Moßhammer 2013-08-07 18:10:39 +02:00
parent 2a2966fc56
commit 6e68826da6
6 changed files with 91 additions and 67 deletions

View File

@ -8,7 +8,6 @@ use Icinga\Config\Config as IcingaConfig;
use Icinga\Form\Dashboard\AddUrlForm; use Icinga\Form\Dashboard\AddUrlForm;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
/** /**
* Handle creation, removal and displaying of dashboards, panes and components * Handle creation, removal and displaying of dashboards, panes and components
* *
@ -45,7 +44,7 @@ class DashboardController extends ActionController
$this->_getParam('component') $this->_getParam('component')
)->store(); )->store();
$this->redirectNow(Url::fromPath('dashboard', array('pane' => $pane))); $this->redirectNow(Url::fromPath('dashboard', array('pane' => $pane)));
} catch(ConfigurationError $exc ) { } catch (ConfigurationError $exc ) {
$this->_helper->viewRenderer('show_configuration'); $this->_helper->viewRenderer('show_configuration');
$this->view->exceptionMessage = $exc->getMessage(); $this->view->exceptionMessage = $exc->getMessage();
@ -74,7 +73,7 @@ class DashboardController extends ActionController
try { try {
$dashboard->store(); $dashboard->store();
$this->redirectNow( $this->redirectNow(
Url::fromPath('dashboard',array('pane' => $form->getValue('pane'))) Url::fromPath('dashboard', array('pane' => $form->getValue('pane')))
); );
} catch (ConfigurationError $exc) { } catch (ConfigurationError $exc) {
$this->_helper->viewRenderer('show_configuration'); $this->_helper->viewRenderer('show_configuration');
@ -100,12 +99,14 @@ class DashboardController extends ActionController
$dashboard->activate($dashboardName); $dashboard->activate($dashboardName);
} }
$this->view->tabs = $dashboard->getTabs(); $this->view->tabs = $dashboard->getTabs();
$this->view->tabs->add('Add', array( $this->view->tabs->add(
'title' => 'Add Url', 'Add',
'iconCls' => 'plus', array(
'url' => Url::fromPath('dashboard/addurl') 'title' => 'Add Url',
)); 'iconCls' => 'plus',
'url' => Url::fromPath('dashboard/addurl')
)
);
$this->view->dashboard = $dashboard; $this->view->dashboard = $dashboard;
} }
} }

View File

@ -25,18 +25,24 @@ class AddUrlForm extends Form
private function addPaneSelectionBox(Dashboard $dashboard) private function addPaneSelectionBox(Dashboard $dashboard)
{ {
$selectPane = new Zend_Form_Element_Select('pane', array( $selectPane = new Zend_Form_Element_Select(
'label' => 'Dashboard', 'pane',
'required' => true, array(
'style' => 'display:inline-block', 'label' => 'Dashboard',
'multiOptions' => $dashboard->getPaneKeyTitleArray() 'required' => true,
)); 'style' => 'display:inline-block',
'multiOptions' => $dashboard->getPaneKeyTitleArray()
)
);
$newDashboardBtn = new Zend_Form_Element_Submit('create_new_pane', array( $newDashboardBtn = new Zend_Form_Element_Submit(
'label' => '+', 'create_new_pane',
'required' => false, array(
'style' => 'display:inline-block' 'label' => '+',
)); 'required' => false,
'style' => 'display:inline-block'
)
);
$newDashboardBtn->removeDecorator('DtDdWrapper'); $newDashboardBtn->removeDecorator('DtDdWrapper');
$selectPane->removeDecorator('DtDdWrapper'); $selectPane->removeDecorator('DtDdWrapper');
@ -54,23 +60,32 @@ class AddUrlForm extends Form
*/ */
private function addNewPaneTextField() private function addNewPaneTextField()
{ {
$txtCreatePane = new Zend_Form_Element_Text('pane', array( $txtCreatePane = new Zend_Form_Element_Text(
'label' => 'New dashboard title', 'pane',
'required' => true, array(
'style' => 'display:inline-block' 'label' => 'New dashboard title',
)); 'required' => true,
'style' => 'display:inline-block'
)
);
// Marks this field as a new pane (and prevents the checkbox being displayed when validation errors occur) // Marks this field as a new pane (and prevents the checkbox being displayed when validation errors occur)
$markAsNewPane = new Zend_Form_Element_Hidden('create_new_pane', array( $markAsNewPane = new Zend_Form_Element_Hidden(
'required' => true, 'create_new_pane',
'value' => 1 array(
)); 'required' => true,
'value' => 1
)
);
$cancelDashboardBtn = new Zend_Form_Element_Submit('use_existing_dashboard', array( $cancelDashboardBtn = new Zend_Form_Element_Submit(
'label' => 'X', 'use_existing_dashboard',
'required' => false, array(
'style' => 'display:inline-block' 'label' => 'X',
)); 'required' => false,
'style' => 'display:inline-block'
)
);
$cancelDashboardBtn->removeDecorator('DtDdWrapper'); $cancelDashboardBtn->removeDecorator('DtDdWrapper');
$txtCreatePane->removeDecorator('DtDdWrapper'); $txtCreatePane->removeDecorator('DtDdWrapper');
@ -89,26 +104,33 @@ class AddUrlForm extends Form
{ {
$dashboard = new Dashboard(); $dashboard = new Dashboard();
$dashboard->readConfig(IcingaConfig::app('dashboard/dashboard')); $dashboard->readConfig(IcingaConfig::app('dashboard/dashboard'));
$this->addElement('text', 'url', array( $this->addElement(
'label' => 'Url', 'text',
'required' => true, 'url',
)); array(
'label' => 'Url',
'required' => true,
)
);
$elems = $dashboard->getPaneKeyTitleArray(); $elems = $dashboard->getPaneKeyTitleArray();
if (empty($elems) || // show textfield instead of combobox when no pane is available if (empty($elems) || // show textfield instead of combobox when no pane is available
($this->getRequest()->getPost('create_new_pane', '0') && // or when a new pane should be created (+ button) ($this->getRequest()->getPost('create_new_pane', '0') && // or when a new pane should be created (+ button)
!$this->getRequest()->getPost('use_existing_dashboard', '0')) // and the user didn't click the 'use existing' button !$this->getRequest()->getPost('use_existing_dashboard', '0')) // and the user didn't click the 'use existing' button
) { ) {
$this->addNewPaneTextField(); $this->addNewPaneTextField();
} else { } else {
$this->addPaneSelectionBox($dashboard); $this->addPaneSelectionBox($dashboard);
} }
$this->addElement('text', 'component', array( $this->addElement(
'label' => 'Title', 'text',
'required' => true, 'component',
)); array(
'label' => 'Title',
'required' => true,
)
);
$this->setSubmitLabel("Add to dashboard"); $this->setSubmitLabel("Add to dashboard");
} }
} }

View File

@ -75,11 +75,14 @@ class Dashboard implements Widget
$this->tabs = new Tabs(); $this->tabs = new Tabs();
foreach ($this->panes as $key => $pane) { foreach ($this->panes as $key => $pane) {
$this->tabs->add($key, array( $this->tabs->add(
'title' => $pane->getTitle(), $key,
'url' => clone($url), array(
'urlParams' => array($this->tabParam => $key) 'title' => $pane->getTitle(),
)); 'url' => clone($url),
'urlParams' => array($this->tabParam => $key)
)
);
} }
} }
return $this->tabs; return $this->tabs;
@ -113,7 +116,7 @@ class Dashboard implements Widget
} }
if (!@file_put_contents($file, $iniString)) { if (!@file_put_contents($file, $iniString)) {
$error = error_get_last(); $error = error_get_last();
if ($error == NULL) { if ($error == null) {
$error = 'Unknown error'; $error = 'Unknown error';
} else { } else {
$error = $error['message']; $error = $error['message'];
@ -340,4 +343,3 @@ class Dashboard implements Widget
} }
} }
} }

View File

@ -103,10 +103,7 @@ class Pane implements Widget
if ($this->hasComponent($title)) { if ($this->hasComponent($title)) {
return $this->components[$title]; return $this->components[$title];
} }
throw new ProgrammingError(sprintf( throw new ProgrammingError(sprintf('Trying to access invalid component: %s', $title));
'Trying to access invalid component: %s',
$title
));
} }
/** /**
@ -148,7 +145,8 @@ class Pane implements Widget
/** /**
* Add a component to this pane, optionally creating it if $component is a string * Add a component to this pane, optionally creating it if $component is a string
* *
* @param string|Component $component The component object or title (if a new component will be created) * @param string|Component $component The component object or title
* (if a new component will be created)
* @param string|null $url An Url to be used when component is a string * @param string|null $url An Url to be used when component is a string
* *
* @return Pane $this * @return Pane $this
@ -160,7 +158,7 @@ class Pane implements Widget
$this->components[$component->getTitle()] = $component; $this->components[$component->getTitle()] = $component;
} elseif (is_string($component) && $url !== null) { } elseif (is_string($component) && $url !== null) {
$this->components[$component] = new Component($component, $url, $this); $this->components[$component] = new Component($component, $url, $this);
} else{ } else {
throw new ConfigurationError('Invalid component added: '.$component); throw new ConfigurationError('Invalid component added: '.$component);
} }
return $this; return $this;
@ -173,8 +171,7 @@ class Pane implements Widget
*/ */
public function toIni() public function toIni()
{ {
if (empty($this->components)) if (empty($this->components)) {
{
return ''; return '';
} }
$ini = '['.$this->getName().']'.PHP_EOL. $ini = '['.$this->getName().']'.PHP_EOL.

View File

@ -149,7 +149,7 @@ class Tab implements Widget
*/ */
public function __construct(array $properties = array()) public function __construct(array $properties = array())
{ {
foreach ($properties as $name=>$value) { foreach ($properties as $name => $value) {
$setter = 'set'.ucfirst($name); $setter = 'set'.ucfirst($name);
if (method_exists($this, $setter)) { if (method_exists($this, $setter)) {
$this->$setter($value); $this->$setter($value);
@ -185,11 +185,14 @@ class Tab implements Widget
$class = $this->active ? ' class="active"' : ''; $class = $this->active ? ' class="active"' : '';
$caption = $this->title; $caption = $this->title;
if ($this->icon !== null) { if ($this->icon !== null) {
$caption = $view->img($this->icon, array( $caption = $view->img(
$this->icon,
array(
'width' => 16, 'width' => 16,
'height' => 16 'height' => 16
)) . ' ' . $caption; )
} else if ($this->iconCls !== null) { ) . ' ' . $caption;
} elseif ($this->iconCls !== null) {
$caption = '<i class="icon-'.$this->iconCls.'"></i> ' . $caption; $caption = '<i class="icon-'.$this->iconCls.'"></i> ' . $caption;
} }
if ($this->url !== null) { if ($this->url !== null) {
@ -205,5 +208,4 @@ class Tab implements Widget
return '<li '.$class.'>'.$tab.'</li>'.PHP_EOL; return '<li '.$class.'>'.$tab.'</li>'.PHP_EOL;
} }
} }