SuiteCRM-Core/core/legacy/DateTimeHandler.php
Clemente Raposo af186a7013 Add RecordList FilterMappers
- Refactor LegacyFilterMapper to allow adding mappers per type
- Add date and date time mappers to convert to proper format
-- Api should receive fields in internal format
-- Legacy search expects user format
-- Convert to user format when calling legacy search

- Add multienum to correctly process criteria
-- Api search criteria receive an array of values
-- For other fields legacy expects just one value not an array
-- For multienum legacy expects an array of values
-- Add mapper to send array of values to legacy for multienums
2021-03-30 19:22:35 +01:00

94 lines
2.2 KiB
PHP

<?php
namespace App\Legacy;
use DateFormatService;
class DateTimeHandler extends LegacyHandler
{
public const HANDLER_KEY = 'date-time';
/**
* @var array
*/
private $datetimeFormatMap;
/**
* @var DateFormatService
*/
private $formatter;
/**
* SystemConfigHandler constructor.
* @param string $projectDir
* @param string $legacyDir
* @param string $legacySessionName
* @param string $defaultSessionName
* @param LegacyScopeState $legacyScopeState
* @param array $datetimeFormatMap
*/
public function __construct(
string $projectDir,
string $legacyDir,
string $legacySessionName,
string $defaultSessionName,
LegacyScopeState $legacyScopeState,
array $datetimeFormatMap
) {
parent::__construct($projectDir, $legacyDir, $legacySessionName, $defaultSessionName, $legacyScopeState);
$this->datetimeFormatMap = $datetimeFormatMap;
}
/**
* @inheritDoc
*/
public function getHandlerKey(): string
{
return self::HANDLER_KEY;
}
/**
* Map Datetime format
* @param string $format
* @return string
*/
public function mapFormat(string $format): string
{
return strtr($format, $this->datetimeFormatMap);
}
/**
* To user date format
* @param string $dateString
* @return string
*/
public function toUserDate(string $dateString): string
{
return $this->getFormatter()->toUserDate($dateString);
}
/**
* To user date format
* @param string $dateString
* @return string
*/
public function toUserDateTime(string $dateString): string
{
return $this->getFormatter()->toUserDateTime($dateString);
}
/**
* @return DateFormatService
*/
protected function getFormatter(): DateFormatService
{
if ($this->formatter !== null) {
return $this->formatter;
}
/* @noinspection PhpIncludeInspection */
require_once 'include/portability/Services/DateTime/DateFormatService.php';
$this->formatter = new DateFormatService();
return $this->formatter;
}
}