Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/wbs24.hitproducts/lib/ |
Upload File : |
<? namespace Wbs24\Hitproducts; use Bitrix\Main\Loader; class Mark { protected $main; protected $moduleId; protected $wrappers; protected $property; protected $salePropertyValue; protected $newPropertyValue; protected $propertyValueTypeToIds = []; public const SALE_MARK_TYPE = "SALE"; public const NEW_MARK_TYPE = "NEW"; public function __construct($objects = []) { $this->main = $objects['Main'] ?? new Main(); $this->moduleId = $this->main->getModuleId(); $this->wrappers = new Wrappers($objects, [ 'Option', 'CIBlockElement', 'CIBlockProperty', ]); $this->property = $this->wrappers->Option->get($this->moduleId, "PROPERTY"); $this->salePropertyValue = $this->wrappers->Option->get($this->moduleId, "SALE_PROPERTY_VALUE"); $this->newPropertyValue = $this->wrappers->Option->get($this->moduleId, "NEW_PROPERTY_VALUE"); } public function set($id, $iblockId, $types) { $valueTypeToIds = $this->getValueTypeToIds($iblockId); $values = $this->getValues($id, $iblockId); foreach ($types as $valueType) { $valueId = $valueTypeToIds[$valueType]; if (!in_array($valueId, $values)) { $values[] = $valueId; } } $this->setValues($id, $values); } public function unset($id, $iblockId, $types) { $valueTypeToIds = $this->getValueTypeToIds($iblockId); $values = $this->getValues($id, $iblockId); foreach ($types as $valueType) { $valueId = $valueTypeToIds[$valueType]; $valueKey = array_search($valueId, $values); if ($valueKey !== false) { unset($values[$valueKey]); } } if ($values == []) $values[] = ''; $this->setValues($id, $values); } protected function getValueTypeToIds($iblockId) { $valueIds = $this->propertyValueTypeToIds; if (!$valueIds) { $result = $this->wrappers->CIBlockProperty->GetPropertyEnum($this->property, [], ["IBLOCK_ID" => $iblockId]); while($prop = $result->GetNext()) { if ($prop['VALUE'] == $this->salePropertyValue) { $valueIds[self::SALE_MARK_TYPE] = $prop['ID']; } if ($prop['VALUE'] == $this->newPropertyValue) { $valueIds[self::NEW_MARK_TYPE] = $prop['ID']; } } $this->propertyValueTypeToIds = $valueIds; } return $valueIds; } protected function getValues($id, $iblockId) { $result = $this->wrappers->CIBlockElement->GetProperty($iblockId, $id, [], ["CODE" => $this->property]); $values = []; while ($prop = $result->Fetch()) { $values[] = $prop['VALUE']; } return $values; } protected function setValues($id, $values) { $this->wrappers->CIBlockElement->SetPropertyValuesEx($id, false, array($this->property => $values)); } }