Skip to content

Commit

Permalink
fix(ZMSKVR-125): sending cancel appointment email sender address
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Fink authored and Thomas Fink committed Feb 14, 2025
1 parent 97b1224 commit 8017efe
Show file tree
Hide file tree
Showing 24 changed files with 241 additions and 34 deletions.
5 changes: 4 additions & 1 deletion zmsapi/src/Zmsapi/ProcessDeleteMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use BO\Slim\Render;
use BO\Mellon\Validator;
use BO\Zmsdb\Mail as Query;
use BO\Zmsdb\Config;
use BO\Zmsdb\Process as ProcessRepository;
use BO\Zmsdb\Department as DepartmentRepository;
Expand Down Expand Up @@ -58,7 +57,11 @@ protected static function writeMail(Process $process)
->toResolvedEntity($collection, $config, 'deleted')
->withDepartment($department);
$mail->testValid();
error_log("outside");
error_log($process->getFirstClient()->hasEmail());
error_log($process->scope->hasEmailFrom());
if ($process->getFirstClient()->hasEmail() && $process->scope->hasEmailFrom()) {
error_log("inside");
$mail = (new \BO\Zmsdb\Mail())->writeInQueue($mail, \App::$now, false);
\App::$log->debug("Send mail", [$mail]);
}
Expand Down
31 changes: 20 additions & 11 deletions zmscitizenapi/src/Zmscitizenapi/Models/ThinnedScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,34 @@
class ThinnedScope extends Entity implements JsonSerializable
{
public static $schema = 'citizenapi/thinnedScope.json';
/** @var int */
/** @var int */
public int $id;
/** @var ThinnedProvider|null */
/** @var ThinnedProvider|null */
public ?ThinnedProvider $provider;
/** @var string|null */
/** @var string|null */
public ?string $shortName;
/** @var bool|null */
/** @var string|null */
public ?string $emailFrom;
/** @var bool|null */
public ?bool $telephoneActivated;
/** @var bool|null */
/** @var bool|null */
public ?bool $telephoneRequired;
/** @var bool|null */
/** @var bool|null */
public ?bool $customTextfieldActivated;
/** @var bool|null */
/** @var bool|null */
public ?bool $customTextfieldRequired;
/** @var string|null */
/** @var string|null */
public ?string $customTextfieldLabel;
/** @var bool|null */
/** @var bool|null */
public ?bool $captchaActivatedRequired;
/** @var string|null */
/** @var string|null */
public ?string $displayInfo;
public function __construct(int $id = 0, ?ThinnedProvider $provider = null, ?string $shortName = null, ?bool $telephoneActivated = null, ?bool $telephoneRequired = null, ?bool $customTextfieldActivated = null, ?bool $customTextfieldRequired = null, ?string $customTextfieldLabel = null, ?bool $captchaActivatedRequired = null, ?string $displayInfo = null)
public function __construct(int $id = 0, ?ThinnedProvider $provider = null, ?string $shortName = null, ?string $emailFrom = null, ?bool $telephoneActivated = null, ?bool $telephoneRequired = null, ?bool $customTextfieldActivated = null, ?bool $customTextfieldRequired = null, ?string $customTextfieldLabel = null, ?bool $captchaActivatedRequired = null, ?string $displayInfo = null)
{
$this->id = $id;
$this->provider = $provider;
$this->shortName = $shortName;
$this->emailFrom = $emailFrom;
$this->telephoneActivated = $telephoneActivated;
$this->telephoneRequired = $telephoneRequired;
$this->customTextfieldActivated = $customTextfieldActivated;
Expand Down Expand Up @@ -64,6 +67,11 @@ public function getShortName(): ?string
return $this->shortName;
}

public function getEmailFrom(): ?string
{
return $this->emailFrom;
}

public function getTelephoneActivated(): ?bool
{
return $this->telephoneActivated;
Expand Down Expand Up @@ -105,6 +113,7 @@ public function toArray(): array
'id' => $this->id,
'provider' => $this->provider,
'shortName' => $this->shortName,
'emailFrom' => $this->emailFrom,
'telephoneActivated' => $this->telephoneActivated,
'telephoneRequired' => $this->telephoneRequired,
'customTextfieldActivated' => $this->customTextfieldActivated,
Expand Down
66 changes: 57 additions & 9 deletions zmscitizenapi/src/Zmscitizenapi/Services/Core/MapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
use BO\Zmsentities\Collection\RequestRelationList;

/**
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @TODO: Extract class has ExcessiveClassComplexity 101 vs 100
*/
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @TODO: Extract class has ExcessiveClassComplexity 101 vs 100
*/
class MapperService
{
public static function mapScopeForProvider(int $providerId, ?ThinnedScopeList $scopes): ThinnedScope
Expand Down Expand Up @@ -67,7 +67,7 @@ public static function mapOfficesWithScope(ProviderList $providerList, bool $sho
foreach ($providerList as $provider) {
$providerScope = self::mapScopeForProvider((int) $provider->id, $scopes);

if (! $showUnpublished && isset($provider->data['public']) && ! (bool) $provider->data['public']) {
if (!$showUnpublished && isset($provider->data['public']) && !(bool) $provider->data['public']) {
continue;
}

Expand All @@ -85,6 +85,7 @@ public static function mapOfficesWithScope(ProviderList $providerList, bool $sho
id: isset($providerScope->id) ? (int) $providerScope->id : 0,
provider: isset($providerScope->provider) ? $providerScope->provider : null,
shortName: isset($providerScope->shortName) ? $providerScope->shortName : null,
emailFrom: isset($providerScope->emailFrom) ? $providerScope->emailFrom : null,
telephoneActivated: isset($providerScope->telephoneActivated) ? (bool) $providerScope->telephoneActivated : null,
telephoneRequired: isset($providerScope->telephoneRequired) ? (bool) $providerScope->telephoneRequired : null,
customTextfieldActivated: isset($providerScope->customTextfieldActivated) ? (bool) $providerScope->customTextfieldActivated : null,
Expand Down Expand Up @@ -134,7 +135,7 @@ public static function mapServicesWithCombinations(
});
foreach ($requestArray as $service) {
if (
! $showUnpublished
!$showUnpublished
&& isset($service->getAdditionalData()['public'])
&& !$service->getAdditionalData()['public']
) {
Expand Down Expand Up @@ -184,7 +185,19 @@ public static function scopeToThinnedScope(Scope $scope): ThinnedScope
$thinnedProvider = null;
}

return new ThinnedScope(id: (int) ($scope->id ?? 0), provider: $thinnedProvider, shortName: $scope->shortName ?? null, telephoneActivated: isset($scope->data['telephoneActivated']) ? (bool) $scope->data['telephoneActivated'] : null, telephoneRequired: isset($scope->data['telephoneRequired']) ? (bool) $scope->data['telephoneRequired'] : null, customTextfieldActivated: isset($scope->data['customTextfieldActivated']) ? (bool) $scope->data['customTextfieldActivated'] : null, customTextfieldRequired: isset($scope->data['customTextfieldRequired']) ? (bool) $scope->data['customTextfieldRequired'] : null, customTextfieldLabel: $scope->data['customTextfieldLabel'] ?? null, captchaActivatedRequired: isset($scope->data['captchaActivatedRequired']) ? (bool) $scope->data['captchaActivatedRequired'] : null, displayInfo: $scope->data['displayInfo'] ?? null);
return new ThinnedScope(
id: (int) ($scope->id ?? 0),
provider: $thinnedProvider,
shortName: $scope->shortName ?? null,
emailFrom: (string) $scope->getEmailFrom() ?? null,
telephoneActivated: isset($scope->data['telephoneActivated']) ? (bool) $scope->data['telephoneActivated'] : null,
telephoneRequired: isset($scope->data['telephoneRequired']) ? (bool) $scope->data['telephoneRequired'] : null,
customTextfieldActivated: isset($scope->data['customTextfieldActivated']) ? (bool) $scope->data['customTextfieldActivated'] : null,
customTextfieldRequired: isset($scope->data['customTextfieldRequired']) ? (bool) $scope->data['customTextfieldRequired'] : null,
customTextfieldLabel: $scope->data['customTextfieldLabel'] ?? null,
captchaActivatedRequired: isset($scope->data['captchaActivatedRequired']) ? (bool) $scope->data['captchaActivatedRequired'] : null,
displayInfo: $scope->data['displayInfo'] ?? null
);
}

/**
Expand Down Expand Up @@ -222,7 +235,22 @@ public static function processToThinnedProcess(Process $myProcess): ThinnedProce
}
}

return new ThinnedProcess(processId: isset($myProcess->id) ? (int) $myProcess->id : 0, timestamp: (isset($myProcess->appointments[0]) && isset($myProcess->appointments[0]->date)) ? strval($myProcess->appointments[0]->date) : null, authKey: isset($myProcess->authKey) ? $myProcess->authKey : null, familyName: (isset($myProcess->clients[0]) && isset($myProcess->clients[0]->familyName)) ? $myProcess->clients[0]->familyName : null, customTextfield: isset($myProcess->customTextfield) ? $myProcess->customTextfield : null, email: (isset($myProcess->clients[0]) && isset($myProcess->clients[0]->email)) ? $myProcess->clients[0]->email : null, telephone: (isset($myProcess->clients[0]) && isset($myProcess->clients[0]->telephone)) ? $myProcess->clients[0]->telephone : null, officeName: (isset($myProcess->scope->contact) && isset($myProcess->scope->contact->name)) ? $myProcess->scope->contact->name : null, officeId: (isset($myProcess->scope->provider) && isset($myProcess->scope->provider->id)) ? (int) $myProcess->scope->provider->id : 0, scope: isset($myProcess->scope) ? self::scopeToThinnedScope($myProcess->scope) : null, subRequestCounts: isset($subRequestCounts) ? array_values($subRequestCounts) : [], serviceId: isset($mainServiceId) ? (int) $mainServiceId : 0, serviceCount: isset($mainServiceCount) ? $mainServiceCount : 0, status: (isset($myProcess->queue) && isset($myProcess->queue->status)) ? $myProcess->queue->status : null);
return new ThinnedProcess(
processId: isset($myProcess->id) ? (int) $myProcess->id : 0,
timestamp: (isset($myProcess->appointments[0]) && isset($myProcess->appointments[0]->date)) ? strval($myProcess->appointments[0]->date) : null,
authKey: isset($myProcess->authKey) ? $myProcess->authKey : null,
familyName: (isset($myProcess->clients[0]) && isset($myProcess->clients[0]->familyName)) ? $myProcess->clients[0]->familyName : null,
customTextfield: isset($myProcess->customTextfield) ? $myProcess->customTextfield : null,
email: (isset($myProcess->clients[0]) && isset($myProcess->clients[0]->email)) ? $myProcess->clients[0]->email : null,
telephone: (isset($myProcess->clients[0]) && isset($myProcess->clients[0]->telephone)) ? $myProcess->clients[0]->telephone : null,
officeName: (isset($myProcess->scope->contact) && isset($myProcess->scope->contact->name)) ? $myProcess->scope->contact->name : null,
officeId: (isset($myProcess->scope->provider) && isset($myProcess->scope->provider->id)) ? (int) $myProcess->scope->provider->id : 0,
scope: isset($myProcess->scope) ? self::scopeToThinnedScope($myProcess->scope) : null,
subRequestCounts: isset($subRequestCounts) ? array_values($subRequestCounts) : [],
serviceId: isset($mainServiceId) ? (int) $mainServiceId : 0,
serviceCount: isset($mainServiceCount) ? $mainServiceCount : 0,
status: (isset($myProcess->queue) && isset($myProcess->queue->status)) ? $myProcess->queue->status : null
);
}

public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess): Process
Expand All @@ -235,7 +263,6 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess):
$processEntity->id = $thinnedProcess->processId;
$processEntity->authKey = $thinnedProcess->authKey ?? null;
$processEntity->customTextfield = $thinnedProcess->customTextfield ?? null;
// Moved to Process level

$client = new Client();
$client->familyName = $thinnedProcess->familyName ?? null;
Expand All @@ -245,7 +272,27 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess):
$appointment = new Appointment();
$appointment->date = $thinnedProcess->timestamp ?? null;
$processEntity->appointments = [$appointment];
// Set scope with all required fields
$scope = new Scope();
if ($thinnedProcess->scope) {
$scope->id = $thinnedProcess->scope->id;
$scope->source = \App::$source_name;

// Set preferences as array structure
$scope->preferences = [
'client' => [
'emailFrom' => $thinnedProcess->scope->getEmailFrom() ?? null,
'telephoneActivated' => $thinnedProcess->scope->getTelephoneActivated() ?? false,
'telephoneRequired' => $thinnedProcess->scope->getTelephoneRequired() ?? false,
'customTextfieldActivated' => $thinnedProcess->scope->getCustomTextfieldActivated() ?? false,
'customTextfieldRequired' => $thinnedProcess->scope->getCaptchaActivatedRequired() ?? false,
'customTextfieldLabel' => $thinnedProcess->scope->getCustomTextfieldLabel() ?? null
],
'notifications' => [
'enabled' => true
]
];
}
if (isset($thinnedProcess->officeName)) {
$scope->contact = new Contact();
$scope->contact->name = $thinnedProcess->officeName;
Expand All @@ -256,6 +303,7 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess):
$scope->provider->source = \App::$source_name;
}
$processEntity->scope = $scope;
$processEntity->scope = $scope;
if (isset($thinnedProcess->status)) {
$processEntity->queue = new \stdClass();
$processEntity->queue->status = $thinnedProcess->status;
Expand Down Expand Up @@ -310,6 +358,6 @@ public static function contactToThinnedContact($contact): ThinnedContact
*/
public static function providerToThinnedProvider(Provider $provider): ThinnedProvider
{
return new ThinnedProvider(id: isset($provider->id) ? (int) $provider->id : null, name: isset($provider->name) ? $provider->name : null, source: isset($provider->source) ? $provider->source : null, lon: isset($provider->data['geo']['lon']) ? (float) $provider->data['geo']['lon'] : null, lat: isset($provider->data['geo']['lat']) ? (float) $provider->data['geo']['lat'] : null, contact: isset($provider->contact) ? self::contactToThinnedContact($provider->contact) : null,);
return new ThinnedProvider(id: isset($provider->id) ? (int) $provider->id : null, name: isset($provider->name) ? $provider->name : null, source: isset($provider->source) ? $provider->source : null, lon: isset($provider->data['geo']['lon']) ? (float) $provider->data['geo']['lon'] : null, lat: isset($provider->data['geo']['lat']) ? (float) $provider->data['geo']['lat'] : null, contact: isset($provider->contact) ? self::contactToThinnedContact($provider->contact) : null, );
}
}
Loading

0 comments on commit 8017efe

Please sign in to comment.