icingaweb2-module-graphite/library/Graphite/Web/Controller/TimeRangePickerTrait.php

120 lines
3.2 KiB
PHP
Raw Permalink Normal View History

2017-09-07 05:08:24 -04:00
<?php
namespace Icinga\Module\Graphite\Web\Controller;
use Icinga\Module\Graphite\Forms\TimeRangePicker\CommonForm;
use Icinga\Module\Graphite\Forms\TimeRangePicker\CustomForm;
2017-09-07 06:27:07 -04:00
use Icinga\Module\Graphite\Forms\TimeRangePicker\TimeRangePickerTrait as TimeRangePicker;
2017-09-07 05:08:24 -04:00
use Icinga\Web\Request;
use Icinga\Web\Url;
use Icinga\Web\View;
trait TimeRangePickerTrait
{
/**
* @var CommonForm
*/
protected $timeRangePickerCommonForm;
/**
* @var CustomForm
*/
protected $timeRangePickerCustomForm;
/**
* Process the given request using the forms
*
* @param Request $request The request to be processed
*
* @return Request The request supposed to be processed
*/
protected function handleTimeRangePickerRequest(Request $request = null)
{
$this->getTimeRangePickerCommonForm()->handleRequest($request);
return $this->getTimeRangePickerCustomForm()->handleRequest($request);
}
/**
* Render all needed forms and links
*
* @param View $view
*
* @return string
2017-09-07 05:08:24 -04:00
*/
protected function renderTimeRangePicker(View $view)
2017-09-07 05:08:24 -04:00
{
$result = $this->getTimeRangePickerCommonForm();
$url = Url::fromRequest();
2017-09-07 06:27:07 -04:00
if ($url->hasParam(TimeRangePicker::getRangeCustomizationParameter())) {
2017-09-07 05:08:24 -04:00
$result .= $this->getTimeRangePickerCustomForm();
} else {
$result .= $view->qlink(
$view->translate('Custom', 'TimeRangePicker'),
2017-09-07 06:27:07 -04:00
$url->with(TimeRangePicker::getRangeCustomizationParameter(), '1'),
2017-09-07 05:44:31 -04:00
null,
2017-09-19 11:27:56 -04:00
[
'class' => 'button-link',
'data-base-target' => '_self'
]
2017-09-07 05:08:24 -04:00
);
}
2017-09-07 05:44:31 -04:00
return '<div class="timerangepicker-forms">' . $result . '</div>';
2017-09-07 05:08:24 -04:00
}
/**
* Get {@link timeRangePickerCommonForm}
*
* @return CommonForm
*/
public function getTimeRangePickerCommonForm()
{
if ($this->timeRangePickerCommonForm === null) {
$this->timeRangePickerCommonForm = new CommonForm();
}
return $this->timeRangePickerCommonForm;
}
/**
* Set {@link timeRangePickerCommonForm}
*
* @param CommonForm $timeRangePickerCommonForm
*
* @return $this
*/
public function setTimeRangePickerCommonForm(CommonForm $timeRangePickerCommonForm)
{
$this->timeRangePickerCommonForm = $timeRangePickerCommonForm;
return $this;
}
/**
* Get {@link timeRangePickerCustomForm}
*
* @return CustomForm
*/
public function getTimeRangePickerCustomForm()
{
if ($this->timeRangePickerCustomForm === null) {
$this->timeRangePickerCustomForm = new CustomForm();
}
return $this->timeRangePickerCustomForm;
}
/**
* Set {@link timeRangePickerCustomForm}
*
* @param CustomForm $timeRangePickerCustomForm
*
* @return $this
*/
public function setTimeRangePickerCustomForm(CustomForm $timeRangePickerCustomForm)
{
$this->timeRangePickerCustomForm = $timeRangePickerCustomForm;
return $this;
}
}