- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/util/scheduler.php
- Класс: BitrixTasksUtilScheduler
- Вызов: Scheduler::reScheduleTask
public function reScheduleTask(array $newData)
{
$task = $this->taskPool[$this->taskId];
// do not deal with tasks with no created date
if((string) $task['CREATED_DATE'] == '')
{
return array();
}
if(isset($newData['MATCH_WORK_TIME']))
{
$task->setMatchWorkTime($newData['MATCH_WORK_TIME'] == 'Y');
}
// define end date...
if((string) $task['END_DATE_PLAN'] == '')
{
if((string) $newData['END_DATE_PLAN'] != '')
{
$task->setEndDatePlan(new DateTime($newData['END_DATE_PLAN']));
}
else
{
$task->setEndDatePlanUserTimeGmt($this->calendar->getEndOfCurrentDayGmt()->toStringGmt());
}
}
// must keep previous values of task; we`ll need it on relcalculating related task`s lags further
$this->taskOriginDates = array(
'START_DATE_PLAN' => $task->getStartDatePlanGmt(true),
'END_DATE_PLAN' => $task->getEndDatePlanGmt(),
);
// $startDate and $endDate are dates that were changed, not just actual dates!
$startDate = null;
$endDate = null;
if($newData['MATCH_WORK_TIME'] == 'Y')
{
// MATCH_WORK_TIME was set to Y, we have to reschedule and re-check existing dates even if no actual date change required
$startDate = isset($newData['START_DATE_PLAN']) ? $newData['START_DATE_PLAN'] : $task['START_DATE_PLAN'];
$endDate = isset($newData['END_DATE_PLAN']) ? $newData['END_DATE_PLAN'] : $task['END_DATE_PLAN'];
}
else
{
// MATCH_WORK_TIME is set to N or even left unchanged, we just take what we have in $newData (if we have smth)
if(isset($newData['START_DATE_PLAN']))
{
$startDate = $newData['START_DATE_PLAN'];
}
if(isset($newData['END_DATE_PLAN']))
{
$endDate = $newData['END_DATE_PLAN'];
}
}
// we need ensure we deal with DateTime objects in $startDate and $endDate, not strings or smth else
$startDate = $this->castToDateTimeGmt($startDate);
$endDate = $this->castToDateTimeGmt($endDate);
if($startDate || $endDate) // smth were changed, do job
{
/*
// we had no end date, but we get it in $newData.
if($endDate && !$task['END_DATE_PLAN'])
{
$task->setEndDatePlanUserTimeGmt($endDate->toStringGmt());
}
if(!$endDate && !$task['END_DATE_PLAN']) // no data to shift
{
return static::makeTaskReturnStruct($task);
}
*/
if($startDate && $endDate) // both changed => shift
{
$task->setStartDatePlanUserTimeGmt($startDate->toStringGmt());
$task->setEndDatePlanUserTimeGmt($endDate->toStringGmt());
$duration = $task->calculateDuration();
$this->matchWorkingTime($this->taskId, $startDate, $endDate, $duration);
}
elseif($startDate) // start changed => resize to left
{
$task->setStartDatePlanUserTimeGmt($startDate->toStringGmt());
$this->matchWorkingTime($this->taskId, $startDate);
}
elseif($endDate) // end changed => resize to right
{
$task->setEndDatePlanUserTimeGmt($endDate->toStringGmt());
$this->matchWorkingTime($this->taskId, null, $endDate);
}
}
return static::makeTaskReturnStruct($task, $newData);
}