Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
MediaType | |
0.00% |
0 / 16 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getL11n | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
setL11n | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
toArray | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package Modules\Media\Models |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace Modules\Media\Models; |
16 | |
17 | use phpOMS\Localization\BaseStringL11n; |
18 | use phpOMS\Localization\ISO639x1Enum; |
19 | |
20 | /** |
21 | * Media type class. |
22 | * |
23 | * @package Modules\Media\Models |
24 | * @license OMS License 2.0 |
25 | * @link https://jingga.app |
26 | * @since 1.0.0 |
27 | */ |
28 | class MediaType implements \JsonSerializable |
29 | { |
30 | /** |
31 | * Article ID. |
32 | * |
33 | * @var int |
34 | * @since 1.0.0 |
35 | */ |
36 | public int $id = 0; |
37 | |
38 | /** |
39 | * Name. |
40 | * |
41 | * Name used for additional identification, doesn't have to be unique. |
42 | * |
43 | * @var string |
44 | * @since 1.0.0 |
45 | */ |
46 | public string $name = ''; |
47 | |
48 | /** |
49 | * Is this media type visible in lists or only internal? |
50 | * |
51 | * @var bool |
52 | * @since 1.0.0 |
53 | */ |
54 | public bool $isVisible = true; |
55 | |
56 | /** |
57 | * Title. |
58 | * |
59 | * @var string|BaseStringL11n |
60 | * @since 1.0.0 |
61 | */ |
62 | protected string | BaseStringL11n $title = ''; |
63 | |
64 | /** |
65 | * Constructor. |
66 | * |
67 | * @param string $name Name |
68 | * |
69 | * @since 1.0.0 |
70 | */ |
71 | public function __construct(string $name = '') |
72 | { |
73 | $this->setL11n($name); |
74 | } |
75 | |
76 | /** |
77 | * @return string |
78 | * |
79 | * @since 1.0.0 |
80 | */ |
81 | public function getL11n() : string |
82 | { |
83 | return $this->title instanceof BaseStringL11n ? $this->title->content : $this->title; |
84 | } |
85 | |
86 | /** |
87 | * Set title |
88 | * |
89 | * @param string|BaseStringL11n $title Media article title |
90 | * @param string $lang Language |
91 | * |
92 | * @return void |
93 | * |
94 | * @since 1.0.0 |
95 | */ |
96 | public function setL11n(string | BaseStringL11n $title, string $lang = ISO639x1Enum::_EN) : void |
97 | { |
98 | if ($title instanceof BaseStringL11n) { |
99 | $this->title = $title; |
100 | } elseif ($this->title instanceof BaseStringL11n) { |
101 | $this->title->content = $title; |
102 | } else { |
103 | $this->title = new BaseStringL11n(); |
104 | $this->title->ref = $this->id; |
105 | $this->title->content = $title; |
106 | $this->title->setLanguage($lang); |
107 | } |
108 | } |
109 | |
110 | /** |
111 | * {@inheritdoc} |
112 | */ |
113 | public function toArray() : array |
114 | { |
115 | return [ |
116 | 'id' => $this->id, |
117 | 'title' => $this->title, |
118 | 'name' => $this->name, |
119 | ]; |
120 | } |
121 | |
122 | /** |
123 | * {@inheritdoc} |
124 | */ |
125 | public function jsonSerialize() : mixed |
126 | { |
127 | return $this->toArray(); |
128 | } |
129 | } |