diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 1b554f97c4..2d70eceacb 100755 --- a/main/exercice/exercise.class.php +++ b/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)) { diff --git a/main/gradebook/lib/be/category.class.php b/main/gradebook/lib/be/category.class.php index b704b148ff..0ffcb4b5c7 100755 --- a/main/gradebook/lib/be/category.class.php +++ b/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) { diff --git a/main/gradebook/lib/be/evallink.class.php b/main/gradebook/lib/be/evallink.class.php index 34484703cf..651e6da3ae 100755 --- a/main/gradebook/lib/be/evallink.class.php +++ b/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() diff --git a/main/gradebook/lib/be/exerciselink.class.php b/main/gradebook/lib/be/exerciselink.class.php index b5d5db16b8..38e5161e50 100755 --- a/main/gradebook/lib/be/exerciselink.class.php +++ b/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); } } } diff --git a/main/gradebook/lib/fe/flatviewtable.class.php b/main/gradebook/lib/fe/flatviewtable.class.php index 77a4e4f0d9..5319a22aad 100755 --- a/main/gradebook/lib/fe/flatviewtable.class.php +++ b/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++; diff --git a/main/gradebook/lib/flatview_data_generator.class.php b/main/gradebook/lib/flatview_data_generator.class.php index 736411a315..405d518b65 100755 --- a/main/gradebook/lib/flatview_data_generator.class.php +++ b/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.' '; diff --git a/main/gradebook/lib/scoredisplay.class.php b/main/gradebook/lib/scoredisplay.class.php index 7881352c45..e46f7b8998 100755 --- a/main/gradebook/lib/scoredisplay.class.php +++ b/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: diff --git a/main/inc/lib/sortable_table.class.php b/main/inc/lib/sortable_table.class.php index 3dc1880e19..0882a37eaa 100755 --- a/main/inc/lib/sortable_table.class.php +++ b/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++; } - } /** diff --git a/main/template/default/layout/footer.tpl b/main/template/default/layout/footer.tpl index 68d0da030f..d3fdb29c11 100755 --- a/main/template/default/layout/footer.tpl +++ b/main/template/default/layout/footer.tpl @@ -20,7 +20,7 @@ {{ plugin_footer_left }} {% endif %} -   +   {% endif %} -   +