<?php
namespace App\Controller;
use App\Service\RedisCache;
use App\Service\AlertService;
use App\Service\UserPermission;
use App\Model\OrganizationModel;
use Knp\Component\Pager\Paginator;
use Pimcore\Log\ApplicationLogger;
use Pimcore\Model\DataObject\Tags;
use App\Model\CustomNotificationLog;
use App\Service\NCMWeatherAPIService;
use App\Model\CustomNotificationModel;
use Pimcore\Model\DataObject\Customer;
use Pimcore\Model\DataObject\Severity;
use Symfony\Component\Process\Process;
use Pimcore\Model\DataObject\Parameters;
use App\Service\CustomNotificationService;
use App\Service\MeteomaticsWeatherService;
use Pimcore\Controller\FrontendController;
use Knp\Component\Pager\PaginatorInterface;
use App\Model\CustomNotificationConfigModel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Pimcore\Model\DataObject\CustomNotificationTags;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Pimcore\Model\DataObject\Fieldcollection\Data\NotificationRule;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use App\Model\EwsNotificationModel;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* Notification controller is responsible for handling various actions related to notificaiton, subscription and alerts sub management.
*
* @Route("/api/ncm/notification")
*/
class NotificationController extends FrontendController
{
private $lang;
protected $organizationModel;
protected $customNotificationModel;
private $ewsNotificationModel;
private $httpClient;
public function __construct(
private TokenStorageInterface $tokenStorageInterface,
private JWTTokenManagerInterface $jwtManager,
private UserPermission $userPermission,
protected TranslatorInterface $translator,
private MeteomaticsWeatherService $MeteomaticsWeatherService,
private CustomNotificationService $customNotificationService,
private AlertService $alertService,
private NCMWeatherAPIService $ncmWeatherApiService,
private ApplicationLogger $logger,
RedisCache $redisCache,
HttpClientInterface $httpClient,
private MeteomaticsWeatherService $mateoMaticsService
) {
header('Content-Type: application/json; charset=UTF-8');
header("Access-Control-Allow-Origin: *");
$this->organizationModel = new OrganizationModel();
$this->customNotificationModel = new CustomNotificationConfigModel();
$this->ncmWeatherApiService = new NCMWeatherAPIService($redisCache, $httpClient);
$this->ewsNotificationModel = new EwsNotificationModel();
}
/**
* @Route("/subscribe-custom-notification", methods={"POST"})
*/
public function subscribeCustomNotification(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$requiredParameters = ['user_id', 'location_id', 'alert_name', 'title', 'color', 'units', 'min_value', 'max_value', 'calculate', 'weather_model', 'alert_on_email', 'alert_on_sms'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$locationId = $params['location_id'];
$alertType = $params['alert_name'];
$title = $params['title'];
$color = $params['color'];
$units = $params['units'];
$minValue = isset($params['min_value']) ? $params['min_value'] : 0;
$maxValue = $params['max_value'];
$weatherModel = $params['weather_model'];
$alertOnEmail = $params['alert_on_email'];
$alertOnSMS = $params['alert_on_sms'];
$calculate = $params['calculate'];
$duration = isset($params['duration']) ? $params['duration'] : 1;
$frequency = isset($params['frequency']) ? $params['frequency'] : 1;
if (!in_array($calculate, array_flip(CUSTOM_NOTIFICATION_RANGE))) {
return $this->json(['success' => false, 'message' => $this->translator->trans('invalid_calculation_type')]);
}
$result = $this->customNotificationService->subscribeAlerts(
$user,
$locationId,
$alertType,
$title,
$color,
$units,
$minValue,
$maxValue,
$weatherModel,
$alertOnEmail,
$alertOnSMS,
$calculate,
$duration,
$frequency,
$this->logger,
$this->translator,
$this->mateoMaticsService
);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/subscribe-custom-notification-by-tag", methods={"POST"})
*/
public function subscribeCustomNotificationByTag(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$requiredParameters = ['user_id', 'tag_id', 'alert_name', 'title', 'color', 'units', 'min_value', 'max_value', 'calculate', 'weather_model', 'alert_on_email', 'alert_on_sms'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$tagId = $params['tag_id'];
$alertType = $params['alert_name'];
$title = $params['title'];
$color = $params['color'];
$units = $params['units'];
$minValue = isset($params['min_value']) ? $params['min_value'] : 0;
$maxValue = $params['max_value'];
$weatherModel = $params['weather_model'];
$alertOnEmail = $params['alert_on_email'];
$alertOnSMS = $params['alert_on_sms'];
$calculate = $params['calculate'];
$duration = isset($params['duration']) ? $params['duration'] : 1;
$frequency = isset($params['frequency']) ? $params['frequency'] : 1;
if (!in_array($calculate, array_flip(CUSTOM_NOTIFICATION_RANGE))) {
return $this->json(['success' => false, 'message' => $this->translator->trans('invalid_calculation_type')]);
}
$result = $this->customNotificationService->subscribeAlertsByTag(
$user,
$tagId,
$alertType,
$title,
$color,
$units,
$minValue,
$maxValue,
$weatherModel,
$alertOnEmail,
$alertOnSMS,
$calculate,
$duration,
$frequency,
$this->logger,
$this->translator,
$this->mateoMaticsService
);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/update-subscribe-custom-notification", methods={"POST"})
*/
public function updateSubscribeCustomNotification(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$requiredParameters = ['user_id', 'id', 'location_id', 'alert_name', 'title', 'color', 'units', 'min_value', 'max_value', 'calculate', 'weather_model', 'alert_on_email', 'alert_on_sms'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$notificationId = $params['id'];
$locationId = $params['location_id'];
$alertType = $params['alert_name'];
$title = $params['title'];
$color = $params['color'];
$units = $params['units'];
$minValue = isset($params['min_value']) ? $params['min_value'] : 0;
$maxValue = $params['max_value'];
$weatherModel = $params['weather_model'];
$alertOnEmail = $params['alert_on_email'];
$alertOnSMS = $params['alert_on_sms'];
$calculate = $params['calculate'];
$duration = isset($params['duration']) ? $params['duration'] : 1;
$frequency = isset($params['frequency']) ? $params['frequency'] : 1;
if (!in_array($calculate, array_flip(CUSTOM_NOTIFICATION_RANGE))) {
return $this->json(['success' => false, 'message' => $this->translator->trans('invalid_calculation_type')]);
}
$result = $this->customNotificationService->updateSubscribeAlerts(
$user,
$notificationId,
$locationId,
$alertType,
$title,
$color,
$units,
$minValue,
$maxValue,
$weatherModel,
$alertOnEmail,
$alertOnSMS,
$calculate,
$duration,
$frequency,
$this->translator,
$this->mateoMaticsService
);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/unsubscribe-custom-notification", methods={"POST"})
*/
public function unsubscribeCustomNotification(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$requiredParameters = ['user_id', 'location_id', 'alert_name'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$locationId = $params['location_id'];
$alertType = $params['alert_name'];
$result = $this->customNotificationService->unSubscribeAlerts($user, $locationId, $alertType, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/unsubscribe-custom-notification-bulk", methods={"POST"})
*/
public function unsubscribeCustomNotificationBulk(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!$user) {
// throw new \Exception('User is not authenticated');
return $this->json(['success' => false, 'message' => $this->translator->trans('User is not authenticated')]);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$requiredParameters = ['notification_id'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$notificationId = $params['notification_id'];
$result = $this->customNotificationService->unSubscribeAlertsBulk($user, $notificationId, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/alert-master", methods={"POST"})
*/
public function alertMaster(Request $request, UserInterface $user): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
if (!$user) {
throw new \Exception('User is not authenticated');
}
$result = $this->customNotificationService->getAlertMaster();
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/manned-alert-filters", methods={"POST"})
*/
public function mannedAlertFilters(Request $request): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->customNotificationService->mannedAlertFilters();
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/manned-alerts", methods={"POST"})
*/
public function mannedAlerts(Request $request, UserInterface $user, PaginatorInterface $paginator): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!$user) {
throw new \Exception('User is not authenticated');
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
if (!isset($params['from_date']) || !isset($params['to_date'])) {
// throw new \Exception('Date range is required');
return $this->json(['success' => false, 'message' => $this->translator->trans('date_range_is_required')]);
}
$result = $this->customNotificationService->getMannedAlerts($params, $paginator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/manned-alerts-direct", methods={"GET"})
*/
public function mannedAlertsDirect(Request $request): JsonResponse
{
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
return $this->json($this->ncmWeatherApiService->getAlerts());
}
/**
* @Route("/get-custom-notification", methods={"POST"})
*/
public function getCustomNotification(Request $request, UserInterface $user, PaginatorInterface $paginator): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!$user) {
// throw new \Exception('User is not authenticated');
return $this->json(['success' => false, 'message' => $this->translator->trans('User is not authenticated')]);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
if (!isset($params['location_id'])) {
//throw new \Exception('Location is mandatory');
return $this->json(['success' => false, 'message' => $this->translator->trans('location_is_mandatory')]);
}
$locationId = $params['location_id'];
$result = $this->customNotificationService->getUserAlerts($user->getId(), $locationId, $params, $paginator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/send-custom-notification", methods={"POST"})
*/
public function sendCustomNotification(Request $request): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$process = new Process(['bin/console', 'app:get-custom-notification']);
$process->setWorkingDirectory(PIMCORE_PROJECT_ROOT);
try {
$process->mustRun();
$result['success'] = true;
$result['message'] = $process->getOutput();
} catch (ProcessFailedException $exception) {
$this->logger->error($exception->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/alert-history", methods={"POST"})
*/
public function alertHistory(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!$user) {
throw new \Exception('User is not authenticated');
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->customNotificationService->getAlertHistory($user, $params);
if (!empty($result['data'])) {
$excelData = \App\Lib\Utility::generateExcelFromArray($result['data']);
$asset = null;
if ($excelData) {
$asset = \App\Lib\Utility::createAsset($excelData, $user->getId() . '_alert_history_.xlsx', 'alert_history');
}
}
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/regions", methods={"POST"})
*/
public function regions(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!$user) {
throw new \Exception('User is not authenticated');
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->ncmWeatherApiService->getRegions(null, isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
private function initiate(Request $request)
{
// Setting locale
$headers = $request->headers->all();
$this->lang = isset($headers['lang']) ? $headers['lang'][0] : DEFAULT_LOCALE;
$this->translator->setLocale($this->lang);
$permissions = $this->userPermission->initiate($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
return $permissions;
}
/**
* @Route("/get-custom-notification-log", methods={"POST"})
*/
public function getCustomNotificationLog(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!$user) {
throw new \Exception('User is not authenticated');
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->customNotificationService->getUserAlerts($user->getId(), 0);
$notificationArr = [];
if (isset($result['success']) && $result['success'] == true && !empty($result['message'])) {
foreach ($result['message'] as $message) {
$notification = $this->customNotificationService->getCustomNotificationLog($message['id']);
if (!empty($notification)) {
$notificationArr[] = $notification;
}
}
$result["message"] = array_values($notificationArr);
}
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/get-custom-notification-by-filters", methods={"POST"})
*/
public function getCustomNotificationByFilters(Request $request, UserInterface $user, PaginatorInterface $paginator): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!$user) {
throw new \Exception('User is not authenticated');
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->customNotificationService->getCustomNotificationAlerts($params, $paginator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/custom-notification-filters", name ="custom-notification-filters" , methods={"POST"})
*/
public function getCustomNotificationFilters(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!$user) {
throw new \Exception('User is not authenticated');
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->customNotificationService->customNotificationFilters($this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/unsubscribe-notification-by-token", name ="unsubscribe-notification-by-token" , methods={"GET"})
*/
public function unSubscribeNotificationByEmail(Request $request): JsonResponse
{
try {
if ($request->query->has('token')) {
if ($request->get('token')) {
$token = $request->get('token');
$result = $this->customNotificationService->updateSubscribeNotification($token, $this->translator);
return $this->json($result);
}
}
return $this->json(["success" => false, "message" => "You have already unsubscribed the custom notification"]);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/unsubscribe-ews-notification-by-token", name ="unsubscribe-ews-notification-by-token" , methods={"GET"})
*/
public function unSubscribeEwsNotificationByEmail(Request $request): JsonResponse
{
try {
if ($request->query->has('token')) {
if ($request->get('token')) {
$token = $request->get('token');
$result = $this->customNotificationService->unSubscribeEwsNotification($token, $this->translator);
return $this->json($result);
}
}
return $this->json(["success" => false, "message" => "You have already unsubscribed the custom notification"]);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/create-manned-alert-subscription", methods={"POST"})
*/
public function mannedAlertSubscription(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$requiredParameters = ['region_id', 'governorate_id', 'alert_type_id', 'phenomena_id'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param]) || empty($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$result = $this->customNotificationService->mannedAlertSubscription($user, $params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/assign-alert-subscription-to-subscriber", methods={"POST"})
*/
public function mannedAlertSubscriber(Request $request, UserInterface $user): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
// Validate required parameters: subscription_id and user_id (can be single id or array of ids)
$missingParams = [];
if (!isset($params['subscription_id'])) {
$missingParams[] = 'subscription_id';
}
if (!isset($params['user_id'])) {
$missingParams[] = 'user_id';
} else {
// if array, ensure non-empty; if scalar, ensure not empty
if (is_array($params['user_id'])) {
$sanitized = array_values(array_unique(array_map('intval', array_filter($params['user_id']))));
if (count($sanitized) === 0) {
$missingParams[] = 'user_id';
} else {
$params['user_id'] = $sanitized;
}
} else if (empty($params['user_id'])) {
$missingParams[] = 'user_id';
}
}
if (!empty($missingParams)) {
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$result = $this->customNotificationService->mannedAlertSubscriber($params, $user, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/list-manned-alert-subscription", methods={"POST"})
*/
public function listMannedAlertSubscription(Request $request, UserInterface $user, PaginatorInterface $paginator): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->customNotificationService->listMannedAlertSubscription($params, $user, $paginator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/delete-manned-alert-subscription", methods={"POST"})
*/
public function deleteMannedAlertSubscription(Request $request, UserInterface $user, PaginatorInterface $paginator): JsonResponse
{
try {
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
if (!isset($params['subscription_id']) || empty($params['subscription_id'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("missing_required_parameter_subscription_id")]);
}
$result = $this->customNotificationService->deleteMannedAlertSubscription($request, $params, $user, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/manned-alert-subscribe", methods={"POST"})
*/
public function mannedAlertSubscribe(Request $request, UserInterface $user, PaginatorInterface $paginator): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if ((!isset($params['subscription_id']) || empty($params['subscription_id'])) && !isset($params['status'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("missing_required_parameter")]);
}
$result = $this->customNotificationService->mannedAlertSubscribe($request, $params, $user, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/advance-alert-subscribe", methods={"POST"}, name="advance_alert_subscribe")
*/
public function advanceAlertSubscribe(Request $request, UserInterface $user, PaginatorInterface $paginator): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!isset($params['notification_id']) || empty($params['notification_id'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("missing_required_parameter")]);
}
if (!isset($params['notifyEmail'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("missing_required_parameter")]);
}
$result = $this->customNotificationService->advanceAlertSubscribe($request, $params, $user, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/custom-alert-subscribe", methods={"POST"}, name="custom_alert_subscribe")
*/
public function customAlertSubscribe(Request $request, UserInterface $user, PaginatorInterface $paginator): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if ((!isset($params['notification_id']) || empty($params['notification_id'])) && !isset($params['status'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("missing_required_parameter")]);
}
$result = $this->customNotificationService->customAlertSubscribe($request, $params, $user, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/create-tag", name="create_tag")
*/
public function createTag(Request $request)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$requiredParameters = ['name', 'lang'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$result = $this->createTag($params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/get-tags", name="get_tags")
*/
public function getTags(Request $request, UserInterface $user, PaginatorInterface $paginator)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!$user) {
throw new \Exception('User is not authenticated');
}
$tags = new CustomNotificationTags\Listing();
$tags->filterByUser($user);
$data = [];
foreach ($tags as $tag) {
$data[] = [
'id' => $tag->getId(),
'name' => $tag->getTagName(),
];
}
return $this->json(['success' => true, 'data' => $data]);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/get-notification-tags", name="get_notification_tags" , methods={"POST"})
*/
public function getNotificationTags(Request $request, UserInterface $user, PaginatorInterface $paginator)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
if (!$user) {
throw new \Exception('User is not authenticated');
}
$result = $this->customNotificationModel->getNotificationTags($user, $paginator, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/get-params", name="get_params")
*/
public function getParametersConfig(Request $request)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$result = $this->customNotificationModel->getParametersConfig($this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/update-parameter-height-depth", name="update_parameter_height_depth", methods={"POST"})
*/
public function updateParameterHeightDepth(Request $request)
{
try {
$params = json_decode($request->getContent(), true) ?? [];
$this->translator->setlocale($params['lang'] ?? DEFAULT_LOCALE);
// $permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
// if (isset($permissions['code']) && $permissions['code'] === 401) {
// return $this->json($permissions, 401);
// }
// if (isset($permissions['success']) && $permissions['success'] === false) {
// return $this->json($permissions);
// }
$result = $this->customNotificationModel->updateParameterHeightDepth($params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
/**
* @Route("/save-notification-config", name="save_notification_config")
*/
public function saveNotificationConfig(Request $request, UserInterface $user)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$requiredParameters = ['notificationName', 'description', 'severity', 'rules', 'lang', 'sequence', 'duration'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$result = $this->customNotificationModel->saveNotificationConfig($params, $user, $this->translator, $this->logger, $this->mateoMaticsService);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans($ex->getMessage())]);
}
}
/**
* @Route("/save-advance-custom-notification-by-tag", name="save_advance_custom_notification_by_tag" , methods={"POST"})
*/
public function saveAdvanceCustomNotificationByTag(Request $request, UserInterface $user)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$requiredParameters = ['notificationName', 'locationTagId', 'description', 'severity', 'rules', 'lang', 'sequence', 'duration'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$result = $this->customNotificationModel->saveAdvanceCustomNotificationByTag($params, $user, $this->translator, $this->logger, $this->mateoMaticsService);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans($ex->getMessage())]);
}
}
/**
* @Route("/list-advanced-custom-notifications", name="list_advanced_custom_notifications")
*/
public function listAdvancedCustomNotifications(Request $request, UserInterface $user, PaginatorInterface $paginator)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$result = $this->customNotificationModel->listAdvancedCustomNotifications($params, $user, $paginator, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans($ex->getMessage())]);
}
}
/**
* @Route("/del-advanced-custom-notifications", name="del_advanced_custom_notifications")
*/
public function delAdvancedCustomNotification(Request $request, UserInterface $user)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$requiredParameters = ['id'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$result = [];
if (isset($params['id']) && is_array($params['id'])) {
// Multiple IDs
$result = $this->customNotificationModel->delMultipleAdvancedCustomNotifications($params, $user, $this->translator);
} else {
// Single ID
$result = $this->customNotificationModel->delAdvancedCustomNotifications($params, $user, $this->translator);
}
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans($ex->getMessage())]);
}
}
/**
* @Route("/get-advanced-custom-notifications", name="get_advanced_custom_notifications")
*/
public function getAdvancedCustomNotification(Request $request, UserInterface $user)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$requiredParameters = ['id'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$result = $this->customNotificationModel->getAdvancedCustomNotifications($params, $user, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans($ex->getMessage())]);
}
}
/**
* @Route("/assign-users", name="assign_users")
*/
public function assignUsers(Request $request, UserInterface $user)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$requiredParameters = ['id'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$result = $this->customNotificationModel->assignUsers($params, $user, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans($ex->getMessage())]);
}
}
/**
* @Route("/assign-alert-subscription", name="assign_alert_subscription",methods={"POST"})
*/
public function assignAlertSubscription(Request $request, UserInterface $user): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$requiredParameters = ['AlertSubscriptionId', 'UserId'];
foreach ($requiredParameters as $param) {
if (!isset($params[$param]) || empty($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$result = $this->customNotificationService->assignAlertSubscription($user, $params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("/governorates", name="api_ncm_notification_governorates", methods={"POST"})
*/
public function getGovernorateByRegionAction(Request $request): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$permissions = $this->userPermission->validateAPI($request, $this->tokenStorageInterface, $this->jwtManager, $this->translator);
if (isset($permissions['code']) && $permissions['code'] === 401) {
return $this->json($permissions, 401);
} elseif ($permissions['success'] === false) {
return $this->json($permissions);
}
$result = $this->ewsNotificationModel->getGovernoratesByRegion($params);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("/test-ews-user-group-list", methods={"POST"})
*/
public function userGroupList(Request $request, UserInterface $user): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
if (!$user) {
return $this->json(['success' => false, 'message' => $this->translator->trans('user_is_not_authenticated')]);
}
$result = \App\Lib\Utility::getTestEwsUserGroupEmailList();
return $this->json(['success' => true, 'data' => $result]);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
}