Browse Source

Deprecating calls to get_db_progress()

Julio Montoya 10 years ago
parent
commit
e4487a82c1
2 changed files with 67 additions and 46 deletions
  1. 37 13
      main/newscorm/learnpath.class.php
  2. 30 33
      main/newscorm/lp_list.php

+ 37 - 13
main/newscorm/learnpath.class.php

@@ -2038,6 +2038,7 @@ class learnpath
      * was found (true), or 0 (false) (optional, defaults to false)
      * @param  int     $session_id
      * @return	integer	Current progress value as found in the database
+     * @deprecated
      */
     public static function get_db_progress(
         $lp_id,
@@ -2238,12 +2239,10 @@ class learnpath
             $is_visible = true;
 
             if (!empty($prerequisite)) {
-                $progress = self::get_db_progress(
+                $progress = self::getProgress(
                     $prerequisite,
                     $student_id,
-                    '%',
-                    $courseCode,
-                    false,
+                    $course['real_id'],
                     $sessionId
                 );
                 $progress = intval($progress);
@@ -2286,21 +2285,46 @@ class learnpath
     }
 
     /**
-     * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
+     * @param int $lpId
+     * @param int $userId
+     * @param int $courseId
+     * @param int $sessionId
+     * @return int
+     */
+    public static function getProgress($lpId, $userId, $courseId, $sessionId = 0)
+    {
+        $lpId = intval($lpId);
+        $userId = intval($userId);
+        $courseId = intval($courseId);
+        $sessionId = intval($sessionId);
+        $progress = 0;
+
+        $sessionCondition = api_get_session_condition($sessionId);
+        $table = Database :: get_course_table(TABLE_LP_VIEW);
+        $sql = "SELECT * FROM $table
+                WHERE
+                    c_id = ".$courseId." AND
+                    lp_id = $lpId AND
+                    user_id = $userId $sessionCondition";
+        $res = Database::query($sql);
+        if (Database :: num_rows($res) > 0) {
+            $row = Database:: fetch_array($res);
+            $progress = $row['progress'];
+        }
+        return $progress;
+
+    }
+
+    /**
+     * Displays a progress bar
      * completed so far.
-     * @param	string	Mode in which we want the values
-     * @param	integer	Progress value to display (optional but mandatory if used in abstract context)
-     * @param	string	Text to display near the progress value (optional but mandatory in abstract context)
-     * @param	boolean true if it comes from a Diplay LP view
+     * @param	integer	$percentage Progress value to display
+     * @param	string	$text_add Text to display near the progress value
      * @return	string	HTML string containing the progress bar
      */
     public static function get_progress_bar($percentage = -1, $text_add = '')
     {
-        /*if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
-            list($percentage, $text_add) = $this->get_progress_bar_text($mode);
-        }*/
         $text = $percentage . $text_add;
-        //@todo use Display::display_progress();
         $output = '<div class="progress progress-striped">
                         <div id="progress_bar_value" class="bar" style="width: '.$text.';"></div>
                     </div>

+ 30 - 33
main/newscorm/lp_list.php

@@ -108,7 +108,6 @@ $userInfo = api_get_user_info();
 $list = new LearnpathList($userId);
 $flat_list = $list->get_flat_list();
 
-
 if (!empty($flat_list)) {
     echo '<table class="data_table">';
     echo '<tr>';
@@ -229,21 +228,17 @@ if (!empty($flat_list)) {
         $dsp_debug = '';
         $dsp_order = '';
 
-        $progress = learnpath::get_db_progress($id, $userId, '%', '', false, api_get_session_id());
+        $progress = learnpath::getProgress(
+            $id,
+            $userId,
+            api_get_course_int_id(),
+            api_get_session_id()
+        );
 
         if ($is_allowed_to_edit) {
             $dsp_progress = '<td><center>'.$progress.'</center></td>';
         } else {
-            $dsp_progress = '<td>'.learnpath::get_progress_bar(
-                    learnpath::get_db_progress(
-                        $id,
-                        $userId,
-                        '%',
-                        '',
-                        false,
-                        api_get_session_id()
-                    )
-                ).'</td>';
+            $dsp_progress = '<td>'.learnpath::get_progress_bar($progress, '%').'</td>';
         }
 
         $dsp_edit = '<td class="td_actions">';
@@ -261,7 +256,8 @@ if (!empty($flat_list)) {
 
             // EDIT LP
             if ($current_session == $details['lp_session']) {
-                $dsp_edit_lp = '<a href="lp_controller.php?'.api_get_cidreq().'&action=edit&lp_id='.$id.'">'.Display::return_icon('settings.png', get_lang('CourseSettings'), '', ICON_SIZE_SMALL).'</a>';
+                $dsp_edit_lp = '<a href="lp_controller.php?'.api_get_cidreq().'&action=edit&lp_id='.$id.'">'.
+                                Display::return_icon('settings.png', get_lang('CourseSettings'), '', ICON_SIZE_SMALL).'</a>';
             } else {
                 $dsp_edit_lp = Display::return_icon('settings_na.png', get_lang('CourseSettings'), '', ICON_SIZE_SMALL);
             }
@@ -269,7 +265,8 @@ if (!empty($flat_list)) {
             // BUILD
             if ($current_session == $details['lp_session']) {
                 if ($details['lp_type'] == 1 || $details['lp_type'] == 2) {
-                    $dsp_build = '<a href="lp_controller.php?'.api_get_cidreq().'&amp;action=add_item&amp;type=step&amp;lp_id='.$id.'">'.Display::return_icon('edit.png', get_lang('LearnpathEditLearnpath'), '', ICON_SIZE_SMALL).'</a>';
+                    $dsp_build = '<a href="lp_controller.php?'.api_get_cidreq().'&amp;action=add_item&amp;type=step&amp;lp_id='.$id.'">'.
+                                  Display::return_icon('edit.png', get_lang('LearnpathEditLearnpath'), '', ICON_SIZE_SMALL).'</a>';
                 } else {
                     $dsp_build = Display::return_icon('edit_na.png', get_lang('LearnpathEditLearnpath'), '', ICON_SIZE_SMALL);
                 }
@@ -279,16 +276,15 @@ if (!empty($flat_list)) {
 
             /* VISIBILITY COMMAND */
 
-            // Session test not necessary if we want to show base course learning paths inside the session (see http://support.chamilo.org/projects/chamilo-18/wiki/Tools_and_sessions).
-            //if ($current_session == $details['lp_session']) {
+            /*  Session test not necessary if we want to show base course learning
+                paths inside the session.
+                See http://support.chamilo.org/projects/chamilo-18/wiki/Tools_and_sessions).
+            */
             if ($details['lp_visibility'] == 0) {
                 $dsp_visible = "<a href=\"".api_get_self()."?".api_get_cidreq()."&lp_id=$id&action=toggle_visible&new_status=1\">".Display::return_icon('invisible.png', get_lang('Show'), '', ICON_SIZE_SMALL)."</a>";
             } else {
                 $dsp_visible = "<a href='".api_get_self()."?".api_get_cidreq()."&lp_id=$id&action=toggle_visible&new_status=0'>".Display::return_icon('visible.png', get_lang('Hide'), '', ICON_SIZE_SMALL)."</a>";
             }
-            //} else {
-            //	$dsp_visible = '<img src="../img/invisible.gif" border="0" title="'.get_lang('Show').'" />';
-            //}
 
             /* PUBLISH COMMAND */
             if ($current_session == $details['lp_session']) {
@@ -358,7 +354,6 @@ if (!empty($flat_list)) {
             }
 
             /*  DEBUG  */
-
             if ($test_mode == 'test' or api_is_platform_admin()) {
                 if ($details['lp_scorm_debug'] == 1) {
                     $dsp_debug = '<a href="lp_controller.php?'.api_get_cidreq().'&action=switch_scorm_debug&lp_id='.$id.'">'.
@@ -369,9 +364,7 @@ if (!empty($flat_list)) {
                 }
             }
 
-
             /* Export */
-
             if ($details['lp_type'] == 1) {
                 $dsp_disk = Display::url(Display::return_icon('cd.gif', get_lang('Export'), array(), ICON_SIZE_SMALL), api_get_self()."?".api_get_cidreq()."&action=export&lp_id=$id");
             } elseif ($details['lp_type'] == 2) {
@@ -381,7 +374,15 @@ if (!empty($flat_list)) {
             }
 
             // Copy
-            $copy = Display::url(Display::return_icon('cd_copy.png', get_lang('Copy'), array(), ICON_SIZE_SMALL), api_get_self()."?".api_get_cidreq()."&action=copy&lp_id=$id");
+            $copy = Display::url(
+                Display::return_icon(
+                    'cd_copy.png',
+                    get_lang('Copy'),
+                    array(),
+                    ICON_SIZE_SMALL
+                ),
+                api_get_self() . "?" . api_get_cidreq() . "&action=copy&lp_id=$id"
+            );
 
             /* Auto Lunch LP code */
             if (api_get_course_setting('enable_lp_auto_launch') == 1) {
@@ -395,14 +396,11 @@ if (!empty($flat_list)) {
                 }
             }
 
-            //if (api_get_setting('pdf_export_watermark_enable') == 'true') {
-            //Export to PDF
+            // Export to PDF
             $export_icon = ' <a href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&lp_id='.$id.'">
 				  '.Display::return_icon('pdf.png', get_lang('ExportToPDFOnlyHTMLAndImages'), '', ICON_SIZE_SMALL).'</a>';
-            //}
-
-            /* DELETE COMMAND */
 
+            /* Delete */
             if ($current_session == $details['lp_session']) {
                 $dsp_delete = "<a href=\"lp_controller.php?".api_get_cidreq()."&action=delete&lp_id=$id\" ".
                     "onclick=\"javascript: return confirmation('".addslashes($name)."');\">".
@@ -412,9 +410,7 @@ if (!empty($flat_list)) {
             }
 
             /* COLUMN ORDER	 */
-
             // Only active while session mode is not active
-
             if ($current_session == 0) {
                 if ($details['lp_display_order'] == 1 && $max != 1) {
                     $dsp_order .= '<a href="lp_controller.php?'.api_get_cidreq().'&action=move_lp_down&lp_id='.$id.'">
@@ -437,7 +433,7 @@ if (!empty($flat_list)) {
             } else {
                 $start_time = $end_time = '';
             }
-        } else { // end if ($is_allowedToEdit)
+        } else {
             //Student
             $export_icon = ' <a href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&lp_id='.$id.'">'.Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL).'</a>';
         }
@@ -459,9 +455,10 @@ if (!empty($flat_list)) {
         $dsp_default_view.$dsp_debug.$dsp_disk.$copy.$lp_auto_lunch_icon.$export_icon.$dsp_delete.$dsp_order.$dsp_edit_close;
 
         echo "</tr>";
-        $current++; //counter for number of elements treated
+        //counter for number of elements treated
+        $current++;
+
     } // end foreach ($flat_list)
-    // TODO: Erint some user-friendly message if counter is still = 0 to tell nothing can be display yet.
     echo "</table>";
 } else {
     if ($is_allowed_to_edit) {