• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/rooms/categories/manager.php
  • Класс: BitrixCalendarRoomsCategoriesManager
  • Вызов: Manager::updateCategory
public function updateCategory(): Manager
{
	if ($this->getError())
	{
		return $this;
	}

	$this->category->update();

	if ($this->category->getError())
	{
		$this->addError($this->category->getError());
	}

	global $DB;
	$tableName = LocationTable::getTableName();
	$categoryId = $this->category->getId();
	$rooms = $this->category->getRooms();

	$result = true;

	if(isset($rooms['toAddCategory']))
	{
		foreach ($rooms['toAddCategory'] as &$toAddId)
		{
			$toAddId = (int)$toAddId;
		}
		$toAddIds = implode(',', $rooms['toAddCategory']);
		$sqlStr = "
			UPDATE $tableName
			SET CATEGORY_ID = $categoryId
			WHERE SECTION_ID IN ($toAddIds)
		";
		$result = $DB->Query($sqlStr, true);
	}

	if($result && isset($rooms['toRemoveCategory']))
	{
		foreach ($rooms['toRemoveCategory'] as &$toRemoveId)
		{
			$toRemoveId = (int)$toRemoveId;
		}
		$toRemoveIds = implode(',', $rooms['toRemoveCategory']);
		$sqlStr = "
			UPDATE $tableName
			SET CATEGORY_ID = null
			WHERE SECTION_ID IN ($toRemoveIds)
		";
		$result = $DB->Query($sqlStr, true);
	}

	if(!$result)
	{
		$this->addError(new Error('An error occurred while saving the category'));
	}

	return $this;
}