| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Controllers\Configuration; |
| 4 |
|
| 5 |
use AcyMailing\Helpers\HeaderHelper; |
| 6 |
|
| 7 |
trait Subscription |
| 8 |
{ |
| 9 |
public function removeNotification() |
| 10 |
{ |
| 11 |
$whichNotification = acym_getVar('string', 'id'); |
| 12 |
|
| 13 |
if ($whichNotification != 0 && empty($whichNotification)) { |
| 14 |
acym_sendAjaxResponse(acym_translation('ACYM_NOTIFICATION_NOT_FOUND'), [], false); |
| 15 |
} |
| 16 |
|
| 17 |
if ('all' === $whichNotification) { |
| 18 |
$this->config->save(['notifications' => '[]']); |
| 19 |
$notifications = []; |
| 20 |
} else { |
| 21 |
$notifications = json_decode($this->config->get('notifications', '[]'), true); |
| 22 |
unset($notifications[$whichNotification]); |
| 23 |
$this->config->save(['notifications' => json_encode($notifications)]); |
| 24 |
} |
| 25 |
$helperHeader = new HeaderHelper(); |
| 26 |
|
| 27 |
acym_sendAjaxResponse('', ['html' => $helperHeader->getNotificationCenterInner($notifications)]); |
| 28 |
} |
| 29 |
|
| 30 |
public function markNotificationRead() |
| 31 |
{ |
| 32 |
$which = acym_getVar('string', 'id'); |
| 33 |
|
| 34 |
$notifications = json_decode($this->config->get('notifications', '[]'), true); |
| 35 |
if (empty($notifications)) { |
| 36 |
acym_sendAjaxResponse('', []); |
| 37 |
} |
| 38 |
|
| 39 |
if (empty($which)) { |
| 40 |
foreach ($notifications as $key => $notification) { |
| 41 |
$notifications[$key]['read'] = true; |
| 42 |
} |
| 43 |
} else { |
| 44 |
foreach ($notifications as $key => $notification) { |
| 45 |
if ($notification['id'] != $which) continue; |
| 46 |
$notifications[$key]['read'] = true; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
$this->config->save(['notifications' => json_encode($notifications)]); |
| 52 |
|
| 53 |
acym_sendAjaxResponse('', []); |
| 54 |
} |
| 55 |
|
| 56 |
public function addNotification() |
| 57 |
{ |
| 58 |
$message = acym_getVar('string', 'message'); |
| 59 |
$level = acym_getVar('string', 'level'); |
| 60 |
|
| 61 |
if (empty($message) || empty($level)) { |
| 62 |
acym_sendAjaxResponse(acym_translation('ACYM_ERROR'), [], false); |
| 63 |
} |
| 64 |
|
| 65 |
$helperHeader = new HeaderHelper(); |
| 66 |
|
| 67 |
$newNotification = new \stdClass(); |
| 68 |
$newNotification->message = $message; |
| 69 |
$newNotification->level = $level; |
| 70 |
$newNotification->read = false; |
| 71 |
$newNotification->date = time(); |
| 72 |
|
| 73 |
$helperHeader->addNotification($newNotification); |
| 74 |
|
| 75 |
acym_sendAjaxResponse('', ['notificationCenter' => $helperHeader->getNotificationCenter()]); |
| 76 |
} |
| 77 |
|
| 78 |
private function loadSurveyAnswers(&$data) |
| 79 |
{ |
| 80 |
$surveyTexts = $this->config->get('unsub_survey', '{}'); |
| 81 |
$data['surveyAnswers'] = json_decode($surveyTexts, true); |
| 82 |
} |
| 83 |
} |
| 84 |
|