modified reports to allow rowspan and colspan settings to work with "remove_column" function

This commit is contained in:
gbateson 2005-09-22 04:40:45 +00:00
parent 0c59601c11
commit bb380677cd
5 changed files with 120 additions and 125 deletions

View File

@ -238,6 +238,53 @@
}
}
if ($mode!='overview') {
// initialise details of responses to questions in these attempts
foreach ($attempts as $a=>$attempt) {
$attempts[$a]->responses = array();
}
foreach ($questions as $q=>$question) {
$questions[$q]->attempts = array();
}
// get reponses to these attempts
$attempt_ids = join(',',array_keys($attempts));
if (!$responses = get_records_sql("SELECT * FROM {$CFG->prefix}hotpot_responses WHERE attempt IN ($attempt_ids)")) {
$responses = array();
}
// ids of questions used in these responses
$questionids = array();
foreach ($responses as $response) {
// shortcuts to the attempt and question ids
$a = $response->attempt;
$q = $response->question;
// check the attempt and question objects exist
// (if they don't exist, something is very wrong!)
if (isset($attempts[$a]) || isset($questions[$q])) {
// add the response for this attempt
$attempts[$a]->responses[$q] = $response;
// add a reference from the question to the attempt which includes this question
$questions[$q]->attempts[] = &$attempts[$a];
// flag this id as being used
$questionids[$q] = true;
}
}
// remove unused questions
$questionids = array_keys($questionids);
foreach ($questions as $id=>$question) {
if (!in_array($id, $questionids)) {
unset($questions[$id]);
}
}
}
/// Open the selected hotpot report and display it

View File

