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();
104 $res = static::getList(array(
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())
145 $res = static::delete($existed[$lid]);
146 if(!$res->isSuccess())
151 $res = static::update($existed[$lid], $name);
152 if(!$res->isSuccess())
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())
191 public static function addAbsentForOwner($primaryOwner, $names, $behaviour = array(
'TREAT_EMPTY_AS_ABSENT' =>
true))
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);