Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
base.php
1
<?php
2
namespace
Bitrix\Sale\Exchange\Integration\Rest\Cmd
;
3
4
use
Bitrix\Main\ArgumentException
;
5
use
Bitrix\Main\Error
;
6
use
Bitrix\Main\Web\Uri
;
7
use
Bitrix\Sale\Exchange\Integration
;
8
use
Bitrix\Sale\Internals\Fields
;
9
use
Bitrix\Sale\Result
;
10
11
class
Base
12
{
13
const
DIRECTORY_PAGE
=
'/rest/'
;
14
15
protected
$query
;
16
protected
$page
;
17
protected
$directory
;
18
19
private
$token;
20
21
public
function
__construct
()
22
{
23
$this->query =
new
Fields
();
24
25
$this->
initialize
(
new
Integration\App\IntegrationB24());
26
}
27
28
public
function
setField
($name, $value)
29
{
30
$this->query->set($name, $value);
31
return
$this;
32
}
33
public
function
setFieldsValues
($values)
34
{
35
if
(is_array($values))
36
{
37
$this->query->setValues($values);
38
}
39
return
$this;
40
}
41
public
function
getFieldsValues
()
42
{
43
return
$this->query->getValues();
44
}
45
public
function
setDirectory
($directory)
46
{
47
$this->directory =
$directory
;
48
return
$this;
49
}
50
public
function
setPageByType
($type)
51
{
52
$registry =
Registry::getRegistry
();
53
$page
= isset($registry[$type]) ? $registry[$type]:
null
;
54
55
if
(is_null(
$page
))
56
{
57
throw
new
ArgumentException
(
"Unsupported cmd type: {$type}"
);
58
}
59
60
$this->
setPage
(
$page
);
61
return
$this;
62
}
63
public
function
setPage
($page)
64
{
65
$this->page =
$page
;
66
return
$this;
67
}
68
public
function
build
()
69
{
70
$uri =
new
Uri
($this->
buildDirectoryPage
());
71
return
$uri
72
->addParams($this->
getFieldsValues
())
73
->getUri();
74
}
75
public
function
call
()
76
{
77
$r =
new
Result
();
78
try
79
{
80
$response = (
new
Integration\Rest\Client\TokenClient
($this->token))
81
->
call
(
82
$this->
buildDirectoryPage
(), $this->
getFieldsValues
());
83
}
84
catch
(\
Exception
$exception)
85
{
86
return
$r->addError(
new
Error
(
"Error: "
.$exception->getMessage()));
87
}
88
89
if
(isset($response[
"error"
]))
90
{
91
return
$r->addError(
new
Error
(
92
"Server Error: "
.$response[
"error_description"
].
" ("
.$response[
"error"
].
")"
93
));
94
}
95
else
if
(!isset($response[
"result"
]))
96
{
97
return
$r->addError(
new
Error
(
"Wrong Server Response."
));
98
}
99
100
return
$r->setData([
'DATA'
=>$response]);
101
}
102
public
function
fill
()
103
{
104
return
$this;
105
}
106
107
protected
function
buildDirectoryPage
()
108
{
109
return
$this->directory.$this->page;
110
}
111
112
protected
function
initialize
(Integration\App\
Base
$application)
113
{
114
$this->token = static::getAppToken($application->getCode());
115
}
116
117
private
static
function
getAppToken($guid)
118
{
119
if
(!is_string($guid) || empty($guid))
120
{
121
return
null
;
122
}
123
124
$token = Integration\Entity\B24integrationTokenTable::getList([
125
"select"
=> [
"*"
],
126
"filter"
=> [
"=GUID"
=> $guid]
127
])->fetchObject();
128
129
return
$token ? $token :
null
;
130
}
131
}
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\DB\Exception
Definition
exception.php:11
Bitrix\Main\DB\Result
Definition
result.php:19
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\Sale\Exchange\Integration\Admin\Registry\getRegistry
static getRegistry()
Definition
registry.php:23
Bitrix\Sale\Exchange\Integration\CRM\Placement\Base
Definition
base.php:11
Bitrix\Sale\Exchange\Integration\Rest\Client\TokenClient
Definition
tokenclient.php:8
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\__construct
__construct()
Definition
base.php:21
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\$page
$page
Definition
base.php:16
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\$directory
$directory
Definition
base.php:17
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\buildDirectoryPage
buildDirectoryPage()
Definition
base.php:107
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\setPage
setPage($page)
Definition
base.php:63
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\build
build()
Definition
base.php:68
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\fill
fill()
Definition
base.php:102
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\setFieldsValues
setFieldsValues($values)
Definition
base.php:33
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\setDirectory
setDirectory($directory)
Definition
base.php:45
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\getFieldsValues
getFieldsValues()
Definition
base.php:41
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\setPageByType
setPageByType($type)
Definition
base.php:50
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\initialize
initialize(Integration\App\Base $application)
Definition
base.php:112
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\DIRECTORY_PAGE
const DIRECTORY_PAGE
Definition
base.php:13
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\setField
setField($name, $value)
Definition
base.php:28
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\call
call()
Definition
base.php:75
Bitrix\Sale\Exchange\Integration\Rest\Cmd\Base\$query
$query
Definition
base.php:15
Bitrix\Sale\Internals\Fields
Definition
fields.php:6
Bitrix\Sale\Result
Definition
result.php:9
Bitrix\Sale\Exchange\Integration\Rest\Cmd
Definition
base.php:2
Bitrix\Sale\Exchange\Integration
modules
sale
lib
exchange
integration
rest
cmd
base.php
Создано системой
1.10.0