Fixing flatview due the recent changes in gradebook see BT#4080

skala
Julio Montoya 13 years ago
parent 09a1c5bff0
commit c5a648671a
  1. 9
      main/gradebook/gradebook_flatview.php
  2. 19
      main/gradebook/lib/be/category.class.php
  3. 11
      main/gradebook/lib/fe/displaygradebook.php
  4. 212
      main/gradebook/lib/flatview_data_generator.class.php

@ -93,7 +93,9 @@ if (!empty($keyword)) {
}
$offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
$flatviewtable = new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams);
$parameters=array('selectcat'=>intval($_GET['selectcat']));
$flatviewtable->set_additional_parameters($parameters);
@ -120,8 +122,7 @@ if (isset($_GET['exportpdf'])) {
// HTML report creation first
$time = time();
$cat_name = trim($cat[0]->get_name());
$time = time();
$course_code = trim($cat[0]->get_course_code());
$organization = api_get_setting('Institution');
@ -262,9 +263,7 @@ if (isset ($_GET['print'])) {
echo print_table($printable_data[1],$printable_data[0], get_lang('FlatView'), $cat[0]->get_name());
exit;
}
if (!empty($_GET['export_report']) && $_GET['export_report'] == 'export_report') {
if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) {

@ -500,7 +500,6 @@ class Category implements GradebookItem
*/
public function calc_score ($stud_id = null, $course_code = '', $session_id = null) {
// 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);
@ -515,7 +514,13 @@ class Category implements GradebookItem
$rescount = 0;
$ressum = 0;
$weightsum = 0;
/*$debug = false;
if ($stud_id == 11) {
$debug = true;
}
if ($debug) var_dump($links);*/
if (!empty($cats)) {
foreach ($cats as $cat) {
$catres = $cat->calc_score($stud_id); // recursive call
@ -530,7 +535,6 @@ class Category implements GradebookItem
}
}
//var_dump($weightsum);
if (!empty($evals)) {
foreach ($evals as $eval) {
$evalres = $eval->calc_score($stud_id);
@ -548,6 +552,7 @@ class Category implements GradebookItem
if (!empty($links)) {
foreach ($links as $link) {
$linkres = $link->calc_score($stud_id);
//if ($debug) var_dump($linkres);
if (isset($linkres) && $link->get_weight() != 0) {
$linkweight = $link->get_weight();
@ -555,7 +560,13 @@ class Category implements GradebookItem
$rescount++;
$weightsum += $linkweight;
$ressum += (($linkres[0]/$link_res_denom) * $linkweight);
}
} else {
//adding if result does not exists
if ($link->get_weight() != 0) {
$linkweight = $link->get_weight();
$weightsum += $linkweight;
}
}
}
}

@ -154,8 +154,15 @@ class DisplayGradebook
*/
function display_header_reduce_flatview($catobj, $showeval, $showlink,$simple_search_form) {
$header = '<div class="actions">';
$header .= '<a href="'.Security::remove_XSS($_SESSION['gradebook_dest']).'?'.api_get_cidreq().'">'. Display::return_icon('back.png',get_lang('FolderView'),'',ICON_SIZE_MEDIUM).'</a>';
// $header .= '<td style="vertical-align: top;"><a href="' . api_get_self() . '?exportpdf=&offset='.Security::remove_XSS($_GET['offset']).'&search=' . Security::remove_XSS($_GET['search']).'&selectcat=' . $catobj->get_id() . '"><img src=../img/file_pdf.gif alt=' . get_lang('ExportPDF') . '/> ' . get_lang('ExportPDF') . '</a>';
if ($catobj->get_parent_id() == 0) {
$select_cat = $catobj->get_id();
$url = Security::remove_XSS($_SESSION['gradebook_dest']);
} else {
$select_cat = $catobj->get_parent_id();
$url = 'gradebook_flatview.php';
}
$header .= '<a href="'.$url.'?'.api_get_cidreq().'&selectcat='.$select_cat.'">'. Display::return_icon('back.png',get_lang('FolderView'),'',ICON_SIZE_MEDIUM).'</a>';
// this MUST be a GET variable not a POST
if (isset($_GET['show'])) {

@ -33,9 +33,10 @@ class FlatViewDataGenerator
$this->evals = (isset($evals) ? $evals : array());
$this->links = (isset($links) ? $links : array());
$this->evals_links = array_merge($this->evals, $this->links);
}
/**
* Get total number of users (rows)
*/
@ -50,7 +51,6 @@ class FlatViewDataGenerator
return count($this->evals_links);
}
/**
* Get array containing column header names (incl user columns)
*/
@ -61,10 +61,17 @@ class FlatViewDataGenerator
if (!isset($items_count)) {
$items_count = count($this->evals_links) - $items_start;
}
}
$grade_model_id = $this->category->get_grade_model_id();
$use_grade_model = true;
if (empty($grade_model_id) || $grade_model_id == -1) {
$use_grade_model = false;
}
//@todo move these in a function
$sum_categories_weight_array = array();
if (isset($this->category) && !empty($this->category)) {
$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)) {
foreach($categories as $category) {
@ -75,32 +82,39 @@ class FlatViewDataGenerator
}
}
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().' <br /> '.get_lang('Max').' '.$this->get_max_result_by_link($count + $items_start).' ';
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
if ($use_grade_model) {
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$allcat = $this->category->get_subcategories(null, $course_code, $session_id);
foreach ($allcat as $sub_cat) {
$headers[] = Display::url($sub_cat->get_name(), api_get_self().'?selectcat='.$sub_cat->get_id()).' <br /> '.$sub_cat->get_weight().' % ';
}
} else {
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().' <br /> '.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().' <br />'.$weight.' % ';
if ($show_detail) {
//$headers[] = $item->get_name().' ('.get_lang('Detail').')';
}
}
}
$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) {
//$headers[] = $item->get_name().' ('.get_lang('Detail').')';
}
}
$headers[] = get_lang('GradebookQualificationTotal').' 100%';
if ($show_detail) {
//$headers[] = get_lang('GradebookQualificationTotal').' ('.get_lang('Detail').')';
}
}
return $headers;
}
function get_max_result_by_link($id) {
$usertable = array ();
$items_count = count ($this->evals) + count ($this->links);
$usertable = array();
$items_count = count ($this->evals) + count ($this->links);
$item_value = 0;
$item_total = 0;
$max = 0;
@ -132,8 +146,7 @@ class FlatViewDataGenerator
}
return $headers;
}
/**
* Get actual array data
@ -201,65 +214,113 @@ class FlatViewDataGenerator
$sum_categories_weight_array[$this->category->get_id()] = $this->category->get_weight();
}
}
$grade_model_id = $this->category->get_grade_model_id();
$parent_id = $this->category->get_parent_id();
$main_cat = Category::load($parent_id, null, null);
$main_weight = $main_cat[0]->get_weight();
$use_grade_model = true;
if (empty($grade_model_id) || $grade_model_id == -1) {
$use_grade_model = false;
}
foreach ($selected_users as $user) {
foreach ($selected_users as $user) {
$row = array ();
$row[] = $user_id = $user[0]; // user id
$row[] = $user[2]; // last name
$row[] = $user[3]; // first name
$row[] = $user_id = $user[0]; //user id
$row[] = $user[2]; //last name
$row[] = $user[3]; //first name
$item_value = 0;
$item_value_total = 0;
$item_total = 0;
$item_total = 0;
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_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;
//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);
if ($use_grade_model) {
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$allcat = $this->category->get_subcategories(null, $course_code, $session_id);
foreach ($allcat as $sub_cat) {
$score = $sub_cat->calc_score($user_id);
$divide = ( ($score[1])==0 ) ? 1 : $score[1];
$sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()];
$item_value = round($score[0]/$divide,2) * 100;
//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);
$item_value = $percentage*$item_value;
}
$item_total += $item->get_weight();
$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
//$temp_score = $temp_score . ' '.$item_value.' / '.$this->category->get_weight();
$temp_score = $temp_score;
if (!$show_all) {
//$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.' ';
$item_total += $sub_cat->get_weight();
$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
$temp_score = $temp_score;
if (!$show_all) {
$row[] = $temp_score.' ';
} else {
$row[] = $temp_score;
}
$item_value_total +=$item_value;
}
} else {
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_id);
$debug = false;
if ($user_id == 11) {
$debug = true;
}
$divide = ( ($score[1])==0 ) ? 1 : $score[1];
//sub cat weight
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
$item_value = round($score[0]/$divide,2);
//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 {
// if ($debug) var_dump($item_value);
//$percentage = round($item->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight(), 2);
//if ($debug) var_dump($item->get_weight().' '.$item_value .' -'.$sub_cat_percentage);
$item_value = $item_value*$item->get_weight();
$item_value = 100*$item_value/$item->get_weight();
}
//if ($debug) var_dump($item_value);
$item_total += $item->get_weight();
$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
//if ($debug) var_dump($temp_score);
if (!$show_all) {
//$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 {
$row[] = '';
}
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
} else {
$row[] = '';
}
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
} else {
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
//$row[] = $score[0];
$row[] = $temp_score.' ';
}
} else {
//$row[] = $scoredisplay->display_score($score, SCORE_DECIMAL);
$row[] = $temp_score;
//$row[] = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
}
$item_value_total +=$item_value;
}
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
//$row[] = $score[0];
$row[] = $temp_score.' ';
}
} else {
//$row[] = $scoredisplay->display_score($score, SCORE_DECIMAL);
$row[] = $temp_score;
//$row[] = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
}
$item_value_total +=$item_value;
}
$item_total = $main_weight;
}
$item_total = round($item_total);
$total_score = array($item_value_total, $item_total);
@ -327,7 +388,6 @@ class FlatViewDataGenerator
return $result;
}
public function get_data_to_graph () {
// do some checks on users/items counts, redefine if invalid values
$usertable = array ();

Loading…
Cancel
Save