' );
array_push($numgrades, count($item));
}
/// Set up flexible table
$this->table = new flexible_table('grade-report-stats-' . $this->courseid);
$this->table->define_columns($tablecolumns);
$this->table->define_headers($tableheaders);
$this->table->define_baseurl($this->baseurl);
$this->table->collapsible(true);
$this->table->set_attribute('cellspacing', '1');
$this->table->set_attribute('id', 'stats-grade');
$this->table->set_attribute('class', 'grade-report-stats gradestable flexible');
$this->table->setup();
/// If ranges are being shown add them to the table
if ($this->get_pref('stats', 'showranges')){
$this->table->add_data($ranges);
$this->table->add_separator();
}
/// Loop threw all the reported data and format it in to cells
/// If stat retured an array of values display the elements or
/// make a link to a popup with the data in it.
foreach($this->reportedstats as $name=>$data) {
$row = array('' . $stats[$name]->name . '');
foreach($data as $itemid=>$stat) {
if(!is_array($stat)) {
array_push($row, grade_format_gradevalue($stat, $this->gtree->items[$itemid], true, $stats[$name]->displaytype, $stats[$name]->decimals));
} else {
$statstring = "";
for($i = 0; $i < 2; $i++) {
if($i >= count($stat)) {
break;
}
$statstring .= grade_format_gradevalue($stat[$i], $this->gtree->items[$itemid], true, $stats[$name]->displaytype, $stats[$name]->decimals) . ', ';
}
if($i < count($stat)) {
$statstring = "encode_array($stat, $this->gtree->items[$itemid], $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');\">". $statstring . '....';
} else {
$statstring = substr($statstring, 0, strlen($statstring) - 2);
}
array_push($row, $statstring);
}
}
$this->table->add_data($row);
}
/// If the number of grades is being shown add it to the table.
if ($this->get_pref('stats', 'shownumgrades')){
$this->table->add_separator();
$this->table->add_data($numgrades);
}
/// Build html
ob_start();
if($this->currentgroup == 0) {
echo 'Group: All participants';
} else {
echo 'Group: ' . groups_get_group_name($this->currentgroup);
}
$this->table->print_html();
$this->html = ob_get_clean();
}
/**
* Builds HTML for toggles on top of report.
* Based on grader report get_toggles_html
* @return string html code for toggles.
*/
public function get_toggles_html() {
global $CFG, $USER;
$html = '';
$html .= $this->print_toggle('numgrades', true);
$html .= $this->print_toggle('groups', true);
$html .= $this->print_toggle('ranges', true);
$html .= '
';
return $html;
}
/**
* Builds HTML for each individual toggle.
* Based on grader report print_toggle
* @param string $type The toggle type.
* @param bool $return Wheather ro return the HTML or print it.
*/
private function print_toggle($type, $return=false) {
global $CFG;
$icons = array('eyecons' => 't/hide.gif',
'numgrades' => 't/grades.gif',
'calculations' => 't/calc.gif',
'locks' => 't/lock.gif',
'averages' => 't/mean.gif',
'nooutcomes' => 't/outcomes.gif');
$pref_name = 'grade_report_statsshow' . $type;
if (array_key_exists($pref_name, $CFG)) {
$show_pref = get_user_preferences($pref_name, $CFG->$pref_name);
} else {
$show_pref = get_user_preferences($pref_name);
}
$strshow = $this->get_lang_string('show' . $type, 'gradereport_stats');
$strhide = $this->get_lang_string('hide' . $type, 'gradereport_stats');
$show_hide = 'show';
$toggle_action = 1;
if ($show_pref) {
$show_hide = 'hide';
$toggle_action = 0;
}
if (array_key_exists($type, $icons)) {
$image_name = $icons[$type];
} else {
$image_name = "t/$type.gif";
}
$string = ${'str' . $show_hide};
$img = '
'. "\n";
$retval = $img . '"
. $string . ' ';
if ($return) {
return $retval;
} else {
echo $retval;
}
}
}
?>