@ -7,50 +7,6 @@ class hotpot_report extends hotpot_default_report {
function display(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options) {
global $CFG;
foreach ($attempts as $a=>$attempt) {
$attempts[$a]->responses = array();
}
foreach ($questions as $q=>$question) {
$questions[$q]->attempts = array();
}
// get reponses to these attempts
$attempt_ids = join(',',array_keys($attempts));
if (!$responses = get_records_sql("SELECT * FROM {$CFG->prefix}hotpot_responses WHERE attempt IN ($attempt_ids)")) {
$responses = array();
}
// ids of questions used in these responses
$questionids = array();
foreach ($responses as $response) {
// shortcuts to the attempt and question ids
$a = $response->attempt;
$q = $response->question;
// check the attempt and question objects exist
// (if they don't exist, something is very wrong!)
if (isset($attempts[$a]) || isset($questions[$q])) {
// add the response for this attempt
$attempts[$a]->responses[$q] = $response;
// add a reference from the question to the attempt which includes this question
$questions[$q]->attempts[] = &$attempts[$a];
// flag this id as being used
$questionids[$q] = true;
}
}
// remove unused questions
$questionids = array_keys($questionids);
foreach ($questions as $id=>$question) {
if (!in_array($id, $questionids)) {
unset($questions[$id]);
}
}
// create the table
$this->create_clickreport_table($hotpot, $cm, $course, $users, $attempts, $questions, $options, $tables=array());

View File

@ -44,6 +44,8 @@ class hotpot_default_report {
}
function set_legend(&$table, &$q, &$value, &$question) {
// $q is the question number
// $value is the value (=text) of the answer
// check the legend is required
if (isset($table->legend) && isset($value)) {
@ -118,10 +120,10 @@ class hotpot_default_report {
return $this->dec_to_ALPHA(intval($dec/26)-1).$this->dec_to_ALPHA($dec % 26);
}
}
function remove_column(&$col, &$table) {
function remove_column(&$table, $target_col) {
if (is_array($table)) {
unset($table[$col]);
unset($table[$target_col]);
$table = array_values($table);
} else if (is_object($table)) {
@ -131,11 +133,43 @@ class hotpot_default_report {
case 'data' :
case 'stat' :
case 'foot' :
$array = &$table->$name;
$count = count($array);
for ($row=0; $row<$count; $row++) {
$this->remove_column($col, $array[$row]);
}
$skipcol = array();
$cells = &$table->$name;
$row_max = count($cells);
for ($row=0; $row<$row_max; $row++) {
$i = 0; // index on $cells[$row]
$col = 0;
while ($col<$target_col && isset($cells[$row][$i])) {
if (empty($skipcol[$col])) {
$cell = $cells[$row][$i++];
if (is_object($cell)) {
if (isset($cell->rowspan) && is_numeric($cell->rowspan) && ($cell->rowspan>0)) {
// skip cells below this one
$skipcol[$col] = $cell->rowspan-1;
}
if (isset($cell->colspan) && is_numeric($cell->colspan) && ($cell->colspan>0)) {
// skip cells to the right of this one
for ($c=1; $c<$cell->colspan; $c++) {
if (empty($skipcol[$col+$c])) {
$skipcol[$col+$c] = 1;
} else {
$skipcol[$col+$c] ++;
}
}
}
}
} else {
$skipcol[$col]--;
}
$col++;
} // end while $col
if ($col==$target_col && isset($cells[$row][$i])) {
$this->remove_column($cells[$row], $i);
}
} // end for $row
break;
case 'head' :
case 'align' :
@ -143,13 +177,13 @@ class hotpot_default_report {
case 'fontsize' :
case 'size' :
case 'wrap' :
$this->remove_column($col, $table->$name);
$this->remove_column($table->$name, $target_col);
break;
case 'statheadercols' :
$array = &$table->$name;
$count = count($array);
for ($i=0; $i<$count; $i++) {
if ($array[$i]>=$col) {
if ($array[$i]>=$target_col) {
$array[$i] --;
}
}
@ -361,14 +395,14 @@ class hotpot_default_report {
}
function print_html_data(&$table) {
if (isset($table->data)) {
$skipcell = array();
$skipcol = array();
foreach ($table->data as $cells) {
print "<tr>\n";
if (is_array($cells)) {
$i = 0; // index on $cells
$col = 0; // column index
while ($col<$table->colspan && isset($cells[$i])) {
if (empty($skipcell[$col])) {
if (empty($skipcol[$col])) {
$cell = &$cells[$i++];
$td = $table->td[$col];
if (is_object($cell)) {
@ -376,16 +410,16 @@ class hotpot_default_report {
if (isset($cell->rowspan) && is_numeric($cell->rowspan) && ($cell->rowspan>0)) {
$td = '<td rowspan="'.$cell->rowspan.'"'.substr($td, 3);
// skip cells below this one
$skipcell[$col] = $cell->rowspan-1;
$skipcol[$col] = $cell->rowspan-1;
}
if (isset($cell->colspan) && is_numeric($cell->colspan) && ($cell->colspan>0)) {
$td = '<td colspan="'.$cell->colspan.'"'.substr($td, 3);
// skip cells to the right of this one
for ($c=1; $c<$cell->colspan; $c++) {
if (empty($skipcell[$col+$c])) {
$skipcell[$col+$c] = 1;
if (empty($skipcol[$col+$c])) {
$skipcol[$col+$c] = 1;
} else {
$skipcell[$col+$c] ++;
$skipcol[$col+$c] ++;
}
}
}
@ -394,7 +428,7 @@ class hotpot_default_report {
}
print $td.$text."</td>\n";
} else {
$skipcell[$col]--;
$skipcol[$col]--;
}
$col++;
} // end while

View File

@ -7,50 +7,6 @@ class hotpot_report extends hotpot_default_report {
function display(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options) {
global $CFG;
foreach ($attempts as $a=>$attempt) {
$attempts[$a]->responses = array();
}
foreach ($questions as $q=>$question) {
$questions[$q]->attempts = array();
}
// get reponses to these attempts
$attempt_ids = join(',',array_keys($attempts));
if (!$responses = get_records_sql("SELECT * FROM {$CFG->prefix}hotpot_responses WHERE attempt IN ($attempt_ids)")) {
$responses = array();
}
// ids of questions used in these responses
$questionids = array();
foreach ($responses as $response) {
// shortcuts to the attempt and question ids
$a = $response->attempt;
$q = $response->question;
// check the attempt and question objects exist
// (if they don't exist, something is very wrong!)
if (isset($attempts[$a]) || isset($questions[$q])) {
// add the response for this attempt
$attempts[$a]->responses[$q] = $response;
// add a reference from the question to the attempt which includes this question
$questions[$q]->attempts[] = &$attempts[$a];
// flag this id as being used
$questionids[$q] = true;
}
}
// remove unused questions
$questionids = array_keys($questionids);
foreach ($questions as $id=>$question) {
if (!in_array($id, $questionids)) {
unset($questions[$id]);
}
}
// create the tables
$tables = array();
$this->create_responses_table($hotpot, $course, $users, $attempts, $questions, $options, $tables);
@ -239,7 +195,7 @@ class hotpot_report extends hotpot_default_report {
if (!$show_penalties) {
$col = 3 + count($questionids);
$this->remove_column($col, $table);
$this->remove_column($table, $col);
}
$tables[] = &$table;

View File

@ -5,8 +5,11 @@
class hotpot_report extends hotpot_default_report {
function display(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options) {
$this->create_scores_table($hotpot, $course, $users, $attempts, $questions, $options, $tables=array());
global $CFG;
// create the table
$tables = array();
$this->create_scores_table($hotpot, $course, $users, $attempts, $questions, $options, $tables);
$this->print_report($course, $hotpot, $tables, $options);
@ -130,21 +133,22 @@ class hotpot_report extends hotpot_default_report {
$data[] = $attemptnumber;
// get responses to questions in this attempt by this user
foreach ($questions as $question) {
$id = $question->id;
foreach ($questions as $id=>$question) {
if (!isset($q[$id])) {
$q[$id] = array('count'=>0, 'total'=>0);
}
$score = get_field('hotpot_responses', 'score', 'attempt', $attempt->id, 'question', $question->id);
if (isset($score)) {
if (isset($attempt->responses[$id])) {
$score = $attempt->responses[$id]->score;
if (is_numeric($score)) {
$q[$id]['count'] ++;
$q[$id]['total'] += $score;
}
if ($is_best_grade) {
$score = '<span class="highlight">'.$score.'</span>';
if ($is_best_grade) {
$score = '<span class="highlight">'.$score.'</span>';
}
} else if (empty($score)) {
$score = $no_value;
}
} else {
$score = $no_value;
@ -179,6 +183,7 @@ class hotpot_report extends hotpot_default_report {
} else {
$score = $no_value;
}
$data[] = $score;
// append data for this attempt
@ -206,7 +211,7 @@ class hotpot_report extends hotpot_default_report {
if (empty($q['grade']['count'])) {
// remove score $col from $table
$this->remove_column($col, $table);
$this->remove_column($table, $col);
} else {
$precision = ($hotpot->grademethod==HOTPOT_GRADEMETHOD_AVERAGE || $hotpot->grade<100) ? 1 : 0;
$averages[] = round($q['grade']['total'] / $q['grade']['count'], $precision);
@ -219,25 +224,22 @@ class hotpot_report extends hotpot_default_report {
foreach ($questions as $id=>$question) {
if (empty($q[$id]['count'])) {
// remove this question $col from $table
$this->remove_column($col, $table);
$this->remove_column($table, $col);
} else {
$averages[] = round($q[$id]['total'] / $q[$id]['count']);
$col++;
$averages[$col++] = round($q[$id]['total'] / $q[$id]['count']);
}
}
if (empty($q['penalties']['count'])) {
// remove penalties $col from $table
$this->remove_column($col, $table);
$this->remove_column($table, $col);
} else {
$averages[] = round($q['penalties']['total'] / $q['penalties']['count']);
$col++;
$averages[$col++] = round($q['penalties']['total'] / $q['penalties']['count']);
}
if (empty($q['score']['count'])) {
// remove score $col from $table
$this->remove_column($col, $table);
$this->remove_column($table, $col);
} else {
$averages[] = round($q['score']['total'] / $q['score']['count']);
$col++;
$averages[$col++] = round($q['score']['total'] / $q['score']['count']);
}
$table->foot = array($averages);