Example #1
0
        $lesson_status_value = "COMPLETED";
    }

    // set credit if needed
    if ($lesson_status_value == "COMPLETED" || $lesson_status_value == "PASSED") {
        if (strtoupper($_POST['credit']) == "CREDIT") {
            $credit_value = "CREDIT";
        }
    }

    //set maxScore to 100 if the SCO didn't change it itself, but gave raw
    if (isset($raw_value) && isset($scoreMax_value) && $raw_value > 0 && $raw_value <= 100 && $scoreMax_value == 0) {
        $scoreMax_value = 100;
    }

    if (isScorm2004Time($_POST['session_time'])) {
        $total_time_value = addScorm2004Time($_POST['total_time'], $_POST['session_time']);
        $session_time_formatted = addScorm2004Time("0000:00:00.00", $_POST['session_time']);
    } else if (isScormTime($_POST['session_time'])) {
        $total_time_value = addScormTime($_POST['total_time'], $_POST['session_time']);
        $session_time_formatted = $_POST['session_time'];
    } else {
        $total_time_value = $_POST['total_time'];
    }

    $sql = "UPDATE `lp_user_module_progress`
            SET
                `lesson_location` = ?s,
                `lesson_status` = ?s,
                `entry` = ?s,
                `raw` = ?d,
Example #2
0
/**
 * This function allow to add times saved in the SCORM 2004 requested format:
 * timeinterval(second,10,2): PThHmMsS
 *
 * @param $time1 a suspected SCORM 1.2 time value, total_time,  in the API
 * @param $time2 a suspected SCORM 2004 time value, session_time to add, in the API
 *
 * @author Thanos Kyritsis <*****@*****.**>
 *
 */
function addScorm2004Time($time1, $time2)
{
    if (isScorm2004Time($time2)) {
        //extract hours, minutes, secondes, ... from time1 and time2
        $mask = "/^([0-9]{2,4}):([0-9]{2}):([0-9]{2}).?([0-9]?[0-9]?)\$/";
        $mask2004 = "/^PT([0-9]{1,2})H([0-9]{1,2})M([0-9]{2}).?([0-9]?[0-9]?)S\$/";
        preg_match($mask, $time1, $matches);
        $hours1 = $matches[1];
        $minutes1 = $matches[2];
        $secondes1 = $matches[3];
        $primes1 = $matches[4];
        preg_match($mask2004, $time2, $matches);
        $hours2 = $matches[1];
        $minutes2 = $matches[2];
        $secondes2 = $matches[3];
        $primes2 = $matches[4];
        // calculate the resulting added hours, secondes, ... for result
        $primesReport = FALSE;
        $secondesReport = FALSE;
        $minutesReport = FALSE;
        $hoursReport = FALSE;
        //calculate primes
        if ($primes1 < 10) {
            $primes1 = $primes1 * 10;
        }
        if ($primes2 < 10) {
            $primes2 = $primes2 * 10;
        }
        $total_primes = $primes1 + $primes2;
        if ($total_primes >= 100) {
            $total_primes -= 100;
            $primesReport = TRUE;
        }
        //calculate secondes
        $total_secondes = $secondes1 + $secondes2;
        if ($primesReport) {
            $total_secondes++;
        }
        if ($total_secondes >= 60) {
            $total_secondes -= 60;
            $secondesReport = TRUE;
        }
        //calculate minutes
        $total_minutes = $minutes1 + $minutes2;
        if ($secondesReport) {
            $total_minutes++;
        }
        if ($total_minutes >= 60) {
            $total_minutes -= 60;
            $minutesReport = TRUE;
        }
        //calculate hours
        $total_hours = $hours1 + $hours2;
        if ($minutesReport) {
            $total_hours++;
        }
        if ($total_hours >= 10000) {
            $total_hours -= 10000;
            $hoursReport = TRUE;
        }
        // construct and return result string
        if ($total_hours < 10) {
            $total_hours = "0" . $total_hours;
        }
        if ($total_minutes < 10) {
            $total_minutes = "0" . $total_minutes;
        }
        if ($total_secondes < 10) {
            $total_secondes = "0" . $total_secondes;
        }
        $total_time = $total_hours . ":" . $total_minutes . ":" . $total_secondes;
        // add primes only if != 0
        if ($total_primes != 0) {
            $total_time .= "." . $total_primes;
        }
        return $total_time;
    } else {
        return $time1;
    }
}