chore: standardize chrono provider

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-02-17 03:11:54 -05:00
parent f3d2e2690b
commit 5c6d508cac
7 changed files with 451 additions and 529 deletions

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ProviderLocalChrono\Providers\Personal;
use KTXF\Chrono\Collection\CollectionContent;
use KTXF\Chrono\Collection\CollectionPropertiesMutableAbstract;
/**
* Personal Chrono Collection Properties Implementation
*/
class CollectionProperties extends CollectionPropertiesMutableAbstract {
/**
* Converts store document values into collection properties.
*/
public function fromStore(array $data): static {
$this->data[self::JSON_PROPERTY_CONTENTS] = CollectionContent::Event->value;
if (isset($data['label'])) {
$this->data[self::JSON_PROPERTY_LABEL] = (string) $data['label'];
}
if (array_key_exists('description', $data)) {
$this->data[self::JSON_PROPERTY_DESCRIPTION] = $data['description'];
}
if (array_key_exists('priority', $data)) {
$this->data[self::JSON_PROPERTY_PRIORITY] = $data['priority'] !== null ? (int) $data['priority'] : null;
}
if (array_key_exists('visibility', $data)) {
$this->data[self::JSON_PROPERTY_VISIBILITY] = $data['visibility'] !== null ? (bool) $data['visibility'] : null;
}
if (array_key_exists('color', $data)) {
$this->data[self::JSON_PROPERTY_COLOR] = $data['color'];
}
if (isset($data['content'])) {
$this->data[self::JSON_PROPERTY_CONTENTS] = (string) $data['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(),
'priority' => $this->getPriority(),
'visibility' => $this->getVisibility(),
'color' => $this->getColor(),
'content' => $content instanceof CollectionContent ? $content->value : null,
], static fn($value) => $value !== null);
}
}