• Модуль: rest
  • Путь к файлу: ~/bitrix/modules/rest/lib/api/placement.php
  • Класс: BitrixRestApiPlacement
  • Вызов: Placement::unbind
static function unbind($params, $n, CRestServer $server)
{
	static::checkPermission($server);

	$params = array_change_key_case($params, CASE_UPPER);

	if (!is_string($params['PLACEMENT']))
	{
		throw new ArgumentTypeException('PLACEMENT', 'string');
	}

	$placement = toUpper($params['PLACEMENT']);
	$placementHandler = $params['HANDLER'];

	if ($placement == '')
	{
		throw new ArgumentNullException("PLACEMENT");
	}

	$cnt = 0;

	$placementList = static::getPlacementList($server);

	if (array_key_exists($placement, $placementList) && !$placementList[$placement]['private'])
	{
		$appInfo = static::getApplicationInfo($server);

		$filter = array(
			'=APP_ID' => $appInfo["ID"],
			'=PLACEMENT' => $placement,
		);

		if (array_key_exists('USER_ID', $params))
		{
			$filter['USER_ID'] = (int)$params['USER_ID'];
		}

		if($placementHandler <> '')
		{
			$filter['=PLACEMENT_HANDLER'] = $placementHandler;
		}

		$dbRes = PlacementTable::getList(array(
			'filter' => $filter
		));

		while($placementHandler = $dbRes->fetch())
		{
			$cnt++;
			$result = PlacementTable::delete($placementHandler["ID"]);
			if($result->isSuccess())
			{
				$cnt++;
			}
		}
	}

	return array('count' => $cnt);
}