• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/lib/ustat/departmenthitstat.php
  • Класс: BitrixIntranetUStatDepartmentHitStat
  • Вызов: DepartmentHitStat::day
public function day(string $section, DateTime $day): void
{
	$collection = $this->getDepartmentsHasDayStatistic($day);
	$departmentIdsWithoutStat = $this->departmentIds;

	foreach ($collection as $item)
	{
		$departmentIdsWithoutStat = array_filter($departmentIdsWithoutStat, function ($id) use($item) {
			return $item->getDeptId() !== (int)$id;
		});

		if (DepartmentDayTable::getEntity()->hasField($section))
		{
			$item->set($section, new SqlExpression('?# + 1', $section));
		}

		$item->setTotal(new SqlExpression('?# + 1', 'TOTAL'));
	}
	foreach ($departmentIdsWithoutStat as $id)
	{
		$departmentDayTable = DepartmentDayTable::createObject();
		if (DepartmentDayTable::getEntity()->hasField($section))
		{
			$departmentDayTable->set($section, 1);
		}
		$departmentDayTable->setDay($day);
		$departmentDayTable->setDeptId($id);
		$departmentDayTable->setTotal(1);
		$collection[] = $departmentDayTable;
	}
	$collection->save();
}