@@ -128,16 +128,15 @@ public function export_csv($header, $data, $file_name = 'export.csv')
128
128
*/
129
129
public static function get_connections_to_course ($ userId , $ courseId , $ sessionId = 0 )
130
130
{
131
- // Database table definitions
132
- $ tbl_track_course = Database::get_main_table (TABLE_STATISTIC_TRACK_E_COURSE_ACCESS );
131
+ $ table = Database::get_main_table (TABLE_STATISTIC_TRACK_E_COURSE_ACCESS );
133
132
134
133
// protect data
135
134
$ userId = (int ) $ userId ;
136
135
$ courseId = (int ) $ courseId ;
137
136
$ sessionId = (int ) $ sessionId ;
138
137
139
138
$ sql = 'SELECT login_course_date, logout_course_date
140
- FROM ' . $ tbl_track_course .'
139
+ FROM ' . $ table .'
141
140
WHERE
142
141
user_id = ' .$ userId .' AND
143
142
c_id = ' .$ courseId .' AND
@@ -147,11 +146,9 @@ public static function get_connections_to_course($userId, $courseId, $sessionId
147
146
$ connections = array ();
148
147
149
148
while ($ row = Database::fetch_array ($ rs )) {
150
- $ timestamp_login_date = api_strtotime ($ row ['login_course_date ' ], 'UTC ' );
151
- $ timestamp_logout_date = api_strtotime ($ row ['logout_course_date ' ], 'UTC ' );
152
149
$ connections [] = array (
153
- 'login ' => $ timestamp_login_date ,
154
- 'logout ' => $ timestamp_logout_date
150
+ 'login ' => api_strtotime ( $ row [ ' login_course_date ' ], ' UTC ' ) ,
151
+ 'logout ' => api_strtotime ( $ row [ ' logout_course_date ' ], ' UTC ' )
155
152
);
156
153
}
157
154
@@ -2648,7 +2645,6 @@ public static function getUserDataAccessTrackingOverview($from, $numberItems, $c
2648
2645
//TODO: Dont use numeric index
2649
2646
foreach ($ data as $ key => $ info ) {
2650
2647
$ start_date = $ info ['col0 ' ];
2651
-
2652
2648
$ end_date = $ info ['logout_course_date ' ];
2653
2649
2654
2650
$ return [$ info ['user_id ' ]] = array (
@@ -2682,17 +2678,16 @@ public static function getUserDataAccessTrackingOverview($from, $numberItems, $c
2682
2678
/**
2683
2679
* Gets the connections to a course as an array of login and logout time
2684
2680
*
2685
- * @param int $user_id
2686
- * @param int $courseId
2681
+ * @param int $user_id
2682
+ * @param int $courseId
2687
2683
* @author Jorge Frisancho Jibaja
2688
2684
* @author Julio Montoya <gugli100@gmail.com> fixing the function
2689
2685
* @version OCT-22- 2010
2690
2686
* @return array
2691
2687
*/
2692
2688
public static function get_connections_to_course_by_date ($ user_id , $ courseId , $ start_date , $ end_date )
2693
2689
{
2694
- // Database table definitions
2695
- $ tbl_track_course = Database::get_main_table (TABLE_STATISTIC_TRACK_E_COURSE_ACCESS );
2690
+ $ table = Database::get_main_table (TABLE_STATISTIC_TRACK_E_COURSE_ACCESS );
2696
2691
$ course_info = api_get_course_info_by_id ($ courseId );
2697
2692
$ user_id = intval ($ user_id );
2698
2693
$ courseId = intval ($ courseId );
@@ -2701,23 +2696,19 @@ public static function get_connections_to_course_by_date($user_id, $courseId, $s
2701
2696
if (!empty ($ course_info )) {
2702
2697
$ end_date = add_day_to ($ end_date );
2703
2698
$ sql = "SELECT login_course_date, logout_course_date
2704
- FROM $ tbl_track_course
2705
- WHERE
2706
- user_id = $ user_id AND
2707
- c_id = $ courseId AND
2708
- login_course_date BETWEEN ' $ start_date' AND ' $ end_date' AND
2709
- logout_course_date BETWEEN ' $ start_date' AND ' $ end_date'
2710
- ORDER BY login_course_date ASC " ;
2699
+ FROM $ table
2700
+ WHERE
2701
+ user_id = $ user_id AND
2702
+ c_id = $ courseId AND
2703
+ login_course_date BETWEEN ' $ start_date' AND ' $ end_date' AND
2704
+ logout_course_date BETWEEN ' $ start_date' AND ' $ end_date'
2705
+ ORDER BY login_course_date ASC " ;
2711
2706
$ rs = Database::query ($ sql );
2712
2707
2713
2708
while ($ row = Database::fetch_array ($ rs )) {
2714
- $ login_date = $ row ['login_course_date ' ];
2715
- $ logout_date = $ row ['logout_course_date ' ];
2716
- $ timestamp_login_date = strtotime ($ login_date );
2717
- $ timestamp_logout_date = strtotime ($ logout_date );
2718
2709
$ connections [] = array (
2719
- 'login ' => $ timestamp_login_date ,
2720
- 'logout ' => $ timestamp_logout_date
2710
+ 'login ' => api_strtotime ( $ row [ ' login_course_date ' ], ' UTC ' ) ,
2711
+ 'logout ' => api_strtotime ( $ row [ ' logout_course_date ' ], ' UTC ' )
2721
2712
);
2722
2713
}
2723
2714
}
@@ -2734,8 +2725,7 @@ public static function get_connections_to_course_by_date($user_id, $courseId, $s
2734
2725
*/
2735
2726
function get_stats ($ user_id , $ courseId , $ start_date = null , $ end_date = null )
2736
2727
{
2737
- // Database table definitions
2738
- $ tbl_track_course = Database::get_main_table (TABLE_STATISTIC_TRACK_E_COURSE_ACCESS );
2728
+ $ table = Database::get_main_table (TABLE_STATISTIC_TRACK_E_COURSE_ACCESS );
2739
2729
2740
2730
$ course_info = api_get_course_info_by_id ($ courseId );
2741
2731
if (!empty ($ course_info )) {
@@ -2749,18 +2739,17 @@ function get_stats($user_id, $courseId, $start_date = null, $end_date = null)
2749
2739
$ user_id = intval ($ user_id );
2750
2740
$ courseId = intval ($ courseId );
2751
2741
$ sql = "SELECT
2752
- SEC_TO_TIME(avg (time_to_sec(timediff(logout_course_date,login_course_date)))) as avrg,
2753
- SEC_TO_TIME(sum (time_to_sec(timediff(logout_course_date,login_course_date)))) as total,
2742
+ SEC_TO_TIME(AVG (time_to_sec(timediff(logout_course_date,login_course_date)))) as avrg,
2743
+ SEC_TO_TIME(SUM (time_to_sec(timediff(logout_course_date,login_course_date)))) as total,
2754
2744
count(user_id) as times
2755
- FROM $ tbl_track_course
2745
+ FROM $ table
2756
2746
WHERE
2757
2747
user_id = $ user_id AND
2758
2748
c_id = $ courseId $ stringStartDate $ stringEndDate
2759
2749
ORDER BY login_course_date ASC " ;
2760
2750
2761
2751
$ rs = Database::query ($ sql );
2762
2752
$ result = array ();
2763
-
2764
2753
if ($ row = Database::fetch_array ($ rs )) {
2765
2754
$ foo_avg = $ row ['avrg ' ];
2766
2755
$ foo_total = $ row ['total ' ];
@@ -2805,21 +2794,26 @@ function convert_to_array($sql_result)
2805
2794
/**
2806
2795
* Converte an array to a table in html
2807
2796
*
2808
- * @param array $sql_result
2797
+ * @param array $result
2809
2798
* @author Jorge Frisancho Jibaja
2810
2799
* @version OCT-22- 2010
2811
2800
* @return string
2812
2801
*/
2813
- function convert_to_string ($ sql_result )
2802
+ function convert_to_string ($ result )
2814
2803
{
2815
- $ result_to_print = '<table> ' ;
2816
- if (!empty ($ sql_result )) {
2817
- foreach ($ sql_result as $ key => $ data ) {
2818
- $ result_to_print .= '<tr><td> ' .date ('d-m-Y (H:i:s) ' , $ data ['login ' ]).'</td><td> ' .api_time_to_hms ($ data ['logout ' ] - $ data ['login ' ]).'</tr></td> ' ."\n" ;
2804
+ $ html = '<table class="table"> ' ;
2805
+ if (!empty ($ result )) {
2806
+ foreach ($ result as $ key => $ data ) {
2807
+ $ html .= '<tr><td> ' ;
2808
+ $ html .= api_get_local_time ($ data ['login ' ]);
2809
+ $ html .= '</td> ' ;
2810
+ $ html .= '<td> ' ;
2811
+ $ html .= api_time_to_hms ($ data ['logout ' ] - $ data ['login ' ]);
2812
+ $ html .= '</tr></td> ' ;
2819
2813
}
2820
2814
}
2821
- $ result_to_print .= '</table> ' ;
2822
- return $ result_to_print ;
2815
+ $ html .= '</table> ' ;
2816
+ return $ html ;
2823
2817
}
2824
2818
2825
2819
@@ -2836,9 +2830,15 @@ function convert_to_string($sql_result)
2836
2830
*/
2837
2831
function grapher ($ sql_result , $ start_date , $ end_date , $ type = "" )
2838
2832
{
2839
- if (empty ($ start_date )) { $ start_date = "" ; }
2840
- if (empty ($ end_date )) { $ end_date = "" ; }
2841
- if ($ type == "" ) { $ type = 'day ' ; }
2833
+ if (empty ($ start_date )) {
2834
+ $ start_date = '' ;
2835
+ }
2836
+ if (empty ($ end_date )) {
2837
+ $ end_date = '' ;
2838
+ }
2839
+ if ($ type == '' ) {
2840
+ $ type = 'day ' ;
2841
+ }
2842
2842
$ main_year = $ main_month_year = $ main_day = [];
2843
2843
2844
2844
$ period = new DatePeriod (
@@ -2888,7 +2888,6 @@ function grapher($sql_result, $start_date, $end_date, $type = "")
2888
2888
break ;
2889
2889
}
2890
2890
2891
- // the nice graphics :D
2892
2891
$ labels = array_keys ($ main_date );
2893
2892
if (count ($ main_date ) == 1 ) {
2894
2893
$ labels = $ labels [0 ];
@@ -2929,7 +2928,6 @@ function grapher($sql_result, $start_date, $end_date, $type = "")
2929
2928
2930
2929
/* Turn of Antialiasing */
2931
2930
$ myPicture ->Antialias = false ;
2932
-
2933
2931
/* Draw the background */
2934
2932
$ settings = array ("R " => 255 , "G " => 255 , "B " => 255 );
2935
2933
$ myPicture ->drawFilledRectangle (0 , 0 , $ mainWidth , $ mainHeight , $ settings );
@@ -3032,7 +3030,10 @@ function grapher($sql_result, $start_date, $end_date, $type = "")
3032
3030
3033
3031
return $ html ;
3034
3032
} else {
3035
- $ foo_img = api_convert_encoding ('<div id="messages" class="warning-message"> ' .get_lang ('GraphicNotAvailable ' ).'</div> ' , 'UTF-8 ' );
3033
+ $ foo_img = api_convert_encoding (
3034
+ '<div id="messages" class="warning-message"> ' .get_lang ('GraphicNotAvailable ' ).'</div> ' ,
3035
+ 'UTF-8 '
3036
+ );
3036
3037
3037
3038
return $ foo_img ;
3038
3039
}
0 commit comments