-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
36784 Plugin can not set supervisor in address record #594
Changes from all commits
da5bba7
74a203f
0f833e3
b11a8cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,14 +61,16 @@ public function __construct( | |
/** | ||
* @param FormData $pFormData | ||
* @param bool $mergeExisting | ||
* @param string $contactType | ||
* @param int|null $estateId | ||
* @return int the new (or updated) address ID | ||
* @throws ApiClientException | ||
* @throws UnknownFieldException | ||
* @throws DependencyException | ||
* @throws NotFoundException | ||
*/ | ||
public function createOrCompleteAddress( | ||
FormData $pFormData, bool $mergeExisting = false, string $contactType = ''): int | ||
FormData $pFormData, bool $mergeExisting = false, string $contactType = '', int $estateId = null): int | ||
{ | ||
$requestParams = $this->getAddressDataForApiCall($pFormData); | ||
$requestParams['checkDuplicate'] = $mergeExisting; | ||
|
@@ -82,6 +84,13 @@ public function createOrCompleteAddress( | |
if ( key_exists( 'newsletter', $requestParams ) ) { | ||
unset( $requestParams['newsletter'] ); | ||
} | ||
if (!empty($estateId)) { | ||
$userName = $this->getSupervisorUsernameByEstateId($estateId); | ||
if (!empty($userName)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the past we got minor bugs with using empty() function because "0" and 0 is also empty true. It is unlikely but what happens if the ID or username is 0? Do you think using isset could be better or could causes other errors? Edit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll check and let you know asap |
||
$requestParams['Benutzer'] = $userName; | ||
} | ||
} | ||
|
||
$pApiClientAction = new APIClientActionGeneric | ||
($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_CREATE, 'address'); | ||
$pApiClientAction->setParameters($requestParams); | ||
|
@@ -170,4 +179,61 @@ public function getAddressDataForEmail(FormData $pFormData): array | |
} | ||
return $addressData; | ||
} | ||
|
||
/** | ||
* @param int $estateId | ||
* @return string | ||
* @throws ApiClientException | ||
* @throws DependencyException | ||
* @throws NotFoundException | ||
*/ | ||
private function getSupervisorUsernameByEstateId(int $estateId): string | ||
{ | ||
$requestParams = [ | ||
'filter' => ['Id' => [['op' => '=', 'val' => $estateId]]], | ||
'data' => ['benutzer'], | ||
]; | ||
|
||
$pApiClientAction = new APIClientActionGeneric | ||
($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_READ, 'estate'); | ||
|
||
$pApiClientAction->setParameters($requestParams); | ||
$pApiClientAction->addRequestToQueue(); | ||
$this->_pSDKWrapper->sendRequests(); | ||
$result = $pApiClientAction->getResultRecords(); | ||
|
||
if (!empty($result) && isset($result[0]["elements"]["benutzer"])) { | ||
$userId = $result[0]["elements"]["benutzer"]; | ||
return $this->getUserNameById($userId); | ||
} else { | ||
return ''; | ||
} | ||
} | ||
|
||
/** | ||
* @param string $userId | ||
* @return string | ||
* @throws ApiClientException | ||
* @throws DependencyException | ||
* @throws NotFoundException | ||
*/ | ||
private function getUserNameById(string $userId): string | ||
{ | ||
$pApiClientAction = new APIClientActionGeneric | ||
($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_GET, 'users'); | ||
|
||
$pApiClientAction->addRequestToQueue(); | ||
$this->_pSDKWrapper->sendRequests(); | ||
$result = $pApiClientAction->getResultRecords(); | ||
|
||
$userResult = array_values(array_filter($result, function($item) use ($userId) { | ||
return $item['id'] == $userId && isset($item["elements"]["username"]); | ||
})); | ||
|
||
if (!empty($userResult)) { | ||
return $userResult[0]["elements"]["username"]; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add PHPDoc for these arguments: $contactType and $estateId for complete documentation? :)