1 | <?php |
||
2 | |||
3 | namespace Telegram\Send; |
||
4 | |||
5 | use Bitrix\Main\Config\Option; |
||
0 ignored issues
–
show
|
|||
6 | use Bitrix\Main\Context; |
||
0 ignored issues
–
show
The type
Bitrix\Main\Context was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
7 | use Bitrix\Main\Mail\Internal\EventTypeTable; |
||
0 ignored issues
–
show
The type
Bitrix\Main\Mail\Internal\EventTypeTable was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
8 | |||
9 | /** |
||
10 | * Class Config |
||
11 | * @package Telegram\Send |
||
12 | */ |
||
13 | class Config |
||
14 | { |
||
15 | public static $module_id = 'telegram.send'; |
||
16 | public static $request; |
||
17 | public static $response = [ |
||
18 | 'updates' => false, |
||
19 | 'message' => false |
||
20 | ]; |
||
21 | |||
22 | /** |
||
23 | * Request |
||
24 | */ |
||
25 | public static function processRequest() |
||
26 | { |
||
27 | self::$request = Context::getCurrent()->getRequest(); |
||
28 | $funcName = self::$request->getPost('funcName'); |
||
29 | if ($funcName) { |
||
30 | self::$funcName(); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Получение всех почтовых шаблонов |
||
36 | * @return array |
||
37 | */ |
||
38 | public static function getMailTemplates():array |
||
39 | { |
||
40 | $getRow = EventTypeTable::getList([ |
||
41 | 'select' => ['ID', 'EVENT_NAME', 'NAME'], |
||
42 | 'filter' => ['=LID' => LANGUAGE_ID], |
||
0 ignored issues
–
show
|
|||
43 | 'order' => ['EVENT_NAME' => 'ASC'] |
||
44 | ]); |
||
45 | |||
46 | return $getRow->fetchAll(); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Получение входящих запросов |
||
51 | */ |
||
52 | public static function getUpdates() |
||
53 | { |
||
54 | $arReturn = []; |
||
55 | $arUpdates = (new Sending)->updatesUser()[0]; |
||
56 | if ($arUpdates['message']['text'] === '/start' && $arUpdates['message']['chat']['id']) { |
||
57 | $arUsers = self::getUser(); |
||
58 | if (!array_key_exists($arUpdates['message']['chat']['id'], $arUsers)) { |
||
59 | $arReturn = $arUpdates['message']['chat']; |
||
60 | } |
||
61 | } |
||
62 | if (!$arReturn) { |
||
63 | self::$response['message'] = self::setNote('Входящих запросов нет', 'ERROR'); |
||
64 | } |
||
65 | self::$response['updates'] = $arReturn; |
||
66 | self::sendResponse(); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Добавленные пользователи |
||
71 | * @return mixed |
||
72 | */ |
||
73 | public static function getUser() |
||
74 | { |
||
75 | return unserialize(Option::get(self::$module_id, 'user')); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Генерация уведомления |
||
80 | * |
||
81 | * @param $message |
||
82 | * @param $type "ERROR"|"OK"|"PROGRESS" |
||
0 ignored issues
–
show
|
|||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | public static function setNote($message, $type):string |
||
87 | { |
||
88 | return (new \CAdminMessage(['MESSAGE' => $message, 'TYPE' => $type]))->Show(); |
||
0 ignored issues
–
show
The type
CAdminMessage was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Отправка json ответа |
||
93 | */ |
||
94 | public static function sendResponse() |
||
95 | { |
||
96 | header('Content-Type: application/json'); |
||
97 | die(json_encode(self::$response)); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Добавление пользователя |
||
102 | */ |
||
103 | public static function setUser() |
||
104 | { |
||
105 | $fields = self::$request->getPost('fields'); |
||
106 | if ($fields) { |
||
107 | $savedUser = self::getUser(); |
||
108 | if (!array_key_exists($fields['id'], $savedUser)) { |
||
109 | $newUser = [ |
||
110 | $fields['id'] => [ |
||
111 | 'nickname' => $fields['nickname'], |
||
112 | 'username' => $fields['username'] |
||
113 | ] |
||
114 | ]; |
||
115 | if ($savedUser) { |
||
116 | $newUser += $savedUser; |
||
117 | } |
||
118 | self::setOption('user', $newUser); |
||
119 | self::$response['message'] = self::setNote('Пользователь добавлен', 'OK'); |
||
120 | } else { |
||
121 | self::$response['message'] = self::setNote('Пользователь уже существует', 'ERROR'); |
||
122 | } |
||
123 | } |
||
124 | self::sendResponse(); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Запись данных в базу |
||
129 | * |
||
130 | * @param $name |
||
131 | * @param $option |
||
132 | * @param bool $serialize |
||
133 | */ |
||
134 | public static function setOption($name, $option, $serialize = true) |
||
135 | { |
||
136 | Option::set(self::$module_id, $name, $serialize ? serialize($option) : $option); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Удаление пользователя |
||
141 | */ |
||
142 | public static function deleteUser() |
||
143 | { |
||
144 | $fields = self::$request->getPost('fields'); |
||
145 | if ($fields) { |
||
146 | $savedUser = self::getUser(); |
||
147 | if (array_key_exists($fields['id'], $savedUser)) { |
||
148 | unset($savedUser[$fields['id']]); |
||
149 | self::setOption('user', $savedUser); |
||
150 | self::$response['message'] = self::setNote('Пользователь удален', 'OK'); |
||
151 | } else { |
||
152 | self::$response['message'] = self::setNote('Этот пользователь уже удален', 'ERROR'); |
||
153 | } |
||
154 | } |
||
155 | self::sendResponse(); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Сохранение настроек |
||
160 | */ |
||
161 | public static function saveConfig() |
||
162 | { |
||
163 | $fields = self::$request->getPost('fields'); |
||
164 | if ($fields) { |
||
165 | foreach ($fields as $field => $value) { |
||
166 | if (\is_array($value)) { |
||
167 | self::setOption($field, $value); |
||
168 | } else { |
||
169 | self::setOption($field, $value, false); |
||
170 | } |
||
171 | } |
||
172 | } |
||
173 | if ($fields['module_on'] === '1') { |
||
174 | self::$response['message'] = self::setNote('Настройки сохранены', 'OK'); |
||
175 | } else { |
||
176 | self::$response['message'] = self::setNote('Модуль отключен', 'ERROR'); |
||
177 | } |
||
178 | self::sendResponse(); |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Активность модуля |
||
183 | * @return string |
||
184 | */ |
||
185 | public static function statusModule():string |
||
186 | { |
||
187 | return Option::get(self::$module_id, 'module_on'); |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * Токен бота |
||
192 | * @return string |
||
193 | */ |
||
194 | public static function getToken():string |
||
195 | { |
||
196 | return Option::get(self::$module_id, 'token'); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * Почтовые шаблоны |
||
201 | * @return mixed |
||
202 | */ |
||
203 | public static function getMail() |
||
204 | { |
||
205 | return unserialize(Option::get(self::$module_id, 'mail')); |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Активность прокси |
||
210 | * @return mixed |
||
211 | */ |
||
212 | public static function statusProxy() |
||
213 | { |
||
214 | return Option::get(self::$module_id, 'proxy_on'); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * Данные прокси |
||
219 | * @return mixed |
||
220 | */ |
||
221 | public static function proxyData() |
||
222 | { |
||
223 | return unserialize(Option::get(self::$module_id, 'proxy')); |
||
224 | } |
||
225 | } // |
||
226 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths