1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
defaultsite.php
См. документацию.
1
<?php
8
namespace
Bitrix\Sale\Location;
9
10
use Bitrix\Main;
11
use Bitrix\Main\Entity;
12
use Bitrix\Main\Localization\Loc;
13
14
use Bitrix\Sale\Location\Util\Assert;
15
16
Loc::loadMessages(__FILE__);
17
34
class
DefaultSiteTable
extends
Entity\DataManager
35
{
36
public
static
function
getFilePath
()
37
{
38
return
__FILE__;
39
}
40
41
public
static
function
getTableName
()
42
{
43
return
'b_sale_loc_def2site'
;
44
}
45
49
public
static
function
addMultipleForOwner
(
$siteId
, $locationCodeList =
array
())
50
{
51
$siteId
= static::checkSiteId(
$siteId
);
52
53
$existed =
array
();
54
$res
= self::getList(
array
(
'filter'
=>
array
(
'SITE_ID'
=>
$siteId
)));
55
while
($item =
$res
->fetch())
56
$existed[$item[
'LOCATION_CODE'
]] =
true
;
57
58
if
(is_array($locationCodeList))
59
{
60
foreach
($locationCodeList as
$location
)
61
{
62
if
(!isset($existed[
$location
]))
63
{
64
$opRes = self::add(
array
(
65
'SITE_ID'
=>
$siteId
,
66
'LOCATION_CODE'
=>
$location
[
'LOCATION_CODE'
],
67
'SORT'
=>
$location
[
'SORT'
],
68
));
69
if
(!$opRes->isSuccess())
70
throw
new
Main\SystemException
(Loc::getMessage(
'SALE_LOCATION_DEFAULTSITE_ENTITY_CANNOT_ADD_EXCEPTION'
));
71
}
72
}
73
}
74
else
75
throw
new
Main\SystemException
(
'Code list is not a valid array'
);
76
77
$GLOBALS
[
'CACHE_MANAGER'
]->ClearByTag(
'sale-location-data'
);
78
}
79
83
public
static
function
updateMultipleForOwner
(
$siteId
, $locationCodeList =
array
(), $behaviour =
array
(
'REMOVE_ABSENT'
=>
true
))
84
{
85
$siteId
= static::checkSiteId(
$siteId
);
86
87
if
(!is_array($locationCodeList))
88
throw
new
Main\SystemException
(
'Code list is not a valid array'
);
89
90
// throw away duplicates and make index array
91
$index =
array
();
92
$locationCodeListTemp =
array
();
93
foreach
($locationCodeList as
$location
)
94
{
95
$index[
$location
[
'LOCATION_CODE'
]] =
true
;
96
$locationCodeListTemp[
$location
[
'LOCATION_CODE'
]] =
$location
;
97
}
98
$locationCodeList = $locationCodeListTemp;
99
100
$res
= self::getList(
array
(
'filter'
=>
array
(
'SITE_ID'
=>
$siteId
)));
101
$update =
array
();
102
$delete =
array
();
103
while
($item =
$res
->Fetch())
104
{
105
if
(!isset($index[$item[
'LOCATION_CODE'
]]))
106
$delete[$item[
'LOCATION_CODE'
]] =
true
;
107
else
108
{
109
unset($index[$item[
'LOCATION_CODE'
]]);
110
$update[$item[
'LOCATION_CODE'
]] =
true
;
111
}
112
}
113
114
if
($behaviour[
'REMOVE_ABSENT'
])
115
{
116
foreach
($delete as
$code
=> $void)
117
{
118
$res
= self::delete(
array
(
'SITE_ID'
=>
$siteId
,
'LOCATION_CODE'
=>
$code
));
119
if
(!
$res
->isSuccess())
120
throw
new
Main\SystemException
(Loc::getMessage(
'SALE_LOCATION_DEFAULTSITE_ENTITY_CANNOT_DELETE_EXCEPTION'
));
121
}
122
}
123
124
foreach
($update as
$code
=> $void)
125
{
126
$res
= self::update(
array
(
'SITE_ID'
=>
$siteId
,
'LOCATION_CODE'
=>
$code
),
array
(
'SORT'
=> $locationCodeList[
$code
][
'SORT'
]));
127
if
(!
$res
->isSuccess())
128
throw
new
Main\SystemException
(Loc::getMessage(
'SALE_LOCATION_DEFAULTSITE_ENTITY_CANNOT_UPDATE_EXCEPTION'
));
129
}
130
131
foreach
($index as
$code
=> $void)
132
{
133
$res
= self::add(
array
(
134
'SORT'
=> $locationCodeList[
$code
][
'SORT'
],
135
'SITE_ID'
=>
$siteId
,
136
'LOCATION_CODE'
=>
$code
137
));
138
if
(!
$res
->isSuccess())
139
throw
new
Main\SystemException
(Loc::getMessage(
'SALE_LOCATION_DEFAULTSITE_ENTITY_CANNOT_ADD_EXCEPTION'
));
140
}
141
142
$GLOBALS
[
'CACHE_MANAGER'
]->ClearByTag(
'sale-location-data'
);
143
}
144
145
private
static
function
checkSiteId(
$siteId
)
146
{
147
$siteId
= Assert::expectStringNotNull(
$siteId
,
'$siteId'
);
148
149
$res
=
Main\SiteTable::getList
(
array
(
'filter'
=>
array
(
'LID'
=>
$siteId
)))->fetch();
150
if
(!
$res
)
151
throw
new
Main\ArgumentOutOfRangeException
(Loc::getMessage(
'SALE_LOCATION_DEFAULTSITE_ENTITY_SITE_ID_UNKNOWN_EXCEPTION'
));
152
153
return
$siteId
;
154
}
155
156
public
static
function
getMap
()
157
{
158
return
array
(
159
160
'SORT'
=>
array
(
161
'data_type'
=>
'integer'
,
162
'title'
=> Loc::getMessage(
'SALE_LOCATION_DEFAULTSITE_ENTITY_SORT_FIELD'
),
163
'default_value'
=>
'100'
164
),
165
'LOCATION_CODE'
=>
array
(
166
'data_type'
=>
'string'
,
167
'required'
=>
true
,
168
'primary'
=>
true
,
169
'title'
=> Loc::getMessage(
'SALE_LOCATION_DEFAULTSITE_ENTITY_LOCATION_ID_FIELD'
)
170
),
171
'SITE_ID'
=>
array
(
172
'data_type'
=>
'string'
,
173
'required'
=>
true
,
174
'primary'
=>
true
,
175
'title'
=> Loc::getMessage(
'SALE_LOCATION_DEFAULTSITE_ENTITY_SITE_ID_FIELD'
)
176
),
177
178
// virtual
179
'LOCATION'
=>
array
(
180
'data_type'
=>
'\Bitrix\Sale\Location\Location'
,
181
'reference'
=>
array
(
182
'=this.LOCATION_CODE'
=>
'ref.CODE'
183
)
184
),
185
186
'SITE'
=>
array
(
187
'data_type'
=>
'\Bitrix\Main\Site'
,
188
'reference'
=>
array
(
189
'=this.SITE_ID'
=>
'ref.LID'
190
)
191
)
192
);
193
}
194
}
Bitrix\Main\ArgumentOutOfRangeException
Определения
ArgumentOutOfRangeException.php:9
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Определения
datamanager.php:431
Bitrix\Main\SystemException
Определения
SystemException.php:9
Bitrix\Sale\Location\DefaultSiteTable
Определения
defaultsite.php:35
Bitrix\Sale\Location\DefaultSiteTable\getMap
static getMap()
Определения
defaultsite.php:156
Bitrix\Sale\Location\DefaultSiteTable\getFilePath
static getFilePath()
Определения
defaultsite.php:36
Bitrix\Sale\Location\DefaultSiteTable\addMultipleForOwner
static addMultipleForOwner($siteId, $locationCodeList=array())
Определения
defaultsite.php:49
Bitrix\Sale\Location\DefaultSiteTable\updateMultipleForOwner
static updateMultipleForOwner($siteId, $locationCodeList=array(), $behaviour=array('REMOVE_ABSENT'=> true))
Определения
defaultsite.php:83
Bitrix\Sale\Location\DefaultSiteTable\getTableName
static getTableName()
Определения
defaultsite.php:41
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$code
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения
options.php:195
$siteId
$siteId
Определения
ajax.php:8
Bitrix\Main\$GLOBALS
$GLOBALS['____1690880296']
Определения
license.php:1
$location
$location
Определения
options.php:2729
bitrix
modules
sale
lib
location
defaultsite.php
Создано системой
1.14.0