From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- .../Announcement/AcknowledgeAnnouncementForm.php | 92 ++++++++++++++ .../forms/Announcement/AnnouncementForm.php | 135 +++++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 application/forms/Announcement/AcknowledgeAnnouncementForm.php create mode 100644 application/forms/Announcement/AnnouncementForm.php (limited to 'application/forms/Announcement') diff --git a/application/forms/Announcement/AcknowledgeAnnouncementForm.php b/application/forms/Announcement/AcknowledgeAnnouncementForm.php new file mode 100644 index 0000000..85fecdc --- /dev/null +++ b/application/forms/Announcement/AcknowledgeAnnouncementForm.php @@ -0,0 +1,92 @@ +setAction(Url::fromPath('announcements/acknowledge')); + $this->setAttrib('class', '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(); + $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; + } + $acknowledged[] = $this->getElement('hash')->getValue(); + $cookie->setAcknowledged($acknowledged); + $this->getResponse()->setCookie($cookie); + return true; + } +} diff --git a/application/forms/Announcement/AnnouncementForm.php b/application/forms/Announcement/AnnouncementForm.php new file mode 100644 index 0000000..4da47e2 --- /dev/null +++ b/application/forms/Announcement/AnnouncementForm.php @@ -0,0 +1,135 @@ +start !== null) { + $entry->start = (new DateTime())->setTimestamp($entry->start); + } + if ($entry->end !== null) { + $entry->end = (new DateTime())->setTimestamp($entry->end); + } + } + + return $entry; + } + + /** + * {@inheritDoc} + */ + protected function createInsertElements(array $formData) + { + $this->addElement( + 'text', + 'author', + array( + 'disabled' => ! $this->getRequest()->isApiRequest(), + 'required' => true, + 'value' => Auth::getInstance()->getUser()->getUsername() + ) + ); + $this->addElement( + 'textarea', + 'message', + array( + 'description' => $this->translate('The message to display to users'), + 'label' => $this->translate('Message'), + 'required' => true + ) + ); + $this->addElement( + 'dateTimePicker', + 'start', + array( + 'description' => $this->translate('The time to display the announcement from'), + 'label' => $this->translate('Start'), + 'placeholder' => new DateTime('tomorrow'), + 'required' => true + ) + ); + $this->addElement( + 'dateTimePicker', + 'end', + array( + 'description' => $this->translate('The time to display the announcement until'), + 'label' => $this->translate('End'), + 'placeholder' => new DateTime('tomorrow +1day'), + 'required' => true + ) + ); + + $this->setTitle($this->translate('Create a new announcement')); + $this->setSubmitLabel($this->translate('Create')); + } + /** + * {@inheritDoc} + */ + protected function createUpdateElements(array $formData) + { + $this->createInsertElements($formData); + $this->setTitle(sprintf($this->translate('Edit announcement %s'), $this->getIdentifier())); + $this->setSubmitLabel($this->translate('Save')); + } + + /** + * {@inheritDoc} + */ + protected function createDeleteElements(array $formData) + { + $this->setTitle(sprintf($this->translate('Remove announcement %s?'), $this->getIdentifier())); + $this->setSubmitLabel($this->translate('Yes')); + $this->setAttrib('class', 'icinga-controls'); + } + + /** + * {@inheritDoc} + */ + protected function createFilter() + { + return Filter::where('id', $this->getIdentifier()); + } + + /** + * {@inheritDoc} + */ + protected function getInsertMessage($success) + { + return $success + ? $this->translate('Announcement created') + : $this->translate('Failed to create announcement'); + } + + /** + * {@inheritDoc} + */ + protected function getUpdateMessage($success) + { + return $success + ? $this->translate('Announcement updated') + : $this->translate('Failed to update announcement'); + } + + /** + * {@inheritDoc} + */ + protected function getDeleteMessage($success) + { + return $success + ? $this->translate('Announcement removed') + : $this->translate('Failed to remove announcement'); + } +} -- cgit v1.2.3