1<?php
2
3
4namespace ComboStrap;
5
6
7use ComboStrap\Meta\Api\Metadata;
8use ComboStrap\Meta\Api\MetadataTabular;
9
10class References extends MetadataTabular
11{
12
13
14    const PROPERTY_NAME = "references";
15
16    public static function createFromResource(MarkupPath $page)
17    {
18        return (new References())
19            ->setResource($page);
20    }
21
22    static public function getDescription(): string
23    {
24        return "The link of the page that references another resources";
25    }
26
27    static public function getLabel(): string
28    {
29        return "References";
30    }
31
32    public static function getName(): string
33    {
34        return self::PROPERTY_NAME;
35    }
36
37    static public function getPersistenceType(): string
38    {
39        return Metadata::DERIVED_METADATA;
40    }
41
42    static public function isMutable(): bool
43    {
44        return false;
45    }
46
47    public function getDefaultValue(): array
48    {
49        return [];
50    }
51
52    public function getUidClass(): ?string
53    {
54        return Reference::class;
55    }
56
57    static public function getChildrenClass(): array
58    {
59        return [Reference::class];
60    }
61
62    public function buildFromReadStore(): References
63    {
64        $metadataStore = $this->getReadStore();
65        if ($metadataStore === null) {
66            LogUtility::msg("The metadata store is unknown. You need to define a resource or a store to build from it");
67            return $this;
68        }
69        if ($metadataStore->isDokuWikiStore()) {
70
71            $relation = $metadataStore->getFromName("relation");
72            if (is_array($relation)) {
73
74                $this->wasBuild = true;
75                $referencesArray = $relation["references"] ?? null;
76                if ($referencesArray !== null) {
77                    $referencesArray = array_keys($referencesArray);
78                }
79                $this->setFromStoreValueWithoutException($referencesArray);
80
81                return $this;
82
83            }
84
85        }
86
87        return parent::buildFromReadStore();
88    }
89
90
91}
92