filterXPath('//selektionsmerkmale/selektionsgruppe') ->each(function (Crawler $node) use (&$groups, &$roles, &$hotelCode) { $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 (1 === preg_match('/^Hausleitung ([A-Z0-9]+)$/', $attribute->label, $matches) && true === $attribute->selected) { $roles[] = 'ROLE_HOUSE_MANAGER'; $hotelCodes[] = $matches[1]; } if (static::BPN_CRM_ID_ADMIN === $attribute->id && true === $attribute->selected) { $roles[] = 'ROLE_ADMIN'; $roles[] = 'ROLE_HOUSE_MANAGER'; } if (static::BPN_CRM_ID_MANAGER === $attribute->id && true === $attribute->selected) { $roles[] = 'ROLE_MANAGER'; } if (static::BPN_CRM_ID_TEAMER === $attribute->id && true === $attribute->selected) { $roles[] = 'ROLE_TEAMER'; } $attributes[] = $attribute; }) ; $group->selections = $attributes; $groups[] = $group; }) ; $roles = array_unique($roles); // Assign default role if none could be resolved if (0 === count($roles)) { $roles = ['ROLE_CUSTOMER']; } $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; }) ; if (true === in_array('ROLE_ADMIN', $roles, true)) { $hotelCodes[] = static::BPN_DEFAULT_HOTEL_CODE; } $response = new CrmAttributes(); $response->selectionGroups = $groups; $response->crmActions = $actions; $response->roles = $roles; $response->hotelCodes = $hotelCodes; return $response; } }