selection id => role */ private const ROLE_BY_CRM_ID = [ 1070 => Role::TEAMER, 1292 => Role::ADMIN, 1293 => Role::MANAGER, 1477 => Role::GROUPS_MANAGER, 1478 => Role::GROUPS_ADMIN, 1483 => Role::CUSTOMER_EXPERT, ]; /** * @param array $houseManagerIds "Hausleitung" selection id => hotel code */ public function __construct(private readonly array $houseManagerIds = []) { } public function parse(Crawler $result): CrmAttributes { $groups = []; $actions = []; $roles = []; $hotelCodes = []; $result ->filterXPath('//selektionsmerkmale/selektionsgruppe') ->each(function (Crawler $node) use (&$groups, &$roles, &$hotelCodes) { $group = new CrmSelectionGroup(); $group->id = (int) $node->attr('id'); $group->label = $node->attr('bezeichnung'); $attributes = []; $node ->filterXPath('//selektion') ->each(function (Crawler $node) use (&$attributes, &$roles, &$hotelCodes) { $attribute = new CrmSelection(); $attribute->id = (int) $node->attr('id'); $attribute->label = $node->attr('bezeichnung'); $attribute->mutable = $this->stringToBool($node->attr('aenderbar')); $attribute->selected = $this->stringToBool($node->attr('auswahl')); if (true === $attribute->selected) { $hotelCode = $this->houseManagerIds[$attribute->id] ?? null; if (null !== $hotelCode) { $roles[] = Role::HOUSE_MANAGER; $hotelCodes[] = $hotelCode; } $role = self::ROLE_BY_CRM_ID[$attribute->id] ?? null; if (null !== $role) { $roles[] = $role; } } $attributes[] = $attribute; }) ; $group->selections = $attributes; $groups[] = $group; }) ; $result ->filterXPath('//crmaktionen/crmaktion') ->each(function (Crawler $node) use (&$actions) { $crmAction = new CrmAction(); $crmAction->id = (int) $node->attr('id'); $crmAction->code = $node->attr('code'); $crmAction->label = $node->attr('bezeichnung'); $crmAction->mutable = $this->stringToBool($node->attr('aenderbar')); $crmAction->selected = $this->stringToBool($node->attr('auswahl')); $actions[] = $crmAction; }) ; $response = new CrmAttributes(); $response->selectionGroups = $groups; $response->crmActions = $actions; $response->roles = array_values(array_unique($roles)); $response->hotelCodes = array_values(array_unique($hotelCodes)); return $response; } }