Adding tooltips in scores, fixing decimals. Everything should be controlled by the platform setting "gradebook decimals" see #5168

skala
Julio Montoya 13 years ago
parent 8aff94067a
commit 8e7aa1ed41
  1. 4
      main/css/base.css
  2. 5
      main/gradebook/gradebook_statistics.php
  3. 31
      main/gradebook/index.php
  4. 9
      main/gradebook/lib/fe/displaygradebook.php
  5. 4
      main/gradebook/lib/fe/evalform.class.php
  6. 39
      main/gradebook/lib/fe/gradebooktable.class.php
  7. 17
      main/gradebook/lib/fe/linkaddeditform.class.php
  8. 41
      main/gradebook/lib/flatview_data_generator.class.php
  9. 43
      main/gradebook/lib/scoredisplay.class.php
  10. 13
      main/inc/lib/display.lib.php
  11. 6
      main/template/default/layout/footer.tpl

@ -4101,3 +4101,7 @@ li.annoucement{
padding-top: 5px; padding-top: 5px;
display:inline-block; display:inline-block;
} }
.boot-tooltip {
cursor: pointer;
}

@ -77,9 +77,7 @@ if (!$displayscore->is_custom() || empty($displays)) {
} }
} }
// Generate table // Generate table
$stattable= '<table class="data_table" cellspacing="0" cellpadding="3">'; $stattable= '<table class="data_table" cellspacing="0" cellpadding="3">';
$stattable .= '<tr><th>' . get_lang('ScoringSystem') . '</th>'; $stattable .= '<tr><th>' . get_lang('ScoringSystem') . '</th>';
$stattable .= '<th>' . get_lang('Percentage') . '</th>'; $stattable .= '<th>' . get_lang('Percentage') . '</th>';
@ -92,8 +90,7 @@ if (!$displayscore->is_custom() || empty($displays)) {
$stattable .= '<td width="150">' . $key . '</td>'; $stattable .= '<td width="150">' . $key . '</td>';
$stattable .= '<td width="550">'.Display::bar_progress($bar).'</td>'; $stattable .= '<td width="550">'.Display::bar_progress($bar).'</td>';
$stattable .= '<td align="right">' . $nr_items[$key] . '</td>'; $stattable .= '<td align="right">' . $nr_items[$key] . '</td>';
//$stattable .= '<td align="right"> ' . ($resultcount > 0 ?round(($nr_items[$key] / $resultcount) * 100,2):0) . '%</td>';
$counter++; $counter++;
} }
$stattable .= '</tr></table>'; $stattable .= '</tr></table>';

