コード例 #1
0
ファイル: lms_grades.lib.php プロジェクト: parkmi/dolschool14
function JLMS_getLpathProgress($row, $user_id = null)
{
    $db =& JFactory::getDbo();
    $user =& JFactory::getUser();
    if (is_null($user_id)) {
        $user_id = $user->get('id');
    }
    $percent = 0;
    if (isset($row->id) && $row->id) {
        if ($row->item_id == 0) {
            $query = "SELECT lps.*" . "\n FROM #__lms_learn_path_steps as lps" . "\n WHERE 1" . "\n AND lps.course_id = '" . $row->course_id . "'" . "\n AND lps.lpath_id = '" . $row->id . "'";
            $db->setQuery($query);
            $all_steps = $db->loadObjectList();
            $query = "SELECT lpsr.*" . "\n FROM #__lms_learn_path_results as lpr, #__lms_learn_path_step_results as lpsr" . "\n WHERE 1" . "\n AND lpr.id = lpsr.result_id" . "\n AND lpr.course_id = '" . $row->course_id . "'" . "\n AND lpr.lpath_id = '" . $row->id . "'" . "\n AND lpr.user_id = '" . $user_id . "'";
            $db->setQuery($query);
            $all_result_steps = $db->loadObjectList();
            $tmp_all_steps = array();
            foreach ($all_steps as $n => $step) {
                $tmp_all_steps[$n] = $step;
                $tmp_all_steps[$n]->step_status = 0;
                foreach ($all_result_steps as $result_step) {
                    if ($step->id == $result_step->step_id) {
                        $tmp_all_steps[$n]->step_status = $result_step->step_status;
                    }
                }
            }
            $all_steps = array();
            $all_steps = $tmp_all_steps;
            if (isset($all_steps) && count($all_steps)) {
                $completed_step = 0;
                foreach ($all_steps as $step) {
                    if (isset($step->step_status) && $step->step_status == 1) {
                        $completed_step++;
                    }
                }
                if ($completed_step) {
                    $percent = round($completed_step / count($all_steps) * 100);
                }
            }
        } else {
            if ($row->item_id) {
                if (isset($row->suspend_data)) {
                    $suspend_data = $row->suspend_data;
                } else {
                    $query = "SELECT lnsst.value" . "\n FROM #__lms_n_scorm as lns, #__lms_n_scorm_scoes_track as lnsst" . "\n WHERE 1" . "\n AND lns.id = lnsst.scormid" . "\n AND lnsst.element = 'cmi.suspend_data'" . "\n AND lns.id = '" . $row->item_id . "'" . "\n AND lns.course_id = '" . $row->course_id . "'" . "\n AND lnsst.userid = '" . $user_id . "'";
                    $db->setQuery($query);
                    $suspend_data = $db->loadResult();
                }
                $percent = checkSuspendDate($suspend_data);
            }
        }
    }
    //	echo '$percent= '.$percent;
    $hide_percent = 0;
    if (isset($row->s_status) && $row->s_status == 1 && $percent == -1 && isset($row->r_start) && $row->r_start) {
        $hide_percent = 1;
        $percent = 100;
    } else {
        if (isset($row->s_status) && $row->s_status == 0 && $percent == -1 && isset($row->r_start) && $row->r_start) {
            $hide_percent = 1;
            $percent = 50;
        } else {
            if (!isset($row->s_status) && $percent == -1 && isset($row->r_start) && !$row->r_start) {
                $hide_percent = 1;
                $percent = 0;
            }
        }
    }
    $class_completed = '';
    if (isset($row->r_status) && $row->r_status == 1) {
        $class_completed .= ' ';
        $class_completed .= 'completed';
    } else {
        if (isset($row->s_status) && $row->s_status == 1) {
            $class_completed .= ' ';
            $class_completed .= 'completed';
        } else {
            $class_completed .= ' ';
            $class_completed .= 'incompleted';
        }
    }
    $suffix_class = '_lpath' . $class_completed;
    return JLMS_HTML::showProgressBar($percent, $row->id, $suffix_class, $hide_percent);
}