Files
kupshop/bundles/KupShop/AdminBundle/Email/ReportActivitiesEmail.php
2025-08-02 16:30:27 +02:00

99 lines
3.5 KiB
PHP

<?php
namespace KupShop\AdminBundle\Email;
use KupShop\KupShopBundle\Email\BaseEmail;
use function Symfony\Component\Clock\now;
class ReportActivitiesEmail extends BaseEmail
{
protected static $name = 'Activity log - notifikace';
protected static $type = 'REPORT_ACTIVITIES_TEMPLATE';
protected static $priority = 0;
protected $template = 'email/email_activity_log_notifications_admin.tpl';
protected $subject = 'Notifikace z Activity logu: {NAZEV_NOTIFIKACE}';
protected array $notification = [];
public function setNotification(array $notification)
{
$this->notification = $notification;
}
public static function getPlaceholders()
{
$placeholders = [
'NOTIFIKACE' => [
'text' => 'Záznam v activity logu',
],
'NAZEV_NOTIFIKACE' => [
'text' => 'Název notifikace',
],
'INSTRUKCE' => [
'text' => 'Instrukce',
],
];
return [self::$type => $placeholders] + (parent::getPlaceholders() ?? []);
}
public function replacePlaceholdersItem($placeholder)
{
if ($placeholder == 'NOTIFIKACE') {
$smarty = createSmarty(true, true);
$smarty->assign('report_notification', $this->notification);
return $smarty->fetch('email/email_activity_log_notifications.tpl');
}
if ($placeholder == 'NAZEV_NOTIFIKACE') {
return $this->notification['notification']['name'];
}
if ($placeholder == 'INSTRUKCE') {
return nl2br($this->notification['notification']['note']);
}
return parent::replacePlaceholdersItem($placeholder);
}
public function renderEmail($message, $data = [], $base_template = 'admin.tpl'): array
{
return parent::renderEmail($message, $data, $base_template);
}
public function testEmail(): array
{
if ($notification = sqlQueryBuilder()->select('*')->from('report_activities_notifications')
->orderBy('RAND()')->setMaxResults(1)->execute()->fetchAllAssociative()) {
$notification = reset($notification);
if ($reportActivities = sqlQueryBuilder()->select('*')->from('report_activities')->setMaxResults(5)->orderBy('date', 'DESC')->execute()->fetchAllAssociative() ?? false) {
$reportActivitiesTmp = [];
foreach ($reportActivities as $reportActivity) {
$reportActivity['url'] = getAdminUrl('reportActivities', [
'acn' => 'edit',
'ID' => $reportActivity['id'],
], true);
$reportActivity['severity_index'] = $reportActivity['severity'];
$reportActivity['severity'] = (!empty($reportActivity['severity']))
? translate('severity_'.$reportActivity['severity'], 'reportActivities', isAdministration: true)
: '';
$reportActivity['type'] = (!empty($reportActivity['type']))
? translate('type_'.$reportActivity['type'], 'reportActivities', isAdministration: true)
: '';
$reportActivitiesTmp[] = $reportActivity;
}
$notification['last_sync'] = now()->format('Y-m-d H:i:s');
$this->setNotification(['report_activities' => $reportActivitiesTmp, 'notification' => $notification]);
}
}
return parent::testEmail();
}
}