[Legacy] Map Alert fields for notifications

This commit is contained in:
Clemente Raposo 2023-02-02 11:41:52 +00:00
parent a1ff63e75c
commit 37deb4787c
6 changed files with 417 additions and 41 deletions

View file

@ -39,6 +39,7 @@ require_once __DIR__ . '/TypeMappers/BooleanMapper.php';
require_once __DIR__ . '/ApiBeanModuleMappers.php';
require_once __DIR__ . '/ModuleMappers/SavedSearch/SavedSearchMappers.php';
require_once __DIR__ . '/ModuleMappers/AOP_Case_Updates/CaseUpdatesMappers.php';
require_once __DIR__ . '/ModuleMappers/Alerts/AlertsMappers.php';
require_once __DIR__ . '/../Bean/Field/Validation/FieldValidatorRegistry.php';
class ApiBeanMapper
@ -79,6 +80,7 @@ class ApiBeanMapper
$this->linkMappers[EmailAddressLinkMapper::getRelateModule()] = [];
$this->linkMappers[EmailAddressLinkMapper::getRelateModule()]['all'] = new EmailAddressLinkMapper();
$this->moduleMappers[CaseUpdatesMappers::getModule()] = new CaseUpdatesMappers();
$this->moduleMappers[AlertsMappers::getModule()] = new AlertsMappers();
$this->linkMappers[DefaultLinkMapper::getRelateModule()] = [];
$this->linkMappers[DefaultLinkMapper::getRelateModule()]['all'] = new DefaultLinkMapper();
}

View file

@ -0,0 +1,100 @@
<?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__ . '/../../../ApiBeanMapper/FieldMappers/FieldMapperInterface.php';
class AlertNameMapper implements FieldMapperInterface
{
public const FIELD_NAME = 'name';
/**
* AlertNameMapper constructor.
*/
public function __construct()
{
}
/**
* @inheritDoc
*/
public static function getField(): string
{
return self::FIELD_NAME;
}
/**
* @inheritDoc
*/
public function toApi(SugarBean $bean, array &$container, string $alternativeName = ''): void
{
$name = self::FIELD_NAME;
if (!empty($alternativeName)) {
$name = $alternativeName;
}
$nameValue = $bean->name ?? '';
if (empty($nameValue)) {
$container[$name] = '';
return;
}
$targetModule = $bean->target_module ?? '';
if (empty($targetModule)) {
$container[$name] = $nameValue;
return;
}
$searchString = $targetModule . ':';
if (strpos($nameValue, $searchString) === 0) {
$nameValue = preg_replace('/^' . $searchString . '/', '', $nameValue);
}
$container[$name] = $nameValue;
}
/**
* @inheritDoc
*/
public function toBean(SugarBean $bean, array &$container, string $alternativeName = ''): void
{
$name = self::getField();
if (!empty($alternativeName)) {
$name = $alternativeName;
}
if (empty($container[$name])) {
return;
}
$container[self::getField()] = $container[$name];
}
}

View file

@ -0,0 +1,54 @@
<?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__ . '/TargetModuleTypeMapper.php';
require_once __DIR__ . '/TargetModuleLabelMapper.php';
require_once __DIR__ . '/AlertNameMapper.php';
require_once __DIR__ . '/../../ApiBeanModuleMappers.php';
class AlertsMappers extends ApiBeanModuleMappers
{
/**
* @var string
*/
public const MODULE = 'Alerts';
public function __construct()
{
$this->fieldMappers[TargetModuleTypeMapper::getField()] = new TargetModuleTypeMapper();
$this->fieldMappers[TargetModuleLabelMapper::getField()] = new TargetModuleLabelMapper();
$this->fieldMappers[AlertNameMapper::getField()] = new AlertNameMapper();
}
/**
* @return string
*/
public static function getModule(): string
{
return self::MODULE;
}
}

View file

@ -0,0 +1,107 @@
<?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__ . '/../../../ApiBeanMapper/FieldMappers/FieldMapperInterface.php';
class TargetModuleLabelMapper implements FieldMapperInterface
{
public const FIELD_NAME = 'target_module_label';
/**
* TargetModuleLabelMapper constructor.
*/
public function __construct()
{
}
/**
* @inheritDoc
*/
public static function getField(): string
{
return self::FIELD_NAME;
}
/**
* @inheritDoc
*/
public function toApi(SugarBean $bean, array &$container, string $alternativeName = ''): void
{
global $app_list_strings, $beanList;
$name = self::FIELD_NAME;
if (!empty($alternativeName)) {
$name = $alternativeName;
}
$targetModule = $bean->target_module ?? '';
if (empty($targetModule)) {
$container[$name] = '';
return;
}
if (empty($beanList) || empty($beanList[$targetModule]) || empty($app_list_strings)) {
$container[$name] = $targetModule;
return;
}
if (!empty($app_list_strings['moduleListSingular'][$targetModule])) {
$container[$name] = $app_list_strings['moduleListSingular'][$targetModule];
return;
}
if (!empty($app_list_strings['moduleList'][$targetModule])) {
$container[$name] = $app_list_strings['moduleList'][$targetModule];
return;
}
$container[$name] = $targetModule;
}
/**
* @inheritDoc
*/
public function toBean(SugarBean $bean, array &$container, string $alternativeName = ''): void
{
$name = self::getField();
if (!empty($alternativeName)) {
$name = $alternativeName;
}
if (empty($container[$name])) {
return;
}
$container[self::getField()] = $container[$name];
}
}

