Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

changed lesson_calculate_ongoing_score function and added some comments

  • Loading branch information...
commit b986908256b7a2c1ab62e5f012150b538c716244 1 parent db22702
authored

Showing 1 changed file with 31 additions and 28 deletions. Show diff stats Hide diff stats

  1. 59  mod/lesson/locallib.php
59  mod/lesson/locallib.php
@@ -48,14 +48,14 @@
48 48
 if (!defined("LESSON_TRUEFALSE")) {
49 49
     define("LESSON_TRUEFALSE",     "2");
50 50
 }
51  
-if (!defined("LESSON_MULTICHOICE")) {
  51
+if (!defined("LESSON_MULTICHOICE")) { // if you change the value of this (WHICH YOU SHOULDNT) then you need to change it in restorelib.php as well
52 52
     define("LESSON_MULTICHOICE",   "3");
53 53
 }
54 54
 if (!defined("LESSON_RANDOM")) {
55 55
     define("LESSON_RANDOM",        "4");
56 56
 }
57  
-if (!defined("LESSON_MATCHING")) {
58  
-    define("LESSON_MATCHING",         "5");
  57
+if (!defined("LESSON_MATCHING")) { // if you change the value of this (WHICH YOU SHOULDNT) then you need to change it in restorelib.php as well
  58
+    define("LESSON_MATCHING",      "5");
59 59
 }
60 60
 if (!defined("LESSON_RANDOMSAMATCH")) {
61 61
     define("LESSON_RANDOMSAMATCH", "6");
@@ -882,26 +882,34 @@ function lesson_is_page_in_cluster($pages, $pageid) {
882 882
 }
883 883
 
884 884
 /*******************************************************************/
885  
-function lesson_print_tree_menu($lessonid, $pageid, $id) {
  885
+function lesson_print_tree_menu($lessonid, $pageid, $id, $showpages=false) {
886 886
 // prints the contents of the left menu
887 887
 
888 888
 	if(!$pages = get_records_select("lesson_pages", "lessonid = $lessonid")) {
889 889
 		error("Error: could not find lesson pages");
890 890
 	}
891 891
 	while ($pageid != 0) {
892  
-		lesson_print_tree_link_menu($pages[$pageid], $id);			
  892
+		lesson_print_tree_link_menu($pages[$pageid], $id, true);			
893 893
 		$pageid = $pages[$pageid]->nextpageid;
894 894
 	}
895 895
 }
896 896
 
897 897
 /*******************************************************************/
898  
-function lesson_print_tree_link_menu($page, $id) { 
  898
+function lesson_print_tree_link_menu($page, $id, $showpages=false) { 
899 899
 // prints the actual link for the left menu
900 900
 
901 901
 	if ($page->qtype == LESSON_BRANCHTABLE && !$page->display) {
902 902
 		return false;
  903
+	} elseif ($page->qtype != LESSON_BRANCHTABLE) {
  904
+		return false;
903 905
 	}
904 906
 	
  907
+	/*elseif ($page->qtype != LESSON_BRANCHTABLE && !$showpages) {
  908
+		return false;
  909
+	} elseif (!in_array($page->qtype, $LESSON_QUESTION_TYPE)) {
  910
+		return false;
  911
+	}*/
  912
+	
905 913
 	// set up some variables  NoticeFix  changed whole function
906 914
 	$output = "";
907 915
 	$close = false;
@@ -910,15 +918,13 @@ function lesson_print_tree_link_menu($page, $id) {
910 918
 	
911 919
 	if($page->id == $_REQUEST['pageid']) { 
912 920
 		$close=true; 
913  
-		$output.="<div class='active'><em>"; 
  921
+		$output.="<strong>"; 
914 922
 	} 
915  
-	if (($page->qtype!=LESSON_BRANCHTABLE)||($page->qtype==LESSON_ENDOFBRANCH)||($page->qtype==21)) {
916  
-		$output .= "";
917  
-	} else {
918  
-		$output .= "<li><a href=\"view.php?id=$id&action=navigation&pageid=$page->id\">".$title."</a></li>\n"; 
919  
-	}
  923
+	
  924
+	$output .= "<li><a href=\"view.php?id=$id&action=navigation&pageid=$page->id\">".$title."</a></li>\n"; 
  925
+	
920 926
 	if($close) {
921  
-		$output.="</em></div>";
  927
+		$output.="</strong>";
922 928
 	}
923 929
 	echo $output;
924 930
 
@@ -986,18 +992,12 @@ function lesson_print_tree($pageid, $lessonid, $cmid, $pixpath) {
986 992
 }
987 993
 
988 994
 /*******************************************************************/
989  
-function lesson_calculate_ongoing_score($lesson, $USER) {
990  
-// this calculates and prints the ongoing score for students
991  
-
992  
-	// get the number of retries
993  
-    if (!$retries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id)) {
994  
-		$retries = 0;
995  
-	}
996  
-
  995
+function lesson_calculate_ongoing_score($lesson, $userid, $retries, $return=false) {
  996
+// this calculates and prints the ongoing score for students	
997 997
 	if (!$lesson->custom) {
998 998
 		$ncorrect = 0;						
999 999
 		if ($pagesanswered = get_records_select("lesson_attempts",  "lessonid = $lesson->id AND 
1000  
-				userid = $USER->id AND retry = $retries order by timeseen")) {
  1000
+				userid = $userid AND retry = $retries order by timeseen")) {
1001 1001
 
1002 1002
 			foreach ($pagesanswered as $pageanswered) {
1003 1003
 				if (@!array_key_exists($pageanswered->pageid, $temp)) {
@@ -1025,7 +1025,7 @@ function lesson_calculate_ongoing_score($lesson, $USER) {
1025 1025
 		$score = 0;
1026 1026
 		$currenthigh = 0;
1027 1027
 		if ($useranswers = get_records_select("lesson_attempts",  "lessonid = $lesson->id AND 
1028  
-				userid = $USER->id AND retry = $retries", "timeseen")) {
  1028
+				userid = $userid AND retry = $retries", "timeseen")) {
1029 1029
 
1030 1030
 			foreach ($useranswers as $useranswer) {
1031 1031
 				if (@!array_key_exists($useranswer->pageid, $temp)) {
@@ -1081,11 +1081,14 @@ function lesson_calculate_ongoing_score($lesson, $USER) {
1081 1081
 		} elseif ($score < 0) {
1082 1082
 			$score = 0;
1083 1083
 		}
1084  
-		
1085  
-		$ongoingoutput->grade = $lesson->grade;
1086  
-		$ongoingoutput->score = $score;
1087  
-		$ongoingoutput->currenthigh = $currenthigh;
1088  
-		print_simple_box(get_string("ongoingcustom", "lesson", $ongoingoutput), "center");
  1084
+		if ($return) {
  1085
+			return $score;
  1086
+		} else {
  1087
+			$ongoingoutput->grade = $lesson->grade;
  1088
+			$ongoingoutput->score = $score;
  1089
+			$ongoingoutput->currenthigh = $currenthigh;
  1090
+			print_simple_box(get_string("ongoingcustom", "lesson", $ongoingoutput), "center");
  1091
+		}
1089 1092
 	}
1090 1093
 }
1091 1094
 

0 notes on commit b986908

Please sign in to comment.
Something went wrong with that request. Please try again.