Diff #4 - trunk/src/Opus/HtmlFunctions/NotificationCondition.php
1,933 bytes
|
|
January 20, 2025 at 08:20
|
Diff
Index: NotificationCondition.php
--- NotificationCondition.php (nonexistent) +++ NotificationCondition.php (revision 4) @@ -0,0 +1,67 @@ +<?php +declare(strict_types = 1); + +namespace App\Webapp\Opus\HtmlFunctions; + +use Apex\Svc\Container; +use App\Webapp\Models\EmailNotification; +use App\Webapp\Notifications\NotificationsConfig; +use App\Webapp\AdminProfiles; +use Apex\Syrus\Parser\StackElement; +use Apex\App\Interfaces\Opus\HtmlFunctionInterface; +use App\Webapp\Exceptions\WebappNotificationException; + +/** + * HTML Function - NotificationCondition + */ +class NotificationCondition implements HtmlFunctionInterface +{ + + #[Inject(Container::class)] + private Container $cntr; + + #[Inject(NotificationsConfig::class)] + private NotificationsConfig $config; + + #[Inject(AdminProfiles::class)] + private AdminProfiles $admin_profiles; + + /** + * Render + * + * @return The HTML code to replace the ERROR: No 'alias' attribute exists within the function tag. tag with. + */ + public function render(string $html, StackElement $e):string + { + + // Initialize + list($sender, $recipient, $condition) = ['', '', []]; + $controller = $attr['controller'] ?? ''; + $notification_id = $attr['notification_id'] ?? 0; + + // Check for notification + if ($notification_id > 0 && $email = EmailNotification::whereId($notification_id)) { + $sender = $email->sender; + $recipient = $email->recipient; + $condition = json_decode($email->condition_vars, true); + $controller = $email->controller; + } + + // Load controller class + if (!class_exists($controller)) { + throw new WebappNotificationException("The e-mail notificatoin controller does not exist at, $controller"); + } + $obj = $this->cntr->make($controller); + + // Get sender and recipient options + $sender_options = $this->config->getContactOptions($obj, 'sender', $sender); + $recipient_options = $this->config->getContactOptions($obj, 'recipient', $recipient); + + + // Return + return $html; + } + +} + +
Full Code
<?php declare(strict_types = 1);
namespace App\Webapp\Opus\HtmlFunctions;
use Apex\Svc\Container; use App\Webapp\Models\EmailNotification; use App\Webapp\Notifications\NotificationsConfig; use App\Webapp\AdminProfiles; use Apex\Syrus\Parser\StackElement; use Apex\App\Interfaces\Opus\HtmlFunctionInterface; use App\Webapp\Exceptions\WebappNotificationException;
/** * HTML Function - NotificationCondition */ class NotificationCondition implements HtmlFunctionInterface {
#[Inject(Container::class)]
private Container $cntr;
#[Inject(NotificationsConfig::class)]
private NotificationsConfig $config;
#[Inject(AdminProfiles::class)]
private AdminProfiles $admin_profiles;
/**
* Render
*
* @return The HTML code to replace the <syrus19> tag with.
*/
public function render(string $html, StackElement $e):string
{
// Initialize
list($sender, $recipient, $condition) = ['', '', []];
$controller = $attr['controller'] ?? '';
$notification_id = $attr['notification_id'] ?? 0;
// Check for notification
if ($notification_id > 0 && $email = EmailNotification::whereId($notification_id)) {
$sender = $email->sender;
$recipient = $email->recipient;
$condition = json_decode($email->condition_vars, true);
$controller = $email->controller;
}
// Load controller class
if (!class_exists($controller)) {
throw new WebappNotificationException("The e-mail notificatoin controller does not exist at, $controller");
}
$obj = $this->cntr->make($controller);
// Get sender and recipient options
$sender_options = $this->config->getContactOptions($obj, 'sender', $sender);
$recipient_options = $this->config->getContactOptions($obj, 'recipient', $recipient);
// Return
return $html;
}
}