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;
display:inline-block;
}
.boot-tooltip {
cursor: pointer;
}

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

@ -731,6 +731,7 @@ if ($category != '0') {
$category_id = intval($_GET['selectcat']);
$course_id = Database::get_course_by_category($category_id);
$show_message = $cat->show_message_resource_delete($course_id);
if ($show_message=='') {
//student
@ -743,8 +744,8 @@ if ($category != '0') {
$alllink_course = $cats_course[0]->get_links($stud_id,true);
$evals_links = array_merge($alleval_course, $alllink_course);
$item_value=0;
$item_total=0;
$item_value = 0;
$item_total = 0;
//@todo move these in a function
$sum_categories_weight_array = array();
@ -768,34 +769,30 @@ if ($category != '0') {
$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;
}
$item_total_value = (float)$item_total_value;
$item_total_value = (float)$item_total_value;
$cattotal = Category :: load($category_id);
//echo 'start';
$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
$my_score_in_gradebook = round($scoretotal[0],2);
//Do not remove this the gradebook/lib/fe/gradebooktable.class.php file load this variable as a global
$scoredisplay = ScoreDisplay :: instance();
//$my_score_in_gradebook = round($scoretotal[0],2);
$my_score_in_gradebook = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE);
//Show certificate
$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
$certificate_min_score = $cats[0]->get_certificate_min_score();
$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);
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)) {
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());

@ -401,16 +401,13 @@ class DisplayGradebook
$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 =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);
$item_value_total +=$item_value;
}
}
$item_total = $main_weight;
$item_total = round($item_total);
$total_score = array($item_value_total, $item_total);
$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"');
}
/**
* 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"');
}
/**
* Builds a form to edit an evaluation
*/
@ -389,6 +391,7 @@ class EvalForm extends FormValidator
$global_weight = $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(),
'name' => $this->evaluation_object->get_name(),
@ -522,7 +525,6 @@ class EvalForm extends FormValidator
parent :: setDefaults($defaults);
}
private function build_stud_label ($id, $username,$lastname, $firstname) {
$opendocurl_start = '';
$opendocurl_end = '';

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

@ -118,20 +118,13 @@ class LinkAddEditForm extends FormValidator
$values['weight'] = $link->get_weight();
} else {
$cat = Category :: load($parent_cat[0]->get_parent_id());
$global_weight = $cat[0]->get_weight();
$values['weight'] = $link->get_weight()/$parent_cat[0]->get_weight()*$global_weight;
/*
* 33 -> 100
* x -> 25
*/
//100 33 25
//$global_weight = $cat[0]->get_weight();
//$values['weight'] = $link->get_weight()/$parent_cat[0]->get_weight()*$global_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'] = $link->get_weight() ;
}
$values['weight'] = $link->get_weight() ;
}
$defaults['weight_mask'] = $values['weight'] ;
$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)) {
for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
$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);
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
$weight = 100*$item->get_weight()/$main_weight;
$headers[] = $item->get_name().' '.$weight.' % ';
}
@ -307,13 +306,14 @@ class FlatViewDataGenerator
foreach ($allcat as $sub_cat) {
$score = $sub_cat->calc_score($user_id);
$real_score = $score;
$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) * $main_weight;
$item_value = $score[0]/$divide*$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 = $sub_cat->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight();
$item_value = $percentage*$item_value;
$item_total += $sub_cat->get_weight();
@ -323,8 +323,9 @@ class FlatViewDataGenerator
$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 = 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 (!$show_all) {
@ -347,11 +348,11 @@ class FlatViewDataGenerator
//sub cat weight
$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
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 {
$item_value = $item_value*$item->get_weight();
//var_dump($item_value.' - '.$item->get_weight());
@ -360,9 +361,13 @@ class FlatViewDataGenerator
}
$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;
//$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 (!$show_all) {
@ -383,9 +388,7 @@ class FlatViewDataGenerator
$item_value_total +=$item_value;
}
$item_total = $main_weight;
}
$item_total = round($item_total);
}
$total_score = array($item_value_total, $item_total);
if (!$show_all) {
@ -425,7 +428,7 @@ class FlatViewDataGenerator
for ($count=0;$count < count($this->evals_links); $count++) {
$item = $this->evals_links [$count];
$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;
}
$data[$user[0]] = $row;
@ -481,16 +484,16 @@ class FlatViewDataGenerator
$score = $item->calc_score($user[0]);
$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();
$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;
}
$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;
$data[] = $row;
@ -522,15 +525,15 @@ class FlatViewDataGenerator
$item = $this->evals_links [$count];
$score = $item->calc_score($user[0]);
$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();
$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)));
}
$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)));
$data[] = $row;

@ -14,8 +14,8 @@ define('SCORE_PERCENT', 2); // XX %
define('SCORE_DIV_PERCENT', 3); // X / Y (XX %)
define('SCORE_AVERAGE', 4); // XX %
define('SCORE_DECIMAL', 5); // 0.50 (X/Y)
define('SCORE_BAR', 6); // Uses the Display::bar_progress function
define('SCORE_SIMPLE', 7); // X
//@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_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_ONLY_DEFAULT',2);
@ -246,6 +246,24 @@ class ScoreDisplay
}
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
@ -256,12 +274,18 @@ class ScoreDisplay
* (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) {
$my_score = ($score==0) ? 1 : $score;
$my_score = $score == 0 ? 1 : $score;
if ($type == SCORE_BAR) {
$percentage = $my_score[0]/$my_score[1]*100;
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)) {
$display = $this->display_default($my_score, $type);
} else {
@ -325,7 +349,7 @@ class ScoreDisplay
private function display_simple_score($score) {
if (isset($score[0])) {
return $score[0];
return $this->format_score($score[0]);
}
return '';
}
@ -335,15 +359,15 @@ class ScoreDisplay
*/
private function display_as_decimal($score) {
$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");
*/
private function display_as_percent($score) {
$score_denom=($score[1]==0) ? 1 : $score[1];
return round(($score[0] / $score_denom) * 100,2) . ' %';
$score_denom = ($score[1]==0) ? 1 : $score[1];
return $this->format_score($score[0]/$score_denom*100) . ' %';
}
/**
@ -355,16 +379,19 @@ class ScoreDisplay
if ($score == 1) {
return '0/0';
} else {
$score[0] =$this->format_score($score[0]);
$score[1] =$this->format_score($score[1]);
return $score[0] . ' / ' . $score[1];
}
}
/**
*
* Depends in the user selections [0 50] Bad [50:100] Good
* @param array $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;
if ($this->upperlimit_included) {
foreach ($this->custom_display_conv as $displayitem) {

@ -1505,7 +1505,16 @@ class Display {
}
$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

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

Loading…
Cancel
Save