From 47fd8e57aec1c4e2ae3dd8c2b71c5524776dfc4e Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Tue, 30 Oct 2007 05:13:52 +0100 Subject: [PATCH] [svn r13593] Added personal statistic reports on objectives --- main/newscorm/learnpath.class.php | 48 +++++++++++++++++++++++++++++++ main/newscorm/lp_stats.php | 29 +++++++++++++++++-- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 142f20060e..8c9f281d11 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -2105,6 +2105,54 @@ class learnpath { } return $list; } + /** + * Return the number of objectives for the given learnpath Item View ID. + * This method can be used as static. + * @param integer Item View ID + * @return integer Number of objectives + */ + function get_objectives_count_from_db($lp_iv_id=0){ + if(empty($lp_iv_id)){return -1;} + $table = Database::get_course_table('lp_iv_objective'); + $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id"; + $res = api_sql_query($sql,__FILE__,__LINE__); + $row = Database::fetch_array($res); + $num = $row[0]; + return $num; + } + /** + * Return the objectives as an array for the given lp_iv_id. + * This method can be used as static. + * @param integer Learnpath Item View ID + * @return array + * @todo Translate labels + */ + function get_iv_objectives_array($lp_iv_id=0){ + $list = array(); + $table = Database::get_course_table('lp_iv_objective'); + $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC"; + $res = api_sql_query($sql,__FILE__,__LINE__); + $num = Database::num_rows($res); + if($num>0){ + $list[] = array( + "order_id"=>htmlentities(get_lang('Order')), + "objective_id"=>htmlentities(get_lang('ObjectiveID')), + "score_raw"=>htmlentities(get_lang('ObjectiveRawScore')), + "score_max"=>htmlentities(get_lang('ObjectiveMaxScore')), + "score_min"=>htmlentities(get_lang('ObjectiveMinScore')), + "status"=>htmlentities(get_lang('ObjectiveStatus'))); + while ($row = Database::fetch_array($res)){ + $list[] = array( + "order_id"=>($row['order_id']+1), + "objective_id"=>urldecode($row['objective_id']),//urldecode because they often have %2F or stuff like that + "score_raw"=>$row['score_raw'], + "score_max"=>$row['score_max'], + "score_min"=>$row['score_min'], + "status"=>$row['status']); + } + } + return $list; + } /** * Generate and return the table of contents for this learnpath. The (flat) table returned can be diff --git a/main/newscorm/lp_stats.php b/main/newscorm/lp_stats.php index 3ee149e4b8..e65284397c 100644 --- a/main/newscorm/lp_stats.php +++ b/main/newscorm/lp_stats.php @@ -168,7 +168,7 @@ foreach ($list as $my_item_id) { //check if there are interactions below $extend_attempt_link = ''; $extend_this_attempt = 0; - if (learnpath :: get_interactions_count_from_db($row['iv_id']) > 0 && !$extend_all) { + if ((learnpath :: get_interactions_count_from_db($row['iv_id']) > 0 || learnpath :: get_objectives_count_from_db($row['iv_id']) > 0 ) && !$extend_all) { if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) { //the extend button for this attempt has been clicked $extend_this_attempt = 1; @@ -227,6 +227,18 @@ foreach ($list as $my_item_id) { .''.urldecode($interaction['student_response'])."\n".''.$interaction['result']."\n".''.$interaction['latency']."\n".''.$interaction['time']."\n"."\n"; $counter ++; } + $list2 = learnpath :: get_iv_objectives_array($row['iv_id']); + foreach ($list2 as $id => $interaction) { + if (($counter % 2) == 0) { + $oddclass = "row_odd"; + } else { + $oddclass = "row_even"; + } + $output .= "\n".''."\n".''."\n".' '."\n".''.$interaction['order_id'].''."\n".''.$interaction['objective_id'].''."\n" + .''.$interaction['status']."\n" + .''.$interaction['score_raw']."\n".''.$interaction['score_max']."\n".''.$interaction['score_min']."\n\n\n"; + $counter ++; + } } } while ($row = Database :: fetch_array($result)); } elseif($num>0) { @@ -236,7 +248,8 @@ foreach ($list as $my_item_id) { $extend_attempt_link = ''; $extend_this_attempt = 0; $inter_num = learnpath :: get_interactions_count_from_db($row['iv_id']); - if ($inter_num > 0 && !$extend_all) { + $objec_num = learnpath :: get_objectives_count_from_db($row['iv_id']); + if (($inter_num > 0 || $objec_num > 0) && !$extend_all) { if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) { //the extend button for this attempt has been clicked $extend_this_attempt = 1; @@ -349,6 +362,18 @@ foreach ($list as $my_item_id) { .''.urldecode($interaction['student_response'])."\n".''.$interaction['result']."\n".''.$interaction['latency']."\n".''.$interaction['time']."\n"."\n"; $counter ++; } + $list2 = learnpath :: get_iv_objectives_array($row['iv_id']); + foreach ($list2 as $id => $interaction) { + if (($counter % 2) == 0) { + $oddclass = "row_odd"; + } else { + $oddclass = "row_even"; + } + $output .= "\n".''."\n".''."\n".' '."\n".''.$interaction['order_id'].''."\n".''.$interaction['objective_id'].''."\n" + .''.$interaction['status']."\n" + .''.$interaction['score_raw']."\n".''.$interaction['score_max']."\n".''.$interaction['score_min']."\n\n\n"; + $counter ++; + } } }