Browse Source

Fixing the reporting page see #5175

Julio Montoya 12 years ago
parent
commit
acb259e89b
3 changed files with 72 additions and 61 deletions
  1. 2 2
      main/inc/lib/sessionmanager.lib.php
  2. 7 15
      main/inc/lib/tracking.lib.php
  3. 63 44
      main/mySpace/index.php

+ 2 - 2
main/inc/lib/sessionmanager.lib.php

@@ -1521,7 +1521,7 @@ class SessionManager {
     /**
      * Get users by session
      * @param  int sesssion id
-     * @param	int	filter by status 
+     * @param	int	filter by status  
      * @return  array a list with an user list
      */
     public static function get_users_by_session($id, $with_status = null) {
@@ -1537,7 +1537,7 @@ class SessionManager {
                     ON $tbl_user.user_id = $tbl_session_rel_user.id_user 
                     AND $tbl_session_rel_user.id_session = $id";
         
-        if (!empty($with_status)) {
+        if (isset($with_status) && $with_status != '') {
         	$with_status = intval($with_status);
         	$sql .= " WHERE relation_type = $with_status ";
         }

+ 7 - 15
main/inc/lib/tracking.lib.php

@@ -1124,9 +1124,8 @@ class Tracking {
 
 			$a_students = array ();
 
-			//////////////////////////////////////////////////////////////
 			// At first, courses where $coach_id is coach of the course //
-			//////////////////////////////////////////////////////////////
+
 			$sql = 'SELECT course_code FROM ' . $tbl_session_course_user . ' WHERE id_session="' . $id_session . '" AND id_user=' . $coach_id.' AND status=2';
 
 			$result = Database::query($sql);
@@ -1145,9 +1144,7 @@ class Tracking {
 				}
 			}
 
-			//////////////////////////////////////////////////////////////
 			// Then, courses where $coach_id is coach of the session    //
-			//////////////////////////////////////////////////////////////
 
 			$dsl_session_coach = 'SELECT id_coach FROM ' . $tbl_session . ' WHERE id="' . $id_session . '" AND id_coach="' . $coach_id . '"';
 			$result = Database::query($dsl_session_coach);
@@ -1176,9 +1173,8 @@ class Tracking {
 			$tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
 			$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
 
-			//////////////////////////////////////////////////////////////
 			// At first, courses where $coach_id is coach of the course //
-			//////////////////////////////////////////////////////////////
+
 			/*$sql = 'SELECT 1
 			FROM ' . $tbl_session_course_user . ' AS session_course_user
 			INNER JOIN ' . $tbl_session_course . ' AS session_course
@@ -1193,9 +1189,7 @@ class Tracking {
 				return true;
 			}
 
-			//////////////////////////////////////////////////////////////
 			// Then, courses where $coach_id is coach of the session    //
-			//////////////////////////////////////////////////////////////
 
 			$sql = 'SELECT session_course_user.id_user
                         FROM ' . $tbl_session_course_user . ' as session_course_user
@@ -1232,9 +1226,8 @@ class Tracking {
 			$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
 			$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
 
-			//////////////////////////////////////////////////////////////
-			// At first, courses where $coach_id is coach of the course //
-			//////////////////////////////////////////////////////////////
+			// At first, courses where $coach_id is coach of the course
+			
 			$sql = 'SELECT DISTINCT course_code FROM ' . $tbl_session_course_user . ' WHERE id_user=' . $coach_id.' AND status=2';
 
 			global $_configuration;
@@ -1254,10 +1247,9 @@ class Tracking {
 			while ($row = Database::fetch_array($result)) {
 				$a_courses[$row['course_code']] = $row['course_code'];
 			}
-
-			//////////////////////////////////////////////////////////////
-			// Then, courses where $coach_id is coach of the session    //
-			//////////////////////////////////////////////////////////////
+			
+			// Then, courses where $coach_id is coach of the session
+			
 			$sql = 'SELECT DISTINCT session_course.course_code
                         FROM ' . $tbl_session_course . ' as session_course
                         INNER JOIN ' . $tbl_session . ' as session

+ 63 - 44
main/mySpace/index.php

@@ -181,9 +181,9 @@ if (empty($session_id)) {
 		$courses = $courses[0]; 
 	}
 	
-	//Getting students from courses and courses in sessions (For show the total students that the user follows)
+	//Getting students from courses and courses in sessions (To show the total students that the user follows)
 	$students 		= CourseManager::get_user_list_from_courses_as_coach($user_id);
-		
+    		
 	// Sessions for the coach
 	$sessions 	 	= Tracking::get_sessions_coached_by_user($user_id);	
 	
@@ -258,21 +258,41 @@ if (empty($session_id)) {
 
 	if ($nb_students > 0 && $view != 'admin') {
 		
-		echo Display::page_subheader('<img src="'.api_get_path(WEB_IMG_PATH).'students.gif">&nbsp;'.get_lang('Students').' ('.$nb_students.')');
-		
 		// average progress
 		$avg_total_progress = $avg_total_progress / $nb_students;
 		// average results to the tests
 		$avg_results_to_exercises = $avg_results_to_exercises / $nb_students;
 		// average courses by student
-		$avg_courses_per_student = round($total_courses / $nb_students, 2);
+		$avg_courses_per_student = round($count_courses / $nb_students, 2);
 		// average time spent on the platform
 		$avg_time_spent = $total_time_spent / $nb_students;
 		// average assignments
 		$nb_assignments = $nb_assignments / $nb_students;
 		// average posts
 		$nb_posts = $nb_posts / $nb_students;
-		
+        
+        
+        echo Display::page_subheader('<img src="'.api_get_path(WEB_IMG_PATH).'teachers.gif">&nbsp;'.get_lang('Overview'));
+        
+        echo '<div class="report_section">
+					<table class="table table-bordered">
+                        <tr>
+							<td>'.get_lang('FollowedUsers').'</td>
+							<td align="right">'.$nb_students.'</td>
+						</tr>
+                        <tr>
+							<td>'.get_lang('FollowedCourses').'</td>
+							<td align="right">'.$count_courses.'</td>
+						</tr>
+                        <tr>
+							<td>'.get_lang('FollowedSessions').'</td>
+							<td align="right">'.$count_sessions.'</td>
+						</tr>
+                        </table>';
+        echo '</div>';
+                        
+		echo Display::page_subheader('<img src="'.api_get_path(WEB_IMG_PATH).'students.gif">&nbsp;'.get_lang('Students').' ('.$nb_students.')');
+        
 		if ($export_csv) {
 			//csv part
 			$csv_content[] = array(get_lang('Students', ''));
@@ -287,19 +307,21 @@ if (empty($session_id)) {
 		} else {
 			// html part
 			echo '<div class="report_section">
-					<table class="table table-bordered">
-						<tr>
+					<table class="table table-bordered">     
+                        <tr>
+							<td>'.get_lang('AverageCoursePerStudent').'</td>
+							<td align="right">'.(is_null($avg_courses_per_student) ? '' : $avg_courses_per_student).'</td>
+						</tr>                        
+                        <tr>
 							<td>'.get_lang('InactivesStudents').'</td>
 							<td align="right">'.$nb_inactive_students.'</td>
 						</tr>
+                        
 						<tr>
 							<td>'.get_lang('AverageTimeSpentOnThePlatform').'</td>
 							<td align="right">'.(is_null($avg_time_spent) ? '' : api_time_to_hms($avg_time_spent)).'</td>
 						</tr>
-						<tr>
-							<td>'.get_lang('AverageCoursePerStudent').'</td>
-							<td align="right">'.(is_null($avg_courses_per_student) ? '' : $avg_courses_per_student).'</td>
-						</tr>
+						
 						<tr>
 							<td>'.get_lang('AverageProgressInLearnpath').'</td>
 							<td align="right">'.(is_null($avg_total_progress) ? '' : round($avg_total_progress, 2).'%').'</td>
@@ -368,7 +390,7 @@ if (api_is_allowed_to_create_course() && $view == 'teacher') {
 		$table -> set_header(4, get_lang('AvgCourseScore').' '.Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
 		$table -> set_header(5, get_lang('AvgExercisesScore').' '.Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
 		$table -> set_header(6, get_lang('AvgMessages'), false);
-		$table -> set_header(7, get_lang('AvgAssignments'), false);
+		$table -> set_header(7, get_lang('AverageAssignments'), false);
 		$table -> set_header(8, get_lang('Details'), false);
 
 		$csv_content[] = array (
@@ -379,7 +401,7 @@ if (api_is_allowed_to_create_course() && $view == 'teacher') {
 			get_lang('AvgCourseScore', ''),
 			get_lang('AvgExercisesScore', ''),
 			get_lang('AvgMessages', ''),
-			get_lang('AvgAssignments', '')
+			get_lang('AverageAssignments', '')
 		);
 		$table->display();
 	}
@@ -387,16 +409,18 @@ if (api_is_allowed_to_create_course() && $view == 'teacher') {
 	// Display list of sessions
 	if ($count_sessions > 0 && !isset($_GET['session_id'])) {
 		echo Display::page_subheader('<img src="'.api_get_path(WEB_IMG_PATH).'session.png">&nbsp;'.get_lang('Sessions').' ('.$count_sessions.')');
+        
 		$table = new SortableTable('tracking_sessions_myspace', 'count_sessions_coached');
 		$table->set_header(0, get_lang('Title'), false);
-		$table->set_header(1, get_lang('Date'), false);
-		$table->set_header(2, get_lang('NbCoursesPerSession'), false);
-		$table->set_header(3, get_lang('Details'), false);
+        $table->set_header(1, get_lang('Date'), false);		
+        $table->set_header(2, get_lang('NbStudentPerSession'), false);
+		$table->set_header(3, get_lang('NbCoursesPerSession'), false);
+		$table->set_header(4, get_lang('Details'), false);
 
 		$all_data = array();
-		foreach ($sessions as $session) {
-			
+		foreach ($sessions as $session) {			
 			$count_courses_in_session = count(Tracking::get_courses_followed_by_coach($user_id, $session['id']));
+            $count_users_in_session = count(SessionManager::get_users_by_session($session['id'], 0));
 			$row = array();
 			$row[] = $session['name'];
 
@@ -405,7 +429,10 @@ if (api_is_allowed_to_create_course() && $view == 'teacher') {
 			} else {
 				$row[] = ' - ';
 			}
-			$row[] = $count_courses_in_session;
+            
+            $row[] = $count_courses_in_session;
+            $row[] = $count_users_in_session;
+			
 			$row[] = '<a href="'.api_get_self().'?session_id='.$session['id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
 			$all_data[] = $row;
 		}
@@ -434,7 +461,7 @@ if (api_is_allowed_to_create_course() && $view == 'teacher') {
 		
 		/*  Start session over view stats */
 		
-		$nb_sessions_past = $nb_sessions_future = $nb_sessions_current = 0;
+		$nb_sessions_past = $nb_sessions_current = 0;
 		$courses = array();
         
 		foreach ($sessions as $session) {            
@@ -447,22 +474,22 @@ if (api_is_allowed_to_create_course() && $view == 'teacher') {
 			$courses = array_merge($courses, Tracking::get_courses_list_from_session($session['id']));
 		}
 		
-		if ($nb_sessions > 0) {
-			$nb_courses_per_session = round(count($courses) / $nb_sessions, 2);
-			$nb_students_per_session = round($nb_students / $nb_sessions, 2);
-		} else {
-			$nb_courses_per_session = null;
-			$nb_students_per_session = null;
-		}		
-		
+        $nb_courses_per_session     = null; 
+        $nb_students_per_session    = null;
+            
+		if ($count_sessions > 0) {
+			$nb_courses_per_session = round(count($courses) / $count_sessions, 2);
+			$nb_students_per_session = round($nb_students / $count_sessions, 2);
+		}
+        
 		if ($export_csv) {
 			//csv part
 			$csv_content[] = array(get_lang('Sessions', ''));
 			$csv_content[] = array(get_lang('NbActiveSessions', '').';'.$nb_sessions_current);
 			$csv_content[] = array(get_lang('NbInactiveSessions', '').';'.$nb_sessions_past);
 			//$csv_content[] = array(get_lang('NbFutureSessions', '').';'.$nb_sessions_future);
-			$csv_content[] = array(get_lang('NbStudentPerSession', '').';'.$nb_students_per_session);
-			$csv_content[] = array(get_lang('NbCoursesPerSession', '').';'.$nb_courses_per_session);
+            $csv_content[] = array(get_lang('NbCoursesPerSession', '').';'.$nb_courses_per_session);
+			$csv_content[] = array(get_lang('NbStudentPerSession', '').';'.$nb_students_per_session);			
 			$csv_content[] = array();
 		} else {
 			// html part
@@ -482,14 +509,6 @@ if (api_is_allowed_to_create_course() && $view == 'teacher') {
 						<td>'.get_lang('NbInactiveSessions').'</td>
 						<td align="right">'.$nb_sessions_past.'</td>
 					</tr>		
-					<tr>
-						<td>'.get_lang('NbStudentPerSession').'</td>
-						<td align="right">'.(is_null($nb_students_per_session) ? '' : $nb_students_per_session).'</td>
-					</tr>
-					<tr>
-						<td>'.get_lang('NbCoursesPerSession').'</td>
-						<td align="right">'.(is_null($nb_courses_per_session) ? '' : $nb_courses_per_session).'</td>
-					</tr>
 				</table>				
 			</div>';
 		}
@@ -629,11 +648,11 @@ if ($is_platform_admin && $view == 'admin' && $display != 'yourstudents') {
 
 		foreach ($global_coaches as $id_coach => $coaches) {
 
-			$time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($coaches['user_id']));
-			$last_connection = Tracking :: get_last_connection_date($coaches['user_id']);
-			$nb_students = count(Tracking :: get_student_followed_by_coach($coaches['user_id']));
-			$nb_courses = count(Tracking :: get_courses_followed_by_coach($coaches['user_id']));
-			$nb_sessions = count(Tracking :: get_sessions_coached_by_user($coaches['user_id']));
+			$time_on_platform   = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($coaches['user_id']));
+			$last_connection    = Tracking :: get_last_connection_date($coaches['user_id']);
+			$nb_students        = count(Tracking :: get_student_followed_by_coach($coaches['user_id']));
+			$nb_courses         = count(Tracking :: get_courses_followed_by_coach($coaches['user_id']));
+			$nb_sessions        = count(Tracking :: get_sessions_coached_by_user($coaches['user_id']));
 
 			$table_row = array();
 			if ($is_western_name_order) {