Exemplo n.º 1
0
function wizardActionContent($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])));
    }
    $dateSpanList = $_SESSION[PARAM_DATETIME];
    $locationList = $_SESSION[PARAM_LOCATION];
    // Location Preference
    $k = 0;
    while (isset($_POST[PARAM_LOCATION . $k])) {
        $desire = parsePreferenceNumber(PARAM_LOCATION, $k);
        $locationDesires[$locationList[$k]] = 0 == $desire ? NULL : $desire;
        $locationTest[$k] = parsePreferenceNumber(PARAM_LOCATION, $k);
        $k += 1;
    }
    $jp = new JobPreference();
    $jp->workerid = $author->workerid;
    $jp->expoid = $expo->expoid;
    $count_jobs = $jp->number_jobs;
    for ($k = 0; $k < $count_jobs; $k++) {
        $field = 'job' . ($k + 1);
        if (isset($locationTest[$k])) {
            $jp->{$field} = $locationTest[$k];
        } else {
            $jp->{$field} = 0;
        }
    }
    $test = JobPreference::selectID($author->workerid, $expo->expoid);
    if (!is_null($test)) {
        $jp->update();
    } else {
        $jp->insert();
    }
    // Time Preference
    $k = 0;
    while (isset($_POST[PARAM_DATETIME . $k])) {
        $desire = parsePreferenceNumber(PARAM_DATETIME, $k);
        $dateSpanDesires[$dateSpanList[$k]] = 0 == $desire ? NULL : $desire;
        $dateSpanTest[$k] = parsePreferenceNumber(PARAM_DATETIME, $k);
        $k += 1;
    }
    $tp = new TimePreference();
    $tp->workerid = $author->workerid;
    $tp->expoid = $expo->expoid;
    $count_shifts = $tp->number_shifts;
    for ($k = 0; $k < $count_shifts; $k++) {
        $field = 'shift' . ($k + 1);
        if (isset($dateSpanTest[$k])) {
            $tp->{$field} = $dateSpanTest[$k];
        } else {
            $tp->{$field} = 0;
        }
    }
    $test = TimePreference::selectID($author->workerid, $expo->expoid);
    if (!is_null($test)) {
        $tp->update();
    } else {
        $tp->insert();
    }
    //exit;
    $gp = GrossPreference::updateHelper_Location_DateSpan($expo->expoid, $author->workerid, $locationDesires, $dateSpanDesires);
}
Exemplo n.º 2
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();
    }
}