Browse Source

Minor - format code.

Julio Montoya 10 years ago
parent
commit
a57b60d384

+ 25 - 19
main/newscorm/learnpath.class.php

@@ -4,6 +4,7 @@
 use \ChamiloSession as Session;
 
 /**
+ * Class learnpath
  * This class defines the parent attributes and methods for Chamilo learnpaths
  * and SCORM learnpaths. It is used by the scorm class.
  *
@@ -1430,11 +1431,11 @@ class learnpath
 
     /**
      * Updates an item's prereq in place
-     * @param	integer	Element ID
-     * @param	string	Prerequisite Element ID
-     * @param	string	Prerequisite item type
-     * @param	string	Prerequisite min score
-     * @param	string	Prerequisite max score
+     * @param	integer	$id Element ID
+     * @param	string	$prerequisite_id Prerequisite Element ID
+     * @param	string	$mastery_score Prerequisite min score
+     * @param	string	$max_score Prerequisite max score
+     *
      * @return	boolean	True on success, false on error
      */
     public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100)
@@ -1473,10 +1474,11 @@ class learnpath
         Database::query($sql);
 
         if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
-            $sql = " UPDATE " . $tbl_lp_item . " SET
-                     mastery_score = " . $mastery_score .
-                //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
-                " WHERE c_id = ".$course_id." AND ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
+            // Will this be enough to ensure unicity?
+            $sql = " UPDATE $tbl_lp_item
+                     SET mastery_score = $mastery_score
+                     WHERE c_id = $course_id AND ref = '$prerequisite_id'";
+
             Database::query($sql);
         }
         // TODO: Update the item object (can be ignored for now because refreshed).
@@ -2656,6 +2658,7 @@ class learnpath
         if (!is_object($this->items[$item_id])) {
             return false;
         }
+        /** @var learnpathItem $oItem */
         $oItem = $this->items[$item_id];
         $prereq = $oItem->get_prereq_string();
 
@@ -8235,7 +8238,8 @@ class learnpath
         $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
         $item_id = intval($item_id);
         /* Current prerequisite */
-        $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND id = " . $item_id;
+        $sql = "SELECT * FROM $tbl_lp_item
+                WHERE c_id = $course_id AND id = " . $item_id;
         $result = Database::query($sql);
         $row    = Database::fetch_array($result);
         $preq_id = $row['prerequisite'];
@@ -8246,8 +8250,8 @@ class learnpath
         $return .= '<table class="data_table">';
         $return .= '<tr>';
         $return .= '<th height="24">' . get_lang('LearnpathPrerequisites') . '</th>';
-        $return .= '<th width="70" height="24">' . get_lang('Minimum') . '</th>';
-        $return .= '<th width="70" height="24">' . get_lang('Maximum') . '</th>';
+        $return .= '<th width="70" >' . get_lang('Minimum') . '</th>';
+        $return .= '<th width="70">' . get_lang('Maximum') . '</th>';
         $return .= '</tr>';
 
         // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
@@ -8257,7 +8261,8 @@ class learnpath
         $return .= '<label for="idNone">' . get_lang('None') . '</label>';
         $return .= '</tr>';
 
