mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-05 10:18:33 +08:00
[Legacy] Add services to generate alerts from reminders and activities
- Port the that was used to generate the alerts to separate services that can be called from Suite 8 side
This commit is contained in:
parent
5ec05f5363
commit
cd716972bb
5 changed files with 776 additions and 3 deletions
248
public/legacy/modules/Alerts/services/AddActivitiesAlerts.php
Normal file
248
public/legacy/modules/Alerts/services/AddActivitiesAlerts.php
Normal file
|
@ -0,0 +1,248 @@
|
|||
<?php
|
||||
/**
|
||||
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
|
||||
* Copyright (C) 2023 SalesAgility Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
|
||||
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License
|
||||
* version 3, these Appropriate Legal Notices must retain the display of the
|
||||
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
|
||||
* feasible for technical reasons, the Appropriate Legal Notices must display
|
||||
* the words "Supercharged by SuiteCRM".
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/AddAlert.php';
|
||||
|
||||
class AddActivitiesAlerts
|
||||
{
|
||||
|
||||
/**
|
||||
* @var AddAlert
|
||||
*/
|
||||
protected $addAlertService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->addAlertService = new AddAlert();
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
global $current_user;
|
||||
|
||||
if (empty($current_user->id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
[$alertDateTimeNow, $dateTimeMax, $dateTimeNow] = $this->getDateRange();
|
||||
|
||||
$this->addMeetingsAlerts($dateTimeNow, $dateTimeMax, $alertDateTimeNow);
|
||||
|
||||
$this->addCallAlerts($dateTimeNow, $dateTimeMax, $alertDateTimeNow);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dateTimeNow
|
||||
* @param string $dateTimeMax
|
||||
* @param string $alertDateTimeNow
|
||||
* @return void
|
||||
*/
|
||||
protected function addCallAlerts(string $dateTimeNow, string $dateTimeMax, string $alertDateTimeNow): void
|
||||
{
|
||||
global $db, $app_strings, $timedate, $current_user;
|
||||
|
||||
$desc = $this->getDescriptionField();
|
||||
|
||||
// Prep Calls Query
|
||||
$selectCalls = "
|
||||
SELECT calls.id, name, reminder_time, $desc, date_start, status, parent_type, parent_id
|
||||
FROM calls LEFT JOIN calls_users ON calls.id = calls_users.call_id
|
||||
WHERE calls_users.user_id ='" . $current_user->id . "'
|
||||
AND calls_users.accept_status != 'decline'
|
||||
AND calls.reminder_time != -1
|
||||
AND calls_users.deleted != 1
|
||||
AND calls.status = 'Planned'
|
||||
AND date_start >= $dateTimeNow
|
||||
AND date_start <= $dateTimeMax";
|
||||
|
||||
$result = $db->query($selectCalls);
|
||||
|
||||
while ($row = $db->fetchByAssoc($result)) {
|
||||
// need to concatenate since GMT times can bridge two local days
|
||||
$timeStart = strtotime($db->fromConvert($row['date_start'], 'datetime'));
|
||||
$timeRemind = $row['reminder_time'];
|
||||
$timeStart -= $timeRemind;
|
||||
$row['description'] = (isset($row['description'])) ? $row['description'] : '';
|
||||
|
||||
$relatedToCall = $this->getRelatedName($row['parent_type'], $row['parent_id']);
|
||||
|
||||
$callDescription = $row['description'] . "\n" . $app_strings['MSG_JS_ALERT_MTG_REMINDER_STATUS'] . $row['status'] . "\n" . $app_strings['MSG_JS_ALERT_MTG_REMINDER_RELATED_TO'] . $relatedToCall;
|
||||
|
||||
$meetingName = $row['name'];
|
||||
$dateStart = $timedate->to_display_date_time($db->fromConvert($row['date_start'], 'datetime'));
|
||||
$alertSubtitle = $app_strings['MSG_JS_ALERT_MTG_REMINDER_TIME'] . $dateStart;
|
||||
$alertDescription = $app_strings['MSG_JS_ALERT_MTG_REMINDER_DESC'] . $callDescription;
|
||||
$alertURL = 'index.php?action=DetailView&module=Calls&record=' . $row['id'];
|
||||
|
||||
$this->addAlertService->run(
|
||||
'Call',
|
||||
$meetingName,
|
||||
$alertDescription,
|
||||
$alertURL,
|
||||
$row['date_start']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dateTimeNow
|
||||
* @param string $dateTimeMax
|
||||
* @param string $alertDateTimeNow
|
||||
* @return void
|
||||
*/
|
||||
protected function addMeetingsAlerts(string $dateTimeNow, string $dateTimeMax, string $alertDateTimeNow): void
|
||||
{
|
||||
|
||||
global $db, $app_strings, $timedate, $current_user, $sugar_config;
|
||||
|
||||
$desc = $this->getDescriptionField();
|
||||
|
||||
// Prep Meetings Query
|
||||
$selectMeetings = "SELECT meetings.id, name,reminder_time, $desc,location, status, parent_type, parent_id, date_start, assigned_user_id
|
||||
FROM meetings LEFT JOIN meetings_users ON meetings.id = meetings_users.meeting_id
|
||||
WHERE meetings_users.user_id ='" . $current_user->id . "'
|
||||
AND meetings_users.accept_status != 'decline'
|
||||
AND meetings.reminder_time != -1
|
||||
AND meetings_users.deleted != 1
|
||||
AND meetings.status = 'Planned'
|
||||
AND date_start >= $dateTimeNow
|
||||
AND date_start <= $dateTimeMax";
|
||||
$result = $db->query($selectMeetings);
|
||||
|
||||
[$meetingIntegration, $sugar_config] = $this->initMeetingIntegration($sugar_config);
|
||||
|
||||
while ($row = $db->fetchByAssoc($result)) {
|
||||
// need to concatenate since GMT times can bridge two local days
|
||||
$timeStart = strtotime($db->fromConvert($row['date_start'], 'datetime'));
|
||||
$timeRemind = $row['reminder_time'];
|
||||
$timeStart -= $timeRemind;
|
||||
|
||||
$url = 'index.php?action=DetailView&module=Meetings&record=' . $row['id'];
|
||||
$instructions = $app_strings['MSG_JS_ALERT_MTG_REMINDER_MEETING_MSG'];
|
||||
|
||||
if (!empty($meetingIntegration) && $meetingIntegration->isIntegratedMeeting($row['id'])) {
|
||||
$url = $meetingIntegration->miUrlGetJsAlert($row);
|
||||
$instructions = $meetingIntegration->miGetJsAlertInstructions();
|
||||
}
|
||||
|
||||
$meetingName = from_html($row['name']);
|
||||
$desc1 = from_html($row['description']);
|
||||
$location = from_html($row['location']);
|
||||
|
||||
$relatedToMeeting = $this->getRelatedName($row['parent_type'], $row['parent_id']);
|
||||
|
||||
$description = empty($desc1) ? '' : $app_strings['MSG_JS_ALERT_MTG_REMINDER_AGENDA'] . $desc1 . "\n";
|
||||
$description .= "\n" . $app_strings['MSG_JS_ALERT_MTG_REMINDER_STATUS'] . $row['status'] . "\n" . $app_strings['MSG_JS_ALERT_MTG_REMINDER_RELATED_TO'] . $relatedToMeeting;
|
||||
|
||||
$dateStart = $timedate->to_display_date_time($db->fromConvert($row['date_start'], 'datetime'));
|
||||
$alertSubtitle = $app_strings['MSG_JS_ALERT_MTG_REMINDER_TIME'] . $dateStart;
|
||||
$alertDescription = $app_strings['MSG_JS_ALERT_MTG_REMINDER_LOC'] . $location . $description . $instructions;
|
||||
|
||||
$this->addAlertService->run(
|
||||
'Meeting',
|
||||
$meetingName,
|
||||
$alertDescription,
|
||||
$url,
|
||||
$row['date_start']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|string
|
||||
*/
|
||||
protected function getDescriptionField()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$desc = $db->convert("description", "text2char");
|
||||
if ($desc !== "description") {
|
||||
$desc .= " description";
|
||||
}
|
||||
|
||||
return $desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getDateRange(): array
|
||||
{
|
||||
global $timedate, $app_list_strings, $db;
|
||||
//Create separate variable to hold timedate value
|
||||
$alertDateTimeNow = $timedate->nowDb();
|
||||
|
||||
$reminder_max_time = $app_list_strings['reminder_max_time'] ?? 0;
|
||||
|
||||
// cn: get a boundary limiter
|
||||
$dateTimeMax = $timedate->getNow()->modify("+{$reminder_max_time} seconds")->asDb();
|
||||
$dateTimeNow = $timedate->getNow()->modify("-60 seconds")->asDb();
|
||||
|
||||
$db = DBManagerFactory::getInstance();
|
||||
$dateTimeNow = $db->convert($db->quoted($dateTimeNow), 'datetime');
|
||||
$dateTimeMax = $db->convert($db->quoted($dateTimeMax), 'datetime');
|
||||
|
||||
return [$alertDateTimeNow, $dateTimeMax, $dateTimeNow];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sugar_config
|
||||
* @return array
|
||||
*/
|
||||
protected function initMeetingIntegration(array $sugar_config): array
|
||||
{
|
||||
$meetingIntegration = null;
|
||||
if (isset($sugar_config['meeting_integration']) && !empty($sugar_config['meeting_integration'])) {
|
||||
if (!class_exists($sugar_config['meeting_integration'])) {
|
||||
require_once("modules/{$sugar_config['meeting_integration']}/{$sugar_config['meeting_integration']}.php");
|
||||
}
|
||||
$meetingIntegration = new $sugar_config['meeting_integration']();
|
||||
}
|
||||
|
||||
return [$meetingIntegration, $sugar_config];
|
||||
}
|
||||
|
||||
/**
|
||||
* To return the name of parent bean.
|
||||
* @param $parentType
|
||||
* @param $parentId
|
||||
* @return string
|
||||
*/
|
||||
protected function getRelatedName($parentType, $parentId): string
|
||||
{
|
||||
if (!empty($parentType) && !empty($parentId)) {
|
||||
$parentBean = BeanFactory::getBean($parentType, $parentId);
|
||||
if (($parentBean instanceof SugarBean) && isset($parentBean->name)) {
|
||||
return $parentBean->name;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
92
public/legacy/modules/Alerts/services/AddAlert.php
Normal file
92
public/legacy/modules/Alerts/services/AddAlert.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
/**
|
||||
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
|
||||
* Copyright (C) 2023 SalesAgility Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
|
||||
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License
|
||||
* version 3, these Appropriate Legal Notices must retain the display of the
|
||||
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
|
||||
* feasible for technical reasons, the Appropriate Legal Notices must display
|
||||
* the words "Supercharged by SuiteCRM".
|
||||
*/
|
||||
|
||||
class AddAlert
|
||||
{
|
||||
|
||||
/**
|
||||
* Add an alert
|
||||
* @param string $target_module
|
||||
* @param string $name
|
||||
* @param string $description
|
||||
* @param string|null $url_redirect
|
||||
* @param string $date_start
|
||||
* @param string $reminder_id
|
||||
* @param string $type
|
||||
* @param bool $is_read
|
||||
* @return void
|
||||
*/
|
||||
public function run(
|
||||
string $target_module,
|
||||
string $name,
|
||||
string $description = '',
|
||||
string $url_redirect = null,
|
||||
string $date_start = '',
|
||||
string $reminder_id = '',
|
||||
string $type = 'info',
|
||||
bool $is_read = false
|
||||
): void {
|
||||
global $current_user;
|
||||
|
||||
$assigned_user_id = $current_user->id;
|
||||
$snooze = null;
|
||||
|
||||
if ($url_redirect === null) {
|
||||
$url_redirect = 'index.php?fakeid=' . uniqid('fake_', true);
|
||||
}
|
||||
|
||||
$result = null;
|
||||
|
||||
if (!empty($reminder_id)) {
|
||||
$alert = BeanFactory::getBean('Alerts');
|
||||
$result = $alert->get_full_list(
|
||||
"",
|
||||
"alerts.assigned_user_id = '" . $current_user->id . "' AND reminder_id = '" . $reminder_id . "'"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Alert $alert */
|
||||
$alert = BeanFactory::newBean('Alerts');
|
||||
$alert->name = $name;
|
||||
$alert->description = $description;
|
||||
$alert->url_redirect = $url_redirect;
|
||||
$alert->target_module = $target_module;
|
||||
$alert->is_read = $is_read;
|
||||
$alert->assigned_user_id = $assigned_user_id;
|
||||
$alert->type = $type;
|
||||
$alert->reminder_id = $reminder_id;
|
||||
$alert->snooze = $snooze;
|
||||
$alert->date_start = $date_start;
|
||||
$alert->save();
|
||||
}
|
||||
|
||||
}
|
58
public/legacy/modules/Alerts/services/AddScheduledAlerts.php
Normal file
58
public/legacy/modules/Alerts/services/AddScheduledAlerts.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
|
||||
* Copyright (C) 2023 SalesAgility Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
|
||||
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License
|
||||
* version 3, these Appropriate Legal Notices must retain the display of the
|
||||
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
|
||||
* feasible for technical reasons, the Appropriate Legal Notices must display
|
||||
* the words "Supercharged by SuiteCRM".
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/AddActivitiesAlerts.php';
|
||||
require_once __DIR__ . '/AddScheduledReminderAlerts.php';
|
||||
|
||||
class AddScheduledAlerts
|
||||
{
|
||||
|
||||
/**
|
||||
* @var AddScheduledReminderAlerts
|
||||
*/
|
||||
protected $addScheduledReminderAlerts;
|
||||
|
||||
/**
|
||||
* @var AddActivitiesAlerts
|
||||
*/
|
||||
protected $addActivitiesAlertsService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->addActivitiesAlertsService = new AddActivitiesAlerts();
|
||||
$this->addScheduledReminderAlerts = new AddScheduledReminderAlerts();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->addActivitiesAlertsService->run();
|
||||
$this->addScheduledReminderAlerts->run();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,375 @@
|
|||
<?php
|
||||
/**
|
||||
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
|
||||
* Copyright (C) 2023 SalesAgility Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
|
||||
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License
|
||||
* version 3, these Appropriate Legal Notices must retain the display of the
|
||||
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
|
||||
* feasible for technical reasons, the Appropriate Legal Notices must display
|
||||
* the words "Supercharged by SuiteCRM".
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/AddAlert.php';
|
||||
|
||||
class AddScheduledReminderAlerts
|
||||
{
|
||||
|
||||
/**
|
||||
* @var AddAlert
|
||||
*/
|
||||
protected $addAlertService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->addAlertService = new AddAlert();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $checkDecline bool
|
||||
* @return void
|
||||
*/
|
||||
public function run($checkDecline = true): void
|
||||
{
|
||||
global $current_user, $timedate, $app_strings;
|
||||
|
||||
if (empty($current_user->id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
[$dateTimeMaxStamp, $dateTimeNowStamp] = $this->getDateRange();
|
||||
|
||||
// Original jsAlert used to a meeting integration.
|
||||
$meetingIntegration = $this->getMeetingIntegration();
|
||||
|
||||
$popupReminders = $this->getScheduledReminders($dateTimeNowStamp, $dateTimeMaxStamp);
|
||||
|
||||
if (empty($popupReminders)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$i_runs = 0;
|
||||
foreach ($popupReminders as $popupReminder) {
|
||||
|
||||
$relatedEventModule = $popupReminder->related_event_module ?? '';
|
||||
|
||||
$relatedEvent = BeanFactory::getBean(
|
||||
$relatedEventModule,
|
||||
$popupReminder->related_event_module_id
|
||||
);
|
||||
$dateTime = DateTime::createFromFormat($timedate->get_date_time_format(), $relatedEvent->date_start);
|
||||
$relatedEventStart = $dateTime ? $dateTime->getTimestamp() : $dateTime;
|
||||
|
||||
if ($this->shouldUpdateExecutionTime($i_runs, $popupReminder)) {
|
||||
$this->updateReminderExecutionTime($popupReminder, $relatedEventStart);
|
||||
$i_runs++;
|
||||
}
|
||||
|
||||
if (!$relatedEvent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$status = $relatedEvent->status ?? '';
|
||||
if ($status !== '' && $relatedEvent->status !== 'Planned') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->isOutsideOfExecutionDateRange($relatedEventStart, $dateTimeNowStamp, $dateTimeMaxStamp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = BeanFactory::getBean('Users', $current_user->id);
|
||||
if ($checkDecline && Reminder::isDecline($relatedEvent, $user)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// The original popup/alert reminders check the accept_status field in related users/leads/contacts etc. and filtered these users who not decline this event.
|
||||
$invitees = $this->getInvitees($popupReminder, $current_user);
|
||||
if (!$invitees) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$relatedEventStart -= $popupReminder->timer_popup;
|
||||
|
||||
$url = $this->getURL($popupReminder);
|
||||
$instructions = $this->getInstructions($app_strings['MSG_JS_ALERT_MTG_REMINDER_MEETING_MSG']);
|
||||
|
||||
if ($popupReminder->related_event_module === 'Meetings') {
|
||||
[$url, $instructions] = $this->addMeetingOverrides($meetingIntegration, $popupReminder, $url,
|
||||
$instructions);
|
||||
}
|
||||
|
||||
$alertTitle = $this->getMeetingName($relatedEvent);
|
||||
$location = $this->getLocation($relatedEvent);
|
||||
|
||||
$relatedToMeeting = $this->getRelatedName($popupReminder);
|
||||
|
||||
$description = $this->getDescription($relatedEvent, $app_strings, $relatedToMeeting);
|
||||
|
||||
|
||||
$time = $this->getAlertTime($relatedEvent);
|
||||
|
||||
$alertSubtitle = $app_strings['MSG_JS_ALERT_MTG_REMINDER_TIME'] . $time;
|
||||
$alertDescription = $app_strings['MSG_JS_ALERT_MTG_REMINDER_LOC'] . $location . $description . $instructions;
|
||||
$this->addAlertService->run(
|
||||
BeanFactory::getBeanName($relatedEvent->module_name) ?? '',
|
||||
$alertTitle,
|
||||
$alertDescription,
|
||||
$url,
|
||||
$time,
|
||||
$popupReminder->id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
protected function getMeetingIntegration(): ?array
|
||||
{
|
||||
global $sugar_config;
|
||||
$meetingIntegration = null;
|
||||
if (isset($sugar_config['meeting_integration']) && !empty($sugar_config['meeting_integration'])) {
|
||||
if (!class_exists($sugar_config['meeting_integration'])) {
|
||||
require_once("modules/{$sugar_config['meeting_integration']}/{$sugar_config['meeting_integration']}.php");
|
||||
}
|
||||
$meetingIntegration = new $sugar_config['meeting_integration']();
|
||||
}
|
||||
|
||||
return $meetingIntegration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dateTimeNowStamp
|
||||
* @param $dateTimeMaxStamp
|
||||
* @return SugarBean[]|null
|
||||
*/
|
||||
protected function getScheduledReminders($dateTimeNowStamp, $dateTimeMaxStamp): ?array
|
||||
{
|
||||
$popupReminders = BeanFactory::getBean('Reminders')->get_full_list(
|
||||
'',
|
||||
"reminders.popup = 1 AND (reminders.date_willexecute = -1 OR reminders.date_willexecute BETWEEN "
|
||||
. $dateTimeNowStamp . " AND " . $dateTimeMaxStamp . ")"
|
||||
);
|
||||
|
||||
return $popupReminders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $relatedEvent
|
||||
* @return string
|
||||
*/
|
||||
protected function getMeetingName($relatedEvent): string
|
||||
{
|
||||
global $app_strings;
|
||||
$default = $app_strings['MSG_JS_ALERT_MTG_REMINDER_NO_EVENT_NAME'];
|
||||
|
||||
return from_html($relatedEvent->name ?? $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $relatedEvent
|
||||
* @param array $app_strings
|
||||
* @param string $relatedToMeeting
|
||||
* @return string
|
||||
*/
|
||||
protected function getDescription($relatedEvent, array $app_strings, string $relatedToMeeting): string
|
||||
{
|
||||
$desc1 = from_html($relatedEvent->description ?? $app_strings['MSG_JS_ALERT_MTG_REMINDER_NO_DESCRIPTION']);
|
||||
$description = empty($desc1) ? '' : $app_strings['MSG_JS_ALERT_MTG_REMINDER_AGENDA'] . $desc1 . "\n";
|
||||
$description .= "\n" . $app_strings['MSG_JS_ALERT_MTG_REMINDER_STATUS'] . (isset($relatedEvent->status) ? $relatedEvent->status : '') . "\n" . $app_strings['MSG_JS_ALERT_MTG_REMINDER_RELATED_TO'] . $relatedToMeeting;
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $relatedEvent
|
||||
* @return string
|
||||
*/
|
||||
protected function getLocation($relatedEvent): string
|
||||
{
|
||||
global $app_strings;
|
||||
$default = $app_strings['MSG_JS_ALERT_MTG_REMINDER_NO_LOCATION'];
|
||||
|
||||
return from_html($relatedEvent->location ?? $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SugarBean $popupReminder
|
||||
* @param $current_user
|
||||
* @return SugarBean[]|null
|
||||
*/
|
||||
protected function getInvitees(SugarBean $popupReminder, $current_user): ?array
|
||||
{
|
||||
$invitees = BeanFactory::getBean('Reminders_Invitees')->get_full_list(
|
||||
'',
|
||||
"reminders_invitees.reminder_id = '{$popupReminder->id}' AND reminders_invitees.related_invitee_module_id = '{$current_user->id}'"
|
||||
);
|
||||
|
||||
return $invitees;
|
||||
}
|
||||
|
||||
/**
|
||||
* To return the name of parent bean.
|
||||
* @param $popupReminder
|
||||
* @return string
|
||||
*/
|
||||
protected function getRelatedName($popupReminder): string
|
||||
{
|
||||
$parentType = $popupReminder->related_event_module;
|
||||
$parentId = $popupReminder->related_event_module_id;
|
||||
|
||||
if (!empty($parentType) && !empty($parentId)) {
|
||||
$parentBean = BeanFactory::getBean($parentType, $parentId);
|
||||
if (($parentBean instanceof SugarBean) && isset($parentBean->name)) {
|
||||
return $parentBean->name;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date range
|
||||
* @return array
|
||||
*/
|
||||
protected function getDateRange(): array
|
||||
{
|
||||
global $timedate, $app_list_strings;
|
||||
|
||||
$reminder_max_time = $app_list_strings['reminder_max_time'] ?? 0;
|
||||
|
||||
$dateTimeMax = $timedate->getNow(true)->modify("+{$reminder_max_time} seconds")->asDb(false);
|
||||
|
||||
$dateTimeNow = $timedate->getNow(true)->asDb(false);
|
||||
|
||||
$dateTimeNowStamp = strtotime(Reminder::unQuoteTime($dateTimeNow));
|
||||
$dateTimeMaxStamp = strtotime(Reminder::unQuoteTime($dateTimeMax));
|
||||
|
||||
return [$dateTimeMaxStamp, $dateTimeNowStamp];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SugarBean $popupReminder
|
||||
* @param $relatedEventStart
|
||||
* @return void
|
||||
*/
|
||||
protected function updateReminderExecutionTime(SugarBean $popupReminder, $relatedEventStart): void
|
||||
{
|
||||
//we have column to save data
|
||||
if (!$relatedEventStart) {
|
||||
$popupReminder->date_willexecute = -2;
|
||||
} else {
|
||||
$popupReminder->date_willexecute = $relatedEventStart;
|
||||
}
|
||||
$popupReminder->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $i_runs
|
||||
* @param SugarBean $popupReminder
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldUpdateExecutionTime(int $i_runs, SugarBean $popupReminder): bool
|
||||
{
|
||||
return $i_runs < 1000 &&
|
||||
isset($popupReminder->fetched_row['date_willexecute']) &&
|
||||
$popupReminder->fetched_row['date_willexecute'] == -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $relatedEventStart
|
||||
* @param $dateTimeNowStamp
|
||||
* @param $dateTimeMaxStamp
|
||||
* @return bool
|
||||
*/
|
||||
protected function isOutsideOfExecutionDateRange($relatedEventStart, $dateTimeNowStamp, $dateTimeMaxStamp): bool
|
||||
{
|
||||
return $relatedEventStart
|
||||
&& ($relatedEventStart <= $dateTimeNowStamp || $relatedEventStart >= $dateTimeMaxStamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $relatedEvent
|
||||
* @return mixed|string
|
||||
*/
|
||||
protected function getAlertTime($relatedEvent)
|
||||
{
|
||||
global $app_strings, $timedate, $db;
|
||||
|
||||
$default = $app_strings['MSG_JS_ALERT_MTG_REMINDER_NO_START_DATE'];
|
||||
$dateStart = $relatedEvent->date_start ?? '';
|
||||
|
||||
if (!empty($dateStart)) {
|
||||
$time_dbFromConvert = $db->fromConvert($dateStart, 'datetime');
|
||||
$time = $timedate->to_display_date_time($time_dbFromConvert);
|
||||
if (!$time) {
|
||||
$time = $dateStart;
|
||||
}
|
||||
if (!$time) {
|
||||
$time = $default;
|
||||
}
|
||||
} else {
|
||||
$time = $default;
|
||||
}
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SugarBean $popupReminder
|
||||
* @return string
|
||||
*/
|
||||
protected function getURL(SugarBean $popupReminder): string
|
||||
{
|
||||
return Reminder::makeAlertURL(
|
||||
$popupReminder->related_event_module,
|
||||
$popupReminder->related_event_module_id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $MSG_JS_ALERT_MTG_REMINDER_MEETING_MSG
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getInstructions($MSG_JS_ALERT_MTG_REMINDER_MEETING_MSG)
|
||||
{
|
||||
return $MSG_JS_ALERT_MTG_REMINDER_MEETING_MSG;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $meetingIntegration
|
||||
* @param SugarBean $popupReminder
|
||||
* @param $url
|
||||
* @param $instructions
|
||||
* @return array
|
||||
*/
|
||||
protected function addMeetingOverrides(
|
||||
?array $meetingIntegration,
|
||||
SugarBean $popupReminder,
|
||||
$url,
|
||||
$instructions
|
||||
): array {
|
||||
if (!empty($meetingIntegration) && $meetingIntegration->isIntegratedMeeting($popupReminder->related_event_module_id)) {
|
||||
$url = $meetingIntegration->miUrlGetJsAlert((array)$popupReminder);
|
||||
$instructions = $meetingIntegration->miGetJsAlertInstructions();
|
||||
}
|
||||
|
||||
return [$url, $instructions];
|
||||
}
|
||||
}
|
|
@ -308,7 +308,7 @@ class Reminder extends Basic
|
|||
$dateTimeMax = $timedate->getNow(true)->modify("+{$app_list_strings['reminder_max_time']} seconds")->asDb(false);
|
||||
|
||||
$dateTimeNow = $timedate->getNow(true)->asDb(false);
|
||||
|
||||
|
||||
|
||||
// Original jsAlert used to a meeting integration.
|
||||
|
||||
|
@ -455,7 +455,7 @@ class Reminder extends Basic
|
|||
return 'index.php?action=DetailView&module=' . $module . '&record=' . $record_id;
|
||||
}
|
||||
|
||||
private static function unQuoteTime($timestr)
|
||||
public static function unQuoteTime($timestr)
|
||||
{
|
||||
$ret = '';
|
||||
for ($i = 0; $i < strlen($timestr); $i++) {
|
||||
|
@ -468,7 +468,7 @@ class Reminder extends Basic
|
|||
|
||||
// --- test for accept status decline is?
|
||||
|
||||
private static function isDecline(SugarBean $event, SugarBean $person)
|
||||
public static function isDecline(SugarBean $event, SugarBean $person)
|
||||
{
|
||||
return self::testEventPersonAcceptStatus($event, $person, 'decline');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue