Manager::createCategory

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

	$this->category->create();

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

	$createdCategoryId = $this->category->getId();
	$rooms = $this->category->getRooms();
	if(!empty($rooms) && $createdCategoryId)
	{
		foreach ($rooms as &$room)
		{
			$room = (int)$room;
		}
		global $DB;
		$tableName = LocationTable::getTableName();
		$roomsIds = implode(',', $rooms);

		$sqlStr = "
			UPDATE $tableName
			SET CATEGORY_ID = $createdCategoryId
			WHERE SECTION_ID IN ($roomsIds)
		";
		$result = $DB->Query($sqlStr, true);
		if(!$result)
		{
			$this->category->delete();
			$this->addError(new Error('An error occurred while saving the category'));
		}
	}

	return $this;
}

Добавить комментарий