-        $sql 	= "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = $course_id AND lp_id = " . $this->lp_id;
+        $sql 	= "SELECT * FROM $tbl_lp_item
+                   WHERE c_id = $course_id AND lp_id = " . $this->lp_id;
         $result = Database::query($sql);
         $arrLP = array ();
         while ($row = Database :: fetch_array($result)) {
@@ -8288,13 +8293,15 @@ class learnpath
         unset($this->arrMenu);
 
         for ($i = 0; $i < count($arrLP); $i++) {
-            if ($arrLP[$i]['id'] == $item_id)
+            if ($arrLP[$i]['id'] == $item_id) {
                 break;
+            }
             $return .= '<tr>';
             $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
             $return .= '<label for="id' . $arrLP[$i]['id'] . '">';
             $return .= '<input' . (($arrLP[$i]['id'] == $preq_id) ? ' checked="checked" ' : '') . (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') ? ' disabled="disabled" ' : ' ') . 'id="id' . $arrLP[$i]['id'] . '" name="prerequisites" style="margin-left:' . $arrLP[$i]['depth'] * 10 . 'px; margin-right:10px;" type="radio" value="' . $arrLP[$i]['id'] . '" />';
             $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
+
             if (file_exists('../img/lp_' . $icon_name . '.png')) {
                 $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
             } else {
@@ -8307,7 +8314,6 @@ class learnpath
             $return .=  $arrLP[$i]['title'] . '</label>';
             $return .= '</td>';
 
-
             if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
                 // lets update max_score Quiz information depending of the Quiz Advanced properties
                 $tmp_obj_lp_item = new LpItem($course_id, $arrLP[$i]['id']);
@@ -8317,19 +8323,19 @@ class learnpath
                 $tmp_obj_lp_item->update_in_bdd();
                 $arrLP[$i]['max_score'] = $tmp_obj_lp_item->max_score;
 
-                $return .= '<td class="exercise" style="border:1px solid #ccc;">';
+                $return .= '<td class="exercise">';
                 $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
                 $return .= '</td>';
-                $return .= '<td class="exercise" style="border:1px solid #ccc;">';
+                $return .= '<td class="exercise">';
                 $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
                 $return .= '</td>';
             }
 
             if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
-                $return .= '<td class="exercise" style="border:1px solid #ccc;">';
+                $return .= '<td class="exercise">';
                 $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
                 $return .= '</td>';
-                $return .= '<td class="exercise" style="border:1px solid #ccc;">';
+                $return .= '<td class="exercise"">';
                 $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
                 $return .= '</td>';
             }

+ 32 - 19
main/newscorm/learnpathItem.class.php

@@ -2512,12 +2512,14 @@ class learnpathItem
                                                 //AND origin_lp_item_id = '.$user_id.'
                                                 $sql = 'SELECT exe_result, exe_weighting
                                                         FROM ' . Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES) . '
-                                                    WHERE   exe_exo_id = ' . $items[$refs_list[$prereqs_string]]->path . '
-                                                        AND exe_user_id = ' . $user_id . '
-                                                        AND orig_lp_id = ' . $this->lp_id . ' AND orig_lp_item_id = ' . $prereqs_string . '
-                                                        AND status <> "incomplete"
-                                                    ORDER BY exe_date DESC
-                                                    LIMIT 0, 1';
+                                                        WHERE
+                                                            exe_exo_id = ' . $items[$refs_list[$prereqs_string]]->path . ' AND
+                                                            exe_user_id = ' . $user_id . ' AND
+                                                            orig_lp_id = ' . $this->lp_id . ' AND
+                                                            orig_lp_item_id = ' . $prereqs_string . ' AND
+                                                            status <> "incomplete"
+                                                        ORDER BY exe_date DESC
+                                                        LIMIT 0, 1';
                                                 $rs_quiz = Database::query($sql);
                                                 if ($quiz = Database :: fetch_array($rs_quiz)) {
                                                     if ($quiz['exe_result'] >= $items[$refs_list[$prereqs_string]]->get_mastery_score()) {
@@ -2535,17 +2537,17 @@ class learnpathItem
                                                     $returnstatus = false;
                                                 }
                                             }
-
                                         } else {
                                             // 3. for multiple attempts we check that there are minimun 1 item completed.
 
                                             // Checking in the database.
                                             $sql = 'SELECT exe_result, exe_weighting
-                                                    FROM ' . Database :: get_main_table(
-                                                    TABLE_STATISTIC_TRACK_E_EXERCISES
-                                                ) . '
-                                                    WHERE exe_exo_id = ' . $items[$refs_list[$prereqs_string]]->path . '
-                                                        AND exe_user_id = ' . $user_id . ' AND orig_lp_id = ' . $this->lp_id . ' AND orig_lp_item_id = ' . $prereqs_string . ' ';
+                                                    FROM ' . Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES) . '
+                                                    WHERE
+                                                        exe_exo_id = ' . $items[$refs_list[$prereqs_string]]->path . ' AND
+                                                        exe_user_id = ' . $user_id . ' AND
+                                                        orig_lp_id = ' . $this->lp_id . ' AND
+                                                        orig_lp_item_id = ' . $prereqs_string . ' ';
                                             //error_log('results 2:'.$items[$refs_list[$prereqs_string]]->path. ':'.$user_id);
 
                                             $rs_quiz = Database::query($sql);
@@ -2600,7 +2602,11 @@ class learnpathItem
                                             );
 
                                             $sql = 'SELECT id FROM ' . $lp_view . '
