Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E-Mail Contacts list for Sending Reports #158

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
23 changes: 23 additions & 0 deletions library/Reporting/Hook/EmailProviderHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Icinga\Module\Reporting\Hook;

use Icinga\Application\Hook;

abstract class EmailProviderHook
TAINCER marked this conversation as resolved.
Show resolved Hide resolved
{
/**
* Get all Contact eMails
TAINCER marked this conversation as resolved.
Show resolved Hide resolved
*
* @return array
*/
abstract public function getContactEmails(): array;
TAINCER marked this conversation as resolved.
Show resolved Hide resolved

/**
* @return array
*/
final public static function getProviders(): array
TAINCER marked this conversation as resolved.
Show resolved Hide resolved
{
return Hook::all('Reporting/EmailProvider');
}
}
30 changes: 30 additions & 0 deletions library/Reporting/Web/Forms/SendForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@

use Icinga\Module\Reporting\Actions\SendMail;
use Icinga\Module\Reporting\Database;
use Icinga\Module\Reporting\Hook\EmailProviderHook;
use Icinga\Module\Reporting\ProvidedReports;
use Icinga\Module\Reporting\Report;
use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator;
use ipl\I18n\Translation;
use ipl\Web\Compat\CompatForm;

class SendForm extends CompatForm
{
use Database;
use ProvidedReports;
use Translation;

/** @var Report */
protected $report;
Expand All @@ -32,6 +35,33 @@ protected function assemble()

(new SendMail())->initConfigForm($this, $this->report);

$this->addElement('radio', 'source_radio', [
TAINCER marked this conversation as resolved.
Show resolved Hide resolved
'label' => $this->translate('E-Mail Source'),
'options' => [
'manual' => $this->translate('Manual input'),
'contacts' => $this->translate('Contacts'),
],
'value' => 'contacts',
TAINCER marked this conversation as resolved.
Show resolved Hide resolved
'class' => 'autosubmit'
]);

if ($this->getPopulatedValue('source_radio', 'contacts') === 'contacts') {
$emails = [null => $this->translate('Select Contacts')];
foreach (EmailProviderHook::getProviders() as $provider) {
$emails = array_merge($emails, $provider->getContactEmails());
}

$this->addElement('select', 'emails_list', [
'multiple' => true,
'label' => $this->translate('Contacts'),
'options' => $emails
]);
} else {
$this->addElement('textarea', 'emails_manual', [
'label' => $this->translate('Contact E-Mails')
]);
}

$this->addElement('submit', 'submit', [
'label' => $this->translate('Send Report')
]);
Expand Down