diff --git a/main/gradebook/gradebook_edit_result.php b/main/gradebook/gradebook_edit_result.php index 6470facb10..c19cb4b9d9 100644 --- a/main/gradebook/gradebook_edit_result.php +++ b/main/gradebook/gradebook_edit_result.php @@ -33,11 +33,11 @@ if ($edit_result_form->validate()) { $scores = ($values['score']); foreach ($scores as $row) { $resultedit = Result :: load (key($scores)); - $row_value = $row ; - if ((!empty ($row_value)) || ($row_value == 0)) { + $row_value = $row; + if ($row_value != '' ) { $resultedit[0]->set_score(floatval(number_format($row_value, api_get_setting('gradebook_number_decimals')))); - } - $resultedit[0]->save(); + $resultedit[0]->save(); + } next($scores); } header('Location: gradebook_view_result.php?selecteval='.$select_eval.'&editallresults='); diff --git a/main/gradebook/lib/be/category.class.php b/main/gradebook/lib/be/category.class.php index a49155d8a5..6beeadd302 100644 --- a/main/gradebook/lib/be/category.class.php +++ b/main/gradebook/lib/be/category.class.php @@ -169,7 +169,9 @@ class Category implements GradebookItem * @param int session id (in case we are in a session) * @param bool Whether to show all "session" categories (true) or hide them (false) in case there is no session id */ - public function load ($id = null, $user_id = null, $course_code = null, $parent_id = null, $visible = null, $session_id = null) { + + + public function load($id = null, $user_id = null, $course_code = null, $parent_id = null, $visible = null, $session_id = null, $order_by = null) { //if the category given is explicitly 0 (not null), then create // a root category object (in memory) if ( isset($id) && (int)$id === 0 ) { @@ -188,10 +190,11 @@ class Category implements GradebookItem } if (isset($user_id)) { $user_id = intval($user_id); - if ($paramcount != 0) { $sql .= ' AND'; + if ($paramcount != 0) { + $sql .= ' AND'; } else { - $sql .= ' WHERE'; - } + $sql .= ' WHERE'; + } $sql .= ' user_id = '.intval($user_id); $paramcount ++; } @@ -225,12 +228,13 @@ class Category implements GradebookItem //} $paramcount ++; } + if (isset($parent_id)) { $parent_id = Database::escape_string($parent_id); if ($paramcount != 0) { - $sql .= ' AND'; + $sql .= ' AND '; } else { - $sql .= ' WHERE'; + $sql .= ' WHERE '; } $sql .= ' parent_id = '.intval($parent_id); $paramcount ++; @@ -244,7 +248,13 @@ class Category implements GradebookItem } $sql .= ' visible = '.intval($visible); $paramcount ++; - } + } + + if (!empty($order_by)) { + if (!empty($order_by) && $order_by != '') { + $sql .= ' '.$order_by; + } + } $result = Database::query($sql); $allcat = array(); if (Database::num_rows($result) > 0) { @@ -1043,16 +1053,14 @@ class Category implements GradebookItem * @param int Session ID (optional) * @return array Array of subcategories */ - public function get_subcategories ($stud_id = null, $course_code = null, $session_id = null) { - $cats = array(); + public function get_subcategories ($stud_id = null, $course_code = null, $session_id = null, $order = null) { // 1 student if (isset($stud_id)) { // special case: this is the root - if ($this->id == 0) { + 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 ); + } else { + return Category::load(null,null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1, $session_id, $order); } } else {// all students // course admin @@ -1062,18 +1070,17 @@ class Category implements GradebookItem return $this->get_root_categories_for_teacher(api_get_user_id(), $course_code, $session_id, false); // inside a course } elseif (!empty($this->course_code)) { - return Category::load(null, null, $this->course_code, $this->id, null, $session_id, false); + return Category::load(null, null, $this->course_code, $this->id, null, $session_id, $order); } elseif (!empty($course_code)) { - return Category::load(null, null, $course_code, $this->id, null, $session_id, false); + return Category::load(null, null, $course_code, $this->id, null, $session_id, $order); // course independent } else { return Category::load(null, api_get_user_id(), 0, $this->id, null); } - } - // platform admin - elseif (api_is_platform_admin()) { + } elseif (api_is_platform_admin()) { + // platform admin //we explicitly avoid listing subcats from another session - return Category::load(null, null, $course_code, $this->id, null, $session_id, false); + return Category::load(null, null, $course_code, $this->id, null, $session_id, $order); } } return array(); diff --git a/main/gradebook/lib/fe/flatviewtable.class.php b/main/gradebook/lib/fe/flatviewtable.class.php index 7652a11f01..a92ddae49b 100644 --- a/main/gradebook/lib/fe/flatviewtable.class.php +++ b/main/gradebook/lib/fe/flatviewtable.class.php @@ -459,7 +459,6 @@ class FlatViewTable extends SortableTable echo $header; } - // retrieve sorting type if ($is_western_name_order) { $users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME : FlatViewDataGenerator :: FVDG_SORT_LASTNAME); @@ -476,13 +475,14 @@ 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]); } else { $this->set_header($column++, $header_names[0]); $this->set_header($column++, $header_names[1]); - } + } while ($column < count($header_names)) { $this->set_header($column, $header_names[$column], false); diff --git a/main/gradebook/lib/fe/gradebooktable.class.php b/main/gradebook/lib/fe/gradebooktable.class.php index ec9917e912..0dea59e162 100644 --- a/main/gradebook/lib/fe/gradebooktable.class.php +++ b/main/gradebook/lib/fe/gradebooktable.class.php @@ -239,7 +239,7 @@ class GradebookTable extends SortableTable { $course_code = api_get_course_id(); $session_id = api_get_session_id(); $parent_id = $item->get_id(); - $cats = Category :: load ($parent_id, null, null, null, null, null, true); + $cats = Category :: load ($parent_id, null, null, null, null, null); $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id); $alleval = $cats[0]->get_evaluations($stud_id); diff --git a/main/gradebook/lib/flatview_data_generator.class.php b/main/gradebook/lib/flatview_data_generator.class.php index bfc6410add..edb12df6b4 100644 --- a/main/gradebook/lib/flatview_data_generator.class.php +++ b/main/gradebook/lib/flatview_data_generator.class.php @@ -55,7 +55,7 @@ class FlatViewDataGenerator * Get array containing column header names (incl user columns) */ public function get_header_names($items_start = 0, $items_count = null , $show_detail = false) { - $headers = array(); + $headers = array(); $headers[] = get_lang('LastName'); $headers[] = get_lang('FirstName'); @@ -63,7 +63,17 @@ class FlatViewDataGenerator $items_count = count($this->evals_links) - $items_start; } - $grade_model_id = $this->category->get_grade_model_id(); + $parent_id = $this->category->get_parent_id(); + + if ($parent_id == 0) { + $main_weight = $this->category->get_weight(); + $grade_model_id = $this->category->get_grade_model_id(); + } else { + $main_cat = Category::load($parent_id, null, null); + $main_weight = $main_cat[0]->get_weight(); + $grade_model_id = $main_cat[0]->get_grade_model_id(); + } + $use_grade_model = true; if (empty($grade_model_id) || $grade_model_id == -1) { $use_grade_model = false; @@ -74,7 +84,7 @@ class FlatViewDataGenerator if (isset($this->category) && !empty($this->category)) { $categories = Category::load(null, null, null, $this->category->get_id()); if (!empty($categories)) { - foreach($categories as $category) { + foreach ($categories as $category) { $sum_categories_weight_array[$category->get_id()] = $category->get_weight(); } } else { @@ -82,25 +92,26 @@ class FlatViewDataGenerator } } - if ($use_grade_model) { + if ($parent_id == 0) { $course_code = api_get_course_id(); $session_id = api_get_session_id(); - $allcat = $this->category->get_subcategories(null, $course_code, $session_id); + $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id'); + foreach ($allcat as $sub_cat) { - $headers[] = Display::url($sub_cat->get_name(), api_get_self().'?selectcat='.$sub_cat->get_id()).' '.$sub_cat->get_weight().' % '; - } + $sub_cat_weight = 100*$sub_cat->get_weight()/$main_weight; + $headers[] = Display::url($sub_cat->get_name(), api_get_self().'?selectcat='.$sub_cat->get_id()).' '.$sub_cat_weight.' % '; + } } else { if (!isset($this->params['only_total_category'])) { for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) { - $item = $this->evals_links[$count + $items_start]; - //$headers[] = $item->get_name().'
'.get_lang('Max').' '.$this->get_max_result_by_link($count + $items_start).' '; + $item = $this->evals_links[$count + $items_start]; $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()]; - $weight = round($item->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight() *100, 2); + $weight = round($item->get_weight()/($sub_cat_percentage)*$sub_cat_percentage/$this->category->get_weight() *100, 2); $headers[] = $item->get_name().' '.$weight.' % '; } - } + } } - $headers[] = get_lang('GradebookQualificationTotal').' 100%'; + $headers[] = get_lang('GradebookQualificationTotal').' 100%'; return $headers; } @@ -124,9 +135,7 @@ class FlatViewDataGenerator if (!isset($items_count)) { $items_count = count($this->evals_links) - $items_start; } - for ($count=0; - ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); - $count++) { + for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) { $item = $this->evals_links [$count + $items_start]; $headers[] = $item->get_name(); } @@ -214,10 +223,9 @@ class FlatViewDataGenerator $use_grade_model = true; if (empty($grade_model_id) || $grade_model_id == -1) { $use_grade_model = false; - } - + } foreach ($selected_users as $user) { - $row = array (); + $row = array(); $row[] = $user_id = $user[0]; //user id $row[] = $user[2]; //last name $row[] = $user[3]; //first name @@ -226,12 +234,12 @@ class FlatViewDataGenerator $item_value_total = 0; $item_total = 0; - $convert_using_the_global_weight = false; + $convert_using_the_global_weight = true; if ($parent_id == 0) { $course_code = api_get_course_id(); $session_id = api_get_session_id(); - $allcat = $this->category->get_subcategories(null, $course_code, $session_id); + $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id'); foreach ($allcat as $sub_cat) { $score = $sub_cat->calc_score($user_id); @@ -241,7 +249,7 @@ class FlatViewDataGenerator $item_value = round($score[0]/$divide,2) * $main_weight; //Fixing total when using one or multiple gradebooks - $percentage = round($sub_cat->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight(), 2); + $percentage = round($sub_cat->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight(), 2); $item_value = $percentage*$item_value; $item_total += $sub_cat->get_weight(); @@ -250,7 +258,8 @@ class FlatViewDataGenerator $score[1] = $main_weight ; } - $temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); + $temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); + //$temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM); if (!isset($this->params['only_total_category'])) { if (!$show_all) { @@ -285,8 +294,11 @@ class FlatViewDataGenerator } //if ($debug) var_dump($item_value); $item_total += $item->get_weight(); - + //SCORE_DIV, SCORE_PERCENT, SCORE_DIV_PERCENT, SCORE_AVERAGE + $temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); + //$temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM); + if (!isset($this->params['only_total_category'])) { if (!$show_all) { @@ -317,16 +329,18 @@ class FlatViewDataGenerator $item_total = round($item_total); $total_score = array($item_value_total, $item_total); - + + if (!$show_all) { $row[] = $scoredisplay->display_score($total_score); - } else { - $row[] = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT_WITH_CUSTOM); + } else { + //$row[] = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT_WITH_CUSTOM); + $row[] = $scoredisplay->display_score($total_score, SCORE_DIV_SIMPLE_WITH_CUSTOM); //$row[] = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT); } unset($score); $data[] = $row; - } + } return $data; } diff --git a/main/gradebook/lib/gradebook_functions.inc.php b/main/gradebook/lib/gradebook_functions.inc.php index 87e4c69a37..030f9b6aa2 100644 --- a/main/gradebook/lib/gradebook_functions.inc.php +++ b/main/gradebook/lib/gradebook_functions.inc.php @@ -807,17 +807,25 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array( } } + $table = new HTML_Table(array('class' => 'data_table')); $row = 0; - $column = 0; + $column = 0; + + $table->setHeaderContents($row, $column, '#');$column++; foreach ($printable_data[0] as $printable_data_cell) { $table->setHeaderContents($row, $column, $printable_data_cell); $column++; } $row++; if ($has_data) { + $counter = 1; foreach ($printable_data[1] as &$printable_data_row) { $column = 0; + $table->setCellContents($row, $column, $counter); + $table->updateCellAttributes($row, $column, 'align="center"'); + $column++; $counter++; + foreach ($printable_data_row as &$printable_data_cell) { $table->setCellContents($row, $column, $printable_data_cell); $table->updateCellAttributes($row, $column, 'align="center"');