@ -731,6 +731,7 @@ if ($category != '0') {
$category_id = intval($_GET['selectcat']); $category_id = intval($_GET['selectcat']);
$course_id = Database::get_course_by_category($category_id); $course_id = Database::get_course_by_category($category_id);
$show_message = $cat->show_message_resource_delete($course_id); $show_message = $cat->show_message_resource_delete($course_id);
if ($show_message=='') { if ($show_message=='') {
//student //student
@ -743,8 +744,8 @@ if ($category != '0') {
$alllink_course = $cats_course[0]->get_links($stud_id,true); $alllink_course = $cats_course[0]->get_links($stud_id,true);
$evals_links = array_merge($alleval_course, $alllink_course); $evals_links = array_merge($alleval_course, $alllink_course);
$item_value=0; $item_value = 0;
$item_total=0; $item_total = 0;
//@todo move these in a function //@todo move these in a function
$sum_categories_weight_array = array(); $sum_categories_weight_array = array();
@ -768,34 +769,30 @@ if ($category != '0') {
$score_denom = ($score[1]==0) ? 1 : $score[1]; $score_denom = ($score[1]==0) ? 1 : $score[1];
$item_value = $score[0]/$score_denom*$item->get_weight(); $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 += $item->get_weight();
$item_total_value += $item_value; $item_total_value += $item_value;
} }
$item_total_value = (float)$item_total_value; $item_total_value = (float)$item_total_value;
$cattotal = Category :: load($category_id); $cattotal = Category :: load($category_id);
//echo 'start';
$scoretotal= $cattotal[0]->calc_score(api_get_user_id()); $scoretotal= $cattotal[0]->calc_score(api_get_user_id());
//Do not remove this the gradebook/lib/fe/gradebooktable.class.php file load this variable as a global //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); $scoredisplay = ScoreDisplay :: instance();
//$my_score_in_gradebook = round($scoretotal[0],2);
$my_score_in_gradebook = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE);
//Show certificate //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
$scoretotal_display = $scoredisplay->display_score($scoretotal,SCORE_DIV_PERCENT); //a student always sees only the teacher's repartition
//var_dump($certificate_min_score, $item_total_value); //var_dump($certificate_min_score, $item_total_value);
if (isset($certificate_min_score) && $item_total_value >= $certificate_min_score) { 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());
$my_certificate = get_certificate_by_user_id($cats[0]->get_id(), api_get_user_id());
if (empty($my_certificate)) { if (empty($my_certificate)) {
register_user_info_about_certificate($category_id, api_get_user_id(), $my_score_in_gradebook, api_get_utc_datetime()); register_user_info_about_certificate($category_id, api_get_user_id(), $my_score_in_gradebook, api_get_utc_datetime());
$my_certificate = get_certificate_by_user_id($cats[0]->get_id(), api_get_user_id()); $my_certificate = get_certificate_by_user_id($cats[0]->get_id(), api_get_user_id());

@ -401,16 +401,13 @@ class DisplayGradebook
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()]; $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
$item_value = round($score[0]/$divide, 2); $item_value = $score[0]/$divide;
//$item_value = $item_value*$item->get_weight(); //$item_value = $item_value*$item->get_weight();
$item_value =round($score[0]/$divide*$item->get_weight(),2)*$sub_cat_percentage/$main_weight; $item_value = $score[0]/$divide*$item->get_weight()*$sub_cat_percentage/$main_weight;
//var_dump($score[0].' '.$divide.' '.$item->get_weight().' - '.$item_value.' '.$sub_cat_percentage); //var_dump($score[0].' '.$divide.' '.$item->get_weight().' - '.$item_value.' '.$sub_cat_percentage);
$item_value_total +=$item_value; $item_value_total +=$item_value;
} }
$item_total = $main_weight; $item_total = $main_weight;
$item_total = round($item_total);
$total_score = array($item_value_total, $item_total); $total_score = array($item_value_total, $item_total);
$scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT); $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);

