• Модуль: timeman
  • Путь к файлу: ~/bitrix/modules/timeman/lib/update/timemanversion19converter.php
  • Класс: BitrixTimemanUpdateTimemanVersion19Converter
  • Вызов: TimemanVersion19Converter::createOrRestoreSchedulesData
private function createOrRestoreSchedulesData($baseDepartmentId)
{
	$this->processedEntitiesData = Application::getConnection()->query("SELECT * FROM `b_timeman_converter_processed_entities`")->fetchAll();
	$this->processedEntitiesData = array_fill_keys(array_values(array_column($this->processedEntitiesData, 'ENTITY_CODE')), true);
	$this->restoreViolationsData();

	$tempData = Application::getConnection()->query("SELECT * FROM b_timeman_converter_collected_schedules")->fetchAll();
	if (empty($tempData))
	{
		$defaultSettings = $this->getDefaultTimemanSettings();

		$this->buildViolationForm($defaultSettings, 'DR' . $baseDepartmentId);

		$commonScheduleForm = $this->getScheduleForm($defaultSettings);
		$commonScheduleForm->assignments = [ScheduleForm::ALL_USERS => ScheduleForm::ALL_USERS];

		return $commonScheduleForm;
	}
	else
	{
		$commonScheduleForm = null;
		foreach ($tempData as $tempValues)
		{
			$key = $tempValues['SCHEDULE_KEY'];
			$this->savedSchedulesMap[$key] = [
				'scheduleId' => $tempValues['SCHEDULE_ID'],
				'shiftId' => $tempValues['SHIFT_ID'],
				'usersUpdated' => (int)$tempValues['USERS_RECORDS_UPDATED'] === 1,
			];
			if (!$this->scheduleForms[$key])
			{
				$this->scheduleForms[$key] = $this->createScheduleForm($key);
				$this->scheduleForms[$key]->assignments = json_decode($tempValues['ASSIGNMENTS'], true);
				$this->scheduleForms[$key]->assignmentsExcluded = json_decode($tempValues['ASSIGNMENTS_EXCLUDED'], true);
				if (!$commonScheduleForm && isset($this->scheduleForms[$key]->assignments[ScheduleForm::ALL_USERS]))
				{
					$commonScheduleForm = $this->scheduleForms[$key];
				}
			}
		}
		return $commonScheduleForm;
	}
}