Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
tracking.php
1<?php
2
3
5
10
11
13{
14 private $manager;
15
16 const PERMISSION_READ = 'D';
17 const PERMISSION_WRITE = 'W';
18
19 public function __construct(Request $request = null)
20 {
21 $this->manager = Manager::getInstance();
22 parent::__construct($request);
23 }
24
25 public function getStatusByShipmentIdAction(int $shipmentId, string $trackingNumber = '')
26 {
27 if($shipmentId <= 0)
28 {
29 $this->addError(new Error(Loc::getMessage('SALE_CONTROLLER_TRACKING_ERROR_SHIPMENT_ZERO')));
30 return null;
31 }
32
33 if($trackingNumber == '')
34 {
35 $this->addError(new Error(Loc::getMessage('SALE_CONTROLLER_TRACKING_ERROR_DELETE_STATUS')));
36 return null;
37 }
38
39 if(!$this->checkPermission(self::PERMISSION_READ))
40 {
41 return null;
42 }
43
44 $result = null;
45 $res = $this->manager->getStatusByShipmentId($shipmentId, $trackingNumber);
46
47 if($res->isSuccess())
48 {
49 $lastChange = '';
50
51 if($res->lastChangeTimestamp > 0)
52 {
53 $lastChange = \Bitrix\Main\Type\DateTime::createFromTimestamp(
54 $res->lastChangeTimestamp
55 )->toString();
56 }
57
58 $result = [
59 'status' => $res->status,
60 'statusName' => Manager::getStatusName($res->status),
61 'description' => $res->description,
62 'lastChange' => $lastChange
63 ];
64
65 if($this->checkPermission(self::PERMISSION_WRITE))
66 {
67 $res = $this->manager->updateShipment($shipmentId, $res);
68
69 if(!$res->isSuccess())
70 {
71 $this->addErrors($res->getErrors());
72 }
73 }
74 }
75 else
76 {
77 $this->addErrors($res->getErrors());
78 }
79
80 return $result;
81 }
82
83 protected function checkPermission($permissionType)
84 {
85 $result = self::getApplication()->GetGroupRight("sale") >= $permissionType;
86
87 if(!$result)
88 {
89 $this->addError(new Error('Access denied'));
90 }
91
92 return $result;
93 }
94
95 protected static function getApplication()
96 {
98 global $APPLICATION;
99
100 return $APPLICATION;
101 }
102}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
__construct(Request $request=null)
Definition tracking.php:19
getStatusByShipmentIdAction(int $shipmentId, string $trackingNumber='')
Definition tracking.php:25
checkPermission($permissionType)
Definition tracking.php:83