Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
tileview.php
1
<?php
8
namespace
Bitrix\Sender\UI
;
9
10
use
Bitrix\Main\Localization\Loc
;
11
use
Bitrix\Main\Type\DateTime
;
12
13
Loc::loadMessages
(__FILE__);
14
19
class
TileView
20
{
21
public
const
MAX_COUNT
= 4;
22
public
const
COLOR_GREY
=
'#eef2f4'
;
23
24
public
const
SECTION_ALL
=
'all'
;
25
public
const
SECTION_LAST
=
'last'
;
26
public
const
SECTION_FREQ
=
'freq'
;
27
public
const
SECTION_SYS
=
'system'
;
28
public
const
SECTION_MY
=
'my'
;
29
31
protected
$tiles
= [];
32
34
protected
$sections
= [];
35
41
public
static
function
create
()
42
{
43
return
new
static
();
44
}
45
49
public
function
__construct
()
50
{
51
52
}
53
65
public
function
addTile
($id, $name, $data = [], $bgColor =
null
, $color =
null
)
66
{
67
$this->tiles[] = $this->
getTile
($id, $name, $data, $bgColor, $color);
68
return
$this;
69
}
70
82
public
function
getTile
($id, $name, $data = [], $bgColor =
null
, $color =
null
)
83
{
84
return
[
85
'id'
=> $id,
86
'name'
=> $name,
87
'data'
=> $data,
88
'bgcolor'
=> $bgColor,
89
'color'
=> $color
90
];
91
}
92
98
public
function
getTiles
()
99
{
100
return
$this->tiles
;
101
}
102
108
public
function
removeTiles
()
109
{
110
$this->tiles = [];
111
return
$this;
112
}
113
122
public
function
addSection
($id, $name =
null
)
123
{
124
$name = $name ?:
Loc::getMessage
(
'SENDER_UI_TILEVIEW_SECTION_'
.mb_strtoupper($id));
125
$name = $name ?: $id;
126
127
$this->sections[$id] = [
128
'id'
=> $id,
129
'name'
=> $name,
130
'items'
=> [],
131
];
132
return
$this;
133
}
134
140
public
function
getSections
()
141
{
142
return
$this->sections
;
143
}
144
150
public
function
removeSections
()
151
{
152
$this->sections = [];
153
return
$this;
154
}
155
161
public
function
get
()
162
{
163
$list =
$this->sections
;
164
$sections
= array_keys($list);
165
166
if
(in_array(self::SECTION_ALL,
$sections
))
167
{
168
$list[
self::SECTION_ALL
][
'items'
] =
$this->tiles
;
169
}
170
171
foreach
($this->tiles as $tile)
172
{
173
foreach
(
$sections
as $section)
174
{
175
if
($section === self::SECTION_ALL)
176
{
177
continue
;
178
}
179
180
if
(empty($tile[
'data'
][$section]))
181
{
182
continue
;
183
}
184
185
self::prepareTileForSorting
($tile, $section);
186
$list[$section][
'items'
][] = $tile;
187
}
188
}
189
190
self::sortTiles
($list);
191
return
array_values($list);
192
}
193
194
protected
static
function
prepareTileForSorting
(&$tile, $section)
195
{
196
if
($section === self::SECTION_LAST)
197
{
198
$last = $tile[
'data'
][
self::SECTION_LAST
];
199
if
($last instanceof
DateTime
)
200
{
201
$tile[
'data'
][
self::SECTION_LAST
] = $last->getTimestamp();
202
}
203
}
204
}
205
206
protected
static
function
sortTiles
(&$list)
207
{
208
foreach
([self::SECTION_LAST, self::SECTION_FREQ] as $section)
209
{
210
if
(!isset($list[$section]))
211
{
212
continue
;
213
}
214
215
// sort & cut
216
usort(
217
$list[$section][
'items'
],
218
function
($a, $b) use ($section)
219
{
220
return
($a[
'data'
][$section] > $b[
'data'
][$section]) ? -1 : 1;
221
}
222
);
223
$list[$section][
'items'
] = array_slice($list[$section][
'items'
], 0, self::MAX_COUNT);
224
}
225
}
226
}
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Sender\UI\TileView
Definition
tileview.php:20
Bitrix\Sender\UI\TileView\removeTiles
removeTiles()
Definition
tileview.php:108
Bitrix\Sender\UI\TileView\__construct
__construct()
Definition
tileview.php:49
Bitrix\Sender\UI\TileView\SECTION_FREQ
const SECTION_FREQ
Definition
tileview.php:26
Bitrix\Sender\UI\TileView\create
static create()
Definition
tileview.php:41
Bitrix\Sender\UI\TileView\addTile
addTile($id, $name, $data=[], $bgColor=null, $color=null)
Definition
tileview.php:65
Bitrix\Sender\UI\TileView\prepareTileForSorting
static prepareTileForSorting(&$tile, $section)
Definition
tileview.php:194
Bitrix\Sender\UI\TileView\getTiles
getTiles()
Definition
tileview.php:98
Bitrix\Sender\UI\TileView\getTile
getTile($id, $name, $data=[], $bgColor=null, $color=null)
Definition
tileview.php:82
Bitrix\Sender\UI\TileView\SECTION_SYS
const SECTION_SYS
Definition
tileview.php:27
Bitrix\Sender\UI\TileView\COLOR_GREY
const COLOR_GREY
Definition
tileview.php:22
Bitrix\Sender\UI\TileView\sortTiles
static sortTiles(&$list)
Definition
tileview.php:206
Bitrix\Sender\UI\TileView\removeSections
removeSections()
Definition
tileview.php:150
Bitrix\Sender\UI\TileView\$tiles
$tiles
Definition
tileview.php:31
Bitrix\Sender\UI\TileView\SECTION_LAST
const SECTION_LAST
Definition
tileview.php:25
Bitrix\Sender\UI\TileView\getSections
getSections()
Definition
tileview.php:140
Bitrix\Sender\UI\TileView\SECTION_ALL
const SECTION_ALL
Definition
tileview.php:24
Bitrix\Sender\UI\TileView\$sections
$sections
Definition
tileview.php:34
Bitrix\Sender\UI\TileView\addSection
addSection($id, $name=null)
Definition
tileview.php:122
Bitrix\Sender\UI\TileView\SECTION_MY
const SECTION_MY
Definition
tileview.php:28
Bitrix\Sender\UI\TileView\MAX_COUNT
const MAX_COUNT
Definition
tileview.php:21
Bitrix\Sender\UI
modules
sender
lib
ui
tileview.php
Создано системой
1.10.0