Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
stepper.php
1<?php
2
3
5
6
12
13Loc::loadMessages(__FILE__);
14
15class Stepper extends Controller
16{
17 const BATCH_LENGTH = 50;
18
19 public function activityBatchAction(array $list, $total=0, $start=0)
20 {
21 $batch = array_slice($list, 0, static::BATCH_LENGTH, true);
22 $slice = array_slice($list, static::BATCH_LENGTH, null, true);
23
24 $start += count($batch);
25
26 $b = $this->getUnprocessedItems($batch);
27 $batch = $b->getData();
28
29 foreach (array_keys($batch) as $orderId)
30 {
31 OrderTable::update($orderId, ['IS_SYNC_B24' => 'Y']);
32 }
33
34 $result['progress'] = round((100*$start)/$total);
35
36 $result['process'] = [
37 'items' => $batch,
38 'list' => $slice,
39 'total' => $total,
40 'start' => $start
41 ];
42
43 if($start == $total)
44 {
45 $result['finish'] = true;
46 }
47
48 if(count($b->getErrorMessages())>0)
49 {
50 $result['error'] = implode("<br>", $b->getErrorMessages());
51 }
52 return $result;
53 }
54
55 public function progressBarAction($value)
56 {
57 require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php");
58
59 ob_start();
60
61 $message = new \CAdminMessage('');
62 $message->ShowMessage(array(
63 "TYPE" => "PROGRESS",
64 "DETAILS" => '#PROGRESS_BAR#'.
65 '<div class="adm-loc-ri-statusbar">'.Loc::getMessage('SALE_ORDER_REQUEST_STATUS').': <span class="bx-ui-loc-ri-loader"></span>&nbsp;<span class="bx-ui-loc-ri-status-text">'.Loc::getMessage('SALE_ORDER_REQUEST_STATUS_PROCESS').'</span></div>',
66 "HTML" => true,
67 "PROGRESS_TOTAL" => 100,
68 "PROGRESS_VALUE" => $value,
69 "PROGRESS_TEMPLATE" => '<span class="bx-ui-loc-ri-percents">#PROGRESS_VALUE#</span>%'
70 ));
71 $res = ob_get_clean();
72 return $res;
73 }
74
75 public function messageOKAction()
76 {
77 return $this->messageByTypeAction(Loc::getMessage('SALE_ORDER_REQUEST_ORDER_IDS_OK'),'OK');
78 }
79
80 public function messageByTypeAction($message, $type)
81 {
82 require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php");
83
84 if($type == 'ERROR')
85 {
86 $adminMessage = new \CAdminMessage(
87 array(
88 "DETAILS" => $message,
89 "TYPE" => "ERROR",
90 "HTML" => true
91 )
92 );
93 }
94 else
95 {
96 $adminMessage = new \CAdminMessage(
97 array(
98 "DETAILS" => $message,
99 "TYPE" => "OK",
100 "HTML" => true
101 )
102 );
103 }
104
105 return $adminMessage->Show();
106 }
107
108 static protected function getInActiveOrders($orderIds)
109 {
110 $registry = \Bitrix\Sale\Registry::getInstance(\Bitrix\Sale\Registry::REGISTRY_TYPE_ORDER);
111
113 $orderClass = $registry->getOrderClassName();
114
115 $r=[];
116 if(count($orderIds)>0)
117 {
118 $list = $orderClass::getList([
119 'select'=>['ID'],
120 'filter'=>['ID'=>$orderIds, 'IS_SYNC_B24'=>'Y']
121 ])->fetchAll();
122
123 if(count($list)>0)
124 {
125 foreach ($list as $l)
126 {
127 $r[] = $l['ID'];
128 }
129 }
130 }
131
132 return $r;
133 }
134
135 protected function getUnprocessedItems($items)
136 {
137 $result = new Result();
138 $list = [];
139 $orderIds = array_keys($items);
140
141 $inActiveOrders = static::getInActiveOrders($orderIds);
142
143 foreach ($items as $index => $item)
144 {
145 $r = $this->checkInActiveOrder($index, $inActiveOrders);
146 if($r->isSuccess())
147 {
148 $list[$index] = $item;
149 }
150 else
151 {
152 $result->addError(new Error(Loc::getMessage('SALE_ORDER_APP_REST_SENDER_ORDER_ERROR').$index.' '.implode(', ', $r->getErrorMessages())));
153 }
154 }
155
156 $result->setData($list);
157 return $result;
158 }
159
160 protected function checkInActiveOrder($id, $list)
161 {
162 $r = new \Bitrix\Sale\Result();
163
164 if(count($list)>0)
165 {
166 if(in_array($id, $list))
167 {
168 $r->addError(new Error(Loc::getMessage('SALE_ORDER_APP_REST_SENDER_Y')));
169 }
170 }
171
172 return $r;
173 }
174}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
activityBatchAction(array $list, $total=0, $start=0)
Definition stepper.php:19