• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/classes/general/calendar_webservice.php
  • Класс: CCalendarWebService
  • Вызов: CCalendarWebService::GetListItemChangesSinceToken
function GetListItemChangesSinceToken($listName, $viewFields = '', $query = '', $rowLimit = 0, $changeToken = '')
{
	global $USER;

	if (!$listName_original = CIntranetUtils::checkGUID($listName))
	{
		return new CSoapFault('Data error', 'Wrong GUID - '.$listName);
	}

	$listName = ToUpper(CIntranetUtils::makeGUID($listName_original));

	$arSections = CCalendarSect::GetList(array('arFilter' => array('XML_ID' => $listName_original)));
	if (!$arSections || !is_array($arSections[0]))
		return new CSoapFault(
			'List not found',
			'List with '.$listName.' GUID not found!'
		);
	$arSection = $arSections[0];

	$userId = (is_object($USER) && $USER->GetID()) ? $USER->GetID() : 1;

	$fetchMeetings = $arSection['CAL_TYPE'] == 'user' && CCalendar::GetMeetingSection($arSection['OWNER_ID']) == $arSection['ID'];
	$arEvents = CCalendarEvent::GetList(
		array(
			'arFilter' => array(
				'CAL_TYPE' => $arSection['CAL_TYPE'],
				'OWNER_ID' => $arSection['OWNER_ID'],
				'SECTION' => $arSection['ID'],
				'DELETED' => '' // We fetch all deleted and current events
			),
			'getUserfields' => false,
			'parseRecursion' => false,
			'fetchAttendees' => false,
			'fetchMeetings' => $fetchMeetings,
			'userId' => $userId
		)
	);

	$last_change = 0;
	$data = new CXMLCreator('listitems');
	$data->setAttribute('MinTimeBetweenSyncs', 0);
	$data->setAttribute('RecommendedTimeBetweenSyncs', 180);
	$data->setAttribute('TimeStamp', $this->__makeDateTime());
	$data->setAttribute('EffectivePermMask', 'FullMask');

	$data->addChild($obChanges = new CXMLCreator('Changes'));

	if (!$changeToken && !defined('OLD_OUTLOOK_VERSION'))
	{
		$obChanges->addChild($this->__getFieldsDefinition());
	}

	$data->addChild($obData = new CXMLCreator('rs:data'));

	$count = 0;
	foreach ($arEvents as  $event)
	{
		if ($event['DELETED'] != 'N' || ($event['IS_MEETING'] && $event['MEETING_STATUS'] == 'N'))
		{
			$obId = new CXMLCreator('Id');
			$obId->setAttribute('ChangeType', 'Delete');
			$obId->setData($event['ID']);
			$obChanges->addChild($obId);
		}
		elseif (!$changeToken || $changeToken < CCalendar::Timestamp($event['TIMESTAMP_X'], false))
		{
			$obData->addChild($this->__getRow($event, $listName, $last_change));
			$count++;
		}
	}

	$last_change = time();
	$obData->setAttribute('ItemCount', $count);

	$data->setAttribute('xmlns:rs', 'urn:schemas-microsoft-com:rowset');
	$data->setAttribute('xmlns:z', '#RowsetSchema');

	if ($last_change > 0)
		$obChanges->setAttribute('LastChangeToken', $last_change);

	CCalendar::SaveMultipleSyncDate($userId, 'outlook', $arSection['ID']);
	return array('GetListItemChangesSinceTokenResult' => $data);
}