@ -234,6 +234,7 @@ class EvalForm extends FormValidator
} }
$this->addElement('style_submit_button' , 'submit', get_lang('Ok'),'class="save"'); $this->addElement('style_submit_button' , 'submit', get_lang('Ok'),'class="save"');
} }
/** /**
* Builds a result form containing inputs for all students with a given course_code * Builds a result form containing inputs for all students with a given course_code
*/ */
@ -377,6 +378,7 @@ class EvalForm extends FormValidator
} }
$this->addElement('style_submit_button', 'submit', get_lang('AddAssessment'),'class="add"'); $this->addElement('style_submit_button', 'submit', get_lang('AddAssessment'),'class="add"');
} }
/** /**
* Builds a form to edit an evaluation * Builds a form to edit an evaluation
*/ */
@ -389,6 +391,7 @@ class EvalForm extends FormValidator
$global_weight = $cat[0]->get_weight(); $global_weight = $cat[0]->get_weight();
$weight_mask = $global_weight*$this->evaluation_object->get_weight()/$parent_cat[0]->get_weight() ; $weight_mask = $global_weight*$this->evaluation_object->get_weight()/$parent_cat[0]->get_weight() ;
} }
$weight_mask = $this->evaluation_object->get_weight();
$this->setDefaults(array ( 'hid_id' => $this->evaluation_object->get_id(), $this->setDefaults(array ( 'hid_id' => $this->evaluation_object->get_id(),
'name' => $this->evaluation_object->get_name(), 'name' => $this->evaluation_object->get_name(),
@ -522,7 +525,6 @@ class EvalForm extends FormValidator
parent :: setDefaults($defaults); parent :: setDefaults($defaults);
} }
private function build_stud_label ($id, $username,$lastname, $firstname) { private function build_stud_label ($id, $username,$lastname, $firstname) {
$opendocurl_start = ''; $opendocurl_start = '';
$opendocurl_end = ''; $opendocurl_end = '';

@ -53,6 +53,7 @@ class GradebookTable extends SortableTable {
} else { } else {
$this->set_header($column++, get_lang('Weight'), false); $this->set_header($column++, get_lang('Weight'), false);
$this->set_header($column++, get_lang('Result'), false); $this->set_header($column++, get_lang('Result'), false);
$this->set_header($column++, get_lang('Actions'), false);
} }
/*if (api_is_allowed_to_edit(null, true)) { /*if (api_is_allowed_to_edit(null, true)) {
@ -150,7 +151,10 @@ class GradebookTable extends SortableTable {
$total_categories_weight = 0; $total_categories_weight = 0;
//Looping categories $scoredisplay = ScoreDisplay :: instance();
//Categories
foreach ($data_array as $data) { foreach ($data_array as $data) {
// list of items inside the gradebook (exercises, lps, forums, etc) // list of items inside the gradebook (exercises, lps, forums, etc)
@ -188,8 +192,7 @@ class GradebookTable extends SortableTable {
//Weight //Weight
//$row[] = $invisibility_span_open .Display::tag('h4', $data['3'] .' / '.$this->currentcat->get_weight()).$invisibility_span_close; //$row[] = $invisibility_span_open .Display::tag('h4', $data['3'] .' / '.$this->currentcat->get_weight()).$invisibility_span_close;
//$average = $data['3']/$this->currentcat->get_weight()*100; //$average = $data['3']/$this->currentcat->get_weight()*100;
$scoredisplay = ScoreDisplay :: instance();
$average = $scoredisplay->display_score(array($data['3'], $this->currentcat->get_weight()), SCORE_PERCENT, SCORE_BOTH, true); $average = $scoredisplay->display_score(array($data['3'], $this->currentcat->get_weight()), SCORE_PERCENT, SCORE_BOTH, true);
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
@ -204,9 +207,8 @@ class GradebookTable extends SortableTable {
$weight_total_links += $data[3]; $weight_total_links += $data[3];
} else { } else {
$cattotal = Category :: load($_GET['selectcat']); $cattotal = Category :: load($_GET['selectcat']);
$scoretotal = $cattotal[0]->calc_score(api_get_user_id()); $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
$item_value = $scoretotal[0]; $item_value = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE);
$item_value = number_format($item_value, api_get_setting('gradebook_number_decimals'), '.', ' ');
} }
//Date //Date
@ -229,13 +231,14 @@ class GradebookTable extends SortableTable {
$row[] = $this->build_edit_column($item); $row[] = $this->build_edit_column($item);
} }
} else { } else {
$score = $item->calc_score(api_get_user_id()); $score = $item->calc_score(api_get_user_id());
//$bar = $scoredisplay->display_score($score, SCORE_BAR);
//$score = $scoredisplay->display_score($score);
$score = $score[0]/$score[1]*$item->get_weight(); $complete_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
$score = $score[0]/$score[1]*$item->get_weight();
$score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE);
$row[] = $score.' '.$this->build_edit_column($item); $row[] = Display::tip($score, $complete_score);
$row[] = $this->build_edit_column($item);
} }
} }
@ -262,6 +265,8 @@ class GradebookTable extends SortableTable {
$total_weight = 0; $total_weight = 0;
//Links
foreach ($data_array as $data) { foreach ($data_array as $data) {
$row = array(); $row = array();
$item = $data[0]; $item = $data[0];
@ -303,8 +308,7 @@ class GradebookTable extends SortableTable {
} else { } else {
$cattotal = Category :: load($_GET['selectcat']); $cattotal = Category :: load($_GET['selectcat']);
$scoretotal = $cattotal[0]->calc_score(api_get_user_id()); $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
$item_value = $scoretotal[0]; $item_value = $scoretotal[0];
$item_value = number_format($item_value, 2, '.', ' ');
} }
//Date //Date
@ -314,7 +318,7 @@ class GradebookTable extends SortableTable {
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
$cat = new Category(); $cat = new Category();
$show_message = $cat->show_message_resource_delete($item->get_course_code()); $show_message = $cat->show_message_resource_delete($item->get_course_code());
if ($show_message===false) { if ($show_message === false) {
$row[] = $this->build_edit_column($item); $row[] = $this->build_edit_column($item);
} }
} else { } else {
@ -323,11 +327,12 @@ class GradebookTable extends SortableTable {
if (count($eval_n_links)> 0 && $status_user!=1 ) { if (count($eval_n_links)> 0 && $status_user!=1 ) {
$value_data = isset($data[4]) ? $data[4] : null; $value_data = isset($data[4]) ? $data[4] : null;
if (!is_null($value_data)) { if (!is_null($value_data)) {
$score = $item->calc_score(api_get_user_id()); //$row[] = Display::tip($data[4], $data[4]);
$row[] = $value_data; $row[] = $data[4];
} }
} }
$row[] = null;
} }
$row['child_of'] = $parent_id; $row['child_of'] = $parent_id;

@ -118,20 +118,13 @@ class LinkAddEditForm extends FormValidator
$values['weight'] = $link->get_weight(); $values['weight'] = $link->get_weight();
} else { } else {
$cat = Category :: load($parent_cat[0]->get_parent_id()); $cat = Category :: load($parent_cat[0]->get_parent_id());
$global_weight = $cat[0]->get_weight(); //$global_weight = $cat[0]->get_weight();
$values['weight'] = $link->get_weight()/$parent_cat[0]->get_weight()*$global_weight; //$values['weight'] = $link->get_weight()/$parent_cat[0]->get_weight()*$global_weight;
/*
* 33 -> 100
* x -> 25
*/
//100 33 25
//var_dump($global_weight, $link->get_weight(), $parent_cat[0]->get_weight()); //var_dump($global_weight, $link->get_weight(), $parent_cat[0]->get_weight());
$weight = $parent_cat[0]->get_weight()* $link->get_weight() / $global_weight; //$weight = $parent_cat[0]->get_weight()* $link->get_weight() / $global_weight;
//$values['weight'] = $weight; //$values['weight'] = $weight;
$values['weight'] = $link->get_weight() ; $values['weight'] = $link->get_weight() ;
}
}
$defaults['weight_mask'] = $values['weight'] ; $defaults['weight_mask'] = $values['weight'] ;
$defaults['select_gradebook'] = $link->get_category_id(); $defaults['select_gradebook'] = $link->get_category_id();

@ -124,8 +124,7 @@ class FlatViewDataGenerator
if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) { if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) {
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]; $item = $this->evals_links[$count + $items_start];
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()]; $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 = 100*$item->get_weight()/$main_weight; $weight = 100*$item->get_weight()/$main_weight;
$headers[] = $item->get_name().' '.$weight.' % '; $headers[] = $item->get_name().' '.$weight.' % ';
} }
@ -307,13 +306,14 @@ class FlatViewDataGenerator
foreach ($allcat as $sub_cat) { foreach ($allcat as $sub_cat) {
$score = $sub_cat->calc_score($user_id); $score = $sub_cat->calc_score($user_id);
$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()]; $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()];
$item_value = round($score[0]/$divide,2) * $main_weight; $item_value = $score[0]/$divide*$main_weight;
//Fixing total when using one or multiple gradebooks //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 = $sub_cat->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight();
$item_value = $percentage*$item_value; $item_value = $percentage*$item_value;
$item_total += $sub_cat->get_weight(); $item_total += $sub_cat->get_weight();
@ -323,8 +323,9 @@ class FlatViewDataGenerator
$score[1] = $main_weight ; $score[1] = $main_weight ;
} }
//$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); $real_score = $scoredisplay->display_score($real_score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
$temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM); $temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM);
$temp_score = Display::tip($temp_score, $real_score);
if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) { if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) {
if (!$show_all) { if (!$show_all) {
@ -347,11 +348,11 @@ class FlatViewDataGenerator
//sub cat weight //sub cat weight
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()]; $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
$item_value = round($score[0]/$divide, 2); $item_value = $score[0]/$divide;
//Fixing total when using one or multiple gradebooks //Fixing total when using one or multiple gradebooks
if ($this->category->get_parent_id() == 0 ) { if ($this->category->get_parent_id() == 0 ) {
$item_value =round($score[0]/$divide*$item->get_weight(),2); $item_value = $score[0]/$divide*$item->get_weight();
} else { } else {
$item_value = $item_value*$item->get_weight(); $item_value = $item_value*$item->get_weight();
//var_dump($item_value.' - '.$item->get_weight()); //var_dump($item_value.' - '.$item->get_weight());
@ -360,9 +361,13 @@ class FlatViewDataGenerator
} }
$item_total += $item->get_weight(); $item_total += $item->get_weight();
//$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); $complete_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
//$temp_score = $item_value.' - '.$scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); //$temp_score = $item_value.' - '.$scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
$temp_score = $item_value; //$temp_score = $item_value;
$temp_score = $scoredisplay->display_score(array($item_value, null), SCORE_DIV_SIMPLE_WITH_CUSTOM);
$temp_score = Display::tip($temp_score, $complete_score);
if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) { if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) {
if (!$show_all) { if (!$show_all) {
@ -383,9 +388,7 @@ class FlatViewDataGenerator
$item_value_total +=$item_value; $item_value_total +=$item_value;
} }
$item_total = $main_weight; $item_total = $main_weight;
} }
$item_total = round($item_total);
$total_score = array($item_value_total, $item_total); $total_score = array($item_value_total, $item_total);
if (!$show_all) { if (!$show_all) {
@ -425,7 +428,7 @@ class FlatViewDataGenerator
for ($count=0;$count < count($this->evals_links); $count++) { for ($count=0;$count < count($this->evals_links); $count++) {
$item = $this->evals_links [$count]; $item = $this->evals_links [$count];
$score = $item->calc_score($user[0]); $score = $item->calc_score($user[0]);
$porcent_score = isset($score[1]) && $score[1] > 0 ? round(($score[0]*100)/$score[1]):0; $porcent_score = isset($score[1]) && $score[1] > 0 ? ($score[0]*100)/$score[1] :0;
$row[$item->get_name()] = $porcent_score; $row[$item->get_name()] = $porcent_score;
} }
$data[$user[0]] = $row; $data[$user[0]] = $row;
@ -481,16 +484,16 @@ class FlatViewDataGenerator
$score = $item->calc_score($user[0]); $score = $item->calc_score($user[0]);
$divide =( ($score[1])==0 ) ? 1 : $score[1]; $divide =( ($score[1])==0 ) ? 1 : $score[1];
$item_value += round($score[0]/$divide*$item->get_weight(),2); $item_value += $score[0]/$divide*$item->get_weight();
$item_total += $item->get_weight(); $item_total += $item->get_weight();
$score_denom = ($score[1]==0) ? 1 : $score[1]; $score_denom = ($score[1]==0) ? 1 : $score[1];
$score_final = round(($score[0] / $score_denom) * 100,2); $score_final = ($score[0] / $score_denom) * 100;
$row[] = $score_final; $row[] = $score_final;
} }
$total_score = array($item_value, $item_total); $total_score = array($item_value, $item_total);
$score_final = round(($item_value / $item_total) * 100,2); $score_final = ($item_value / $item_total) * 100;
$row[] = $score_final; $row[] = $score_final;
$data[] = $row; $data[] = $row;
@ -522,15 +525,15 @@ class FlatViewDataGenerator
$item = $this->evals_links [$count]; $item = $this->evals_links [$count];
$score = $item->calc_score($user[0]); $score = $item->calc_score($user[0]);
$divide=( ($score[1])==0 ) ? 1 : $score[1]; $divide=( ($score[1])==0 ) ? 1 : $score[1];
$item_value+=round($score[0]/$divide*$item->get_weight(),2); $item_value+= $score[0]/$divide*$item->get_weight();
$item_total+=$item->get_weight(); $item_total+=$item->get_weight();
$score_denom=($score[1]==0) ? 1 : $score[1]; $score_denom=($score[1]==0) ? 1 : $score[1];
$score_final = round(($score[0] / $score_denom) * 100,2); $score_final = ($score[0] / $score_denom) * 100;
$row[] = array ($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM,null, true))); $row[] = array ($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM,null, true)));
} }
$total_score=array($item_value,$item_total); $total_score=array($item_value,$item_total);
$score_final = round(($item_value / $item_total) * 100,2); $score_final = ($item_value / $item_total) * 100;
$row[] =array ($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); $row[] =array ($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true)));
$data[] = $row; $data[] = $row;

