8namespace Bitrix\Sale\Location\Name;
11use Bitrix\Main\Entity;
12use Bitrix\Main\Localization\Loc;
14use Bitrix\Sale\Location\Util\Assert;
16Loc::loadMessages(__FILE__);
36 $primaryOwner = Assert::expectIntegerPositive($primaryOwner,
'$primaryOwner');
39 if(!is_array($names) || empty($names))
42 $langField = static::getLanguageFieldName();
43 $refField = static::getReferenceFieldName();
45 foreach($names as $lid =>
$name)
47 $lid = Assert::castTrimLC($lid);
50 foreach(
$name as $arg)
61 $res = static::add(array_merge(
64 $refField => $primaryOwner
69 if(!
$res->isSuccess())
72 Loc::getMessage(
'SALE_LOCATION_NAME_NAME_ENTITY_CANNOT_ADD_NAMES_EXCEPTION').
76 $res->getErrorMessages()).
83 $GLOBALS[
'CACHE_MANAGER']->ClearByTag(
'sale-location-data');
95 $primaryOwner = Assert::expectIntegerPositive($primaryOwner,
'$primaryOwner');
100 $langField = static::getLanguageFieldName();
101 $refField = static::getReferenceFieldName();
105 'filter' =>
array($refField => $primaryOwner),
106 'select' =>
array(
'ID', $langField)
109 while($item =
$res->Fetch())
110 $existed[$item[$langField]] = $item[
'ID'];
112 foreach($names as $lid =>
$name)
114 $lid = Assert::castTrimLC($lid);
117 foreach(
$name as $arg)
126 if(!isset($existed[$lid]))
130 $res = static::add(array_merge(
133 $refField => $primaryOwner
137 if(!
$res->isSuccess())
138 throw new Main\SystemException(Loc::getMessage(
'SALE_LOCATION_NAME_NAME_ENTITY_CANNOT_ADD_NAMES_EXCEPTION'));
145 $res = static::delete($existed[$lid]);
146 if(!
$res->isSuccess())
147 throw new Main\SystemException(Loc::getMessage(
'SALE_LOCATION_NAME_NAME_ENTITY_CANNOT_DELETE_NAMES_EXCEPTION'));
151 $res = static::update($existed[$lid],
$name);
152 if(!
$res->isSuccess())
153 throw new Main\SystemException(Loc::getMessage(
'SALE_LOCATION_NAME_NAME_ENTITY_CANNOT_UPDATE_NAMES_EXCEPTION'));
167 $primaryOwner = Assert::expectIntegerPositive($primaryOwner,
'$primaryOwner');
170 $listRes = static::getList(
array(
171 'filter' =>
array(static::getReferenceFieldName() => $primaryOwner),
172 'select' =>
array(
'ID')
176 while($item = $listRes->fetch())
178 $res = static::delete($item[
'ID']);
179 if(!
$res->isSuccess())
180 throw new Main\SystemException(Loc::getMessage(
'SALE_LOCATION_NAME_NAME_ENTITY_CANNOT_DELETE_NAMES_EXCEPTION'));
193 $primaryOwner = Assert::expectIntegerPositive($primaryOwner,
'$primaryOwner');
195 if(!is_array($names))
198 if(!is_array($behaviour))
199 $behaviour =
array();
200 if(!isset($behaviour[
'TREAT_EMPTY_AS_ABSENT']))
201 $behaviour[
'TREAT_EMPTY_AS_ABSENT'] =
true;
207 foreach($names as $lid =>
$data)
209 $namesLC[Assert::castTrimLC($lid)] =
$data;
213 $langField = static::getLanguageFieldName();
214 $refField = static::getReferenceFieldName();
216 $names2Update =
array();
217 $res = static::getList(
array(
'filter' =>
array(
'='.$refField => $primaryOwner)));
218 while($item =
$res->fetch())
220 $isEmpty = static::checkEmpty($item);
222 if($isEmpty && $behaviour[
'TREAT_EMPTY_AS_ABSENT'])
224 $names2Update[$item[
'ID']] = $names[$item[$langField]];
227 unset($names[$item[$langField]]);
230 foreach($names as $lid =>
$data)
232 $data[$langField] = $lid;
233 $data[$refField] = $primaryOwner;
238 foreach($names2Update as $id =>
$data)
240 static::update($id,
$data);
256 $dbConnection->query(
'delete from '.static::getTableName().
' where '.static::getReferenceFieldName().
' in ('.$sql.
')');
261 return !is_array($item) || (string) $item[
'NAME'] ==
'';
static getConnection($name="")
static deleteMultipleForOwner($primaryOwner)
static getLanguageFieldName()
static addMultipleForOwner($primaryOwner, $names=array())
static getReferenceFieldName()
static deleteMultipleByParentRangeSql($sql)
static updateMultipleForOwner($primaryOwner, $names)
static addAbsentForOwner($primaryOwner, $names, $behaviour=array('TREAT_EMPTY_AS_ABSENT'=> true))
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$GLOBALS['____1690880296']