Feat: Make CRM ids configurable
This commit is contained in:
@@ -9,9 +9,17 @@ use App\BusProNet\Model\CrmAttributesResponse;
|
||||
use App\BusProNet\Model\CrmAttributeGroup;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use App\BusProNet\Model\BaseResponse;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ResponseParser
|
||||
{
|
||||
private array $config;
|
||||
|
||||
public function __construct(array $options)
|
||||
{
|
||||
$this->config = $this->resolveOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
@@ -55,7 +63,7 @@ class ResponseParser
|
||||
$title = (string) $xml->xpath('adressdaten/titel')[0];
|
||||
|
||||
$gender = (string) $xml->xpath('adressdaten/geschlecht')[0];
|
||||
$gender = $gender === 'W' ? 'f' : strtolower($gender);
|
||||
$gender = strtolower($gender) === 'w' ? 'f' : strtolower($gender);
|
||||
|
||||
$date = $xml->xpath('adressdaten/geburtsdatum');
|
||||
$dateOfBirth = $date ?\DateTimeImmutable::createFromFormat('d.m.Y', (string) $date[0]) : null;
|
||||
@@ -122,13 +130,13 @@ class ResponseParser
|
||||
;
|
||||
$attributes[] = $attribute;
|
||||
|
||||
if (CrmAttribute::ATTR_ID_ADMIN === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
if ($this->config['bpn_crm_id_admin'] === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isAdmin = true;
|
||||
}
|
||||
if (CrmAttribute::ATTR_ID_MANAGER === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
if ($this->config['bpn_crm_id_manager'] === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isManager = true;
|
||||
}
|
||||
if (CrmAttribute::ATTR_ID_TEAMER === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
if ($this->config['bpn_crm_id_teamer'] === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isTeamer = true;
|
||||
}
|
||||
}
|
||||
@@ -146,4 +154,15 @@ class ResponseParser
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function resolveOptions(array $options): array
|
||||
{
|
||||
$optionsResolver = new OptionsResolver();
|
||||
$optionsResolver->setRequired(['bpn_crm_id_admin', 'bpn_crm_id_manager', 'bpn_crm_id_teamer']);
|
||||
$optionsResolver->setAllowedTypes('bpn_crm_id_admin', 'int');
|
||||
$optionsResolver->setAllowedTypes('bpn_crm_id_manager', 'int');
|
||||
$optionsResolver->setAllowedTypes('bpn_crm_id_teamer', 'int');
|
||||
|
||||
return $optionsResolver->resolve($options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user