Browse Source

Improve UI in new min time LP feature see BT#15020

Julio 6 years ago
parent
commit
e1eb8b411e

+ 8 - 4
main/inc/lib/api.lib.php

@@ -5086,7 +5086,7 @@ function api_max_sort_value($user_course_category, $user_id)
  *
  * @return string the formated time
  */
-function api_time_to_hms($seconds)
+function api_time_to_hms($seconds, $space = ':')
 {
     // $seconds = -1 means that we have wrong data in the db.
     if ($seconds == -1) {
@@ -5108,6 +5108,10 @@ function api_time_to_hms($seconds)
     // How many seconds
     $sec = floor($seconds - ($hours * 3600) - ($min * 60));
 
+    if ($hours < 10) {
+        $hours = "0$hours";
+    }
+
     if ($sec < 10) {
         $sec = "0$sec";
     }
@@ -5116,7 +5120,7 @@ function api_time_to_hms($seconds)
         $min = "0$min";
     }
 
-    return "$hours:$min:$sec";
+    return $hours.$space.$min.$space.$sec;
 }
 
 /* FILE SYSTEM RELATED FUNCTIONS */
@@ -6242,7 +6246,7 @@ function api_is_element_in_the_session($tool, $element_id, $session_id = null)
     }
     $course_id = api_get_course_int_id();
 
-    $sql = "SELECT session_id FROM $table_tool 
+    $sql = "SELECT session_id FROM $table_tool
             WHERE c_id = $course_id AND $key_field =  ".$element_id;
     $rs = Database::query($sql);
     if ($element_session_id = Database::result($rs, 0, 0)) {
@@ -8067,7 +8071,7 @@ function api_get_password_checker_js($usernameInputId, $passwordInputId)
     ];
 
     $js = api_get_asset('pwstrength-bootstrap/dist/pwstrength-bootstrap.min.js');
