Browse Source

[svn r13593] Added personal statistic reports on objectives

Yannick Warnier 17 years ago
parent
commit
47fd8e57ae
2 changed files with 75 additions and 2 deletions
  1. 48 0
      main/newscorm/learnpath.class.php
  2. 27 2
      main/newscorm/lp_stats.php

+ 48 - 0
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

+ 27 - 2
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) {
 					.'<td>'.urldecode($interaction['student_response'])."</td>\n".'<td>'.$interaction['result']."</td>\n".'<td>'.$interaction['latency']."</td>\n".'<td>'.$interaction['time']."</td>\n"."</tr>\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 .= "<tr class='$oddclass'>\n".'<td></td>'."\n".'<td></td>'."\n".'<td>&nbsp;</td>'."\n".'<td>'.$interaction['order_id'].'</td>'."\n".'<td colspan="2">'.$interaction['objective_id'].'</td>'."\n"
+					.'<td colspan="2">'.$interaction['status']."</td>\n"
+					.'<td>'.$interaction['score_raw']."</td>\n".'<td>'.$interaction['score_max']."</td>\n".'<td>'.$interaction['score_min']."</td>\n<td></td>\n</tr>\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) {
 				.'<td>'.urldecode($interaction['student_response'])."</td>\n".'<td>'.$interaction['result']."</td>\n".'<td>'.$interaction['latency']."</td>\n".'<td>'.$interaction['time']."</td>\n"."</tr>\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 .= "<tr class='$oddclass'>\n".'<td></td>'."\n".'<td></td>'."\n".'<td>&nbsp;</td>'."\n".'<td>'.$interaction['order_id'].'</td>'."\n".'<td colspan="2">'.$interaction['objective_id'].'</td>'."\n"
+				.'<td colspan="2">'.$interaction['status']."</td>\n"
+				.'<td>'.$interaction['score_raw']."</td>\n".'<td>'.$interaction['score_max']."</td>\n".'<td>'.$interaction['score_min']."</td>\n<td></td>\n</tr>\n";
+				$counter ++;
+			}
 		}
 		
 	}