1<?php
2
3/* Copyright (c) 2017 Alex Killing <killing@leifos.de> Extended GPL, see docs/LICENSE */
4
5namespace ILIAS\UI\Implementation\Component\Item;
6
7use ILIAS\UI\Component as C;
8use ILIAS\UI\Implementation\Component\ComponentHelper;
9
10/**
11 * Common interface to all items.
12 */
13abstract class Item implements C\Item\Item
14{
15    use ComponentHelper;
16
17    /**
18     * @var \ILIAS\Data\Color color
19     */
20    protected $color = null;
21
22    /**
23     * @var string|\ILIAS\UI\Component\Button\Shy
24     */
25    protected $title;
26
27    /**
28     * @var string
29     */
30    protected $desc;
31
32    /**
33     * @var array
34     */
35    protected $props;
36
37    /**
38     * @var \ILIAS\UI\Component\Dropdown\Standard
39     */
40    protected $actions;
41
42    /**
43     * @var null|string|\ILIAS\UI\Component\Image\Image
44     */
45    protected $lead = null;
46
47    public function __construct($title)
48    {
49        if (!$title instanceof \ILIAS\UI\Component\Button\Shy) {
50            $this->checkStringArg("title", $title);
51        }
52        $this->title = $title;
53        $this->props = [];
54    }
55
56    /**
57     * @inheritdoc
58     */
59    public function getTitle()
60    {
61        return $this->title;
62    }
63
64    /**
65     * @inheritdoc
66     */
67    public function withDescription($desc)
68    {
69        $this->checkStringArg("description", $desc);
70        $clone = clone $this;
71        $clone->desc = $desc;
72        return $clone;
73    }
74
75    /**
76     * @inheritdoc
77     */
78    public function getDescription()
79    {
80        return $this->desc;
81    }
82
83    /**
84     * @inheritdoc
85     */
86    public function withProperties(array $props)
87    {
88        $clone = clone $this;
89        $clone->props = $props;
90        return $clone;
91    }
92
93    /**
94     * @inheritdoc
95     */
96    public function getProperties()
97    {
98        return $this->props;
99    }
100
101    /**
102     * @inheritdoc
103     */
104    public function withActions(\ILIAS\UI\Component\Dropdown\Standard $actions)
105    {
106        $clone = clone $this;
107        $clone->actions = $actions;
108        return $clone;
109    }
110
111    /**
112     * @inheritdoc
113     */
114    public function getActions()
115    {
116        return $this->actions;
117    }
118
119    /**
120     * @inheritdoc
121     */
122    public function withColor(\ILIAS\Data\Color $color)
123    {
124        $clone = clone $this;
125        $clone->color = $color;
126
127        return $clone;
128    }
129
130    /**
131     * @inheritdoc
132     */
133    public function getColor()
134    {
135        return $this->color;
136    }
137
138    /**
139     * @inheritdoc
140     */
141    public function withLeadImage(\ILIAS\UI\Component\Image\Image $image)
142    {
143        $clone = clone $this;
144        $clone->lead = $image;
145        return $clone;
146    }
147
148    /**
149     * @inheritdoc
150     */
151    public function withLeadIcon(\ILIAS\UI\Component\Icon\Icon $icon)
152    {
153        $clone = clone $this;
154        $clone->lead = $icon;
155        return $clone;
156    }
157
158    /**
159     * @inheritdoc
160     */
161    public function withLeadText($text)
162    {
163        $this->checkStringArg("lead_text", $text);
164        $clone = clone $this;
165        $clone->lead = (string) $text;
166        return $clone;
167    }
168
169    /**
170     * @inheritdoc
171     */
172    public function withNoLead()
173    {
174        $clone = clone $this;
175        $clone->lead = null;
176        return $clone;
177    }
178
179    /**
180     * @inheritdoc
181     */
182    public function getLead()
183    {
184        return $this->lead;
185    }
186}
187