|
By dservos:
CONTRIB-496
Added printer friendly version.
Added option to invert the table.
Fixed a bug that happened when no students where in the class.
|
| 238 |
if (empty($this->users)) { |
if (empty($this->users)) { |
| 239 |
$this->userselect = ''; |
$this->userselect = ''; |
| 240 |
$this->users = array(); |
$this->users = array(); |
| 241 |
|
$this->userselect_params = array(); |
| 242 |
} else { |
} else { |
| 243 |
if(isset($DB) && !is_null($DB)) { |
if(isset($DB) && !is_null($DB)) { |
| 244 |
list($usql, $params) = $DB->get_in_or_equal(array_keys($this->users)); |
list($usql, $params) = $DB->get_in_or_equal(array_keys($this->users)); |
| 381 |
* TODO: Deal with tables growing to wide. |
* TODO: Deal with tables growing to wide. |
| 382 |
* TODO: Make it look nice. |
* TODO: Make it look nice. |
| 383 |
*/ |
*/ |
| 384 |
public function adapt_data() { |
public function adapt_data($printerversion = false) { |
| 385 |
global $CFG; |
global $CFG; |
| 386 |
|
|
| 387 |
|
$inverted = $this->get_pref('stats', 'showinverted'); |
| 388 |
|
|
| 389 |
/// Set up table arrays |
/// Set up table arrays |
| 390 |
$tablecolumns = array('statistic'); |
$tablecolumns = array('statistic'); |
| 391 |
$tableheaders = array($this->get_lang_string('statistic', 'gradereport_stats')); |
$tableheaders = array($this->get_lang_string('statistic', 'gradereport_stats')); |
| 392 |
|
|
| 393 |
|
/// Loop threw items and build arrays |
| 394 |
|
if ($inverted) { |
| 395 |
|
if($this->get_pref('stats', 'showranges')) { |
| 396 |
|
array_push($tablecolumns, 'range'); |
| 397 |
|
array_push($tableheaders, $this->get_lang_string('range', 'gradereport_stats')); |
| 398 |
|
} |
| 399 |
|
|
| 400 |
|
foreach($this->reportedstats as $name=>$data) { |
| 401 |
|
array_push($tablecolumns, $name); |
| 402 |
|
array_push($tableheaders, $this->stats[$name]->name); |
| 403 |
|
} |
| 404 |
|
|
| 405 |
|
if($this->get_pref('stats', 'shownumgrades')) { |
| 406 |
|
array_push($tablecolumns, 'num_grades'); |
| 407 |
|
array_push($tableheaders, $this->get_lang_string('num_grades', 'gradereport_stats')); |
| 408 |
|
} |
| 409 |
|
} else { |
| 410 |
/// Set up range column and number of grades column |
/// Set up range column and number of grades column |
| 411 |
$ranges = array(format_text('<strong>' . $this->get_lang_string('range', 'gradereport_stats') . '</strong>', FORMAT_HTML)); |
$ranges = array(format_text('<strong>' . $this->get_lang_string('range', 'gradereport_stats') . '</strong>', FORMAT_HTML)); |
| 412 |
$numgrades = array(format_text('<strong>' . $this->get_lang_string('num_grades', 'gradereport_stats') . '</strong>', FORMAT_HTML)); |
$numgrades = array(format_text('<strong>' . $this->get_lang_string('num_grades', 'gradereport_stats') . '</strong>', FORMAT_HTML)); |
| 413 |
|
|
| 414 |
/// Loop threw items and build arrays |
foreach($this->finalgrades as $itemid=>$grades) { |
|
foreach($this->finalgrades as $itemid=>$item) { |
|
| 415 |
array_push($tablecolumns, $itemid); |
array_push($tablecolumns, $itemid); |
| 416 |
array_push($tableheaders, format_text($this->gtree->items[$itemid]->get_name(), FORMAT_HTML)); |
array_push($tableheaders, format_text($this->gtree->items[$itemid]->get_name(), FORMAT_HTML)); |
| 417 |
array_push($ranges, format_text('<strong>' . grade_format_gradevalue($this->gtree->items[$itemid]->grademin, $this->gtree->items[$itemid], true) . '-' . grade_format_gradevalue($this->gtree->items[$itemid]->grademax, $this->gtree->items[$itemid], true) . '<strong>' , FORMAT_HTML)); |
array_push($ranges, format_text('<strong>' . grade_format_gradevalue($this->gtree->items[$itemid]->grademin, $this->gtree->items[$itemid], true) . '-' . grade_format_gradevalue($this->gtree->items[$itemid]->grademax, $this->gtree->items[$itemid], true) . '</strong>' , FORMAT_HTML)); |
| 418 |
array_push($numgrades, format_text(count($item), FORMAT_HTML)); |
array_push($numgrades, format_text(count($grades), FORMAT_HTML)); |
| 419 |
|
} |
| 420 |
} |
} |
| 421 |
|
|
| 422 |
/// Set up flexible table |
/// Set up flexible table |
| 423 |
$this->table = new flexible_table('grade-report-stats-' . $this->courseid); |
$this->table = new flexible_table('grade-report-stats-' . $this->courseid); |
| 424 |
$this->table->define_columns($tablecolumns); |
$this->table->define_columns($tablecolumns); |
| 425 |
$this->table->define_headers($tableheaders); |
$this->table->define_headers($tableheaders); |
| 426 |
|
if ($printerversion) { |
| 427 |
|
$this->table->collapsible(false); |
| 428 |
|
$this->table->set_attribute('cellspacing', '1'); |
| 429 |
|
$this->table->set_attribute('border', '1'); |
| 430 |
|
} else { |
| 431 |
$this->table->define_baseurl($this->baseurl); |
$this->table->define_baseurl($this->baseurl); |
| 432 |
$this->table->collapsible(true); |
$this->table->collapsible(true); |
| 433 |
$this->table->set_attribute('cellspacing', '1'); |
$this->table->set_attribute('cellspacing', '1'); |
| 434 |
$this->table->set_attribute('id', 'stats-grade'); |
$this->table->set_attribute('id', 'stats-grade'); |
| 435 |
$this->table->set_attribute('class', 'grade-report-stats gradestable flexible'); |
$this->table->set_attribute('class', 'grade-report-stats gradestable flexible'); |
| 436 |
|
} |
| 437 |
$this->table->setup(); |
$this->table->setup(); |
| 438 |
|
|
| 439 |
/// If ranges are being shown add them to the table |
/// If ranges are being shown add them to the table |
| 440 |
|
if(!$inverted){ |
| 441 |
if ($this->get_pref('stats', 'showranges')){ |
if ($this->get_pref('stats', 'showranges')){ |
| 442 |
$this->table->add_data($ranges); |
$this->table->add_data($ranges); |
| 443 |
$this->table->add_separator(); |
$this->table->add_separator(); |
| 444 |
} |
} |
| 445 |
|
} |
| 446 |
|
|
| 447 |
/// Loop threw all the reported data and format it in to cells |
/// Loop threw all the reported data and format it in to cells |
| 448 |
/// If stat retured an array of values display the elements or |
/// If stat retured an array of values display the elements or |
| 449 |
/// make a link to a popup with the data in it. |
/// make a link to a popup with the data in it. |
| 450 |
|
if($inverted) { |
| 451 |
|
foreach($this->finalgrades as $itemid=>$grades) { |
| 452 |
|
$item = $this->gtree->items[$itemid]; |
| 453 |
|
$row = array(format_text('<strong>' . $item->get_name() . '</strong>' , FORMAT_HTML)); |
| 454 |
|
|
| 455 |
|
if($this->get_pref('stats', 'showranges')) { |
| 456 |
|
array_push($row, format_text('<strong>' . grade_format_gradevalue($item->grademin, $item, true) . '-' . grade_format_gradevalue($item->grademax, $item, true) . '</strong>' , FORMAT_HTML)); |
| 457 |
|
} |
| 458 |
|
|
| 459 |
|
foreach($this->reportedstats as $name=>$data) { |
| 460 |
|
$stat = $data[$itemid]; |
| 461 |
|
|
| 462 |
|
if(!is_array($stat)) { |
| 463 |
|
array_push($row, format_text(grade_format_gradevalue($stat, $item, true, $this->stats[$name]->displaytype, $this->stats[$name]->decimals), FORMAT_HTML)); |
| 464 |
|
} else { |
| 465 |
|
$statstring = ""; |
| 466 |
|
|
| 467 |
|
for($i = 0; $i < 2; $i++) { |
| 468 |
|
if($i >= count($stat)) { |
| 469 |
|
break; |
| 470 |
|
} |
| 471 |
|
$statstring .= grade_format_gradevalue($stat[$i], $item, true, $this->stats[$name]->displaytype, $this->stats[$name]->decimals) . ', '; |
| 472 |
|
} |
| 473 |
|
|
| 474 |
|
if($i < count($stat)) { |
| 475 |
|
if(!$printerversion) { |
| 476 |
|
$statstring = "<a href=\"#\" onClick=\"javascript:window.open('{$CFG->wwwroot}/grade/report/stats/arrayview.php?id={$this->courseid}&data={$this->encode_array($stat, $item, $this->stats[$name])}','{$this->get_lang_string('moredata', 'gradereport_stats')}','width=300,height=500,menubar=no,status=no,location=no,directories=no,toolbar=no,scrollbars=yes');\">". format_text($statstring, FORMAT_HTML) . '....</a>'; |
| 477 |
|
} else { |
| 478 |
|
$statstring .= '...'; |
| 479 |
|
} |
| 480 |
|
} else { |
| 481 |
|
$statstring = substr($statstring, 0, strlen($statstring) - 2); |
| 482 |
|
} |
| 483 |
|
array_push($row, $statstring); |
| 484 |
|
} |
| 485 |
|
} |
| 486 |
|
|
| 487 |
|
if($this->get_pref('stats', 'shownumgrades')) { |
| 488 |
|
array_push($row, format_text(count($grades), FORMAT_HTML)); |
| 489 |
|
} |
| 490 |
|
|
| 491 |
|
$this->table->add_data($row); |
| 492 |
|
} |
| 493 |
|
} else { |
| 494 |
foreach($this->reportedstats as $name=>$data) { |
foreach($this->reportedstats as $name=>$data) { |
| 495 |
$row = array(format_text('<strong>' . $this->stats[$name]->name . '</strong>', FORMAT_HTML)); |
$row = array(format_text('<strong>' . $this->stats[$name]->name . '</strong>', FORMAT_HTML)); |
| 496 |
|
|
| 508 |
} |
} |
| 509 |
|
|
| 510 |
if($i < count($stat)) { |
if($i < count($stat)) { |
| 511 |
|
if(!$printerversion) { |
| 512 |
$statstring = "<a href=\"#\" onClick=\"javascript:window.open('{$CFG->wwwroot}/grade/report/stats/arrayview.php?id={$this->courseid}&data={$this->encode_array($stat, $this->gtree->items[$itemid], $this->stats[$name])}','{$this->get_lang_string('moredata', 'gradereport_stats')}','width=300,height=500,menubar=no,status=no,location=no,directories=no,toolbar=no,scrollbars=yes');\">". format_text($statstring, FORMAT_HTML) . '....</a>'; |
$statstring = "<a href=\"#\" onClick=\"javascript:window.open('{$CFG->wwwroot}/grade/report/stats/arrayview.php?id={$this->courseid}&data={$this->encode_array($stat, $this->gtree->items[$itemid], $this->stats[$name])}','{$this->get_lang_string('moredata', 'gradereport_stats')}','width=300,height=500,menubar=no,status=no,location=no,directories=no,toolbar=no,scrollbars=yes');\">". format_text($statstring, FORMAT_HTML) . '....</a>'; |
| 513 |
} else { |
} else { |
| 514 |
|
$statstring .= '...'; |
| 515 |
|
} |
| 516 |
|
} else { |
| 517 |
$statstring = substr($statstring, 0, strlen($statstring) - 2); |
$statstring = substr($statstring, 0, strlen($statstring) - 2); |
| 518 |
} |
} |
| 519 |
array_push($row, $statstring); |
array_push($row, $statstring); |
| 521 |
} |
} |
| 522 |
$this->table->add_data($row); |
$this->table->add_data($row); |
| 523 |
} |
} |
| 524 |
|
} |
| 525 |
|
|
| 526 |
/// If the number of grades is being shown add it to the table. |
/// If the number of grades is being shown add it to the table. |
| 527 |
|
if(!$inverted) { |
| 528 |
if ($this->get_pref('stats', 'shownumgrades')){ |
if ($this->get_pref('stats', 'shownumgrades')){ |
| 529 |
$this->table->add_separator(); |
$this->table->add_separator(); |
| 530 |
$this->table->add_data($numgrades); |
$this->table->add_data($numgrades); |
| 531 |
} |
} |
| 532 |
|
} |
| 533 |
|
|
| 534 |
/// Build html |
/// Build html |
| 535 |
ob_start(); |
ob_start(); |
| 554 |
$html .= $this->print_toggle('numgrades', true); |
$html .= $this->print_toggle('numgrades', true); |
| 555 |
$html .= $this->print_toggle('groups', true); |
$html .= $this->print_toggle('groups', true); |
| 556 |
$html .= $this->print_toggle('ranges', true); |
$html .= $this->print_toggle('ranges', true); |
| 557 |
|
$html .= $this->print_toggle('inverted', true); |
| 558 |
$html .= '</div>'; |
$html .= '</div>'; |
| 559 |
|
|
| 560 |
return $html; |
return $html; |
| 574 |
'calculations' => 't/calc.gif', |
'calculations' => 't/calc.gif', |
| 575 |
'locks' => 't/lock.gif', |
'locks' => 't/lock.gif', |
| 576 |
'averages' => 't/mean.gif', |
'averages' => 't/mean.gif', |
| 577 |
|
'inverted' => 't/switch_whole.gif', |
| 578 |
'nooutcomes' => 't/outcomes.gif'); |
'nooutcomes' => 't/outcomes.gif'); |
| 579 |
|
|
| 580 |
$pref_name = 'grade_report_statsshow' . $type; |
$pref_name = 'grade_report_statsshow' . $type; |