View file

@ -0,0 +1,102 @@
<?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__ . '/../../../ApiBeanMapper/FieldMappers/FieldMapperInterface.php';
class TargetModuleTypeMapper implements FieldMapperInterface
{
public const FIELD_NAME = 'target_module_type';
/**
* TargetModuleTypeMapper constructor.
*/
public function __construct()
{
}
/**
* @inheritDoc
*/
public static function getField(): string
{
return self::FIELD_NAME;
}
/**
* @inheritDoc
*/
public function toApi(SugarBean $bean, array &$container, string $alternativeName = ''): void
{
global $beanList;
$name = self::FIELD_NAME;
if (!empty($alternativeName)) {
$name = $alternativeName;
}
$targetModule = $bean->target_module ?? '';
if (empty($targetModule)) {
$container[$name] = '';
return;
}
if (empty($beanList) || !is_array($beanList)) {
$container[$name] = $targetModule;
return;
}
foreach ($beanList as $moduleName => $beanName) {
if ($beanName === $targetModule){
$container[$name] = $moduleName;
return;
}
}
$container[$name] = $targetModule;
}
/**
* @inheritDoc
*/
public function toBean(SugarBean $bean, array &$container, string $alternativeName = ''): void
{
$name = self::getField();
if (!empty($alternativeName)) {
$name = $alternativeName;
}
if (empty($container[$name])) {
return;
}
$container[self::getField()] = $container[$name];
}
}

View file

@ -43,47 +43,58 @@ $dictionary['Alert'] = [
'audited' => false,
'duplicate_merge' => true,
'fields' => [
'is_read' =>
[
'name' => 'is_read',
'vname' => 'LBL_IS_READ',
'type' => 'bool',
'massupdate' => false,
'studio' => 'false',
],
'target_module' =>
[
'name' => 'target_module',
'vname' => 'LBL_TYPE',
'type' => 'varchar',
'massupdate' => false,
'studio' => 'false',
],
'type' =>
[
'name' => 'type',
'vname' => 'LBL_TYPE',
'type' => 'varchar',
'massupdate' => false,
'studio' => 'false',
],
'url_redirect' =>
[
'name' => 'url_redirect',
'vname' => 'LBL_TYPE',
'type' => 'varchar',
'massupdate' => false,
'studio' => 'false',
],
'reminder_id' =>
[
'name' => 'reminder_id',
'type' => 'id',
'required' => false,
'reportable' => false,
'studio' => 'false',
'comment' => 'The id of the reminder that created this alert',
],
'is_read' => [
'name' => 'is_read',
'vname' => 'LBL_IS_READ',
'type' => 'bool',
'massupdate' => false,
'studio' => 'false',
],
'target_module' => [
'name' => 'target_module',
'vname' => 'LBL_TYPE',
'type' => 'varchar',
'massupdate' => false,
'studio' => 'false',
],
'target_module_type' => [
'name' => 'target_module',
'vname' => 'LBL_TARGET_MODULE_TYPE',
'type' => 'varchar',
'massupdate' => false,
'studio' => 'false',
'source' => 'non-db',
],
'target_module_label' => [
'name' => 'target_module_label',
'vname' => 'LBL_TARGET_MODULE_LABEL',
'type' => 'varchar',
'massupdate' => false,
'studio' => 'false',
'source' => 'non-db',
],
'type' => [
'name' => 'type',
'vname' => 'LBL_TYPE',
'type' => 'varchar',
'massupdate' => false,
'studio' => 'false',
],
'url_redirect' => [
'name' => 'url_redirect',
'vname' => 'LBL_TYPE',
'type' => 'varchar',
'massupdate' => false,
'studio' => 'false',
],
'reminder_id' => [
'name' => 'reminder_id',
'type' => 'id',
'required' => false,
'reportable' => false,
'studio' => 'false',
'comment' => 'The id of the reminder that created this alert',
],
'snooze' => [
'name' => 'snooze',
'type' => 'datetime',