예제 #1
0
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();
    }
}
예제 #2
0
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
}