Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
color.php
1<?php
2namespace Bitrix\Im;
3
6
7Loc::loadMessages(__FILE__);
8
14class 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}
static getNameByNumber($number)
Definition color.php:155
static getSafeColors()
Definition color.php:80
static getColorByNumber($number)
Definition color.php:144
static getName($code)
Definition color.php:135
static getCode($color)
Definition color.php:103
const MAX_COLOR_COUNT
Definition color.php:16
static getRandomCode()
Definition color.php:200
static getNames()
Definition color.php:66
static getColors()
Definition color.php:58
static getRandomColor()
Definition color.php:193
static isSafeColor($code)
Definition color.php:186
static isEnabled()
Definition color.php:50
static getColor($code)
Definition color.php:121
static getReplaceColors()
Definition color.php:112
static getSafeColorNames()
Definition color.php:88
static getCodeByNumber($number)
Definition color.php:166
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29