Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
restservice.php
1<?php
2
4
8
9if (!Main\Loader::includeModule('rest'))
10{
11 return;
12}
13
18class RestService extends \IRestService
19{
20 const SCOPE = 'cashbox';
21
22 protected const ERROR_CHECK_FAILURE = 'ERROR_CHECK_FAILURE';
23
24 public static function onRestAppDelete(array $fields): void
25 {
26 if (!Main\Loader::includeModule('rest'))
27 {
28 return;
29 }
30
31 if (empty($fields['APP_ID']) || empty($fields['CLEAN']) || $fields['CLEAN'] !== true)
32 {
33 return;
34 }
35
36 $app = Rest\AppTable::getByClientId($fields['APP_ID']);
37 if (!$app)
38 {
39 return;
40 }
41
42 $restHandlerResult = Sale\Internals\CashboxRestHandlerTable::getList([
43 'select' => ['ID', 'CODE'],
44 'filter' => [
45 '=APP_ID' => $app['CLIENT_ID'],
46 ],
47 ]);
48 while ($restHandler = $restHandlerResult->fetch())
49 {
50 $cashboxResult = Sale\Cashbox\Manager::getList([
51 'select' => ['ID'],
52 'filter' => [
53 '=HANDLER' => '\\' . Sale\Cashbox\CashboxRest::class,
54 ],
55 ]);
56 while ($cashbox = $cashboxResult->fetch())
57 {
58 $cashboxObj = Sale\Cashbox\Manager::getObjectById($cashbox['ID']);
59 if ($cashboxObj)
60 {
61 $handlerCode = $cashboxObj->getValueFromSettings('REST', 'REST_CODE');
62 if ($handlerCode === $restHandler['CODE'])
63 {
64 Sale\Cashbox\Manager::delete($cashbox['ID']);
65 }
66 }
67 }
68
69 Sale\Internals\CashboxRestHandlerTable::delete($restHandler['ID']);
70 }
71 }
72
76 public static function onRestServiceBuildDescription()
77 {
78 return [
79 static::SCOPE => [
80 // handlers
81 'sale.cashbox.handler.add' => [HandlerService::class, 'addHandler'],
82 'sale.cashbox.handler.update' => [HandlerService::class, 'updateHandler'],
83 'sale.cashbox.handler.delete' => [HandlerService::class, 'deleteHandler'],
84 'sale.cashbox.handler.list' => [HandlerService::class, 'getHandlerList'],
85
86 // cashbox
87 'sale.cashbox.add' => [CashboxService::class, 'addCashbox'],
88 'sale.cashbox.update' => [CashboxService::class, 'updateCashbox'],
89 'sale.cashbox.delete' => [CashboxService::class, 'deleteCashbox'],
90 'sale.cashbox.list' => [CashboxService::class, 'getCashboxList'],
91
92 'sale.cashbox.settings.get' => [CashboxService::class, 'getCashboxSettings'],
93 'sale.cashbox.settings.update' => [CashboxService::class, 'updateCashboxSettings'],
94
95 'sale.cashbox.ofd.settings.get' => [CashboxService::class, 'getCashboxOfdSettings'],
96 'sale.cashbox.ofd.settings.update' => [CashboxService::class, 'updateCashboxOfdSettings'],
97
98 // check
99 'sale.cashbox.check.apply' => [CheckService::class, 'applyCheck'],
100
101 // ofd
102 'sale.ofd.list' => [OfdService::class, 'getOfdList'],
103 'sale.ofd.settings.get' => [OfdService::class, 'getOfdSettings'],
104 ]
105 ];
106 }
107
112 protected static function prepareIncomingParams(array $data)
113 {
114 return self::arrayChangeKeyCaseRecursive($data);
115 }
116
122 private static function arrayChangeKeyCaseRecursive($array, $case = CASE_UPPER)
123 {
124 $result = $array;
125 foreach ($result as $key => $value)
126 {
127 if (is_array($result[$key]))
128 {
129 $result[$key] = self::arrayChangeKeyCaseRecursive($result[$key], $case);
130 }
131 }
132
133 $result = array_change_key_case($result, $case);
134
135 return $result;
136 }
137
143 protected static function prepareHandlerParams($data, \CRestServer $server)
144 {
145 $data = self::prepareIncomingParams($data);
146 $data['APP_ID'] = $server->getClientId();
147
148 return $data;
149 }
150}
static includeModule($moduleName)
Definition loader.php:69
static prepareHandlerParams($data, \CRestServer $server)
static onRestAppDelete(array $fields)
static prepareIncomingParams(array $data)