'Funktion', 'department' => 'Abteilung', 'location' => 'Standort', 'phone' => 'Telefon', 'mobile' => 'Mobil', 'email' => 'E-Mail-Adresse', ]; /** Felder der Personensuche auf der Startseite (Einstellung) */ public const PEOPLE_SEARCH_FIELDS = 'people.search_fields'; public const DEFAULT_PEOPLE_SEARCH_FIELDS = ['email', 'phone', 'mobile', 'location']; public function __construct(private readonly ProfileFields $profileFields) {} /** * @return array auswählbare Felder für Einstellungen */ public function options(): array { return self::CORE_FIELDS + collect($this->profileFields->options())->mapWithKeys(fn ($label, $key) => ['custom.'.$key => $label.' (Profilfeld)'])->all(); } /** * @param iterable $people * @param list $fields Schlüssel aus options() * @return list}> */ public function cards(iterable $people, ?User $viewer, array $fields): array { $result = []; foreach ($people as $person) { if (! $person->is_active) { continue; } $values = []; $custom = collect($this->profileFields->visibleValues($person, $viewer))->keyBy('key'); foreach ($fields as $field) { if (isset(self::CORE_FIELDS[$field])) { $value = $person->{$field}; if (filled($value)) { $values[] = ['key' => $field, 'label' => self::CORE_FIELDS[$field], 'value' => (string) $value, 'type' => in_array($field, ['phone', 'mobile'], true) ? 'phone' : ($field === 'email' ? 'email' : 'text')]; } } elseif (str_starts_with($field, 'custom.') && ($item = $custom->get(substr($field, 7)))) { $values[] = ['key' => $field, 'label' => $item['label'], 'value' => (string) $item['value'], 'type' => $item['type'] ?? 'text']; } } $result[] = [ 'id' => $person->id, 'name' => $person->name, 'initials' => $person->initials, 'avatar_url' => $person->avatarUrl(160), 'subtitle' => collect([$person->job_title, $person->department])->filter()->implode(' · ') ?: null, 'fields' => $values, ]; } return $result; } }