Files
provider_local_people/lib/Providers/Personal/CollectionProperties.php
T
Sebastian df9e2f2956 fix: content type
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-06-25 23:42:30 -04:00

72 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ProviderLocalPeople\Providers\Personal;
use KTXF\People\Collection\CollectionContent;
use KTXF\People\Collection\CollectionPropertiesMutableAbstract;
/**
* Collection Properties Implementation
*/
class CollectionProperties extends CollectionPropertiesMutableAbstract {
/**
* Converts store document values into collection properties.
*/
public function fromStore(array $data): static {
$this->data[self::PROPERTY_CONTENT] = [
CollectionContent::Individual->value,
CollectionContent::Organization->value,
CollectionContent::Group->value
];
if (isset($data['label'])) {
$this->data[self::PROPERTY_LABEL] = (string) $data['label'];
}
if (array_key_exists('description', $data)) {
$this->data[self::PROPERTY_DESCRIPTION] = $data['description'];
}
if (array_key_exists('rank', $data)) {
$this->data[self::PROPERTY_RANK] = $data['rank'] !== null ? (int) $data['rank'] : null;
}
if (array_key_exists('visibility', $data)) {
$this->data[self::PROPERTY_VISIBILITY] = $data['visibility'] !== null ? (bool) $data['visibility'] : null;
}
if (array_key_exists('color', $data)) {
$this->data[self::PROPERTY_COLOR] = $data['color'];
}
if (isset($data['content'])) {
$content = is_array($data['content']) ? $data['content'] : [$data['content']];
$this->data[self::PROPERTY_CONTENT] = array_values(array_map(
static fn($item) => $item instanceof CollectionContent ? $item->value : (string) $item,
$content
));
}
return $this;
}
/**
* Converts collection properties into store document values.
*/
public function toStore(): array {
$content = $this->content();
return array_filter([
'label' => $this->getLabel(),
'description' => $this->getDescription(),
'rank' => $this->getRank(),
'visibility' => $this->getVisibility(),
'color' => $this->getColor(),
'content' => $content !== [] ? array_map(static fn(CollectionContent $item) => $item->value, $content) : null,
], static fn($value) => $value !== null);
}
}