<?php
namespace App\Command;
use Datetime;
use Pimcore\Db;
use GuzzleHttp\Client;
use Pimcore\Log\Simple;
use App\Service\RedisCache;
use App\Model\LocationModel;
use GuzzleHttp\Psr7\Request;
use App\Service\EmailService;
use Pimcore\Model\DataObject;
use App\Model\EwsNotificationModel;
use App\Service\NCMWeatherAPIService;
use App\Service\MeteomaticsWeatherService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use App\C2IntegrationBundle\Service\C2Service;
use App\Service\RichService;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Pimcore\Model\DataObject\FetchSentEwsEmail;
use Symfony\Contracts\Translation\TranslatorInterface;
use Pimcore\Log\ApplicationLogger;
class StoreMannedToEwsAlertCommnad extends Command
{
protected static $defaultName = 'app:get-manned-in-ews-alerts';
const HOURS = 24;
var $emailService = null;
private $templating;
private $nCMWeatherAPIService;
private $redisCache;
private $locationModel;
private $ewsNotificationModel;
private $c2Service;
private $richService;
private $httpClient;
private $logger;
public function __construct(EngineInterface $templating, RedisCache $redisCache, RichService $richService, HttpClientInterface $httpClient, protected TranslatorInterface $translator, ApplicationLogger $logger)
{
parent::__construct();
$this->templating = $templating;
$this->nCMWeatherAPIService = new NCMWeatherAPIService($redisCache, $httpClient);
$this->redisCache = $redisCache;
$this->locationModel = new LocationModel();
$this->ewsNotificationModel = new EwsNotificationModel();
$this->c2Service = new C2Service();
$this->richService = $richService;
$this->logger = $logger;
}
protected function configure()
{
$this->setDescription('Retrieve manned alerts by location and strore in EwsNotification object');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->emailService = new EmailService();
$mateoMaticsService = new MeteomaticsWeatherService($this->redisCache);
// Fetching alerts
$alerts = $this->nCMWeatherAPIService->getAlerts();
if ($alerts) {
foreach ($alerts as $alert) {
try {
// Create update alert
$ewsAlert = $this->createUpdateAlertNotification($alert, $output);
if (!$ewsAlert) {
$output->writeln('Nothing updated on notification = ' . $alert['id']);
continue;
}
if ($_ENV['SEND_EMAIL_NOTIFICATION'] == "false") {
$output->writeln('Email is not allowed on this environment');
continue;
}
if (!$ewsAlert->getIsSent()) {
$mannedAlertSubscription = new DataObject\MannedAlertSubscription\Listing();
$mannedAlertSubscription->setOrderKey("o_creationDate");
$mannedAlertSubscription->setOrder("desc");
foreach ($mannedAlertSubscription as $subscription) {
if ($subscription->getIsPublic() == false) {
// $subscriptionRegion = $subscription->getIsPublic() ?? false;
$subscriptionRegion = false;
if ($subscription->getRegion()) {
if ($subscription->getRegion()->getRegionId() == $alert['regionID']) {
$subscriptionRegion = true;
}
}
// $alertType = $subscription->getIsPublic() ?? false;
$alertType = false;
if ($subscription->getAlertType()) {
foreach ($subscription->getAlertType() as $alertType) {
if ($alertType->getAlertTypeId() == $alert['alertType']) {
$alertType = true;
break;
}
}
}
// $alertGovernorate = $subscription->getIsPublic() ?? false;
$alertGovernorate = false;
$alertGovernoratesIds = array_column($alert['governorates'], 'id');
if ($subscription->getGovernorate()) {
foreach ($subscription->getGovernorate() as $governorate) {
if (in_array($governorate->getGovernoteId(), $alertGovernoratesIds)) {
$alertGovernorate = true;
break;
}
}
}
// $phenomena = $subscription->getIsPublic() ?? false;
$phenomena = false;
if ($subscription->getAlertStatus()) {
foreach ($subscription->getAlertStatus() as $subscriptionAlertStatus) {
if ($subscriptionAlertStatus->getAlertStatusId() == $alert['alertStatusID']) {
$phenomena = true;
break;
}
}
}
// // logic for send email to those subscribers whose alert is updated
// $ewsObjectArray = ($subscription) ? $subscription->getMatchedEwsAlerts() : [];
// if ($ewsObjectArray) {
// // Loop through the alerts
// foreach ($ewsObjectArray as $ewsAlert) {
// // Check if the alert ID matches and is updated
// $currentEwsAlert = $ewsAlert->getObject();
// $data = $ewsAlert->getData();
// if ($currentEwsAlert->getId() === $ewsAlert->getId() && $data['isUpdated'] == true) {
// if (!empty($subscription->getCreator())) {
// $users = [];
// $owner = $subscription->getCreator();
// $subscribers = $subscription->getSubscribers();
// // Ensure $owner is an array
// $owner = [$owner];
// // Merge $owner and $subscribers into $users
// $users = array_merge($owner, $subscribers);
// // if ($user->getSendEwsEmail() == true || is_null($user->getSendEwsEmail())) {
// $email = $this->sendEmailNotification($users, $alert, $this->templating);
// // if ($email) {
// // $ewsNotification->setIsEmailSent(true);
// // $ewsNotification->save();
// // }
// // }
// }
// break; // Stop the loop once a match is found
// }
// }
// }
// check if all conditions are true then send email
if ($subscriptionRegion && $alertType && $alertGovernorate && $phenomena) {
if (!empty($subscription->getCreator())) {
$users = [];
$owner = $subscription->getCreator();
$subscribers = $subscription->getSubscribers();
// Ensure $owner is an array
$owner = [$owner];
// Merge $owner and $subscribers into $users
$users = array_merge($owner, $subscribers);
foreach ($users as $user) {
if ($user instanceof \Pimcore\Model\DataObject\Customer) {
if ($user->getSevereWeatherAlert()) {
$email = $this->sendEmailNotification($user, $alert, null, true, $ewsAlert);
}
}
}
// // Retrieve existing alerts from the subscription
// $existingAlerts = $subscription->getMatchedEwsAlerts();
// // Assuming $viewNotification has a method getId() to get its unique ID
// $newAlertId = $ewsAlert->getId();
// // Filter out the existing alert with the same ID, if any
// $filteredAlerts = array_filter($existingAlerts, function ($alert) use ($newAlertId) {
// // Assuming $alert is an ObjectMetadata instance with a method to get the underlying alert ID
// return $alert->getObject()->getId() !== $newAlertId;
// });
// // Create a new ObjectMetadata instance for the new alert
// $objectMetadata = new DataObject\Data\ObjectMetadata('matchedEwsAlerts', ['isUpdated'], $ewsAlert);
// $objectMetadata->setIsUpdated(false);
// // Add the new ObjectMetadata instance to the filtered alerts array
// $filteredAlerts[] = $objectMetadata;
// // Set the updated array back to the subscription
// $subscription->setMatchedEwsAlerts($filteredAlerts);
// $subscription->save();
}
}
}
}
// if ($userGroupIds) {
// $email = $this->sendExcelEmailNotification($userGroupIds, $alert, $this->templating);
// }
}
$ewsAlert->setIsSent(true);
$ewsAlert->save();
} catch (\Exception $ex) {
p_r($ex->getMessage());
}
}
}
return 0;
}
private function sendEmailNotification($user, $alert, $email = null, $actualUser, $alertObject)
{
$mailSent = null;
if ($alert) {
$governatesArr = $alert['governorates'];
$governates = [];
if ($governatesArr) {
foreach ($governatesArr as $gov) {
$governates[] = $gov['nameEn'];
}
}
$alertHazardsArr = $alert['alertHazards'];
$alertHazards = [];
$alertHazards_ar = [];
if ($alertHazardsArr) {
foreach ($alertHazardsArr as $alertHazard) {
$alertHazards[] = $alertHazard['descriptionEn'];
$alertHazards_ar[] = ['nameAr' => $alertHazard['descriptionAr']];
}
}
$alertActionsArr = $alert['alertActions'];
$alertActions = [];
if ($alertActionsArr) {
foreach ($alertActionsArr as $alertAction) {
$alertActions[] = $alertAction['descriptionEn'];
}
}
$data = $alert;
$data['sender'] = 'National Center for Meteorology';
// $subject =$alert['searchEwsIdAr'] ??'Severe Weather Alert - ' . $alert['regionEn'];
$subject = $alert['alertStatusAr'] . ' - ' . $alert['regionAR'];
if ($user) {
$data['name'] = $email ? $user : $user->getName();
// extra param js
$alertObj = \Pimcore\Model\DataObject\AlertType::getByAlertTypeId($alert['alertType'], true);
$alertName = $alertObj->getColor() ? $alertObj->getColor() : '';
$alert['user_name'] = $email ? $user : $user->getName();
$alert['host'] = API_BASE_URL;
$alert['alertColor'] = $alertName;
$currentDate = new \DateTime($alert['fromDate']);
$searchIdAr = 'النظام الالي للإنذار المبكر | ' . $currentDate->format('dmY') . '-' . $alert['id'] . ' | ' . $alert['alertTypeAr'] . ' | ' . $alert['alertStatusAr'];
$alert['searchEwsIdAr'] = $searchIdAr;
$alert['alertHazard'] = $alertHazards_ar;
$alert['last_modified_date'] = $alert['lastModified'];
$alert['tokenURL'] = null; // for now this is null but we have to develop unsubscribe functionality for this as well
if ($actualUser) {
// general un subscribe function
$token = \App\Lib\Utility::getUnSubscribeToken($user->getId());
$alert['tokenURL'] = BASE_URL . '/unsubscribe/email?token=' . $token;
}
$alert['mannedAlertDatailUrl'] = "https://ncm.gov.sa/Ar/alert/Pages/MapDetail.aspx?AlertId=" . $alert['id'];
$html = $this->templating->render('web2print/_manned_alert_notification_ar.html.twig', $alert);
$mannedAlert = \Pimcore\Model\DataObject\EwsNotification::getByAlertId($alert['id'], true);
$purpose = MANNED_ALERT_MESSAGE;
if ($email) {
$mailSent = $this->c2Service->sendDefaultEmail($_ENV['EWS_MAIL_TEMPLATE'], $mannedAlert->getId(), $email, $html, $subject, $purpose);
} else {
$mailSent = $this->c2Service->sendNotificationEmail($_ENV['EWS_MAIL_TEMPLATE'], $mannedAlert->getId(), $user->getId(), $html, $subject, $purpose);
}
if ($user->getPhoneNo() && strlen($user->getPhoneNo()) == 9) {
$messageSMS = sprintf(SMS_MESSAGE["MANNED_ALERT"], strtoupper($alertName) . " alert raised in " . $alert['regionAR'] . ' for ' . $alert['alertStatusAr'] . " event");
$this->richService->sendSms(SAUDI_CALL_CODE . $user->getPhoneNo(), $messageSMS);
}
if ($alertObject->getEnableSmsNotification() && $user->getPhoneNo() && strlen($user->getPhoneNo()) == 9) {
$smsTemplate = \Pimcore\Model\WebsiteSetting::getByName('MANNED_ALERT', null);
if ($smsTemplate != null && $smsTemplate->getData() != null) {
$messageSMS = sprintf(SMS_MESSAGE["MANNED_ALERT"], strtoupper($alertName) . " alert raised in " . $alert['regionAR'] . ' for ' . $alert['alertStatusAr'] . " event");
try {
$responseSMS = $this->richService->sendMannedAlertNotificationSMS($alertObject, $user, $purpose, $messageSMS);
if (!$responseSMS) {
$this->logger->error('Failed to send SMS to ' . SAUDI_CALL_CODE . $user->getPhoneNo());
}
} catch (\Exception $e) {
$this->logger->error('Exception occurred while sending SMS: ' . $e->getMessage());
}
}
}
}
}
return $mailSent;
}
private function sendExcelEmailNotification($userGroupIds, $alert, $templating)
{
$mailSent = null;
if ($alert) {
$governatesArr = $alert['governorates'];
$governates = [];
if ($governatesArr) {
foreach ($governatesArr as $gov) {
$governates[] = $gov['nameEn'];
}
}
$data = $alert;
$data['sender'] = 'National Center for Meteorology';
// $subject = $alert['searchEwsIdAr'] ??'Severe Weather Alert - ' . $gov['nameEn'];
//$subject = $alert['alertStatusAr'] . ' - ' . $alert['regionAR'];
// $subject = 'النظام الالي للإنذار المبكر :' . ' - ' . $alert['searchEwsIdAr'];
$parts = explode('|', $alert['searchEwsIdAr']);
$excluded = implode('|', array_slice($parts, 1));
$subject = 'النظام الالي للإنذار المبكر :' . $excluded;
if ($userGroupIds) {
foreach ($userGroupIds as $userGroupId) {
if ($userGroupId) {
$userGroup = \Pimcore\Model\DataObject\EwsAndReportUserGroup::getById($userGroupId, true);
if ($userGroup instanceof \Pimcore\Model\DataObject\EwsAndReportUserGroup) {
foreach (json_decode($userGroup->getJsonData()) as $currentUser) {
if (isset($currentUser->firstName) && isset($currentUser->lastName) && isset($currentUser->email)) {
// extra param js
$alertObj = \Pimcore\Model\DataObject\AlertType::getByAlertTypeId($alert['alertType'], true);
$alertName = $alertObj->getColor() ? $alertObj->getColor() : '';
$alert['user_name'] = $currentUser->firstName . ' ' . $currentUser->lastName;
$alert['host'] = API_BASE_URL;
$alert['alertColor'] = $alertName;
$backgroundColor = '#fcb82526';
$borderColor = '#000000';
$textColor = '#000000';
if (isset($alert['alertColor']) && !empty(trim($alert['alertColor']))) {
$alertColorLower = strtolower(trim($alert['alertColor']));
if ($alertColorLower === 'red') {
$backgroundColor = '#f6000017';
$borderColor = '#F60000';
$textColor = '#F60000';
} elseif ($alertColorLower === 'orange') {
$backgroundColor = '#ff66001f';
$borderColor = '#FF6600';
$textColor = '#FF6600';
} elseif ($alertColorLower === 'yellow') {
$backgroundColor = '#fcb82526';
$borderColor = '#FCB825';
$textColor = '#FCB825';
}
}
$alert['backgroundColor'] = $backgroundColor;
$alert['borderColor'] = $borderColor;
$alert['textColor'] = $textColor;
$alert['tokenURL'] = null;
$alert['mannedAlertDatailUrl'] = null;
$html = $templating->render('web2print/_manned_alert_notification_ar.html.twig', $alert);
// $email = $currentUser->email;
// $param = ['user' => $currentUser, 'message' => $html, 'url' => null];
// $mailSent = $emailService->sendMail($param, "abdul.muqeet@centric.ae", '/email/alert_notification', $subject);
$purpose = EWS_MESSAGE;
$mailSent = $this->c2Service->sendDefaultEmail($_ENV['EWS_MAIL_TEMPLATE'], $alert['id'], $currentUser->email, $html, $subject, $purpose);
if ($mailSent) {
$status = "sent";
$this->saveEmailStatus($currentUser->email, $currentUser->firstName . ' ' . $currentUser->lastName, $alert, $status);
} else {
$status = "not sent";
$this->saveEmailStatus($currentUser->email, $currentUser->firstName . ' ' . $currentUser->lastName, $alert, $status);
}
}
}
}
}
}
}
}
return $mailSent;
}
private function saveEmailStatus($userEmail, $userName, $alert, $emailStatus)
{
// Get all governorates names in string seprated by ,
$nameEnArray = array_column($alert["governorates"], "nameEn");
$nameEnString = implode(", ", $nameEnArray);
$nameArArray = array_column($alert["governorates"], "nameAr");
$nameArString = implode(", ", $nameArArray);
$ewsEmailStatus = new FetchSentEwsEmail();
$ewsEmailStatus->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath("/Other/FetchSentEwsEmail/"));
$ewsEmailStatus->setKey(\Pimcore\Model\Element\Service::getValidKey($userEmail . "-" . strtotime("now") . "-" . rand(1, 10000), 'object'));
$ewsEmailStatus->setEwsId($alert['id']);
$ewsEmailStatus->setUserName($userName);
$ewsEmailStatus->setEmail($userEmail);
//$ewsEmailStatus->setLocationName($locationName);
$ewsEmailStatus->setAlertType($alert['alertTypeEn'], 'en');
$ewsEmailStatus->setAlertType($alert['alertTypeAr'], 'ar');
$ewsEmailStatus->setAlertStatus($alert['alertStatusEn'], 'en');
$ewsEmailStatus->setAlertStatus($alert['alertStatusAr'], 'ar');
$ewsEmailStatus->setRegionName($alert['regionEn'], 'en');
$ewsEmailStatus->setRegionName($alert['regionAR'], 'ar');
$ewsEmailStatus->setGovernorateNames($nameEnString, 'en');
$ewsEmailStatus->setGovernorateNames($nameArString, 'ar');
$ewsEmailStatus->setStatus($emailStatus);
$ewsEmailStatus->setPublished(true);
$ewsEmailStatus->save();
return $ewsEmailStatus;
}
private function createUpdateAlertNotification($alert, $output)
{
// Generate the hash for the current alert data
$alertHash = md5(json_encode($alert));
// Retrieve the existing EwsNotification object by alert ID
$ewsNotification = \Pimcore\Model\DataObject\EwsNotification::getByAlertId($alert['id'], true);
// Check if the ews alert already exists
if ($ewsNotification) {
// Compare the old hash with the new hash
if ($ewsNotification->getHash() === $alertHash) {
// If the hashes match, the alert has not changed; ignore it
return null;
}
} else {
// If the alert does not exist, create a new MannedAlertNotification object
$ewsNotification = new DataObject\EwsNotification();
$ewsNotification->setKey($alert['id']);
$date = date('Y-m-d', strtotime($alert['fromDate']));
$ewsNotification->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/EWSNotification/' . $date));
$ewsNotification->setGuid(\App\Lib\Utility::getUUID()->toRfc4122());
}
$ewsNotification->setIsManned(true);
// Update the MannedAlertNotification object with the new alert data
$ewsNotification->setAlertId($alert['id']);
$ewsNotification->setTitle($alert['title']);
$ewsNotification->setAlertType($this->getAlertType($alert['alertType'], $alert['alertTypeAr'], $alert['alertTypeEn']));
$fromDate = \Carbon\Carbon::createFromFormat('m/d/Y h:i:s A', $alert['fromDate']);
$toDate = \Carbon\Carbon::createFromFormat('m/d/Y h:i:s A', $alert['toDate']);
$lastModified = \Carbon\Carbon::createFromFormat('m/d/Y h:i:s A', $alert['lastModified']);
$ewsNotification->setStartDate($fromDate);
$ewsNotification->setEndDate($toDate);
$ewsNotification->setLastModifiedDate($lastModified);
$ewsNotification->setAlertStatusCategory($this->getAlertStatusCategory($alert['alertStatusCategory'])); // need to fix
$ewsNotification->setStatus("active");
$alertStatus = $this->getAlertStatus($alert['alertStatusID'], $alert['alertStatusAr'], $alert['alertStatusEn']);
if ($alertStatus) {
$ewsNotification->setAlertStatus($alertStatus);
}
$alertHazardArr = [];
if ($alert['alertHazards']) {
foreach ($alert['alertHazards'] as $alertHazard) {
$alertHazardArr[] = $this->getAlertHazard($alertHazard['id'], $alertHazard['descriptionAr'], $alertHazard['descriptionEn']);
}
$ewsNotification->setAlertHazard(array_filter($alertHazardArr));
}
$ewsNotification->setRegion($this->getRegion($alert['regionID'], $alert['regionAR'], $alert['regionEn']));
$alertGovernorateArr = [];
if ($alert['governorates']) {
foreach ($alert['governorates'] as $alertGovernorate) {
$alertGovernorateArr[] = $this->getGovernorates($alertGovernorate['id'], $alertGovernorate['nameAr'], $alertGovernorate['nameEn'], $alertGovernorate['longitude'], $alertGovernorate['latitude']);
}
$ewsNotification->setGovernorate(array_filter($alertGovernorateArr));
}
$ewsNotification->setOtherLocation($alert['otherLocationsEn'], 'en');
$ewsNotification->setOtherLocation($alert['otherLocationsAr'], 'ar');
if ($alert['otherLocationsAr']) {
$otherLocation = \Pimcore\Model\DataObject\EwsOtherLocation::getByName($alert['otherLocationsAr'], 'en', true);
$ewsNotification->setEwsOtherLocations($otherLocation);
}
$ewsNotification->settweetID($alert['tweetID']);
$alertAlertActionArr = [];
if ($alert['alertActions']) {
foreach ($alert['alertActions'] as $alertAlertAction) {
$alertAlertActionArr[] = $this->getAlertAction($alertAlertAction['id'], $alertAlertAction['descriptionAr'], $alertAlertAction['descriptionEn']);
}
$ewsNotification->setAlertAction(array_filter($alertAlertActionArr));
}
// Set the hash for the alert
$ewsNotification->setHash($alertHash);
$ewsNotification->setRawText(json_encode($alert));
$ewsNotification->setIsSent(false);
$ewsNotification->setOmitMandatoryCheck(true);
// saving here just to get the id
$ewsNotification->save();
$currentDate = new \DateTime();
$formattedDate = $currentDate->format('dmY') . '-' . $ewsNotification->getId();
$searchIdEn = 'Early Warning System | ' . $formattedDate . ' | ' . ucfirst($ewsNotification->getAlertType()?->getColor()) . ' Alert | ' . $ewsNotification->getAlertStatus()?->getName("en");
$searchIdAr = $this->translator->trans('Early Warning System', [], null, "ar") . ' | ' . $formattedDate . ' | ' . $this->translator->trans(ucfirst($ewsNotification->getAlertType()?->getColor()) . ' Alert', [], null, "ar") . ' | ' . $ewsNotification->getAlertStatus()?->getName("ar");
$ewsNotification->setEwsSearchId($searchIdEn, "en");
$ewsNotification->setEwsSearchId($searchIdAr, "ar");
// Save the updated MannedAlertNotification object
$ewsNotification->setPublished(TRUE);
$ewsNotification->save();
return $ewsNotification;
}
private function getAlertType($id, $nameAr, $nameEn)
{
$alertType = \Pimcore\Model\DataObject\AlertType::getByAlertTypeId($id, true);
if (!$alertType) {
$alertType = new \Pimcore\Model\DataObject\AlertType();
$alertType->setKey($id);
$alertType->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/AlertType'));
$alertType->setAlertTypeId($id);
$alertType->setName($nameAr, "en");
$alertType->setName($nameEn, "ar");
$alertType->setPublished(true);
$alertType->save();
}
return $alertType;
}
private function getAlertStatusCategory($name)
{
$alertStatusCategory = \Pimcore\Model\DataObject\AlertStatusCategory::getByName($name, true);
if (!$alertStatusCategory) {
$alertStatusCategory = new \Pimcore\Model\DataObject\AlertStatusCategory();
$alertStatusCategory->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/AlertStatusCategory'));
$alertStatusCategory->setKey($name);
$alertStatusCategory->setName($name);
$alertStatusCategory->setPublished(true);
$alertStatusCategory->save();
}
return $alertStatusCategory;
}
private function getAlertStatus($id, $nameAr, $nameEn)
{
$alertStatus = \Pimcore\Model\DataObject\AlertStatus::getByAlertStatusId($id, true);
if (!$alertStatus) {
$alertStatus = new \Pimcore\Model\DataObject\AlertStatus();
$alertStatus->setKey($id);
$alertStatus->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/AlertStatus'));
$alertStatus->setAlertStatusId($id);
$alertStatus->setName($nameAr, 'ar');
$alertStatus->setName($nameEn, 'en');
$alertStatus->setPublished(true);
$alertStatus->save();
}
return $alertStatus;
}
private function getAlertHazard($id, $descriptionAr, $descriptionEn)
{
$alertHazard = \Pimcore\Model\DataObject\AlertHazard::getByAlertHazardId($id, true);
if (!$alertHazard) {
$alertHazard = new \Pimcore\Model\DataObject\AlertHazard();
$alertHazard->setKey($id);
$alertHazard->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/AlertHazard'));
$alertHazard->setAlertHazardId($id);
$alertHazard->setName($descriptionAr, "ar");
$alertHazard->setName($descriptionEn, "en");
$alertHazard->setPublished(true);
$alertHazard->save();
} else {
$alertHazard->setName($descriptionAr, "ar");
$alertHazard->setName($descriptionEn, "en");
$alertHazard->save();
}
return $alertHazard;
}
private function getRegion($id, $nameAr, $nameEn)
{
$region = \Pimcore\Model\DataObject\Region::getByRegionId($id, true);
if (!$region) {
$region = new \Pimcore\Model\DataObject\Region();
$region->setKey($id);
$region->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/Region'));
$region->setRegionId($id);
$region->setName($nameAr, 'ar');
$region->setName($nameEn, 'en');
$region->setPublished(true);
$region->save();
}
return $region;
}
private function getGovernorates($id, $nameAr, $nameEn, $longitude, $latitude)
{
$governorate = \Pimcore\Model\DataObject\Governorate::getByGovernoteId($id, true);
if (!$governorate) {
$governorate = new \Pimcore\Model\DataObject\Governorate();
$governorate->setKey($id);
$governorate->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/Governorate'));
$governorate->setGovernoteId($id);
$governorate->setName($nameAr, "ar");
$governorate->setName($nameEn, "en");
$governorate->setLongitude($longitude);
$governorate->setLatitude($latitude);
$governorate->setPublished(true);
$governorate->save();
}
return $governorate;
}
private function getAlertAction($id, $descriptionAr, $descriptionEn)
{
$alertAction = \Pimcore\Model\DataObject\AlertAction::getByAlertActionId($id, true);
if (!$alertAction) {
$alertAction = new \Pimcore\Model\DataObject\AlertAction();
$alertAction->setKey($id);
$alertAction->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/AlertAction'));
$alertAction->setAlertActionId($id);
$alertAction->setName($descriptionAr, "ar");
$alertAction->setName($descriptionEn, "en");
$alertAction->setPublished(true);
$alertAction->save();
}
return $alertAction;
}
}