- Модуль: location
- Путь к файлу: ~/bitrix/modules/location/lib/infrastructure/service/recentaddressesservice.php
- Класс: BitrixLocationInfrastructureServiceRecentAddressesService
- Вызов: RecentAddressesService::add
public function add(Address $address): void
{
$normalizedAddress = $this->getNormalizedAddress($address);
$recentAddressList = RecentAddressTable::query()
->setSelect(['ID', 'ADDRESS'])
->where('USER_ID', $this->currentUserId)
->setOrder(['USED_AT' => 'DESC'])
->setLimit(self::MAX_CNT)
->fetchAll()
;
$isExisting = false;
foreach ($recentAddressList as $recentAddressListItem)
{
$recentAddress = null;
try
{
$recentAddress = Address::fromJson($recentAddressListItem['ADDRESS']);
}
catch (Exception $e) {}
if ($recentAddress === null)
{
continue;
}
if ($this->areAddressesEqual($normalizedAddress, $recentAddress))
{
RecentAddressTable::update(
(int)$recentAddressListItem['ID'],
[
'ADDRESS' => $normalizedAddress->toJson(),
'USED_AT' => new DateTime(),
]
);
$isExisting = true;
break;
}
}
if (!$isExisting)
{
RecentAddressTable::add([
'USER_ID' => $this->currentUserId,
'ADDRESS' => $normalizedAddress->toJson(),
]);
}
}