2016-11-29 15:12:33 +01:00
|
|
|
<?php
|
|
|
|
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
|
|
|
|
|
|
|
|
namespace Icinga\Forms\Announcement;
|
|
|
|
|
2016-12-13 11:03:09 +01:00
|
|
|
use Icinga\Data\Filter\Filter;
|
2016-11-29 15:12:33 +01:00
|
|
|
use Icinga\Web\Announcement\AnnouncementCookie;
|
2016-12-13 11:03:09 +01:00
|
|
|
use Icinga\Web\Announcement\AnnouncementIniRepository;
|
2016-11-29 15:12:33 +01:00
|
|
|
use Icinga\Web\Form;
|
2017-11-20 13:35:17 +01:00
|
|
|
use Icinga\Web\Url;
|
2016-11-29 15:12:33 +01:00
|
|
|
|
|
|
|
class AcknowledgeAnnouncementForm extends Form
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
2017-11-20 13:35:17 +01:00
|
|
|
$this->setAction(Url::fromPath('announcements/acknowledge'));
|
2016-11-29 15:12:33 +01:00
|
|
|
$this->setAttrib('class', 'form-inline acknowledge-announcement-control');
|
|
|
|
$this->setRedirectUrl('layout/announcements');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function addSubmitButton()
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'button',
|
|
|
|
'btn_submit',
|
|
|
|
array(
|
|
|
|
'class' => 'link-button spinner',
|
|
|
|
'decorators' => array(
|
|
|
|
'ViewHelper',
|
|
|
|
array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls'))
|
|
|
|
),
|
|
|
|
'escape' => false,
|
|
|
|
'ignore' => true,
|
|
|
|
'label' => $this->getView()->icon('cancel'),
|
|
|
|
'title' => $this->translate('Acknowledge this announcement'),
|
|
|
|
'type' => 'submit'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function createElements(array $formData = array())
|
|
|
|
{
|
|
|
|
$this->addElements(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'hidden',
|
|
|
|
'hash',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
|
|
|
'validators' => array('NotEmpty'),
|
|
|
|
'decorators' => array('ViewHelper')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function onSuccess()
|
|
|
|
{
|
|
|
|
$cookie = new AnnouncementCookie();
|
2016-12-13 11:03:09 +01:00
|
|
|
$repo = new AnnouncementIniRepository();
|
|
|
|
$query = $repo->findActive();
|
|
|
|
$filter = array();
|
|
|
|
foreach ($cookie->getAcknowledged() as $hash) {
|
|
|
|
$filter[] = Filter::expression('hash', '=', $hash);
|
|
|
|
}
|
|
|
|
$query->addFilter(Filter::matchAny($filter));
|
|
|
|
$acknowledged = array();
|
|
|
|
foreach ($query as $row) {
|
|
|
|
$acknowledged[] = $row->hash;
|
|
|
|
}
|
2016-11-29 15:12:33 +01:00
|
|
|
$acknowledged[] = $this->getElement('hash')->getValue();
|
|
|
|
$cookie->setAcknowledged($acknowledged);
|
|
|
|
$this->getResponse()->setCookie($cookie);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|