Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
deliveryrequest.php
1<?php
2
4
8
14{
21 public function createAction(array $shipmentIds, array $additional = [], int $deliveryId = null)
22 {
23 if (!$this->checkPermission('U'))
24 {
25 return null;
26 }
27
28 if (is_null($deliveryId))
29 {
30 if ($shipmentIds && $shipmentIds[0])
31 {
32 $shipment = ShipmentRepository::getInstance()->getById((int)$shipmentIds[0]);
33 if ($shipment && $shipment->getDelivery())
34 {
35 $deliveryId = $shipment->getDelivery()->getId();
36 }
37 }
38 }
39
41 $result = Requests\Manager::createDeliveryRequest($deliveryId, $shipmentIds, $additional);
42
43 if (!$result->isSuccess())
44 {
45 $this->addErrors($result->getErrors());
46 return null;
47 }
48
49 return [
50 'result' => true,
51 'message' => $this->getMessageFromResult($result)
52 ];
53 }
54
61 public function executeAction(int $requestId, string $actionType, array $additional = [])
62 {
63 if (!$this->checkPermission('U'))
64 {
65 return null;
66 }
67
69 $result = Requests\Manager::executeDeliveryRequestAction($requestId, $actionType, $additional);
70
71 if (!$result->isSuccess())
72 {
73 $this->addErrors($result->getErrors());
74 return null;
75 }
76
77 return [
78 'result' => true,
79 'message' => $this->getMessageFromResult($result)
80 ];
81 }
82
87 public function deleteAction(int $requestId)
88 {
89 if (!$this->checkPermission('U'))
90 {
91 return null;
92 }
93
95 $result = Requests\Manager::deleteDeliveryRequest($requestId);
96
97 if (!$result->isSuccess())
98 {
99 $this->addErrors($result->getErrors());
100 return null;
101 }
102
103 return [
104 'result' => true,
105 'message' => $this->getMessageFromResult($result)
106 ];
107 }
108
113 private function getMessageFromResult(Requests\Result $result): string
114 {
115 return implode(
116 '; ',
117 array_map(
118 function ($message)
119 {
120 return $message->getMessage();
121 },
122 $result->getMessages()
123 )
124 );
125 }
126
131 private function checkPermission(string $permissionType): bool
132 {
133 $result = $GLOBALS['APPLICATION']->GetGroupRight('sale') >= $permissionType;
134
135 if (!$result)
136 {
137 $this->addError(new Error('Access denied'));
138 }
139
140 return $result;
141 }
142}
$GLOBALS['____1444769544']
Definition license.php:1