public static function assignAsYouGo(Expo $expo, Worker $worker) { if ($expo->scheduleAssignAsYouGo) { $workerList = NULL; $stationList = NULL; $assignmentList = NULL; try { // needed for all $workerList = WorkerSchedule::selectExpo($expo->expoid); $stationList = JobSchedule::selectExpo($expo->expoid); $assignmentList = ShiftAssignment::selectExpo($expo->expoid); } catch (PDOException $ex) { logMessage("FirstComeFirstServed", "assignAsYouGo(" . $expo->titleString() . ", " . $worker->email . ") - " . $ex->getMessage()); return; } foreach ($workerList as $w) { if ($w->workerid == $worker->workerid) { $worker = $w; break; } } // $w $aas = new FirstComeFirstServed($expo->expoid, $stationList, $workerList, $assignmentList, TRUE); $stationList = NULL; $assignmentList = NULL; $workerList = NULL; $d1 = new DateTime(); logMessage("FirstComeFirstServed", "**** assignSchedule(" . $expoId . ") ****", $d1->format('H:i'), "\n"); $aas->assignWorker($worker, $expoId); $d2 = new DateTime(); logMessage("FirstComeFirstServed", "****assignSchedule(" . $expoId . ") ****", $d2->format('H:i'), " elapsed: ", $d2->getTimestamp() - $d1->getTimestamp(), "\n"); // $aas->logJobListState("FirstComeFirstServed", "jobs after assignment"); // $aas->logWorkerListState("FirstComeFirstServed", "workers after assignment"); AbstractScheduler::commitSchedule($expo->expoid, TRUE, $aas->getSchedule()); } return; }
public function __construct($expoId, array $jobList = NULL, array $workerList = NULL, array $assignmentList = NULL, $keepAssignmentsFlag = TRUE) { if (is_null($expoId)) { throw new Exception("must pass in an expoId to AbstractScheduler"); } $this->expoid = $expoId; if (is_null($jobList)) { $jobList = JobSchedule::selectExpo($expoId); } $this->jobList = $jobList; $jobList = NULL; if (is_null($workerList)) { $workerList = WorkerSchedule::selectExpo($expoId); } $this->workerList = $workerList; $workerList = NULL; if (is_null($assignmentList)) { $assignmentList = ShiftAssignment::selectExpo($expoId); } $this->assignmentList = $assignmentList; $assignmentList = NULL; $this->setup($keepAssignmentsFlag, $expoId); // todo - pass in parameter }
} catch (ParseSWWATException $ex) { header('Location: WorkerLoginPage.php'); include 'WorkerLoginPage.php'; return; } $keepFlag = isset($_POST[PARAM_SCHEDULE_KEEP]); $_SESSION[PARAM_SCHEDULE_ALGO] = $_POST[PARAM_SCHEDULE_ALGO]; $_SESSION[PARAM_SCHEDULE_KEEP] = $_POST[PARAM_SCHEDULE_KEEP]; $workerList = NULL; $stationList = NULL; $assignmentList = NULL; try { // needed for all $workerList = WorkerSchedule::selectExpo($expo->expoid); // needed for all excepting PREFERENCEASSIGN $stationList = JobSchedule::selectExpo($expo->expoid); $assignmentList = ShiftAssignment::selectExpo($expo->expoid); } catch (PDOException $ex) { $_POST[PARAM_PAGE_MESSAGE] = "Please try to schedule at a later time."; logMessage("ScheduleExpoAction", "Database screwup" . $ex->getMessage()); header('Location: ScheduleExpoPage.php'); include 'ScheduleExpoPage.php'; return; } if (!is_null($algorithm)) { $aas = NULL; if (0 == strcmp(ASSIGNANDSUBTRACT, $algorithm)) { $aas = new AssignAndSubtract($expo->expoid, $stationList, $workerList, $assignmentList, $keepFlag); } else { if (0 == strcmp(FIRSTCOMEFIRSTSERVE, $algorithm)) { $aas = new FirstComeFirstServed($expo->expoid, $stationList, $workerList, $assignmentList, $keepFlag);
public function getJobSchedule() { return $this->hasMany(JobSchedule::className(), ['job_id' => 'job_id']); }
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; }