1<?php
2
3namespace ComboStrap;
4
5use ComboStrap\Meta\Api\Metadata;
6use ComboStrap\Meta\Api\MetadataImage;
7use ComboStrap\Meta\Store\MetadataDokuWikiStore;
8
9/**
10 * A derived meta that captures the first raster image
11 * via {@link \syntax_plugin_combo_media::registerFirstImage()}
12 */
13class FirstRasterImage extends MetadataImage
14{
15
16    /**
17     * Our first image metadata
18     * We can't overwrite the {@link \Doku_Renderer_metadata::$firstimage first image}
19     * We put it then in directly under the root
20     */
21    public const PROPERTY_NAME = "first-image-raster";
22
23    public static function createForPage(ResourceCombo $resource): FirstRasterImage
24    {
25        return (new FirstRasterImage())
26            ->setResource($resource);
27    }
28
29    static public function getDescription(): string
30    {
31        return "The first raster image of the page";
32    }
33
34    static public function getLabel(): string
35    {
36        return "First Raster image";
37    }
38
39    public static function getName(): string
40    {
41        return self::PROPERTY_NAME;
42    }
43
44
45    static public function isMutable(): bool
46    {
47        return false;
48    }
49
50    /**
51     * @return WikiPath
52     * @throws ExceptionNotFound
53     */
54    public function getValue(): WikiPath
55    {
56
57        $store = $this->getReadStore();
58        if (!($store instanceof MetadataDokuWikiStore)) {
59            throw new ExceptionNotFound();
60        }
61
62        /**
63         *
64         * Image set by {@link \syntax_plugin_combo_media::registerFirstImage()}
65         */
66        $firstImageId = $store->getFromName(FirstRasterImage::PROPERTY_NAME);
67
68        if ($firstImageId !== null) {
69            return WikiPath::createMediaPathFromId($firstImageId);
70        }
71
72        throw new ExceptionNotFound();
73
74    }
75
76    static public function getPersistenceType(): string
77    {
78        return Metadata::DERIVED_METADATA;
79    }
80
81    static public function getDrive(): string
82    {
83        return WikiPath::MEDIA_DRIVE;
84    }
85
86}
87