1<?php
2
3
4namespace ComboStrap;
5
6
7use ComboStrap\Meta\Api\Metadata;
8use ComboStrap\Meta\Api\MetadataInteger;
9
10/**
11 * @package ComboStrap
12 * Represents the level in the tree
13 */
14class PageLevel extends MetadataInteger
15{
16
17
18    public const PROPERTY_NAME = "level";
19
20
21    public static function createForPage(ResourceCombo $page): PageLevel
22    {
23        return (new PageLevel())
24            ->setResource($page);
25    }
26
27
28    /**
29     * @return int
30     */
31    public function getValue(): int
32    {
33        return substr_count($this->getResource()->getPathObject()->toAbsoluteId(), WikiPath::NAMESPACE_SEPARATOR_DOUBLE_POINT) - 1;
34    }
35
36
37    static public function getName(): string
38    {
39        return self::PROPERTY_NAME;
40    }
41
42
43    static public function getPersistenceType(): string
44    {
45        return Metadata::DERIVED_METADATA;
46    }
47
48
49    static public function getTab(): string
50    {
51        return MetaManagerForm::TAB_PAGE_VALUE;
52    }
53
54    static public function getDescription(): string
55    {
56        return "The level of the page on the file system (The home page is at level 0)";
57    }
58
59    static public function getLabel(): string
60    {
61        return "Page Level";
62    }
63
64    static public function isMutable(): bool
65    {
66        return false;
67    }
68
69    static public function getCanonical(): string
70    {
71        return self::PROPERTY_NAME;
72    }
73
74
75    static public function isOnForm(): bool
76    {
77        return true;
78    }
79
80}
81