-                                                    WHERE c_id = ' . $course_id . ' AND user_id = ' . $user_id . '  AND lp_id = ' . $this->lp_id . ' LIMIT 0, 1';
+                                                    WHERE
+                                                        c_id = ' . $course_id . ' AND
+                                                        user_id = ' . $user_id . '  AND
+                                                        lp_id = ' . $this->lp_id . '
+                                                    LIMIT 0, 1';
                                             $rs_lp = Database::query($sql);
                                             $lp_id = Database :: fetch_row(
                                                 $rs_lp
@@ -2608,7 +2614,11 @@ class learnpathItem
                                             $my_lp_id = $lp_id[0];
 
                                             $sql = 'SELECT status FROM ' . $lp_item_view . '
-                                                   WHERE c_id = ' . $course_id . ' AND lp_view_id = ' . $my_lp_id . ' AND lp_item_id = ' . $refs_list[$prereqs_string] . ' LIMIT 0, 1';
+                                                   WHERE
+                                                        c_id = ' . $course_id . ' AND
+                                                        lp_view_id = ' . $my_lp_id . ' AND
+                                                        lp_item_id = ' . $refs_list[$prereqs_string] . '
+                                                    LIMIT 0, 1';
                                             $rs_lp = Database::query($sql);
                                             $status_array = Database :: fetch_row(
                                                 $rs_lp
@@ -2670,11 +2680,11 @@ class learnpathItem
                         );
                     }
                     $orstatus = $orstatus || $this->parse_prereq(
-                            $condition,
-                            $items,
-                            $refs_list,
-                            $user_id
-                        );
+                        $condition,
+                        $items,
+                        $refs_list,
+                        $user_id
+                    );
                     if ($orstatus) {
                         // Shortcircuit OR.
                         if (self::debug > 1) {
@@ -2711,15 +2721,18 @@ class learnpathItem
                 }
             }
         }
+
         if (empty($this->prereq_alert)) {
             $this->prereq_alert = get_lang('LearnpathPrereqNotCompleted');
         }
+
         if (self::debug > 1) {
             error_log(
                 'New LP - End of parse_prereq. Error code is now ' . $this->prereq_alert,
                 0
             );
         }
+
         return false;
     }
 

+ 9 - 8
main/newscorm/lp_edit_item_prereq.php

@@ -38,7 +38,7 @@ $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
 
 // Using the resource linker as a tool for adding resources to the learning path.
 if ($action == 'add' and $type == 'learnpathitem') {
-    $htmlHeadXtra[] = "<script language='JavaScript' type='text/javascript'> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
+    $htmlHeadXtra[] = "<script> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
 }
 if ((!$is_allowed_to_edit) || ($isStudentView)) {
     error_log('New LP - User not authorized in lp_edit_item_prereq.php');
@@ -69,14 +69,15 @@ $interbreadcrumb[] = array('url' => api_get_self() . "?action=add_item&type=step
 
 // Theme calls.
 $show_learn_path = true;
-$lp_theme_css = $_SESSION['oLP']->get_theme();
+/** @var learnpath $lp */
+$lp = $_SESSION['oLP'];
+$lp_theme_css = $lp->get_theme();
 
 Display::display_header(get_lang('LearnpathPrerequisites'), 'Path');
 
 $suredel = trim(get_lang('AreYouSureToDelete'));
 ?>
 <script>
-    /* <![CDATA[ */
     function stripslashes(str) {
         str=str.replace(/\\'/g,'\'');
         str=str.replace(/\\"/g,'"');
@@ -97,19 +98,19 @@ $suredel = trim(get_lang('AreYouSureToDelete'));
 
 /* DISPLAY SECTION */
 
-echo $_SESSION['oLP']->build_action_menu();
+echo $lp->build_action_menu();
 
 echo '<div class="row-fluid">';
 echo '<div class="span3">';
-echo $_SESSION['oLP']->return_new_tree();
+echo $lp->return_new_tree();
 echo '</div>';
 echo '<div class="span9">';
 if (isset($is_success) && $is_success == true) {
-    echo $_SESSION['oLP']->display_manipulate($_GET['id'], null);
+    echo $lp->display_manipulate($_GET['id'], null);
     echo Display::return_message(get_lang("PrerequisitesAdded"));
 } else {
-    echo $_SESSION['oLP']->display_manipulate($_GET['id'], null);
-    echo $_SESSION['oLP']->display_item_prerequisites_form($_GET['id']);
+    echo $lp->display_manipulate($_GET['id'], null);
+    echo $lp->display_item_prerequisites_form($_GET['id']);
 }
 echo '</div>';