@ -14,8 +14,8 @@ define('SCORE_PERCENT', 2); // XX %
define('SCORE_DIV_PERCENT', 3); // X / Y (XX %) define('SCORE_DIV_PERCENT', 3); // X / Y (XX %)
define('SCORE_AVERAGE', 4); // XX % define('SCORE_AVERAGE', 4); // XX %
define('SCORE_DECIMAL', 5); // 0.50 (X/Y) define('SCORE_DECIMAL', 5); // 0.50 (X/Y)
define('SCORE_BAR', 6); // Uses the Display::bar_progress function define('SCORE_BAR', 6); // Uses the Display::bar_progress function
define('SCORE_SIMPLE', 7); // X
//@todo where is number 6? //@todo where is number 6?
@ -25,7 +25,7 @@ define('SCORE_DIV_PERCENT_WITH_CUSTOM', 9); // X / Y (XX %) - Good!
define('SCORE_CUSTOM', 10); // Good! define('SCORE_CUSTOM', 10); // Good!
define('SCORE_DIV_SIMPLE_WITH_CUSTOM', 11); // X - Good! define('SCORE_DIV_SIMPLE_WITH_CUSTOM', 11); // X - Good!
define('SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS', 12); // X (ex) - Good! define('SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS', 12); // X - Good!
define('SCORE_BOTH',1); define('SCORE_BOTH',1);
define('SCORE_ONLY_DEFAULT',2); define('SCORE_ONLY_DEFAULT',2);
@ -246,6 +246,24 @@ class ScoreDisplay
} }
Database::query($sql); Database::query($sql);
} }
public function get_number_decimals() {
$number_decimals = api_get_setting('gradebook_number_decimals');
if (!isset($number_decimals)) {
$number_decimals = 0;
}
return $number_decimals;
}
/**
* Formats a number depending of the number of decimals
*
* @param float a score
* @return float the score formatted
*/
public function format_score($score) {
return floatval(number_format($score, $this->get_number_decimals()));
}
/** /**
* Display a score according to the current settings * Display a score according to the current settings
@ -256,12 +274,18 @@ class ScoreDisplay
* (only taken into account if custom score display is enabled and for course/platform admin) * (only taken into account if custom score display is enabled and for course/platform admin)
*/ */
public function display_score($score, $type = SCORE_DIV_PERCENT, $what = SCORE_BOTH, $no_color = false) { public function display_score($score, $type = SCORE_DIV_PERCENT, $what = SCORE_BOTH, $no_color = false) {
$my_score = ($score==0) ? 1 : $score; $my_score = $score == 0 ? 1 : $score;
if ($type == SCORE_BAR) { if ($type == SCORE_BAR) {
$percentage = $my_score[0]/$my_score[1]*100; $percentage = $my_score[0]/$my_score[1]*100;
return Display::bar_progress($percentage); return Display::bar_progress($percentage);
} }
if ($type == SCORE_SIMPLE) {
$simple_score = $this->format_score($my_score[0]);
return $simple_score;
}
if ($this->custom_enabled && isset($this->custom_display_conv)) { if ($this->custom_enabled && isset($this->custom_display_conv)) {
$display = $this->display_default($my_score, $type); $display = $this->display_default($my_score, $type);
} else { } else {
@ -325,7 +349,7 @@ class ScoreDisplay
private function display_simple_score($score) { private function display_simple_score($score) {
if (isset($score[0])) { if (isset($score[0])) {
return $score[0]; return $this->format_score($score[0]);
} }
return ''; return '';
} }
@ -335,15 +359,15 @@ class ScoreDisplay
*/ */
private function display_as_decimal($score) { private function display_as_decimal($score) {
$score_denom = ($score[1]==0) ? 1 : $score[1]; $score_denom = ($score[1]==0) ? 1 : $score[1];
return round(($score[0]/ $score_denom),2); return $this->format_score($score[0]/$score_denom);
} }
/** /**
* Returns "100 %" for array("100", "100"); * Returns "100 %" for array("100", "100");
*/ */
private function display_as_percent($score) { private function display_as_percent($score) {
$score_denom=($score[1]==0) ? 1 : $score[1]; $score_denom = ($score[1]==0) ? 1 : $score[1];
return round(($score[0] / $score_denom) * 100,2) . ' %'; return $this->format_score($score[0]/$score_denom*100) . ' %';
} }
/** /**
@ -355,16 +379,19 @@ class ScoreDisplay
if ($score == 1) { if ($score == 1) {
return '0/0'; return '0/0';
} else { } else {
$score[0] =$this->format_score($score[0]);
$score[1] =$this->format_score($score[1]);
return $score[0] . ' / ' . $score[1]; return $score[0] . ' / ' . $score[1];
} }
} }
/** /**
* *
* Depends in the user selections [0 50] Bad [50:100] Good * Depends in the user selections [0 50] Bad [50:100] Good
* @param array $score * @param array $score
*/ */
private function display_custom ($score) { private function display_custom ($score) {
$my_score_denom= ($score[1]==0)?1:$score[1]; $my_score_denom= ($score[1]==0) ? 1 : $score[1];
$scaledscore = $score[0] / $my_score_denom; $scaledscore = $score[0] / $my_score_denom;
if ($this->upperlimit_included) { if ($this->upperlimit_included) {
foreach ($this->custom_display_conv as $displayitem) { foreach ($this->custom_display_conv as $displayitem) {

@ -1505,7 +1505,16 @@ class Display {
} }
$html .= '</ul></div>'; $html .= '</ul></div>';
} }
return $html; return $html;
}
/**
* Prints a tooltip
*/
function tip($text, $tip) {
if (empty($tip)) {
return $text;
}
return self::span($text, array('class' => 'boot-tooltip', 'title' => $tip));
} }
} //end class Display } //end class Display

@ -72,6 +72,12 @@ $(document).ready( function() {
$(this).parentsUntil("tr").parent().removeClass("row_selected"); $(this).parentsUntil("tr").parent().removeClass("row_selected");
} }
}); });
var tip_options = {
placement : 'right',
}
$('.boot-tooltip').tooltip(tip_options);
}); });
</script> </script>
{% endraw %} {% endraw %}

Loading…
Cancel
Save