-    $js .= "<script>    
+    $js .= "<script>
     var errorMessages = {
         password_to_short : \"".get_lang('PasswordIsTooShort')."\",
         same_as_username : \"".get_lang('YourPasswordCannotBeTheSameAsYourUsername')."\"

+ 13 - 22
main/lp/lp_list.php

@@ -171,7 +171,7 @@ if ($filteredCategoryId) {
 $test_mode = api_get_setting('server_type');
 $showBlockedPrerequisite = api_get_configuration_value('show_prerequisite_as_blocked');
 $allowLpChamiloExport = api_get_configuration_value('allow_lp_chamilo_export');
-
+$allowMinTime = api_get_configuration_value('lp_minimum_time');
 $user = api_get_user_entity($userId);
 $ending = true;
 
@@ -218,7 +218,7 @@ foreach ($categories as $item) {
 
     $listData = [];
     $lpTimeList = [];
-    if (api_get_configuration_value('lp_minimum_time')) {
+    if ($allowMinTime) {
         $lpTimeList = Tracking::getCalculateTime($userId, api_get_course_int_id(), api_get_session_id());
     }
 
@@ -404,7 +404,7 @@ foreach ($categories as $item) {
 
             $dsp_time = '';
             $linkMinTime = '';
-            if (api_get_configuration_value('lp_minimum_time')) {
+            if ($allowMinTime) {
                 // Time info
                 // Minimum time (in minutes) to pass the learning path
                 $accumulateWorkTime = learnpath::getAccumulateWorkTimePrerequisite($id, api_get_course_int_id());
@@ -412,29 +412,12 @@ foreach ($categories as $item) {
                     // TT --- Tiempo total del curso
                     $accumulateWorkTimeTotal = learnpath::getAccumulateWorkTimeTotal(api_get_course_int_id());
 
-                    // Spent time (in seconds) so far in the learning path
-                    /*$lpTime = Tracking::get_time_spent_in_lp(
-                        $userId,
-                        api_get_course_id(),
-                        [$id],
-                        api_get_session_id()
-                    );*/
-
                     $lpTime = isset($lpTimeList[TOOL_LEARNPATH][$id]) ? $lpTimeList[TOOL_LEARNPATH][$id] : 0;
 
                     // Connect with the plugin_licences_course_session table
                     // which indicates what percentage of the time applies
                     $perc = 100;
                     $tc = $accumulateWorkTimeTotal;
-                    /*if (!empty($current_session) && $current_session != 0) {
-                        $sql = "SELECT hours, perc FROM plugin_licences_course_session WHERE session_id = $current_session";
-                        $res = Database::query($sql);
-                        if (Database::num_rows($res) > 0) {
-                            $aux = Database::fetch_assoc($res);
-                            $perc = $aux['perc'];
-                            $tc = ($aux['hours'] * 60);
-                        }
-                    }*/
 
                     // Percentage of the learning paths
                     $pl = 0;
@@ -453,9 +436,16 @@ foreach ($categories as $item) {
                                 $accumulateWorkTime * 60
                             )
                         );
-                        $linkMinTime .= '<b>'.api_time_to_hms($lpTime).' / '.api_time_to_hms($accumulateWorkTime * 60).'</b>';
+                        $linkMinTime .= '&nbsp;<b>'.api_time_to_hms($lpTime).' / '.api_time_to_hms($accumulateWorkTime * 60).'</b>';
                     } else {
-                        $linkMinTime = sprintf(get_lang('YouHaveSpentXTime'), api_time_to_hms($lpTime));
+                        $linkMinTime = Display::return_icon(
+                            'check.png',
+                            get_lang('LpMinTimeWarning').' - '.api_time_to_hms($lpTime).' / '.api_time_to_hms(
+                                $accumulateWorkTime * 60
+                            )
+                        );
+                        $linkMinTime .= '&nbsp;<b>'.api_time_to_hms($lpTime).' / '.api_time_to_hms($accumulateWorkTime * 60).'</b>';
+                        //$linkMinTime = sprintf(get_lang('YouHaveSpentXTime'), api_time_to_hms($lpTime));
                     }
 
                     // Calculate the percentage exceeded of the time for the "exceeding the minimum time" bar
@@ -1023,6 +1013,7 @@ $template->assign('introduction', $introduction);
 $template->assign('data', $data);
 $template->assign('lp_is_shown', $lpIsShown);
 $template->assign('filtered_category', $filteredCategoryId);
+$template->assign('allow_min_time', $allowMinTime);
 $templateName = $template->get_template('learnpath/list.tpl');
 $content = $template->fetch($templateName);
 $template->assign('content', $content);

+ 2 - 16
main/lp/lp_view.php

@@ -567,16 +567,6 @@ if (api_get_configuration_value('lp_minimum_time')) {
     $perc = 100;
     // Time from the course
     $tc = $timeTotalCourse;
-    if (!empty($sessionId) && $sessionId != 0) {
-        /*$sql = "SELECT hours, perc FROM plugin_licences_course_session WHERE session_id = $sessionId";
-        $res = Database::query($sql);
-        if (Database::num_rows($res) > 0) {
-            $aux = Database::fetch_assoc($res);
-            $perc = $aux['perc'];
-            $tc = $aux['hours'] * 60;
-        }*/
-    }
-
     // Percentage of the learning paths
     $pl = 0;
     if (!empty($timeTotalCourse)) {
@@ -590,12 +580,6 @@ if (api_get_configuration_value('lp_minimum_time')) {
         $lpMinTime = '('.$time_min.' min)';
     }
 
-    /*$lpTime = Tracking::get_time_spent_in_lp(
-        $user_id,
-        $course_code,
-        [$_SESSION['oLP']->lp_id],
-        $sessionId
-    );*/
     $lpTimeList = Tracking::getCalculateTime($user_id, api_get_course_int_id(), api_get_session_id());
     $lpTime = isset($lpTimeList[TOOL_LEARNPATH][$lp_id]) ? (int) $lpTimeList[TOOL_LEARNPATH][$lp_id] : 0;
 
@@ -614,6 +598,8 @@ if (api_get_configuration_value('lp_minimum_time')) {
     $template->assign('hour', $hour);
     $template->assign('minute', date('i', $lpTime));
     $template->assign('second', date('s', $lpTime));
+
+    $template->assign('hour_min', api_time_to_hms($timeLp*60, '</div><div class="divider">:</div><div>'));
 }
 
 $template->assign('lp_accumulate_work_time', $lpMinTime);

+ 20 - 3
main/template/default/learnpath/list.tpl

@@ -110,11 +110,17 @@
                                     <th>{{ "PublicationDate"|get_lang }}</th>
                                     <th>{{ "ExpirationDate"|get_lang }}</th>
                                     <th>{{ "Progress"|get_lang }}</th>
+                                    {% if allow_min_time %}
+                                        <th>{{ "TimeSpentTimeRequired"|get_lang }}</th>
+                                    {% endif %}
                                     <th>{{ "AuthoringOptions"|get_lang }}</th>
                                 {% else %}
                                     {% if not is_invitee %}
                                         <th>{{ "Progress"|get_lang }}</th>
                                     {% endif %}
+                                    {% if allow_min_time %}
+                                        <th>{{ "TimeSpentTimeRequired"|get_lang }}</th>
+                                    {% endif %}
                                     <th>{{ "Actions"|get_lang }}</th>
                                 {% endif %}
                             </tr>
@@ -142,17 +148,28 @@
                                         <td>
                                             {{ row.dsp_progress }}
                                         </td>
+                                        {% if allow_min_time %}
+                                            <td>
+                                            {% if row.info_time_prerequisite %}
+                                                {{ row.info_time_prerequisite }}
+                                            {% endif %}
+                                            </td>
+                                        {% endif %}
                                     {% else %}
                                         {% if not is_invitee %}
                                             <td>
                                                 {{ row.dsp_progress }}
                                             </td>
                                         {% endif %}
+                                        {% if allow_min_time %}
+                                            <td>
+                                                {% if row.info_time_prerequisite %}
+                                                    {{ row.info_time_prerequisite }}
+                                                {% endif %}
+                                            </td>
+                                        {% endif %}
                                     {% endif %}
                                     <td>
-                                        {% if row.info_time_prerequisite %}
-                                            {{ row.info_time_prerequisite }}
-                                        {% endif %}
                                         {{ row.action_build }}
                                         {{ row.action_edit }}
                                         {{ row.action_visible }}

+ 4 - 0
main/template/default/learnpath/view.tpl

@@ -87,6 +87,10 @@
                                 <div id="minute">{{ minute }}</div>
                                 <div class="divider">:</div>
                                 <div id="second">{{ second }}</div>
+
+                                <div id="slash"> / </div>
+                                <div class="divider"></div>
+                                <div>{{ hour_min }}</div>
                             </div>
                         </div>
                         {% endset %}