Passed
Push — master ( 6b6049...51add7 )
by Julius
28:38 queued 13:15
created

WidgetItem::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright 2021, Julien Veyssier <[email protected]>
7
 *
8
 * @author Julien Veyssier <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCP\Dashboard\Model;
28
29
use JsonSerializable;
30
31
/**
32
 * Interface WidgetItem
33
 *
34
 * This class is used by IAPIWidget interface.
35
 * It represents an widget item data that can be provided to clients via the Dashboard API
36
 * @see IAPIWidget::getWidgetItems
37
 *
38
 * @since 22.0.0
39
 *
40
 */
41
final class WidgetItem implements JsonSerializable {
42
	/** @var string */
43
	private $title = '';
44
45
	/** @var string */
46
	private $subtitle = '';
47
48
	/** @var string */
49
	private $link = '';
50
51
	/** @var string */
52
	private $iconUrl = '';
53
54
	/** @var string
55
	 * Timestamp or ID used by the dashboard API to avoid getting already retrieved items
56
	 */
57
	private $sinceId = '';
58
59
60
	/**
61
	 * WidgetItem constructor
62
	 *
63
	 * @since 22.0.0
64
	 *
65
	 * @param string $type
66
	 */
67
	public function __construct(string $title = '',
68
								string $subtitle = '',
69
								string $link = '',
70
								string $iconUrl = '',
71
								string $sinceId = '') {
72
		$this->title = $title;
73
		$this->subtitle = $subtitle;
74
		$this->iconUrl = $iconUrl;
75
		$this->link = $link;
76
		$this->sinceId = $sinceId;
77
	}
78
79
	/**
80
	 * Get the item title
81
	 *
82
	 * @since 22.0.0
83
	 *
84
	 * @return string
85
	 */
86
	public function getTitle(): string {
87
		return $this->title;
88
	}
89
90
	/**
91
	 * Get the item subtitle
92
	 *
93
	 * @since 22.0.0
94
	 *
95
	 * @return string
96
	 */
97
	public function getSubtitle(): string {
98
		return $this->subtitle;
99
	}
100
101
	/**
102
	 * Get the item link
103
	 *
104
	 * @since 22.0.0
105
	 *
106
	 * @return string
107
	 */
108
	public function getLink(): string {
109
		return $this->link;
110
	}
111
112
	/**
113
	 * Get the item icon URL
114
	 * The icon should be a square svg or a jpg/png of at least 44x44px
115
	 *
116
	 * @since 22.0.0
117
	 *
118
	 * @return string
119
	 */
120
	public function getIconUrl(): string {
121
		return $this->iconUrl;
122
	}
123
124
	/**
125
	 * Get the item since ID
126
	 *
127
	 * @since 22.0.0
128
	 *
129
	 * @return string
130
	 */
131
	public function getSinceId(): string {
132
		return $this->sinceId;
133
	}
134
135
	/**
136
	 * @since 22.0.0
137
	 *
138
	 * @return array
139
	 */
140
	public function jsonSerialize(): array {
141
		return [
142
			'subtitle' => $this->getSubtitle(),
143
			'title' => $this->getTitle(),
144
			'link' => $this->getLink(),
145
			'iconUrl' => $this->getIconUrl(),
146
			'sinceId' => $this->getSinceId(),
147
		];
148
	}
149
}
150