• Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/posting/segmentdatabuilder.php
  • Класс: BitrixSenderPostingSegmentDataBuilder
  • Вызов: SegmentDataBuilder::addToDB
public function addToDB(?Result $data)
{
	if ($data)
	{
		$rows = [];
		$rowsDataCounter = [
			$this->groupId => [

			],
		];
		$counter = 0;
		while ($row = $data->fetch())
		{
			$rows[] = [
				'GROUP_ID' => $this->groupId,
				'FILTER_ID' => $this->filterId,
				'CRM_ENTITY_ID'  => $row['CRM_ENTITY_ID'],
				'NAME' => $row['NAME'],
				'CRM_ENTITY_TYPE_ID' => $row['CRM_ENTITY_TYPE_ID'],
				'CRM_ENTITY_TYPE' => $row['CRM_ENTITY_TYPE'],
				'CONTACT_ID' => $row['CRM_CONTACT_ID'],
				'COMPANY_ID' => $row['CRM_COMPANY_ID'],
				'EMAIL' => $row['EMAIL'] ?? null,
				'IM' => $row['IM'] ?? null,
				'PHONE' => $row['PHONE'] ?? null,
				'HAS_EMAIL' => $row['EMAIL'] ? 'Y' : 'N',
				'HAS_IMOL' => $row['IM'] ? 'Y' : 'N',
				'HAS_PHONE' => $row['PHONE'] ? 'Y' : 'N',
				'SENDER_TYPE_ID' => $this->detectSenderType($row),
			];
			$detectedTypes = $this->detectSenderTypes($row);

			foreach ($detectedTypes as $type)
			{
				if (!isset($rowsDataCounter[$this->groupId][$type]))
				{
					$rowsDataCounter[$this->groupId][$type] = 0;
				}
				$rowsDataCounter[$this->groupId][$type]++;
			}
			$counter++;

			if ($counter === self::MINIMAL_PER_PAGE)
			{
				SegmentDataTable::addMulti($rows, true);
				$rows = [];
				$counter = 0;
			}
		}

		if ($rows)
		{
			$this->updateCounters($rowsDataCounter);
			SegmentDataTable::addMulti($rows, true);
		}
	}
}