$paramList = array(); // should be in order for display $optionList = array(); usort($workerList, "WorkerCompare"); $k = 0; foreach ($workerList as $worker) { $optionList[] = array($k, $worker->assignString()); $paramList[$k] = $worker; $k++; } // workerList // should be in order for display $optionOutList = array(); usort($workerOutList, "WorkerCompare"); foreach ($workerOutList as $worker) { $shiftPreference = ShiftPreference::selectID($worker->workerid, $job->jobid); $workerstring = $worker->assignString(); if ($shiftPreference->desirePercent != NULL) { $workerstring .= ' (' . $shiftPreference->desirePercent . '%)'; } $optionOutList[] = array($k, $workerstring); $paramList[$k] = $worker; $k++; } // workerOutList // paramlist is a combination of the two; such that the posted PARAM_LIST_MULTIPLE is correct $_SESSION[PARAM_LIST] = $paramList; // ok, start the html include 'section/header.php'; ?>
function setShiftPreferences($workerId, $expoId, $locations) { $timePrefs = NewTimePreference::selectID($workerId, $expoId); $locationPrefs = JobPreference::selectID($workerId, $expoId); $jobs = Job::selectExpo($expoId); foreach ($jobs as $job) { $sp = new ShiftPreference(); $sp->workerid = $workerId; $sp->jobid = $job->jobid; $sp->stationid = $job->stationid; $sp->expoid = $expoId; $station = Station::selectID($job->stationid); //time preference $timeZone = swwat_format_timezone($station->startTime); $startTime = swwat_format_epoch($station->startTime); $stopTime = swwat_format_epoch($station->stopTime); $zeroFlag = FALSE; $tdesire = 0; $count = 0; foreach ($timePrefs as $timePref) { $epoch = date_format(new DateTime($timePref->day, new DateTimeZone($timeZone)), 'U'); for ($i = 0; $i < 24; $i++) { $startHour = $epoch; $endHour = strtotime("+1 hours", $epoch); if ($startHour >= $startTime && $endHour <= $stopTime) { $field = 'hour' . ($i + 1); $value = $timePref->{$field}; if ($value == 0) { $zeroFlag = TRUE; } $tdesire += $value; $count++; } $epoch = strtotime("+1 hours", $epoch); } } if ($zeroFlag || $count == 0) { $tdesire = 0; } else { $tdesire = $tdesire / $count; } // location preference $index = array_search($station->location, $locations); $field = 'job' . ($index + 1); $ldesire = $locationPrefs->{$field}; $desire = 0; if ($tdesire != 0 && $ldesire != 0) { $desire = ($tdesire + $ldesire) / 2; } $sp->desirePercent = $desire; $sp->update(); } }
<?php // $Id: ShiftPreferenceExplicitAction.php 1800 2012-09-07 04:23:26Z preston $ Copyright (c) ConSked, LLC. All Rights Reserved. include 'util/authenticate.php'; require_once 'db/ShiftPreference.php'; require_once 'db/StationJob.php'; require_once 'db/Worker.php'; require_once 'properties/constants.php'; require_once 'swwat/gizmos/parse.php'; require_once 'util/log.php'; require_once 'util/session.php'; /** * This Controller is used by the StationViewPage's submit button */ $author = getWorkerAuthenticated(); $job = getStationCurrent(); // note only works for CIW when station:job = 1:1 $preference = ShiftPreference::selectID($author->workerid, $job->jobid); try { $desire = swwat_parse_integer(html_entity_decode($_POST[PARAM_DESIRE]), 3, FALSE); $preference->setDesire($desire); $preference->update(); } catch (ParseSWWATException $ex) { // ignore, but do nothing! } header('Location: StationViewPage.php'); include 'StationViewPage.php';
} else { header('Location: SiteAdminPage.php'); include 'SiteAdminPage.php'; return; } } else { // maybe the crew is not assigned to anything! if (!is_null($expo) && $expo->isRunning()) { header('Location: WorkerSchedulePage.php'); include 'WorkerSchedulePage.php'; return; } else { $expoList = Expo::selectWorker($worker->workerid); if (count($expoList) == 1) { $future = $expoList[0]->isFuture(); $preferncesEntered = ShiftPreference::preferencesEntered($expoList[0]->expoid, $worker->workerid); } if (count($expoList) == 1 && $future && !$preferencesEntered) { setExpoCurrent($expoList[0]); header('Location: PreferenceWelcomePage.php'); include 'PreferenceWelcomePage.php'; return; } else { header('Location: WorkerViewPage.php'); include 'WorkerViewPage.php'; return; } } } } catch (RequirePasswordReset $ex) { header('Location: WorkerLoginChangePage.php');
function createStationPreferenceHTMLList($workerid, $jobid) { $preference = ShiftPreference::selectID($workerid, $jobid); $_POST[PARAM_DESIRE] = $preference->desirePercent; echo '<form method="POST" name="stationviewpage_stationsetpreference_form" action="ShiftPreferenceExplicitAction.php">'; swwat_createInputValidateInteger(PARAM_DESIRE, "stationviewpage_stationsetpreference_form", 3, FALSE); echo ' <input class="fieldValue" type="Submit" value="Save Preference"/><p/>'; echo '</form>'; }
function reviewActionContent($author, $expo) { if (isset($_POST[PARAM_MAXHOURS]) && !is_null($_POST[PARAM_MAXHOURS])) { $author->updateMaxHours($expo->expoid, swwat_parse_string(html_entity_decode($_POST[PARAM_MAXHOURS]))); } $jobList = Job::selectExpo($expo->expoid); usort($jobList, "JobCompare"); $prefJobidList = array(); $prefDesireList = array(); if (count($_POST) > 0) { $keys = array_keys($_POST); $values = array_values($_POST); for ($k = 0; $k < count($_POST); $k++) { if (strpos($keys[$k], 'title') !== false) { list($prefJobidList[], $prefDesireList[]) = explode(':', $values[$k]); } } } $shiftpreference = new ShiftPreference(); foreach ($jobList as $j) { $shiftpreference->workerid = $author->workerid; $shiftpreference->jobid = $j->jobid; $shiftpreference->stationid = $j->stationid; $shiftpreference->expoid = $j->expoid; $pos = array_search($j->jobid, $prefJobidList); if ($pos === false) { $shiftpreference->desirePercent = NULL; } else { $shiftpreference->desirePercent = $prefDesireList[$pos]; if ($shiftpreference->desirePercent == 0) { $shiftpreference->desirePercent = NULL; } } $shiftpreference->update(); } // note post $shiftpreference save if ($expo->scheduleAssignAsYouGo) { if ($expo->scheduleWorkerReset) { $shifts = ShiftAssignment::selectWorker($expo->expoid, $author->workerid); ShiftAssignment::deleteList($shifts); } FirstComeFirstServed::assignAsYouGo($expo, $author); if ($expo->scheduleVisible) { mailSchedule($expo, $author); header('Location: WorkerSchedulePage.php'); include 'WorkerSchedulePage.php'; return; } } // assignAsYouGo }
private static function select($sqlWorker, $sqlPrefs, $params) { $workers = NULL; $prefList = NULL; try { $workers = simpleSelect("WorkerSchedule", $sqlWorker, $params); $prefList = simpleSelect("ShiftPreference", $sqlPrefs, $params); } catch (PDOException $pe) { logMessage('WorkerScheduleView::select(' . var_export($params, TRUE) . ')', $pe->getMessage()); } $workerList = array(); foreach ($workers as $worker) { $workerList[$worker->workerid] = $worker; } // $worker $workers = NULL; // gc foreach ($prefList as $preference) { if (array_key_exists($preference->workerid, $workerList)) { $worker = $workerList[$preference->workerid]; $worker->jobPreferences[$preference->jobid] = $preference; } } // $preference foreach ($workerList as $worker) { $worker->jobPreferences = ShiftPreference::sort($worker->jobPreferences, FALSE); } // $worker $prefList = NULL; // gc return $workerList; }