Jelajahi Sumber

Merge pull request #1708 from jloguercio/1.11.x

Added Access logs link and reworked access details chart - Refs BT#12212
José Loguercio 8 tahun lalu
induk
melakukan
d3f8ec476f

+ 1 - 0
main/inc/ajax/myspace.ajax.php

@@ -7,6 +7,7 @@ require_once __DIR__.'/../global.inc.php';
 $action = $_GET['a'];
 
 switch ($action) {
+    // At this date : 23/02/2017, a minor review can't determine where is used this case 'access_detail'
     case 'access_detail':
         $user_id = intval($_REQUEST['student']);
         $course_code = Security::remove_XSS($_REQUEST['course']);

+ 25 - 10
main/inc/lib/myspace.lib.php

@@ -2814,23 +2814,38 @@ function grapher($sql_result, $start_date, $end_date, $type = "")
     if (empty($start_date)) { $start_date =""; }
     if (empty($end_date)) { $end_date =""; }
     if ($type == ""){ $type = 'day'; }
-    $main_year  = $main_month_year = $main_day = array();
-    // get last 8 days/months
-    $last_days      = 5;
-    $last_months    = 3;
-    for ($i = $last_days; $i >= 0; $i--) {
-        $main_day[date ('d-m-Y', time () - $i * 3600 * 24)] = 0;
+    $main_year  = $main_month_year = $main_day = [];
+
+    $period = new DatePeriod(
+        new DateTime($start_date),
+        new DateInterval('P1D'),
+        new DateTime($end_date)
+    );
+
+    foreach ($period as $date) {
+        $main_day[$date->format('d-m-Y')] = 0;
     }
-    for ($i = $last_months; $i >= 0; $i--) {
-        $main_month_year[date ('m-Y', time () - $i * 30 * 3600 * 24)] = 0;
+
+    $period = new DatePeriod(
+        new DateTime($start_date),
+        new DateInterval('P1M'),
+        new DateTime($end_date)
+    );
+
+    foreach ($period as $date) {
+        $main_month_year[$date->format('m-Y')] = 0;
     }
 
     $i = 0;
     if (is_array($sql_result) && count($sql_result) > 0) {
         foreach ($sql_result as $key => $data) {
             //creating the main array
-            $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
-            $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
+            if (isset($main_month_year[date('m-Y', $data['login'])])) {
+                $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
+            }
+            if (isset($main_day[date('d-m-Y', $data['login'])])) {
+                $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
+            }
             if ($i > 500) {
                 break;
             }

+ 31 - 21
main/mySpace/access_details.php

@@ -132,28 +132,38 @@ echo Display::page_subheader(
 $form->setDefaults(array('from' => $from, 'to' => $to));
 $form->display();
 ?>
-<div id="cev_results" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
-    <div class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
-        <?php echo get_lang('Statistics'); ?>
-    </div><br />
-    <div id="cev_cont_stats">
-    <?php
-    if ($result_to_print != "")  {
-        $rst = get_stats($user_id, $courseId);
-        $foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
-        $foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
-        $foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
-        echo $foo_stats;
-    } else {
-        echo Display::display_warning_message(get_lang('NoDataAvailable'));
-    }
-    ?>
+<br />
+<br />
+<div class="text-center" id="graph"></div>
+<br />
+<br />
+<div class="row">
+    <div id="cev_results" class="ui-tabs ui-widget ui-widget-content ui-corner-all col-md-6">
+        <div class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
+            <?php echo get_lang('Statistics'); ?>
+        </div><br />
+        <div id="cev_cont_stats">
+            <?php
+            if ($result_to_print != "")  {
+                $rst = get_stats($user_id, $courseId);
+                $foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
+                $foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
+                $foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
+                echo $foo_stats;
+            } else {
+                echo Display::display_warning_message(get_lang('NoDataAvailable'));
+            }
+            ?>
+        </div>
+        <br />
     </div>
-    <br />
-</div><br />
-
-<div id="messages"></div>
-<div id="graph"></div>
+    <div class="ui-tabs ui-widget ui-widget-content ui-corner-all col-md-6 col-md-6">
+        <div class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
+            <?php echo get_lang('Details'); ?>
+        </div><br />
+        <div id="messages"></div>
+    </div>
+</div>
 
 <?php
 Display:: display_footer();

+ 3 - 0
main/mySpace/myStudents.php

@@ -534,6 +534,9 @@ if (!empty($student_id)) {
             <tr>
                 <td><?php echo get_lang('OnLine') . ' : '.$online; ?> </td>
             </tr>
+            <tr>
+                <td><a href="access_details.php?student=<?php echo $student_id; ?>&course=<?php echo $course_code; ?>&origin=<?php echo $origin; ?>&cidReq=<?php echo $course_code; ?>&id_session=<?php echo $sessionId; ?>"><?php echo get_lang('SeeAccess'); ?></a></td>
+            </tr>
             <?php
 
             // Display timezone if the user selected one and if the admin allows the use of user's timezone