1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
spotlight.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Main\UI;
4
5
use Bitrix\Main\ArgumentTypeException;
6
use Bitrix\Main\Config\Option;
7
use Bitrix\Main\Type\DateTime;
8
9
class
Spotlight
10
{
11
const
USER_TYPE_OLD
=
"OLD"
;
12
const
USER_TYPE_NEW
=
"NEW"
;
13
const
USER_TYPE_ALL
=
"ALL"
;
14
15
const
CATEGORY_NAME
=
"spotlight"
;
16
17
private
$id;
18
private
$userType;
19
private
$userTimeSpan;
20
private
$lifetime;
21
private
$startDate =
null
;
22
private
$endDate =
null
;
23
31
public
function
__construct
($id)
32
{
33
if
(!is_string($id))
34
{
35
throw
new
ArgumentTypeException
(
"id"
,
"string"
);
36
}
37
38
$this->
id
= $id;
39
40
$this->userTimeSpan = 3600 * 24 * 30;
41
$this->userType = static::USER_TYPE_OLD;
42
$this->lifetime = 3600 * 24 * 30;
43
}
44
50
public
function
isAvailable
(
$userId
=
false
)
51
{
52
$now = time();
53
54
if
(
55
($this->
getStartDate
() && $now < $this->
getStartDate
()) ||
56
($this->
getEndDate
() && $now > $this->
getEndDate
())
57
)
58
{
59
return
false
;
60
}
61
62
$userId
= $this->getUserId(
$userId
);
63
if
(
$userId
< 1)
64
{
65
return
false
;
66
}
67
68
if
($this->
isViewed
(
$userId
))
69
{
70
return
false
;
71
}
72
73
$activationDate = $this->
getActivationDate
();
74
if
($this->
getLifetime
() && $activationDate + $this->
getLifetime
() < $now)
75
{
76
return
false
;
77
}
78
79
$userType = $this->
getUserType
();
80
if
($userType !== static::USER_TYPE_ALL)
81
{
82
$registerDate = $this->getRegisterDate(
$userId
);
83
if
($registerDate ===
false
)
84
{
85
return
false
;
86
}
87
88
$newUserDate = $activationDate - $this->
getUserTimeSpan
();
89
if
($userType === static::USER_TYPE_OLD && $registerDate > $newUserDate)
90
{
91
return
false
;
92
}
93
94
if
($userType === static::USER_TYPE_NEW && $registerDate < $newUserDate)
95
{
96
return
false
;
97
}
98
}
99
100
return
true
;
101
}
102
103
public
function
getActivationDate
()
104
{
105
$activationDate = intval(Option::get(static::CATEGORY_NAME, $this->getActDateOptionName(), 0));
106
if
($activationDate === 0)
107
{
108
$activationDate = $this->
activate
();
109
}
110
111
return
$activationDate;
112
}
113
114
public
function
activate
($activationDate =
false
)
115
{
116
$activationDate = is_int($activationDate) ? $activationDate : time();
117
Option::set(static::CATEGORY_NAME, $this->getActDateOptionName(), $activationDate);
118
119
return
$activationDate;
120
}
121
122
public
function
deactivate
()
123
{
124
Option::delete(static::CATEGORY_NAME,
array
(
"name"
=> $this->getActDateOptionName()));
125
}
126
127
public
function
isViewed
(
$userId
)
128
{
129
return
$this->
getViewDate
(
$userId
) > 0;
130
}
131
132
public
function
getViewDate
(
$userId
)
133
{
134
$userId
= intval(
$userId
);
135
136
return
intval(\CUserOptions::getOption(static::CATEGORY_NAME, $this->getViewDateOptionName(), 0,
$userId
));
137
}
138
139
public
function
setViewDate
(
$userId
, $date =
false
)
140
{
141
$userId
= intval(
$userId
);
142
$date = is_int($date) ? $date : time();
143
\CUserOptions::setOption(static::CATEGORY_NAME, $this->getViewDateOptionName(), $date,
false
,
$userId
);
144
145
return
$date;
146
}
147
148
public
function
unsetViewDate
(
$userId
)
149
{
150
$userId
= intval(
$userId
);
151
\CUserOptions::deleteOption(static::CATEGORY_NAME, $this->getViewDateOptionName(),
false
,
$userId
);
152
}
153
154
private
function
getViewDateOptionName()
155
{
156
return
"view_date_"
.$this->getId();
157
}
158
159
private
function
getActDateOptionName()
160
{
161
return
"activation_date_"
.$this->getId();
162
}
163
164
private
function
getRegisterDate(
$userId
)
165
{
166
$user
= $this->getUser(
$userId
);
167
if
(
$user
)
168
{
169
return
DateTime::tryParse(
$user
[
"DATE_REGISTER"
])?->getTimestamp() ??
false
;
170
}
171
return
false
;
172
}
173
174
private
function
getUserId(
$userId
=
false
)
175
{
176
return
$userId
===
false
&& is_object(
$GLOBALS
[
"USER"
]) ?
$GLOBALS
[
"USER"
]->getID() : intval(
$userId
);
177
}
178
179
private
function
getUser(
$userId
)
180
{
181
return \CUser::GetByID(
$userId
)->Fetch();
182
}
183
187
public
function
getId
()
188
{
189
return
$this->id;
190
}
191
195
public
function
getUserType
()
196
{
197
return
$this->userType;
198
}
199
203
public
function
setUserType
($userType)
204
{
205
if
(in_array($userType, static::getUserTypes()))
206
{
207
$this->userType = $userType;
208
}
209
}
210
211
public
static
function
getUserTypes
()
212
{
213
static
$types =
null
;
214
if
($types !==
null
)
215
{
216
return
$types;
217
}
218
219
$types =
array
();
220
$refClass = new \ReflectionClass(__CLASS__);
221
foreach
($refClass->getConstants() as
$name
=> $value)
222
{
223
if
(str_starts_with(
$name
,
"USER_TYPE"
))
224
{
225
$types[] = $value;
226
}
227
}
228
229
return
$types;
230
}
231
235
public
function
getUserTimeSpan
()
236
{
237
return
$this->userTimeSpan;
238
}
239
243
public
function
setUserTimeSpan
($userTimeSpan)
244
{
245
if
(is_int($userTimeSpan) && $userTimeSpan >= 0)
246
{
247
$this->userTimeSpan = $userTimeSpan;
248
}
249
}
250
254
public
function
getLifetime
()
255
{
256
return
$this->lifetime;
257
}
258
262
public
function
setLifetime
($lifetime)
263
{
264
if
(is_int($lifetime) && $lifetime >= 0)
265
{
266
$this->lifetime = $lifetime;
267
}
268
}
269
273
public
function
getStartDate
()
274
{
275
return
$this->startDate
;
276
}
277
281
public
function
setStartDate
($startDate)
282
{
283
if
(is_int($startDate) || $startDate ===
null
)
284
{
285
$this->startDate = $startDate;
286
}
287
}
288
292
public
function
getEndDate
()
293
{
294
return
$this->endDate;
295
}
296
300
public
function
setEndDate
($endDate)
301
{
302
if
(is_int($endDate) || $endDate)
303
{
304
$this->endDate = $endDate;
305
}
306
}
307
}
$startDate
$startDate
Определения
basket_discount_convert.php:125
$userId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения
check_mail.php:18
Bitrix\Main\ArgumentTypeException
Определения
ArgumentTypeException.php:9
Bitrix\Main\UI\Spotlight
Определения
spotlight.php:10
Bitrix\Main\UI\Spotlight\getStartDate
getStartDate()
Определения
spotlight.php:273
Bitrix\Main\UI\Spotlight\getId
getId()
Определения
spotlight.php:187
Bitrix\Main\UI\Spotlight\__construct
__construct($id)
Определения
spotlight.php:31
Bitrix\Main\UI\Spotlight\USER_TYPE_OLD
const USER_TYPE_OLD
Определения
spotlight.php:11
Bitrix\Main\UI\Spotlight\setUserTimeSpan
setUserTimeSpan($userTimeSpan)
Определения
spotlight.php:243
Bitrix\Main\UI\Spotlight\CATEGORY_NAME
const CATEGORY_NAME
Определения
spotlight.php:15
Bitrix\Main\UI\Spotlight\getUserTypes
static getUserTypes()
Определения
spotlight.php:211
Bitrix\Main\UI\Spotlight\getViewDate
getViewDate($userId)
Определения
spotlight.php:132
Bitrix\Main\UI\Spotlight\getUserTimeSpan
getUserTimeSpan()
Определения
spotlight.php:235
Bitrix\Main\UI\Spotlight\getEndDate
getEndDate()
Определения
spotlight.php:292
Bitrix\Main\UI\Spotlight\activate
activate($activationDate=false)
Определения
spotlight.php:114
Bitrix\Main\UI\Spotlight\deactivate
deactivate()
Определения
spotlight.php:122
Bitrix\Main\UI\Spotlight\getActivationDate
getActivationDate()
Определения
spotlight.php:103
Bitrix\Main\UI\Spotlight\USER_TYPE_ALL
const USER_TYPE_ALL
Определения
spotlight.php:13
Bitrix\Main\UI\Spotlight\setStartDate
setStartDate($startDate)
Определения
spotlight.php:281
Bitrix\Main\UI\Spotlight\setViewDate
setViewDate($userId, $date=false)
Определения
spotlight.php:139
Bitrix\Main\UI\Spotlight\getLifetime
getLifetime()
Определения
spotlight.php:254
Bitrix\Main\UI\Spotlight\getUserType
getUserType()
Определения
spotlight.php:195
Bitrix\Main\UI\Spotlight\isViewed
isViewed($userId)
Определения
spotlight.php:127
Bitrix\Main\UI\Spotlight\isAvailable
isAvailable($userId=false)
Определения
spotlight.php:50
Bitrix\Main\UI\Spotlight\setEndDate
setEndDate($endDate)
Определения
spotlight.php:300
Bitrix\Main\UI\Spotlight\setUserType
setUserType($userType)
Определения
spotlight.php:203
Bitrix\Main\UI\Spotlight\USER_TYPE_NEW
const USER_TYPE_NEW
Определения
spotlight.php:12
Bitrix\Main\UI\Spotlight\unsetViewDate
unsetViewDate($userId)
Определения
spotlight.php:148
Bitrix\Main\UI\Spotlight\setLifetime
setLifetime($lifetime)
Определения
spotlight.php:262
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$name
$name
Определения
menu_edit.php:35
Bitrix\Main\$user
$user
Определения
mysql_to_pgsql.php:33
Bitrix\Main\$GLOBALS
$GLOBALS['____1690880296']
Определения
license.php:1
bitrix
modules
main
lib
ui
spotlight.php
Создано системой
1.14.0