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