Browse Source

Merge branch '1.9.x' of github.com:chamilo/chamilo-lms into julio6666

Julio Montoya 11 years ago
parent
commit
625c0cd4b6
3 changed files with 174 additions and 11 deletions
  1. 64 11
      main/exercice/exercise.class.php
  2. 101 0
      main/inc/lib/lp_item.lib.php
  3. 9 0
      main/newscorm/learnpath.class.php

+ 64 - 11
main/exercice/exercise.class.php

@@ -376,7 +376,7 @@ class Exercise {
     /**
      * returns random answers status.
      *
-     * @author - Juan Carlos Ra�a
+     * @author - Juan Carlos Rana
      */
     function selectRandomAnswers() {
         return $this->random_answers;
@@ -634,7 +634,7 @@ class Exercise {
     /**
      * sets to 0 if answers are not selected randomly
      * if answers are selected randomly
-     * @author - Juan Carlos Ra�a
+     * @author - Juan Carlos Rana
      * @param - integer $random_answers - random answers
      */
     function updateRandomAnswers($random_answers) {
@@ -1264,6 +1264,7 @@ class Exercise {
             $this->random_answers=0;
         }
         $this->save($type);
+
     }
 
     function search_engine_save() {
@@ -1540,7 +1541,7 @@ class Exercise {
             $lp_id = 0;
         }
         if (empty($lp_item_id)) {
-            $lp_item_id = 0;
+            $lp_item_id   = 0;
         }
         if (empty($lp_item_view_id)) {
             $lp_item_view_id = 0;
@@ -3681,16 +3682,16 @@ class Exercise {
                 $questionList = array();
                 $tabCategoryQuestions = Testcategory::getQuestionsByCat($this->id);
                 $isRandomByCategory = $this->selectRandomByCat();
-                // on tri les categories en fonction du terme entre [] en tête de la description de la catégorie
+                // on tri les categories en fonction du terme entre [] en tete de la description de la categorie
                 /*
                  * ex de catégories :
-                 * [biologie] Maîtriser les mécanismes de base de la génétique
-                 * [biologie] Relier les moyens de défenses et les agents infectieux
-                 * [biologie] Savoir où est produite l'énergie dans les cellules et sous quelle forme
-                 * [chimie] Classer les molécules suivant leur pouvoir oxydant ou réducteur
-                 * [chimie] Connaître la définition de la théorie acide/base selon Brönsted
-                 * [chimie] Connaître les charges des particules
-                 * On veut dans l'ordre des groupes définis par le terme entre crochet au début du titre de la catégorie
+                 * [biologie] Maitriser les mecanismes de base de la genetique
+                 * [biologie] Relier les moyens de depenses et les agents infectieux
+                 * [biologie] Savoir ou est produite l'enrgie dans les cellules et sous quelle forme
+                 * [chimie] Classer les molles suivant leur pouvoir oxydant ou reacteur
+                 * [chimie] Connaître la denition de la theoie acide/base selon Brönsted
+                 * [chimie] Connaître les charges des particules
+                 * On veut dans l'ordre des groupes definis par le terme entre crochet au debut du titre de la categorie
                 */
                 // If test option is Grouped By Categories
                 if ($isRandomByCategory == 2) {
@@ -3897,4 +3898,56 @@ class Exercise {
         }
         return $list;
     }
+
+
+    /**
+     * Calculate the max_score of the quiz, depending of question inside, and quiz advanced option
+     */
+    public function get_max_score() {
+        $out_max_score = 0;
+        $tab_question_list = $this->selectQuestionList(true);   // list of question's id !!! the array key start at 1 !!!
+        // test is randomQuestions - see field random of test
+        if ($this->random > 0 && $this->randomByCat == 0) {
+            $nb_random_questions = $this->random;
+            $tab_questions_score = array();
+            for ($i=1; $i <= count($tab_question_list); $i++) {
+                $tmpobj_question = Question::read($tab_question_list[$i]);
+                $tab_questions_score[] = $tmpobj_question->weighting;
+            }
+            rsort($tab_questions_score);
+            // add the first $nb_random_questions value of score array to get max_score
+            for ($i=0; $i < min($nb_random_questions, count($tab_questions_score)); $i++) {
+                $out_max_score += $tab_questions_score[$i];
+            }
+        }
+        // test is random by category
+        // get the $nb_random_questions best score question of each category
+        else if ($this->random > 0 && $this->randomByCat > 0) {
+            $nb_random_questions = $this->random;
+            $tab_categories_scores = array();
+            for ($i=1; $i <= count($tab_question_list); $i++) {
+                $question_category_id = Testcategory::getCategoryForQuestion($tab_question_list[$i]);
+                if (!is_array($tab_categories_scores[$question_category_id])) {
+                    $tab_categories_scores[$question_category_id] = array();
+                }
+                $tmpobj_question = Question::read($tab_question_list[$i]);
+                $tab_categories_scores[$question_category_id][] = $tmpobj_question->weighting;
+            }
+            // here we've got an array with first key, the category_id, second key, score of question for this cat
+            while (list($key, $tab_scores) = each($tab_categories_scores)) {
+                rsort($tab_scores);
+                for ($i=0; $i < min($nb_random_questions, count($tab_scores)); $i++) {
+                    $out_max_score += $tab_scores[$i];
+                }
+            }
+        }
+        // standart test, just add each question score
+        else {
+            for ($i=1; $i <= count($tab_question_list); $i++) {
+                $tmpobj_question = Question::read($tab_question_list[$i]);
+                $out_max_score += $tmpobj_question->weighting;
+            }
+        }
+        return $out_max_score;
+    }
 }

+ 101 - 0
main/inc/lib/lp_item.lib.php

@@ -0,0 +1,101 @@
+<?php
+
+/**
+ * Class lp_item
+ *  made to manipulate datas of lp_item table
+ *
+ * This class is still incomplte
+ * You can add lp_item database manipulation function here
+ *
+ */
+
+
+class LpItem {
+    public $c_id=0;
+    public $id=0;
+    public $lp_id=0;
+    public $item_type="";
+    public $ref="";
+    public $title="";
+    public $description="";
+    public $path="";
+    public $min_score=0;
+    public $max_score=0;
+    public $mastery_score=0;
+    public $parent_item_id=0;
+    public $previous_item_id=0;
+    public $next_item_id=0;
+    public $display_order=0;
+    public $prerequisite="";
+    public $parameters="";
+    public $launch_data="";
+    public $max_time_allowed="";
+    public $terms="";
+    public $search_did=0;
+    public $audio="";
+
+    public function __construct($in_c_id=0, $in_id=0) {
+        if ($in_c_id > 0 && $in_id >0) {
+            $item_view_table = Database::get_course_table(TABLE_LP_ITEM);
+            $sql = "SELECT * FROM $item_view_table WHERE c_id=".Database::escape_string($in_c_id)."
+                    AND id=".Database::escape_string($in_id);
+
+            $res = Database::query($sql);
+            $data = Database::fetch_array($res);
+            if (Database::num_rows($res) > 0) {
+                $this->c_id = $data['c_id'];
+                $this->id = $data['id'];
+                $this->lp_id = $data['lp_id'];
+                $this->item_type = $data['item_type'];
+                $this->ref = $data['ref'];
+                $this->title = $data['title'];
+                $this->description = $data['description'];
+                $this->path = $data['path'];
+                $this->min_score = $data['min_score'];
+                $this->max_score = $data['max_score'];
+                $this->mastery_score = $data['mastery_score'];
+                $this->parent_item_id = $data['parent_item_id'];
+                $this->previous_item_id = $data['previous_item_id'];
+                $this->next_item_id = $data['next_item_id'];
+                $this->display_order = $data['display_order'];
+                $this->prerequisite = $data['prerequisite'];
+                $this->parameters = $data['parameters'];
+                $this->launch_data = $data['launch_data'];
+                $this->max_time_allowed = $data['max_time_allowed'];
+                $this->terms = $data['terms'];
+                $this->search_did = $data['search_did'];
+                $this->audio = $data['audio'];
+            }
+        }
+    }
+
+    public function update_in_bdd() {
+        $item_view_table = Database::get_course_table(TABLE_LP_ITEM);
+        if ($this->c_id > 0 && $this->id > 0) {
+            $sql = "UPDATE $item_view_table SET
+                    lp_id = '".Database::escape_string($this->lp_id)."' ,
+                    item_type = '".Database::escape_string($this->item_type)."' ,
+                    ref = '".Database::escape_string($this->ref)."' ,
+                    title = '".Database::escape_string($this->title)."' ,
+                    description = '".Database::escape_string($this->description)."' ,
+                    path = '".Database::escape_string($this->path)."' ,
+                    min_score = '".Database::escape_string($this->min_score)."' ,
+                    max_score = '".Database::escape_string($this->max_score)."' ,
+                    mastery_score = '".Database::escape_string($this->mastery_score)."' ,
+                    parent_item_id = '".Database::escape_string($this->parent_item_id)."' ,
+                    previous_item_id = '".Database::escape_string($this->previous_item_id)."' ,
+                    next_item_id = '".Database::escape_string($this->next_item_id)."' ,
+                    display_order = '".Database::escape_string($this->display_order)."' ,
+                    prerequisite = '".Database::escape_string($this->prerequisite)."' ,
+                    parameters = '".Database::escape_string($this->parameters)."' ,
+                    launch_data = '".Database::escape_string($this->launch_data)."' ,
+                    max_time_allowed = '".Database::escape_string($this->max_time_allowed)."' ,
+                    terms = '".Database::escape_string($this->terms)."' ,
+                    search_did = '".Database::escape_string($this->search_did)."' ,
+                    audio = '".Database::escape_string($this->audio)."'
+                    WHERE c_id=".$this->c_id." AND id=".$this->id;
+            Database::query($sql);
+        }
+    }
+
+}

+ 9 - 0
main/newscorm/learnpath.class.php

@@ -7894,6 +7894,15 @@ class learnpath {
             //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
 
             if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
+                // lets update max_score Quiz information depending of the Quiz Advanced properties
+                require_once api_get_path(LIBRARY_PATH)."lp_item.lib.php";
+                $tmp_obj_lp_item = new LpItem($course_id, $arrLP[$i]['id']);
+                $tmp_obj_exercice = new Exercise();
+                $tmp_obj_exercice->read($tmp_obj_lp_item->path);
+                $tmp_obj_lp_item->max_score = $tmp_obj_exercice->get_max_score();
+                $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 .= '<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>';