public function addJob(JobSchedule $job, $expoId, $override = FALSE) { if (array_key_exists($job->jobid, $this->jobList)) { return; } // already added if (!$override) { $expo = Expo::selectID($expoId); $preference = $this->jobPreferences[$job->jobid]; if (is_null($preference->desirePercent)) { $job->subWorker($this, $expoId, TRUE); // we may have added it throw new ScheduleImpossibleException("Worker:" . $this->workerid . " cannot work in Job:" . $job->jobid); } $newJobMinutes = $this->jobMinutes + $job->jobMinutes(); if ($newJobMinutes > $this->maxMinutes) { $job->subWorker($this, $expoId, TRUE); // we may have added it throw new ScheduleOverMaxHoursException("Worker:" . $this->workerid . " cannot work in Job:" . $job->jobid . " as will have total minutes above max:" . ($newJobMinutes - $this->maxMinutes)); } if ($newJobMinutes > 60 * $expo->expoHourCeiling) { $job->subWorker($this, $expoId, TRUE); // we may have added it throw new ScheduleOverMaxHoursException("Worker:" . $this->workerid . " cannot work in Job:" . $job->jobid . " as will have total minutes above expo max:" . ($newJobMinutes - 60 * $expo->expoHourCeiling)); } foreach ($this->jobList as $existing) { if ($job->isTimeConflict($existing)) { if ($expo->allowScheduleTimeConflict) { logMessage("WorkerSchedule", "overlapping conflict allowed"); if ($job->isStartTimeConflict($existing)) { $job->subWorker($this, $expoId, TRUE); // we may have added it $sce = new ScheduleConflictException("Worker:" . $this->workerid . " cannot work in Job:" . $job->jobid . " due to identical start time conflict with existing Job:" . $existing->jobid); $sce->conflict = $existing; logMessage("WorkerSchedule", $sce); throw $sce; } } else { $job->subWorker($this, $expoId, TRUE); // we may have added it $sce = new ScheduleConflictException("Worker:" . $this->workerid . " cannot work in Job:" . $job->jobid . " due to conflict with existing Job:" . $existing->jobid); $sce->conflict = $existing; logMessage("WorkerSchedule", $sce); throw $sce; } // allowScheduleTimeConflict } } // $existing } // $override $this->jobList[$job->jobid] = $job; $this->jobMinutes += $job->jobMinutes(); $job->addWorker($this, $expoId, $override); // must be at very end return; }