26 $result =
new Main\Entity\Result();
28 $propertyId = (int)$propertyId;
31 $result->addError(
new Main\
Error(
39 $result->addError(
new Main\
Error(
45 if ($features ===
null)
47 $result->addError(
new Main\
Error(
54 foreach ($features as $row)
56 $row[
'PROPERTY_ID'] = $propertyId;
57 $internalResult = Iblock\PropertyFeatureTable::add($row);
58 if (!$internalResult->isSuccess())
60 $result->addErrors($internalResult->getErrors());
64 $resultIds[] = $internalResult->getId();
66 unset($internalResult, $row);
68 $result->setData($resultIds);
81 $result =
new Main\Entity\Result();
83 $propertyId = (int)$propertyId;
86 $result->addError(
new Main\
Error(
94 $result->addError(
new Main\
Error(
101 if ($features ===
null)
103 $result->addError(
new Main\
Error(
110 $iterator = Iblock\PropertyFeatureTable::getList([
112 'filter' => [
'=PROPERTY_ID' => $propertyId]
114 while ($row = $iterator->fetch())
118 unset($row, $iterator);
120 foreach ($features as $index => $row)
122 if (isset($currentList[$index]))
124 $internalResult = Iblock\PropertyFeatureTable::update(
125 $currentList[$index][
'ID'],
126 [
'IS_ENABLED' => $row[
'IS_ENABLED']]
131 $row[
'PROPERTY_ID'] = $propertyId;
132 $internalResult = Iblock\PropertyFeatureTable::add($row);
134 if (!$internalResult->isSuccess())
136 $result->addErrors($internalResult->getErrors());
140 unset($internalResult, $index, $row);
155 $result =
new Main\Entity\Result();
157 $propertyId = (int)$propertyId;
158 if ($propertyId <= 0)
160 $result->addError(
new Main\
Error(
166 if (empty($features))
168 $result->addError(
new Main\
Error(
174 if ($features ===
null)
176 $result->addError(
new Main\
Error(
184 $iterator = Iblock\PropertyFeatureTable::getList([
186 'filter' => [
'=PROPERTY_ID' => $propertyId]
188 while ($row = $iterator->fetch())
190 $row[
'ID'] = (int)$row[
'ID'];
192 $idList[$row[
'ID']] = $row[
'ID'];
194 unset($row, $iterator);
196 foreach ($features as $index => $row)
198 if (isset($currentList[$index]))
200 $internalResult = Iblock\PropertyFeatureTable::update(
201 $currentList[$index][
'ID'],
202 [
'IS_ENABLED' => $row[
'IS_ENABLED']]
204 if ($internalResult->isSuccess())
205 unset($idList[$currentList[$index][
'ID']]);
209 $row[
'PROPERTY_ID'] = $propertyId;
210 $internalResult = Iblock\PropertyFeatureTable::add($row);
212 if (!$internalResult->isSuccess())
214 $result->addErrors($internalResult->getErrors());
218 unset($internalResult, $index, $row);
223 $conn = Main\Application::getConnection();
224 $helper = $conn->getSqlHelper();
226 ' where '.$helper->quote(
'PROPERTY_ID').
' = '.$propertyId.
227 ' and '.$helper->quote(
'ID').
' in ('.implode(
',', $idList).
')';
228 $conn->queryExecute($query);
229 unset($query, $helper, $conn);
248 foreach ($list as $rawRow)
270 if (!isset($feature[
'MODULE_ID']))
272 $feature[
'MODULE_ID'] = trim((
string)$feature[
'MODULE_ID']);
273 if ($feature[
'MODULE_ID'] ===
'')
275 if (!isset($feature[
'FEATURE_ID']))
277 $feature[
'FEATURE_ID'] = trim((
string)$feature[
'FEATURE_ID']);
278 if ($feature[
'FEATURE_ID'] ===
'')
280 if (!isset($feature[
'IS_ENABLED']))
282 $feature[
'IS_ENABLED'] = trim((
string)$feature[
'IS_ENABLED']);
283 if ($feature[
'IS_ENABLED'] !==
'Y' && $feature[
'IS_ENABLED'] !==
'N')
287 'MODULE_ID' => $feature[
'MODULE_ID'],
288 'FEATURE_ID' => $feature[
'FEATURE_ID'],
289 'IS_ENABLED' => $feature[
'IS_ENABLED']
299 public static function getIndex(array $feature): string
301 return $feature[
'MODULE_ID'].
':'.$feature[
'FEATURE_ID'];
313 $parts = explode(
':', $index);
314 if (count($parts) === 2)
317 'MODULE_ID' => $parts[0],
318 'FEATURE_ID' => $parts[1],
334 $result = self::getIblockFeatureList();
338 __CLASS__.
'::'.self::EVENT_ID_FEATURE_LIST,
339 [
'property' => $property,
'description' => $description]
342 foreach($event->getResults() as $eventResult)
344 if ($eventResult->getType() !== Main\EventResult::SUCCESS)
346 $list = $eventResult->getParameters();
347 if (empty($list) || !is_array($list))
349 foreach ($list as $item)
351 if (empty($item) || !is_array($item))
353 $item = self::prepareFeatureDescription($item);
378 $iblockId = (int)$iblockId;
385 '=MODULE_ID' =>
'iblock',
386 '=FEATURE_ID' => self::FEATURE_ID_LIST_PAGE_SHOW
405 $iblockId = (int)$iblockId;
412 '=MODULE_ID' =>
'iblock',
413 '=FEATURE_ID' => self::FEATURE_ID_DETAIL_PAGE_SHOW
450 if (Main\
Config\Option::get(
'iblock',
'property_features_enabled') !==
'Y')
459 if (!isset($filter[
'=MODULE_ID']) || !isset($filter[
'=FEATURE_ID']))
464 $getCode = (isset($parameters[
'CODE']) && $parameters[
'CODE'] ==
'Y');
467 $filter[
'=PROPERTY.IBLOCK_ID'] = $iblockId;
468 $filter[
'=PROPERTY.ACTIVE'] =
'Y';
469 $filter[
'=IS_ENABLED'] =
'Y';
470 $iterator = Iblock\PropertyFeatureTable::getList([
472 'IBLOCK_PROPERTY_ID' =>
'PROPERTY.ID',
473 'IBLOCK_PROPERTY_CODE' =>
'PROPERTY.CODE',
474 'IBLOCK_PROPERTY_SORT' =>
'PROPERTY.SORT',
478 'IBLOCK_PROPERTY_SORT' =>
'ASC',
479 'IBLOCK_PROPERTY_ID' =>
'ASC',
482 while ($row = $iterator->fetch())
484 $result[(int)$row[
'IBLOCK_PROPERTY_ID']] = self::getPropertyCode(
486 'ID' => $row[
'IBLOCK_PROPERTY_ID'],
487 'CODE' => $row[
'IBLOCK_PROPERTY_CODE']
492 unset($row, $iterator);
493 unset($filter, $getCode);
495 return (!empty($result) ? array_values($result) :
null);
505 protected static function getPropertyCode(array $property,
bool $getCode =
false): string
507 $property[
'ID'] = (string)$property[
'ID'];
510 $property[
'CODE'] = trim((
string)$property[
'CODE']);
511 if ($property[
'CODE'] ===
'')
513 $property[
'CODE'] =
null;
516 return ($property[
'CODE'] ?? $property[
'ID']);
520 return $property[
'ID'];
530 private static function prepareFeatureDescription(array $row): array
535 !isset($row[
'MODULE_ID'])
536 || !isset($row[
'FEATURE_ID'])
537 || !isset($row[
'FEATURE_NAME'])
542 'MODULE_ID' => $row[
'MODULE_ID'],
543 'FEATURE_ID' => $row[
'FEATURE_ID'],
544 'FEATURE_NAME' => $row[
'FEATURE_NAME']
554 private static function getIblockFeatureList(): array
558 'MODULE_ID' =>
'iblock',
560 'FEATURE_NAME' =>
Loc::getMessage(
'PROPERTY_FEATURE_NAME_LIST_PAGE_SHOW')
563 'MODULE_ID' =>
'iblock',
565 'FEATURE_NAME' =>
Loc::getMessage(
'PROPERTY_FEATURE_NAME_DETAIL_PAGE_SHOW')
577 return (Main\
Config\Option::get(
'iblock',
'property_features_enabled') ==
'Y');
587 return Iblock\PropertyFeatureTable::getCount([], [
'ttl' => 86400]) > 0;
static getIndex(array $feature)
static getDetailPageShowProperties($iblockId, array $parameters=[])
const FEATURE_ID_DETAIL_PAGE_SHOW
static getPropertyCode(array $property, bool $getCode=false)
static setFeatures($propertyId, array $features)
static updateFeatures($propertyId, array $features)
static isPropertyFeaturesExist()
static getPropertyFeatureList(array $property, array $description=[])
static checkFeature(array $feature)
static getListPageShowPropertyCodes($iblockId, array $parameters=[])
const FEATURE_ID_LIST_PAGE_SHOW
static addFeatures($propertyId, array $features)
static checkFeatureList(array $list)
static isEnabledFeatures()
const EVENT_ID_FEATURE_LIST
static parseIndex(string $index)
static getFilteredPropertyCodes(int $iblockId, array $filter, array $parameters=[])
static getDetailPageShowPropertyCodes($iblockId, array $parameters=[])
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)