Explorar o código

Using jqgrid instead of old table see BT#6770

Julio Montoya %!s(int64=11) %!d(string=hai) anos
pai
achega
df4a46393a

+ 62 - 1
main/inc/ajax/model.ajax.php

@@ -31,6 +31,7 @@ if (!in_array($sord, array('asc','desc'))) {
     $sord = 'desc';
 }
 
+// Actions allowed to other roles.
 if (!in_array(
     $action,
     array(
@@ -45,7 +46,8 @@ if (!in_array(
         'get_user_skill_ranking',
         'get_usergroups_teacher',
         'get_user_course_report_resumed',
-        'get_user_course_report'
+        'get_user_course_report',
+        'get_sessions_tracking'
     )
 )) {
     api_protect_admin_script(true);
@@ -220,6 +222,14 @@ switch ($action) {
         $hotpot_path = $_REQUEST['path'];
         $count = get_count_exam_hotpotatoes_results($hotpot_path);
         break;
+    case 'get_sessions_tracking':
+        if (api_is_drh()) {
+            $count = SessionManager::get_sessions_followed_by_drh(api_get_user_id(), null, null, true);
+        } else {
+            // Sessions for the coach
+            $count = Tracking::get_sessions_coached_by_user(api_get_user_id(), null, null, true);
+        }
+        break;
     case 'get_sessions':
         $courseId = isset($_GET['course_id']) && !empty($_GET['course_id']) ? intval($_GET['course_id']) : null;
         if (!empty($courseId)) {
@@ -482,6 +492,56 @@ switch ($action) {
 		$columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date',  'score', 'actions');
 		$result = get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition); //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
 		break;
+    case 'get_sessions_tracking':
+        if (api_is_drh()) {
+            $sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id(), $start, $limit);
+        } else {
+            // Sessions for the coach
+            $sessions = Tracking::get_sessions_coached_by_user(api_get_user_id(), $start, $limit);
+        }
+
+        $columns =  array(
+            'name',
+            'date',
+            'course_per_session',
+            'student_per_session',
+            'details'
+        );
+
+        $result = array();
+        foreach ($sessions as $session) {
+            if (api_drh_can_access_all_session_content()) {
+                $count_courses_in_session = count(SessionManager::get_course_list_by_session_id($session['id']));
+            } else {
+                $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));
+            $session_date = array();
+            if (!empty($session['date_start']) && $session['date_start'] != '0000-00-00') {
+                $session_date[] = get_lang('From').' '.api_format_date($session['date_start'], DATE_FORMAT_SHORT);
+            }
+
+            if (!empty($session['date_end']) && $session['date_end'] != '0000-00-00') {
+                $session_date[] = get_lang('Until').' '.api_format_date($session['date_end'], DATE_FORMAT_SHORT);
+            }
+
+            if (empty($session_date)) {
+                $session_date_string = '-';
+            } else {
+                $session_date_string = implode(' ', $session_date);
+            }
+            $sessionUrl = api_get_path(WEB_CODE_PATH).'mySpace/index.php?session_id='.$session['id'];
+            $result[] = array(
+                'name' => $session['name'],
+                'date' => $session_date_string,
+                'course_per_session' => $count_courses_in_session,
+                'student_per_session' => $count_users_in_session,
+                'details' => Display::url(Display::return_icon('2rightarrow.gif'), $sessionUrl)
+            );
+        }
+
+        break;
     case 'get_sessions':
         $columns = array(
             'name', 'nbr_courses', 'nbr_users', 'category_name', 'date_start','date_end', 'coach_name', 'session_active', 'visibility'
@@ -711,6 +771,7 @@ $allowed_actions = array(
     'get_usergroups_teacher',
     'get_gradebooks',
     'get_sessions',
+    'get_sessions_tracking',
     'get_session_lp_progress',
     'get_exercise_results',
     'get_hotpotatoes_exercise_results',

+ 29 - 12
main/inc/lib/sessionmanager.lib.php

@@ -1707,36 +1707,53 @@ class SessionManager
 	 * @param int		Human resources manager or Session admin id
 	 * @return array 	sessions
 	 */
-	public static function get_sessions_followed_by_drh($hr_manager_id)
+	public static function get_sessions_followed_by_drh($userId, $start = null, $limit = null, $getCount = false)
     {
 		// Database Table Definitions
 		$tbl_session 			= 	Database::get_main_table(TABLE_MAIN_SESSION);
 		$tbl_session_rel_user 	= 	Database::get_main_table(TABLE_MAIN_SESSION_USER);
         $tbl_session_rel_access_url =   Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
 
-		$hr_manager_id = intval($hr_manager_id);
+		$userId = intval($userId);
 		$assigned_sessions_to_hrm = array();
 
+        $select = " SELECT * ";
+        if ($getCount) {
+            $select = " SELECT count(s.id) as count ";
+        }
+
+         $limitCondition = null;
+        if (!empty($start) && !empty($limit)) {
+            $limitCondition = " LIMIT ".intval($start). ", ".intval($limit);
+        }
+
 		if (api_is_multiple_url_enabled()) {
-           $sql = "SELECT * FROM $tbl_session s
+           $sql = " $select FROM $tbl_session s
                     INNER JOIN $tbl_session_rel_user sru ON (sru.id_session = s.id)
                     LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id)
                     WHERE
-                        sru.id_user = '$hr_manager_id' AND
+                        sru.id_user = '$userId' AND
                         sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' AND
-                        access_url_id = ".api_get_current_access_url_id()."";
+                        access_url_id = ".api_get_current_access_url_id()."
+                        $limitCondition";
         } else {
-            $sql = "SELECT * FROM $tbl_session s
+            $sql = "$select FROM $tbl_session s
                      INNER JOIN $tbl_session_rel_user sru
                      ON
                         sru.id_session = s.id AND
-                        sru.id_user = '$hr_manager_id' AND
-                        sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' ";
+                        sru.id_user = '$userId' AND
+                        sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."'
+                        $limitCondition";
         }
-		$rs_assigned_sessions = Database::query($sql);
-		if (Database::num_rows($rs_assigned_sessions) > 0) {
-			while ($row_assigned_sessions = Database::fetch_array($rs_assigned_sessions))	{
-				$assigned_sessions_to_hrm[$row_assigned_sessions['id']] = $row_assigned_sessions;
+		$result = Database::query($sql);
+        if ($getCount) {
+            $row = Database::fetch_array($result);
+            return $row['count'];
+        }
+
+        if (Database::num_rows($result) > 0) {
+			while ($row = Database::fetch_array($result))	{
+				$assigned_sessions_to_hrm[$row['id']] = $row;
 			}
 		}
 		return $assigned_sessions_to_hrm;

+ 50 - 32
main/inc/lib/tracking.lib.php

@@ -1312,7 +1312,7 @@ class Tracking {
      * @param    int        Coach id
      * @return    array    Sessions list
      */
-    public static function get_sessions_coached_by_user($coach_id)
+    public static function get_sessions_coached_by_user($coach_id, $start = 0, $limit = 0, $getCount = false)
     {
         // table definition
         $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
@@ -1320,52 +1320,70 @@ class Tracking {
 
         $coach_id = intval($coach_id);
 
-        // session where we are general coach
-        $sql = 'SELECT DISTINCT id, name, date_start, date_end
-                    FROM ' . $tbl_session . '
-                    WHERE id_coach=' . $coach_id;
+        $select = " SELECT * FROM ";
 
-        if (api_is_multiple_url_enabled()) {
-            $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
-            $access_url_id = api_get_current_access_url_id();
-            if ($access_url_id != -1){
-                $sql = 'SELECT DISTINCT id, name, date_start, date_end
-                    FROM ' . $tbl_session . ' session INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
-                    ON (session.id = session_rel_url.session_id)
-                    WHERE id_coach=' . $coach_id.' AND access_url_id = '.$access_url_id;
-            }
+        if ($getCount) {
+            $select = " SELECT count(DISTINCT id) as count FROM ";
         }
 
-        $rs = Database::query($sql);
-        while ($row = Database::fetch_array($rs)) {
-            $a_sessions[$row["id"]] = $row;
+        $limitCondition = null;
+        if (!empty($start) && !empty($limit)) {
+            $limitCondition = " LIMIT ".intval($start).", ".intval($limit);
         }
 
-        // session where we are coach of a course
-        $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
-                    FROM ' . $tbl_session . ' as session
-                    INNER JOIN ' . $tbl_session_course_user . ' as session_course_user
+        // session where we are general coach
+        $sql = " $select
+
+                (SELECT DISTINCT id, name, date_start, date_end
+                    FROM $tbl_session
+                    WHERE id_coach = $coach_id
+                UNION
+
+                SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
+                    FROM $tbl_session as session
+                    INNER JOIN $tbl_session_course_user  as session_course_user
                         ON session.id = session_course_user.id_session
-                        AND session_course_user.id_user=' . $coach_id.' AND session_course_user.status=2';
+                        AND session_course_user.id_user= $coach_id AND session_course_user.status=2
+                )
+                as sessions $limitCondition
+                ";
 
         if (api_is_multiple_url_enabled()) {
             $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
             $access_url_id = api_get_current_access_url_id();
             if ($access_url_id != -1){
-                $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
-                    FROM ' . $tbl_session . ' as session
-                    INNER JOIN ' . $tbl_session_course_user . ' as session_course_user
-                        ON session.id = session_course_user.id_session AND session_course_user.id_user=' . $coach_id.' AND session_course_user.status=2
-                    INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url
-                    ON (session.id = session_rel_url.session_id)
-                    WHERE access_url_id = '.$access_url_id;
+                $sql = "
+                    $select
+                    (
+                        SELECT DISTINCT id, name, date_start, date_end
+                        FROM $tbl_session session INNER JOIN $tbl_session_rel_access_url session_rel_url
+                        ON (session.id = session_rel_url.session_id)
+                        WHERE id_coach = $coach_id AND access_url_id = $access_url_id
+
+                        UNION
+
+                        SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
+                        FROM $tbl_session as session
+                        INNER JOIN $tbl_session_course_user as session_course_user
+                            ON session.id = session_course_user.id_session AND session_course_user.id_user= $coach_id AND session_course_user.status=2
+                        INNER JOIN $tbl_session_rel_access_url session_rel_url
+                        ON (session.id = session_rel_url.session_id)
+                        WHERE access_url_id = $access_url_id
+                    ) as sessions $limitCondition
+                    ";
             }
         }
 
         $rs = Database::query($sql);
+        if ($getCount) {
+            $row = Database::fetch_array($rs);
+            return $row['count'];
+        }
+
         while ($row = Database::fetch_array($rs)) {
             $a_sessions[$row["id"]] = $row;
         }
+
         if (is_array($a_sessions)) {
             foreach ($a_sessions as & $session) {
                 if ($session['date_start'] == '0000-00-00') {
@@ -2035,7 +2053,7 @@ class Tracking {
      * Get total clicks by session
      * @param    int        Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
      * @return    array     data
-     * @todo    implement total click by $course_id 
+     * @todo    implement total click by $course_id
      */
     public static function get_total_clicks_by_session($session_id = null) {
         $tables = array(
@@ -2057,12 +2075,12 @@ class Tracking {
             #TABLE_STATISTIC_TRACK_E_OPEN,
             );
 
-        if (isset($_GET['session_id']) && !empty($_GET['session_id'])) 
+        if (isset($_GET['session_id']) && !empty($_GET['session_id']))
         {
             $sessionId = intval($_GET['session_id']);
         }
 
-        foreach ($tables as $tableName => $fields) 
+        foreach ($tables as $tableName => $fields)
         {
             $sql = sprintf('SELECT %s as user, count(*) as total FROM %s WHERE %s = %s GROUP BY %s', $fields[1], $tableName, $fields[0], $sessionId, $fields[1]);
             $rs = Database::query($sql);

+ 59 - 87
main/mySpace/index.php

@@ -238,9 +238,6 @@ if (empty($session_id)) {
         $students[] = $studentData['user_id'];
     }*/
 
-	// Sessions for the coach
-	$sessions = Tracking::get_sessions_coached_by_user($user_id);
-
 	// If is drh
 	if ($is_drh) {
         if (api_drh_can_access_all_session_content()) {
@@ -265,7 +262,11 @@ if (empty($session_id)) {
             }
             $sessions = SessionManager::get_sessions_followed_by_drh($user_id);
         }
-	}
+	} else {
+        // Sessions for the coach
+
+        $sessions = Tracking::get_sessions_coached_by_user($user_id);
+    }
 
     //var_dump(count($students));exit;
 
@@ -363,8 +364,7 @@ if (empty($session_id)) {
                         </table>';
         echo '</div>';
 
-		echo Display::page_subheader('<img src="'.api_get_path(WEB_IMG_PATH).'students.gif">
-		    &nbsp;'.get_lang('Students').' ('.$nb_students.')');
+		echo Display::page_subheader(Display::return_icon('students.gif').'&nbsp;'.get_lang('Students').' ('.$nb_students.')');
 
 		if ($export_csv) {
 			//csv part
@@ -465,7 +465,7 @@ if ($count_courses || $count_sessions) {
 	//If we are in course
 	if (empty($session_id)) {
 		if ($count_courses) {
-			$title = '<img src="'.api_get_path(WEB_IMG_PATH).'course.gif"> '.get_lang('Courses').' ('.$count_courses.') ';
+			$title = Display::return_icon('course.gif').' '.get_lang('Courses').' ('.$count_courses.') ';
 		}
 	} else {
 		//If we are in Course Session
@@ -512,68 +512,38 @@ if ((api_is_allowed_to_create_course() || api_is_drh()) && in_array($view, array
 	// 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('NbStudentPerSession'), false);
-		$table->set_header(4, get_lang('Details'), false);
-
-		$all_data = array();
-		foreach ($sessions as $session) {
-            if (api_drh_can_access_all_session_content()) {
-                $count_courses_in_session = count(SessionManager::get_course_list_by_session_id($session['id']));
-            } else {
-                $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'];
-
-            $session_date = array();
-			if (!empty($session['date_start']) && $session['date_start'] != '0000-00-00') {
-                $session_date[] = get_lang('From').' '.api_format_date($session['date_start'], DATE_FORMAT_SHORT);
-            }
-
-            if (!empty($session['date_end']) && $session['date_end'] != '0000-00-00') {
-                $session_date[] = get_lang('Until').' '.api_format_date($session['date_end'], DATE_FORMAT_SHORT);
-            }
-
-            if (empty($session_date)) {
-                $session_date_string = '-';
-            } else {
-                $session_date_string = implode(' ', $session_date);
-            }
-
-            $row[] = $session_date_string;
-            $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;
-		}
-
-		if (!isset($tracking_column)) {
-			$tracking_column = 0;
-		}
-
-		if (isset($_GET['tracking_direction']) &&  $_GET['tracking_direction'] == 'DESC') {
-			usort($all_data, 'rsort_sessions');
-		} else {
-			usort($all_data, 'sort_sessions');
-		}
-
-		if ($export_csv) {
-			usort($csv_content, 'sort_sessions');
-		}
-
-		foreach ($all_data as $row) {
-			$table -> addRow($row);
-		}
-
-		/*  Start session over view stats */
+		echo Display::page_subheader(Display::return_icon('session.png').' '.get_lang('Sessions').' ('.$count_sessions.')');
+
+        $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions_tracking';
+
+        //The order is important you need to check the the $column variable in the model.ajax.php file
+        $columns = array(
+            get_lang('Title'),
+            get_lang('Date'),
+            get_lang('NbCoursesPerSession'),
+            get_lang('NbStudentPerSession'),
+            get_lang('Details')
+        );
+
+        // Column config
+        $columnModel   = array(
+            array('name'=>'name',               'index'=>'name',        'width'=>'255',   'align'=>'left'),
+            array('name'=>'date',                'index'=>'date', 'width'=>'150',  'align'=>'left','sortable'=>'false'),
+            array('name'=>'course_per_session',  'index'=>'course_per_session',     'width'=>'150','sortable'=>'false'),
+            array('name'=>'student_per_session', 'index'=>'student_per_session',     'width'=>'100','sortable'=>'false'),
+            array('name'=>'details',             'index'=>'details',     'width'=>'100','sortable'=>'false'),
+        );
+
+        $extraParams = array(
+            'autowidth' => 'true',
+            'height' => 'auto'
+        );
+
+        $js = '<script>
+        $(function() {
+            '.Display::grid_js('session_tracking', $url, $columns, $columnModel, $extraParams, array(), null, true).'
+        });
+        </script>';
 
 		$nb_sessions_past = $nb_sessions_current = 0;
 		$courses = array();
@@ -601,7 +571,6 @@ if ((api_is_allowed_to_create_course() || api_is_drh()) && in_array($view, array
 			$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('NbCoursesPerSession', '').';'.$nb_courses_per_session);
 			$csv_content[] = array(get_lang('NbStudentPerSession', '').';'.$nb_students_per_session);
 			$csv_content[] = array();
@@ -620,9 +589,12 @@ if ((api_is_allowed_to_create_course() || api_is_drh()) && in_array($view, array
 				</table>
 			</div>';
 		}
-		/*  End session overview */
-		$table -> display();
-	}
+
+
+        echo $js;
+        echo Display::grid_html('session_tracking');
+
+    }
 }
 
 if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourstudents') {
@@ -638,9 +610,8 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
 	echo ' | <a href="'.api_get_self().'?view=admin&amp;display=courseoverview">'.get_lang('DisplayCourseOverview').'</a>';
     echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'tracking/question_course_report.php?view=admin">'.get_lang('LPQuestionListResults').'</a>';
     echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'tracking/course_session_report.php?view=admin">'.get_lang('LPExerciseResultsBySession').'</a>';
-
-
 	echo '<br /><br />';
+
 	if ($display === 'useroverview') {
 		MySpace::display_tracking_user_overview();
 	} else if($display == 'sessionoverview') {
@@ -678,18 +649,18 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
 		$parameters['view'] = 'admin';
 		$table->set_additional_parameters($parameters);
 		if ($is_western_name_order) {
-			$table -> set_header(0, get_lang('FirstName'), true);
-			$table -> set_header(1, get_lang('LastName'), true);
+			$table->set_header(0, get_lang('FirstName'), true);
+			$table->set_header(1, get_lang('LastName'), true);
 		} else {
-			$table -> set_header(0, get_lang('LastName'), true);
-			$table -> set_header(1, get_lang('FirstName'), true);
+			$table->set_header(0, get_lang('LastName'), true);
+			$table->set_header(1, get_lang('FirstName'), true);
 		}
-		$table -> set_header(2, get_lang('TimeSpentOnThePlatform'), false);
-		$table -> set_header(3, get_lang('LastConnexion'), false);
-		$table -> set_header(4, get_lang('NbStudents'), false);
-		$table -> set_header(5, get_lang('CountCours'), false);
-		$table -> set_header(6, get_lang('NumberOfSessions'), false);
-		$table -> set_header(7, get_lang('Sessions'), false);
+		$table->set_header(2, get_lang('TimeSpentOnThePlatform'), false);
+		$table->set_header(3, get_lang('LastConnexion'), false);
+		$table->set_header(4, get_lang('NbStudents'), false);
+		$table->set_header(5, get_lang('CountCours'), false);
+		$table->set_header(6, get_lang('NumberOfSessions'), false);
+		$table->set_header(7, get_lang('Sessions'), false);
 
 		if ($is_western_name_order) {
 			$csv_header[] = array (
@@ -830,9 +801,9 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
 		}
 
 		foreach ($all_datas as $row) {
-			$table -> addRow($row, 'align="right"');
+			$table->addRow($row, 'align="right"');
 		}
-		$table -> display();
+		$table->display();
 	}
 }
 
@@ -847,6 +818,7 @@ if ($export_csv) {
 if (!$export_csv) {
 	Display::display_footer();
 }
+
 /**
  * Get number of courses for sortable with pagination
  * @return int