Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
color.php
1
<?php
2
namespace
Bitrix\Im
;
3
4
use
Bitrix\Main\Localization\Loc
;
5
use
Bitrix\Main\Config\Option
;
6
7
Loc::loadMessages
(__FILE__);
8
14
class
Color
15
{
16
public
const
MAX_COLOR_COUNT
= 99;
17
18
private
static
$colors = Array(
19
'RED'
=>
'#df532d'
,
20
'GREEN'
=>
'#64a513'
,
21
'MINT'
=>
'#4ba984'
,
22
'LIGHT_BLUE'
=>
'#4ba5c3'
,
23
'DARK_BLUE'
=>
'#3e99ce'
,
24
'PURPLE'
=>
'#8474c8'
,
25
'AQUA'
=>
'#1eb4aa'
,
26
'PINK'
=>
'#f76187'
,
27
'LIME'
=>
'#58cc47'
,
28
'BROWN'
=>
'#ab7761'
,
29
'AZURE'
=>
'#29619b'
,
30
'KHAKI'
=>
'#728f7a'
,
31
'SAND'
=>
'#ba9c7b'
,
32
'ORANGE'
=>
'#e8a441'
,
33
'MARENGO'
=>
'#556574'
,
34
'GRAY'
=>
'#909090'
,
35
'GRAPHITE'
=>
'#5e5f5e'
,
36
'COPILOT'
=>
'#8d51eb'
,
37
);
38
39
private
static
$replaceColors = Array(
40
'LIGHT_BLUE'
=>
'AZURE'
,
41
'AQUA'
=>
'SAND'
,
42
'PINK'
=>
'KHAKI'
,
43
);
44
45
private
static
$unsafeColors = Array(
'ORANGE'
=>
'#e8a441'
);
46
50
public
static
function
isEnabled
()
51
{
52
return
(
bool
)Option::get(
'im'
,
'color_enable'
);
53
}
54
58
public
static
function
getColors
()
59
{
60
return
self::$colors;
61
}
62
66
public
static
function
getNames
()
67
{
68
$result = Array();
69
foreach
(self::$colors as $code => $color)
70
{
71
$result[$code] =
Loc::getMessage
(
'IM_COLOR_'
.$code);
72
}
73
74
return
$result;
75
}
76
80
public
static
function
getSafeColors
()
81
{
82
return
array_diff(self::$colors, self::$unsafeColors);
83
}
84
88
public
static
function
getSafeColorNames
()
89
{
90
$result = Array();
91
foreach
(self::getSafeColors() as $code => $color)
92
{
93
$result[$code] =
Loc::getMessage
(
'IM_COLOR_'
.$code);
94
}
95
96
return
$result;
97
}
98
103
public
static
function
getCode
($color)
104
{
105
$colors = array_flip(self::$colors);
106
return
isset($colors[$color])? $colors[$color]:
null
;
107
}
108
112
public
static
function
getReplaceColors
()
113
{
114
return
self::$replaceColors;
115
}
116
121
public
static
function
getColor
($code)
122
{
123
if
(!self::isEnabled())
124
{
125
$code =
'MARENGO'
;
126
}
127
128
return
isset(self::$colors[$code])? self::$colors[$code]:
null
;
129
}
130
135
public
static
function
getName
($code)
136
{
137
return
isset(self::$colors[$code])?
Loc::getMessage
(
'IM_COLOR_'
.$code):
null
;
138
}
139
144
public
static
function
getColorByNumber
($number)
145
{
146
$code =
self::getCodeByNumber
($number);
147
148
return
self::getColor
($code);
149
}
150
155
public
static
function
getNameByNumber
($number)
156
{
157
$code =
self::getCodeByNumber
($number);
158
159
return
self::getName
($code);
160
}
161
166
public
static
function
getCodeByNumber
($number)
167
{
168
$colors = array_keys(self::getColors());
169
170
$number = intval($number);
171
if
(!$number)
172
{
173
$code = $colors[mt_rand(0, 9)];
174
}
175
else
176
{
177
$number = intval(mb_substr($number.
''
, -1));
178
$number = $number == 0? 9: $number - 1;
179
180
$code = $colors[$number];
181
}
182
183
return
$code;
184
}
185
186
public
static
function
isSafeColor
($code)
187
{
188
$colors =
self::getSafeColors
();
189
190
return
isset($colors[$code]);
191
}
192
193
public
static
function
getRandomColor
()
194
{
195
$colors = array_values(self::getColors());
196
197
return
$colors[mt_rand(0, count($colors)-1)];
198
}
199
200
public
static
function
getRandomCode
()
201
{
202
$colors = array_keys(self::getColors());
203
204
return
$colors[mt_rand(0, count($colors)-1)];
205
}
206
}
Bitrix\Im\Color
Definition
color.php:15
Bitrix\Im\Color\getNameByNumber
static getNameByNumber($number)
Definition
color.php:155
Bitrix\Im\Color\getSafeColors
static getSafeColors()
Definition
color.php:80
Bitrix\Im\Color\getColorByNumber
static getColorByNumber($number)
Definition
color.php:144
Bitrix\Im\Color\getName
static getName($code)
Definition
color.php:135
Bitrix\Im\Color\getCode
static getCode($color)
Definition
color.php:103
Bitrix\Im\Color\MAX_COLOR_COUNT
const MAX_COLOR_COUNT
Definition
color.php:16
Bitrix\Im\Color\getRandomCode
static getRandomCode()
Definition
color.php:200
Bitrix\Im\Color\getNames
static getNames()
Definition
color.php:66
Bitrix\Im\Color\getColors
static getColors()
Definition
color.php:58
Bitrix\Im\Color\getRandomColor
static getRandomColor()
Definition
color.php:193
Bitrix\Im\Color\isSafeColor
static isSafeColor($code)
Definition
color.php:186
Bitrix\Im\Color\isEnabled
static isEnabled()
Definition
color.php:50
Bitrix\Im\Color\getColor
static getColor($code)
Definition
color.php:121
Bitrix\Im\Color\getReplaceColors
static getReplaceColors()
Definition
color.php:112
Bitrix\Im\Color\getSafeColorNames
static getSafeColorNames()
Definition
color.php:88
Bitrix\Im\Color\getCodeByNumber
static getCodeByNumber($number)
Definition
color.php:166
Bitrix\Main\Config\Option
Definition
option.php:15
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\Im
modules
im
lib
color.php
Создано системой
1.10.0