Diff #4 - trunk/src/Notifications/NotificationOptions.php
1,719 bytes
|
|
January 20, 2025 at 08:20
|
Diff
Index: NotificationOptions.php
--- NotificationOptions.php (nonexistent) +++ NotificationOptions.php (revision 4) @@ -0,0 +1,64 @@ +<?php +declare(strict_types = 1); + +namespace App\Webapp\Notifications; + +use Apex\Svc\Db; +use Apex\App\Base\Implementors; +use Apex\App\Interfaces\EmailNotificationControllerInterface; +use Apex\App\Attr\Inject; + +/** + * Notification options + */ +class NotificationOptions +{ + + #[Inject(Db::class)] + private Db $db; + + #[Inject(Implementors::class)] + private Implementors $implementors; + + /** + * Create options + */ + public function create(string $selected = 'custom'):string + { + + // Initialize + $controller = ''; + $titles = $this->implementors->getPropertyValues(EmailNotificationControllerInterface::class, 'title'); + + // Start options + $chk = $selected == 'custom' ? 'selected="selected"' : ''; + $options = ""; + + // Go through notifications + $rows = $this->db->query("SELECT id,subject,controller FROM internal_email_notifications ORDER BY controller,subject"); + foreach ($rows as $row) { + + // Add optgroup label, if needed + if ($row['controller'] != 'controller') { + + if ($controller != '') { + $options .= "\n"; + } + + // Add label + $title = $titles[$row['controller']] ?? 'Unknown Controller'; + $options .= "
Full Code
<?php declare(strict_types = 1);
namespace App\Webapp\Notifications;
use Apex\Svc\Db; use Apex\App\Base\Implementors; use Apex\App\Interfaces\EmailNotificationControllerInterface; use Apex\App\Attr\Inject;
/** * Notification options */ class NotificationOptions {
#[Inject(Db::class)]
private Db $db;
#[Inject(Implementors::class)]
private Implementors $implementors;
/**
* Create options
*/
public function create(string $selected = 'custom'):string
{
// Initialize
$controller = '';
$titles = $this->implementors->getPropertyValues(EmailNotificationControllerInterface::class, 'title');
// Start options
$chk = $selected == 'custom' ? 'selected="selected"' : '';
$options = "<option value=\"custom\" $chk>Send Custom Message</option>";
// Go through notifications
$rows = $this->db->query("SELECT id,subject,controller FROM internal_email_notifications ORDER BY controller,subject");
foreach ($rows as $row) {
// Add optgroup label, if needed
if ($row['controller'] != 'controller') {
if ($controller != '') {
$options .= "</optgroup>\n";
}
// Add label
$title = $titles[$row['controller']] ?? 'Unknown Controller';
$options .= "<optgroup label=\"$title\">\n";
$controller = $row['controller'];
}
// Add to options
$chk = $selected == $row['id'] ? 'selected="selected"' : '';
$options .= "<option value=\"$row[id]\" $chk>$row[subject]</option>\n";
}
// Return
return $options;
}
}