Should fix some bugs when using multiple gradebooks in a course see #4047 (partial needs some cleaning for the scores)

skala
Julio Montoya 14 years ago
parent 031305eff8
commit 5a75c4ff13
  1. 1
      main/gradebook/gradebook_flatview.php
  2. 54
      main/gradebook/index.php
  3. 36
      main/gradebook/lib/be/category.class.php
  4. 68
      main/gradebook/lib/fe/displaygradebook.php
  5. 84
      main/gradebook/lib/flatview_data_generator.class.php

@ -96,7 +96,6 @@ if (!empty($keyword)) {
$offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
$flatviewtable = new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams);
if (isset ($_GET['exportpdf'])) {
$interbreadcrumb[] = array (

@ -697,40 +697,65 @@ if ($category != '0') {
if (!api_is_allowed_to_edit()) {
// generating the total score for a course
$cats_course = Category :: load ($category_id, null, null, null, null, null, false);
$cats_course = Category :: load ($category_id, null, null, null, null, null, false);
$alleval_course = $cats_course[0]->get_evaluations($stud_id,true);
$alllink_course = $cats_course[0]->get_links($stud_id,true);
$evals_links = array_merge($alleval_course, $alllink_course);
$item_value=0;
$item_total=0;
//@todo move these in a function
$sum_categories_weight_array = array();
if (isset($cats_course) && !empty($cats_course)) {
$categories = Category::load(null, null, null, $category_id);
if (!empty($categories)) {
foreach($categories as $category) {
$sum_categories_weight_array[$category->get_id()] = $category->get_weight();
}
} else {
$sum_categories_weight_array[$category_id] = $cats_course[0]->get_weight();
}
}
$item_total_value = 0;
$item_value = 0;
for ($count=0; $count < count($evals_links); $count++) {
$item = $evals_links[$count];
$score = $item->calc_score($stud_id);
$score_denom=($score[1]==0) ? 1 : $score[1];
$item_value+=$score[0]/$score_denom*$item->get_weight();
$item_total+=$item->get_weight();
$score_denom = ($score[1]==0) ? 1 : $score[1];
$item_value = $score[0]/$score_denom*$item->get_weight();
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
$percentage = round($item->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$cats_course[0]->get_weight(), 2);
$item_total += $item->get_weight();
$item_total_value += $item_value;
}
if (!empty($allcat)) {
$count_categories = count($allcat);
$item_value = $item_value/$count_categories;
}
$item_value = number_format($item_value, 2, '.', ' ');
$item_total_value = (float)$item_total_value;
$cattotal = Category :: load($category_id);
//echo 'start';
$scoretotal= $cattotal[0]->calc_score(api_get_user_id());
//echo 'end'; var_dump($scoretotal);
//Do not remove this the gradebook/lib/fe/gradebooktable.class.php file load this variable as a global
$my_score_in_gradebook = round($scoretotal[0],2);
//Show certificate
$certificate_min_score = $cats[0]->get_certificate_min_score();
$certificate_min_score = $cats[0]->get_certificate_min_score();
$scoredisplay = ScoreDisplay :: instance();
$scoretotal_display = $scoredisplay->display_score($scoretotal,SCORE_DIV_PERCENT); //a student always sees only the teacher's repartition
if (isset($certificate_min_score) && $item_value >= $certificate_min_score) {
//var_dump($certificate_min_score, $item_total_value);
if (isset($certificate_min_score) && $item_total_value >= $certificate_min_score) {
$my_certificate = get_certificate_by_user_id($cats[0]->get_id(), api_get_user_id());
if (empty($my_certificate)) {
@ -794,8 +819,7 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
$alleval = $cat->get_evaluations($stud_id);
$alllink = $cat->get_links($stud_id);
if ($cat->get_parent_id() != 0 ) {
if ($cat->get_parent_id() != 0 ) {
$i++;
} else {
//This is the father

@ -219,7 +219,7 @@ class Category implements GradebookItem
$sql .= ' visible = '.intval($visible);
$paramcount ++;
}
//echo $sql;
//echo $sql.'<br />';
$result = Database::query($sql);
$allcat = array();
if (Database::num_rows($result) > 0) {
@ -488,35 +488,43 @@ class Category implements GradebookItem
}
// calculate score
$rescount = 0;
$ressum = 0;
$weightsum = 0;
$rescount = 0;
$ressum = 0;
$weightsum = 0;
if (!empty($cats)) {
foreach ($cats as $cat) {
$catres = $cat->calc_score ($stud_id); // recursive call
if (isset($catres) && $cat->get_weight() != 0) {
$catweight = $cat->get_weight();
$catres = $cat->calc_score($stud_id); // recursive call
if ($cat->get_weight() != 0) {
$catweight = $cat->get_weight();
$rescount++;
$weightsum += $catweight;
$ressum += (($catres[0]/$catres[1]) * $catweight);
}
if (isset($catres)) {
$ressum += (($catres[0]/$catres[1]) * $catweight);
}
}
}
//var_dump($weightsum);
if (!empty($evals)) {
foreach ($evals as $eval) {
$evalres = $eval->calc_score($stud_id);
$evalres = $eval->calc_score($stud_id);
if (isset($evalres) && $eval->get_weight() != 0) {
$evalweight = $eval->get_weight();
$rescount++;
$weightsum += $evalweight;
$ressum += (($evalres[0]/$evalres[1]) * $evalweight);
} else {
}
}
}
if (!empty($links)) {
foreach ($links as $link) {
$linkres = $link->calc_score($stud_id);
$linkres = $link->calc_score($stud_id);
if (isset($linkres) && $link->get_weight() != 0) {
$linkweight = $link->get_weight();
$link_res_denom = ($linkres[1]==0) ? 1 : $linkres[1];
@ -526,6 +534,7 @@ class Category implements GradebookItem
}
}
}
if ($rescount == 0) {
return null;
} else {
@ -997,10 +1006,11 @@ class Category implements GradebookItem
// 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_create_course() ? null : 1, $session_id );
} else {
return Category::load(null,null, $course_code, $this->id, api_is_allowed_to_create_course() ? null : 1, $session_id );
}
} else {// all students
// course admin

@ -192,10 +192,7 @@ class DisplayGradebook
$header .= '<b>'.get_lang('SearchResults').' :</b>';
}*/
echo $header;
}
}
function display_header_gradebook_per_gradebook($catobj, $showtree, $selectcat, $is_course_admin, $is_platform_admin, $simple_search_form, $show_add_qualification = true, $show_add_link = true) {
@ -237,8 +234,7 @@ class DisplayGradebook
$scoreinfo = get_lang('StatsStudent') . ' :<b> '.api_get_person_name($user['firstname'], $user['lastname']).'</b><br />';
if ((!$catobj->get_id() == '0') && (!isset ($_GET['studentoverview'])) && (!isset ($_GET['search']))) {
$scoreinfo.= '<h2>'.get_lang('Total') . ' : ' . $scorecourse_display . '</h2>';
}
}
Display :: display_normal_message($scoreinfo, false);
}
// show navigation tree and buttons?
@ -302,8 +298,7 @@ class DisplayGradebook
if (api_is_allowed_to_edit(null, true)) {
if ($selectcat == '0') {
if ($show_add_qualification === true) {
if ($show_add_qualification === true) {
}
if ($show_add_link) {
//$header .= '<td><a href="gradebook_add_eval.php?'.api_get_cidreq().'"><img src="../img/filenew.gif" alt="' . get_lang('NewEvaluation') . '" /> ' . get_lang('NewEvaluation') . '</a>';
@ -354,8 +349,7 @@ class DisplayGradebook
//$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visiblecat=' . $catobj->get_id() . '&amp;' . $visibility_command . '=&amp;selectcat=0 ">'.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'','32').'</a>';
if ($catobj->get_name() != api_get_course_id()) {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deletecat=' . $catobj->get_id() . '&amp;selectcat=0&amp;cidReq='.$catobj->get_course_code().'" onclick="return confirmation();">'.Display::return_icon('delete.png', get_lang('DeleteAll'),'','32').'</a>';
}
}
$header .= Display::div($modify_icons, array('class'=>'right'));
}
@ -411,26 +405,41 @@ class DisplayGradebook
$evals_links = array_merge($allevals, $alllinks);
$item_value=0;
$item_total=0;
//@todo move these in a function
$sum_categories_weight_array = array();
if (isset($catobj) && !empty($catobj)) {
$categories = Category::load(null, null, null, $catobj->get_id());
if (!empty($categories)) {
foreach($categories as $category) {
$sum_categories_weight_array[$category->get_id()] = $category->get_weight();
}
} else {
$sum_categories_weight_array[$catobj->get_id()] = $catobj->get_weight();
}
}
$item_total_value = 0;
for ($count=0; $count < count($evals_links); $count++) {
$item = $evals_links[$count];
$score = $item->calc_score($user_id);
$my_score_denom=($score[1]==0) ? 1 : $score[1];
$item_value +=$score[0]/$my_score_denom*$item->get_weight();
$item_total +=$item->get_weight();
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
//var_dump($item_value.' - '.$item_total);
$item = $evals_links[$count];
$score = $item->calc_score($user_id);
$my_score_denom =($score[1]==0) ? 1 : $score[1];
$item_value = $score[0]/$my_score_denom * $item->get_weight();
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
$percentage = round($item->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$catobj->get_weight(), 2);
//$item_value = $percentage*$item_value;
//$item_total += $percentage*100;
$item_total += $item->get_weight();
$item_total_value += $item_value;
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
}
$children = $catcourse[0]->get_subcategories(api_get_user_id(), api_get_course_id(), api_get_session_id());
$count = 1;
if (!empty($children)) {
$count = count($children);
}
$item_value = $item_value/$count;
$item_total = $item_total/$count;
$item_value = number_format($item_value, 2, '.', ' ');
$item_value = number_format($item_total_value, 2);
$total_score = array($item_value, $item_total);
$scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
@ -508,8 +517,7 @@ class DisplayGradebook
$header .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'"><img src="../img/icons/32/new_folder.png" alt="' . get_lang('AddGradebook') . '" /></a></td>';
if ($selectcat == '0') {
if ($show_add_qualification === true) {
if ($show_add_qualification === true) {
}
if ($show_add_link) {
//$header .= '<td><a href="gradebook_add_eval.php?'.api_get_cidreq().'"><img src="../img/filenew.gif" alt="' . get_lang('NewEvaluation') . '" /> ' . get_lang('NewEvaluation') . '</a>';

@ -58,25 +58,29 @@ class FlatViewDataGenerator
$headers = array();
$headers[] = get_lang('LastName');
$headers[] = get_lang('FirstName');
if (!isset($items_count)) {
$items_count = count($this->evals_links) - $items_start;
}
$count_categories = 1;
if (isset($this->category) && !empty($this->category)) {
$categories = Category::load(null, null, null, $this->category->get_id());
//@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)) {
$count_categories = count($categories) ;
foreach($categories as $category) {
$sum_categories_weight_array[$category->get_id()] = $category->get_weight();
}
} else {
$sum_categories_weight_array[$this->category->get_id()] = $this->category->get_weight();
}
}
for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
$item = $this->evals_links [$count + $items_start];
$item = $this->evals_links[$count + $items_start];
//$headers[] = $item->get_name().' <br /> '.get_lang('Max').' '.$this->get_max_result_by_link($count + $items_start).' ';
$weight = round($item->get_weight()/($count_categories*100), 2)*100;
$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) {
//$headers[] = $item->get_name().' ('.get_lang('Detail').')';
@ -182,15 +186,18 @@ class FlatViewDataGenerator
if ($ignore_score_color) {
$displaytype |= SCORE_IGNORE_SPLIT;
}
$count_categories = 1;
if (isset($this->category) && !empty($this->category)) {
$categories = Category::load(null, null, null, $this->category->get_id());
if (!empty($categories)) {
$count_categories = count($categories);
}
}
//@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)) {
foreach($categories as $category) {
$sum_categories_weight_array[$category->get_id()] = $category->get_weight();
}
} else {
$sum_categories_weight_array[$this->category->get_id()] = $this->category->get_weight();
}
}
foreach ($selected_users as $user) {
$row = array ();
@ -198,21 +205,34 @@ class FlatViewDataGenerator
$row[] = $user[2]; // last name
$row[] = $user[3]; // first name
$item_value=0;
$item_total=0;
$item_value = 0;
$item_value_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];
$item = $this->evals_links[$count + $items_start];
$score = $item->calc_score($user[0]);
$divide = ( ($score[1])==0 ) ? 1 : $score[1];
$item_value += round($score[0]/$divide*$item->get_weight(),2);
$item_total += $item->get_weight();
$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;
$item_total += $percentage*100;
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))) {
$row[] = $score[0];
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[] = $score[0].' ('.$item_value.'%) ';
} else {
$row[] = '';
}
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
} else {
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
@ -223,12 +243,10 @@ class FlatViewDataGenerator
$row[] = $score[0];
//$row[] = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
}
}
$item_value = round($item_value / $count_categories, 2);
$item_total = round($item_total / $count_categories, 2);
$total_score = array($item_value, $item_total);
$item_value_total +=$item_value;
}
$total_score = array($item_value_total, $item_total);
if (!$show_all) {
$row[] = $scoredisplay->display_score($total_score);

Loading…
Cancel
Save