diff --git a/main/gradebook/gradebook_flatview.php b/main/gradebook/gradebook_flatview.php index 5f51eb9a28..946dad7db0 100644 --- a/main/gradebook/gradebook_flatview.php +++ b/main/gradebook/gradebook_flatview.php @@ -109,7 +109,7 @@ if (isset ($_GET['exportpdf'])) { // Beginning of PDF report creation - $printable_data = get_printable_data($users, $alleval, $alllinks); + $printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks); $export = $export_pdf_form->exportValues(); // Reading report's CSS @@ -170,11 +170,10 @@ if (isset ($_GET['exportpdf'])) { if (!empty($total)) { foreach($total as $label => $count) { $total_custom_score = round($count/count($user_results), 2) *100; - $html .= Display::tag('tr', Display::tag('td', $label).Display::tag('td', Display::tag('strong', $total_custom_score.' %'))); + $html .= Display::tag('tr', Display::tag('td', $label).': '.Display::tag('td', Display::tag('strong', $total_custom_score.' %'))); } } - $html .= ''; - + $html .= ''; $html .= ''; $headers = $printable_data[0]; unset($headers[0]); @@ -182,7 +181,8 @@ if (isset ($_GET['exportpdf'])) { unset($headers[count($headers)+1]); foreach ($headers as $head) { - $html .= Display::tag('tr', Display::tag('td', 'P1').Display::tag('td', Display::tag('strong', $head))); + //$html .= Display::tag('tr', Display::tag('td', 'P1').Display::tag('td', Display::tag('strong', $head))); + $html .= Display::tag('tr', Display::tag('td', Display::tag('strong', $head))); } $html .= '

'; diff --git a/main/gradebook/lib/flatview_data_generator.class.php b/main/gradebook/lib/flatview_data_generator.class.php index ab37e14df3..cd0df13c84 100644 --- a/main/gradebook/lib/flatview_data_generator.class.php +++ b/main/gradebook/lib/flatview_data_generator.class.php @@ -54,7 +54,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) { + public function get_header_names($items_start = 0, $items_count = null , $show_detail = false) { $headers = array(); $headers[] = get_lang('LastName'); $headers[] = get_lang('FirstName'); @@ -80,6 +80,7 @@ class FlatViewDataGenerator //$headers[] = $item->get_name().'
'.get_lang('Max').' '.$this->get_max_result_by_link($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); $headers[] = $item->get_name().' '.$weight.' % '; if ($show_detail) { @@ -189,6 +190,7 @@ class FlatViewDataGenerator } //@todo move these in a function $sum_categories_weight_array = array(); + if (isset($this->category) && !empty($this->category)) { $categories = Category::load(null, null, null, $this->category->get_id()); if (!empty($categories)) { @@ -202,7 +204,7 @@ class FlatViewDataGenerator foreach ($selected_users as $user) { $row = array (); - $row[] = $user[0]; // user id + $row[] = $user_id = $user[0]; // user id $row[] = $user[2]; // last name $row[] = $user[3]; // first name @@ -212,18 +214,23 @@ class FlatViewDataGenerator for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) { - $item = $this->evals_links[$count + $items_start]; - - $score = $item->calc_score($user[0]); - - $divide = ( ($score[1])==0 ) ? 1 : $score[1]; - + $item = $this->evals_links[$count + $items_start]; + + $score = $item->calc_score($user_id); + $divide = ( ($score[1])==0 ) ? 1 : $score[1]; $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()]; $item_value = round($score[0]/$divide,2) * 100; - $percentage = round($item->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight(), 2); - $item_value = $percentage*$item_value; + //Fixing total when using one or multiple gradebooks + if ($this->category->get_parent_id() == 0 ) { + $item_value = $item_value; + $item_value =round($score[0]/$divide*$item->get_weight(),2); + } else { + $percentage = round($item->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight(), 2); + $item_value = $percentage*$item_value; + } + $item_total += $item->get_weight(); $temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); @@ -235,8 +242,6 @@ class FlatViewDataGenerator //$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT); if (in_array($item->get_type() , array(LINK_EXERCISE, LINK_DROPBOX, LINK_STUDENTPUBLICATION, LINK_LEARNPATH, LINK_FORUM_THREAD, LINK_ATTENDANCE,LINK_SURVEY))) { - - if (!empty($score[0])) { $row[] = $temp_score.' '; } else { @@ -255,9 +260,10 @@ class FlatViewDataGenerator } $item_value_total +=$item_value; } - + $item_total = round($item_total); $total_score = array($item_value_total, $item_total); + if (!$show_all) { $row[] = $scoredisplay->display_score($total_score); diff --git a/main/gradebook/lib/gradebook_functions.inc.php b/main/gradebook/lib/gradebook_functions.inc.php index 24a022730e..752a3954a9 100644 --- a/main/gradebook/lib/gradebook_functions.inc.php +++ b/main/gradebook/lib/gradebook_functions.inc.php @@ -393,10 +393,14 @@ function get_table_type_course($type,$course) { return Database::get_course_table($table_evaluated[$type][0],$_configuration['db_prefix'].$course); } -function get_printable_data($users, $alleval, $alllinks) { +function get_printable_data($cat, $users, $alleval, $alllinks) { $datagen = new FlatViewDataGenerator ($users, $alleval, $alllinks); $offset = isset($_GET['offset']) ? $_GET['offset'] : '0'; $offset = intval($offset); + + // step 2: generate rows: students + $datagen->category = $cat; + $count = (($offset + 10) > $datagen->get_total_items_count()) ? ($datagen->get_total_items_count() - $offset) : LIMIT; $header_names = $datagen->get_header_names($offset, $count, true); $data_array = $datagen->get_data(FlatViewDataGenerator :: FVDG_SORT_LASTNAME, 0, null, $offset, $count, true,true);