Procházet zdrojové kódy

Merge branch '1.9.x' into 1.10.x

Julio Montoya před 10 roky
rodič
revize
50833f8c31

+ 2 - 2
main/exercice/exercise.class.php

@@ -2341,14 +2341,14 @@ class Exercise
                             $choice[$ind] = 1;
                         }
 
-                        $studentChoice = $choice[$numAnswer];
+                        $studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
                         $real_answers[$answerId] = (bool)$studentChoice;
 
                         if ($studentChoice) {
                             $questionScore  +=$answerWeighting;
                         }
                     } else {
-                        $studentChoice = $choice[$numAnswer];
+                        $studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null;
                         $real_answers[$answerId] = (bool)$studentChoice;
 
                         if (isset($studentChoice)) {

+ 19 - 11
main/gradebook/lib/be/category.class.php

@@ -292,7 +292,6 @@ class Category implements GradebookItem
                 // otherwise a special parameter is given to ask explicitely
                 $sql .= " AND (session_id IS NULL OR session_id = 0) ";
             } else {*/
-
             if (empty($session_id)) {
                 $sql .= ' AND (session_id IS NULL OR session_id = 0) ';
             } else {
@@ -326,14 +325,15 @@ class Category implements GradebookItem
                 $sql .= ' '.$order_by;
             }
         }
+
         $result = Database::query($sql);
-        $allcat = array();
 
+        $categories = array();
         if (Database::num_rows($result) > 0) {
-            $allcat = Category::create_category_objects_from_sql_result($result);
+            $categories = Category::create_category_objects_from_sql_result($result);
         }
 
-        return $allcat;
+        return $categories;
     }
 
     /**
@@ -731,7 +731,7 @@ class Category implements GradebookItem
      */
     public function calc_score($stud_id = null, $course_code = '', $session_id = null)
     {
-        // get appropriate subcategories, evaluations and links
+        // Get appropriate subcategories, evaluations and links
         if (!empty($course_code)) {
             $cats  = $this->get_subcategories($stud_id, $course_code, $session_id);
             $evals = $this->get_evaluations($stud_id, false, $course_code);
@@ -782,10 +782,9 @@ class Category implements GradebookItem
         }
 
         if (!empty($links)) {
-            /** @var EvalLink $link */
+            /** @var EvalLink|ExerciseLink $link */
             foreach ($links as $link) {
                 $linkres = $link->calc_score($stud_id);
-
                 if (!empty($linkres) && $link->get_weight() != 0) {
                     $linkweight = $link->get_weight();
                     $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1];
@@ -1296,14 +1295,23 @@ class Category implements GradebookItem
 
         // 1 student
         if (isset($stud_id)) {
-            // special case: this is the root
+            // Special case: this is the root
             if ($this->id == 0) {
                 return Category::get_root_categories_for_student($stud_id, $course_code, $session_id);
             } else {
-                return Category::load(null,null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1, $session_id, $order);
+                return Category::load(
+                    null,
+                    null,
+                    $course_code,
+                    $this->id,
+                    api_is_allowed_to_edit() ? null : 1,
+                    $session_id,
+                    $order
+                );
             }
-        } else {// all students
-            // course admin
+        } else {
+            // All students
+            // Course admin
             if (api_is_allowed_to_edit() && !api_is_platform_admin()) {
                 // root
                 if ($this->id == 0) {

+ 12 - 4
main/gradebook/lib/be/evallink.class.php

@@ -19,18 +19,26 @@ abstract class EvalLink extends AbstractLink
         parent::__construct();
     }
 
-    // Functions implementing AbstractLink
-
+    /**
+     * @return bool
+     */
     public function has_results()
     {
         $eval = $this->get_evaluation();
+
         return $eval->has_results();
     }
 
-    public function calc_score($stud_id = null)
+    /**
+     * @param int $userId
+     *
+     * @return array
+     */
+    public function calc_score($userId = null)
     {
         $eval = $this->get_evaluation();
-        return $eval->calc_score($stud_id);
+
+        return $eval->calc_score($userId);
     }
 
     public function get_link()

+ 1 - 1
main/gradebook/lib/be/exerciselink.class.php

@@ -221,7 +221,7 @@ class ExerciseLink extends AbstractLink
             if ($student_count == 0) {
                 return null;
             } else {
-                return array ($sum , $student_count);
+                return array($sum, $student_count);
             }
         }
     }

+ 11 - 8
main/gradebook/lib/fe/flatviewtable.class.php

@@ -47,6 +47,7 @@ class FlatViewTable extends SortableTable
         $mainCourseCategory = null
     ) {
         parent :: __construct('flatviewlist', null, null, (api_is_western_name_order() xor api_sort_by_first_name()) ? 1 : 0);
+
         $this->selectcat = $selectcat;
 
         $this->datagen = new FlatViewDataGenerator(
@@ -368,10 +369,13 @@ class FlatViewTable extends SortableTable
         }
 
         // retrieve sorting type
+
         if ($is_western_name_order) {
-            $users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME : FlatViewDataGenerator :: FVDG_SORT_LASTNAME);
+            //$users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME : FlatViewDataGenerator :: FVDG_SORT_LASTNAME);
+            $users_sorting = FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME;
         } else {
-            $users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_LASTNAME : FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME);
+            //$users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_LASTNAME : FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME);
+            $users_sorting = FlatViewDataGenerator :: FVDG_SORT_LASTNAME;
         }
         if ($this->direction == 'DESC') {
             $users_sorting |= FlatViewDataGenerator :: FVDG_SORT_DESC;
@@ -382,16 +386,15 @@ class FlatViewTable extends SortableTable
 
         $header_names = $this->datagen->get_header_names($this->offset, $selectlimit);
 
-        $column = 0;
-
         if ($is_western_name_order) {
-            $this->set_header($column++, $header_names[1]);
-            $this->set_header($column++, $header_names[0]);
+            $this->set_header(0, $header_names[1]);
+            $this->set_header(1, $header_names[0]);
         } else {
-            $this->set_header($column++, $header_names[0]);
-            $this->set_header($column++, $header_names[1]);
+            $this->set_header(0, $header_names[0]);
+            $this->set_header(1, $header_names[1]);
         }
 
+        $column = 2;
         while ($column < count($header_names)) {
             $this->set_header($column, $header_names[$column], false);
             $column++;

+ 16 - 9
main/gradebook/lib/flatview_data_generator.class.php

@@ -157,9 +157,11 @@ class FlatViewDataGenerator
             $session_id,
             'ORDER BY id'
         );
+
         $evaluationsAdded = array();
         if ($parent_id == 0 && !empty($allcat)) {
             // Means there are any subcategory
+
             foreach ($allcat as $sub_cat) {
                 $sub_cat_weight = round(100 * $sub_cat->get_weight() / $main_weight, 1);
                 $add_weight = " $sub_cat_weight %";
@@ -216,7 +218,8 @@ class FlatViewDataGenerator
                 $max = $score[0];
             }
         }
-        return $max ;
+
+        return $max;
     }
 
     /**
@@ -389,7 +392,12 @@ class FlatViewDataGenerator
 
             $course_code = api_get_course_id();
             $session_id = api_get_session_id();
-            $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id');
+            $allcat = $this->category->get_subcategories(
+                null,
+                $course_code,
+                $session_id,
+                'ORDER BY id'
+            );
 
             $evaluationsAdded = array();
 
@@ -400,7 +408,7 @@ class FlatViewDataGenerator
 
                     $real_score = $score;
 
-                    $divide = ( ($score[1])==0 ) ? 1 : $score[1];
+                    $divide = $score[1] == 0 ? 1 : $score[1];
 
                     $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()];
                     $item_value  = $score[0]/$divide*$main_weight;
@@ -410,10 +418,10 @@ class FlatViewDataGenerator
                     $item_value = $percentage*$item_value;
                     $item_total += $sub_cat->get_weight();
                     /*
-                                        if ($convert_using_the_global_weight) {
-                                            $score[0] = $score[0]/$main_weight*$sub_cat->get_weight();
-                                            $score[1] = $main_weight ;
-                                        }
+                        if ($convert_using_the_global_weight) {
+                            $score[0] = $score[0]/$main_weight*$sub_cat->get_weight();
+                            $score[1] = $main_weight ;
+                        }
                     */
                     if (api_get_setting('gradebook_show_percentage_in_reports') == 'false') {
                         //if (true)
@@ -427,8 +435,7 @@ class FlatViewDataGenerator
                     }
 
                     if (!isset($this->params['only_total_category']) ||
-                        (isset($this->params['only_total_category']) &&
-                            $this->params['only_total_category'] == false)
+                        (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)
                     ) {
                         if (!$show_all) {
                             $row[] = $temp_score.' ';

+ 2 - 0
main/gradebook/lib/scoredisplay.class.php

@@ -364,9 +364,11 @@ class ScoreDisplay
                 return $this->display_as_div($score).' (' . $this->display_as_percent($score) . ')'.$custom;
             case SCORE_DIV_SIMPLE_WITH_CUSTOM :         // X - Good!
                 $custom = $this->display_custom($score);
+
                 if (!empty($custom)) {
                     $custom = ' - '.$custom;
                 }
+
                 return $this->display_simple_score($score).$custom;
                 break;
             case SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS:

+ 4 - 2
main/inc/lib/sortable_table.class.php

@@ -244,7 +244,7 @@ class SortableTable extends HTML_Table
     public function return_table()
     {
         $empty_table = false;
-        $this->processHeaders();
+
         $content = $this->get_table_html();
 
         if ($this->get_total_number_of_items() == 0) {
@@ -574,6 +574,8 @@ class SortableTable extends HTML_Table
 
         $table_data = $this->get_table_data($from);
 
+        $this->processHeaders();
+
         if (is_array($table_data)) {
             $count = 1;
             foreach ($table_data as & $row) {
@@ -697,6 +699,7 @@ class SortableTable extends HTML_Table
     public function processHeaders()
     {
         $counter = 0;
+
         foreach ($this->headers as $column => $columnInfo) {
             $label = $columnInfo['label'];
             $sortable = $columnInfo['sortable'];
@@ -743,7 +746,6 @@ class SortableTable extends HTML_Table
 
             $counter++;
         }
-
     }
 
     /**

+ 67 - 67
main/template/default/layout/footer.tpl

@@ -20,7 +20,7 @@
                         {{ plugin_footer_left }}
                     </div>
                 {% endif %}
-                 &nbsp;
+                &nbsp;
             </div>
 
             <div id="footer_center" class="span4">
@@ -30,7 +30,7 @@
                         {{ plugin_footer_center }}
                     </div>
                 {% endif %}
-                 &nbsp;
+                &nbsp;
             </div>
 
             <div id="footer_right" class="span4">
@@ -62,27 +62,7 @@
 {% raw %}
 <script>
 
-$("form").on("click", ' .advanced_parameters', function() {
-    var id = $(this).attr('id') + '_options';
-    var button = $(this);
-    $("#"+id).toggle(function() {
-        button.toggleClass('active');
-    });
-});
-
-
-/* Makes row highlighting possible */
-$(document).ready( function() {
-    /**
-     * Advanced options
-     * Usage
-     * <a id="link" href="url">Advanced</a>
-     * <div id="link_options">
-     *     hidden content :)
-     * </div>
-     * */
-    $(".advanced_options").on("click", function(event) {
-        event.preventDefault();
+    $("form").on("click", ' .advanced_parameters', function() {
         var id = $(this).attr('id') + '_options';
         var button = $(this);
         $("#"+id).toggle(function() {
@@ -90,58 +70,78 @@ $(document).ready( function() {
         });
     });
 
-    /**
-     * <a class="advanced_options_open" href="http://" rel="div_id">Open</a>
-     * <a class="advanced_options_close" href="http://" rel="div_id">Close</a>
-     * <div id="div_id">Div content</div>
-     * */
-    $(".advanced_options_open").on("click", function(event) {
-        event.preventDefault();
-        var id = $(this).attr('rel');
-        $("#"+id).show();
-    });
 
-    $(".advanced_options_close").on("click", function(event) {
-        event.preventDefault();
-        var id = $(this).attr('rel');
-        $("#"+id).hide();
-    });
+    /* Makes row highlighting possible */
+    $(document).ready( function() {
+        /**
+         * Advanced options
+         * Usage
+         * <a id="link" href="url">Advanced</a>
+         * <div id="link_options">
+         *     hidden content :)
+         * </div>
+         * */
+        $(".advanced_options").on("click", function(event) {
+            event.preventDefault();
+            var id = $(this).attr('id') + '_options';
+            var button = $(this);
+            $("#"+id).toggle(function() {
+                button.toggleClass('active');
+            });
+        });
 
-    // Chosen select
-    $(".chzn-select").chosen({
-        disable_search_threshold: 10
-    });
+        /**
+         * <a class="advanced_options_open" href="http://" rel="div_id">Open</a>
+         * <a class="advanced_options_close" href="http://" rel="div_id">Close</a>
+         * <div id="div_id">Div content</div>
+         * */
+        $(".advanced_options_open").on("click", function(event) {
+            event.preventDefault();
+            var id = $(this).attr('rel');
+            $("#"+id).show();
+        });
 
-    $(".jp-jplayer audio").addClass('skip');
+        $(".advanced_options_close").on("click", function(event) {
+            event.preventDefault();
+            var id = $(this).attr('rel');
+            $("#"+id).hide();
+        });
 
-    // Mediaelement
-    jQuery('video:not(.skip), audio:not(.skip)').mediaelementplayer(/* Options */);
+        // Chosen select
+        $(".chzn-select").chosen({
+            disable_search_threshold: 10
+        });
+
+        $(".jp-jplayer audio").addClass('skip');
+
+        // Mediaelement
+        jQuery('video:not(.skip), audio:not(.skip)').mediaelementplayer(/* Options */);
+
+        // Table highlight.
+        $("form .data_table input:checkbox").click(function() {
+            if ($(this).is(":checked")) {
+                $(this).parentsUntil("tr").parent().addClass("row_selected");
 
-    // Table highlight.
-    $("form .data_table input:checkbox").click(function() {
-        if ($(this).is(":checked")) {
-            $(this).parentsUntil("tr").parent().addClass("row_selected");
+            } else {
+                $(this).parentsUntil("tr").parent().removeClass("row_selected");
+            }
+        });
 
-        } else {
-            $(this).parentsUntil("tr").parent().removeClass("row_selected");
+        /* For non HTML5 browsers */
+        if ($("#formLogin".length > 1)) {
+            $("input[name=login]").focus();
         }
-    });
 
-    /* For non HTML5 browsers */
-    if ($("#formLogin".length > 1)) {
-        $("input[name=login]").focus();
-    }
-
-    /* For IOS users */
-    $('.autocapitalize_off').attr('autocapitalize', 'off');
-
-    //Tool tip (in exercises)
-    var tip_options = {
-        placement : 'right'
-    }
-    $('.boot-tooltip').tooltip(tip_options);
-});
-{% endraw %}
+        /* For IOS users */
+        $('.autocapitalize_off').attr('autocapitalize', 'off');
+
+        //Tool tip (in exercises)
+        var tip_options = {
+            placement : 'right'
+        };
+        $('.boot-tooltip').tooltip(tip_options);
+    });
+    {% endraw %}
 
 </script>