--- tmp/cvs/contrib/questionnaire/locallib.php 2006-07-28 20:58:12.000000000 +0100 +++ locallib.php 2006-12-23 16:21:18.000000000 +0000 @@ -1589,17 +1589,18 @@ 'WHERE a.response_id=\''.$rid.'\' AND a.question_id=q.id '.$qids; if ($records = get_records_sql($sql)) { foreach ($records as $row) { - /// Change the data object into a numerically indexed array. - ///*** Because of the way the following code works, we need to remove the non-numeric keys of the array. - ///*** The problem is that the Moodle db calls returns hask and numeric keys for each value (2 per). + $newrow = array(); + $row = (array)$row; - $qid = array_shift($row); - foreach ($row as $key => $val) { - if (!is_numeric($key)) unset($row[$key]); - } - $val = array_pop($row); - $values[$qid] = $row; - array_push($values["$qid"], ($val == 'Y') ? get_string('yes') : get_string('no'), $val); + $newrow[0] = $row['content']; + if( $row['choice_id'] == 'Y' ){ + $newrow[1] = get_string('yes'); + }else{ + $newrow[1] = get_string('no'); + } + $newrow[2] = $row['choice_id']; + + $values[$row['id']] = $newrow; } } @@ -1611,21 +1612,22 @@ 'WHERE a.response_id=\''.$rid.'\' AND a.question_id=q.id AND a.choice_id=c.id '.$qids; if ($records = get_records_sql($sql)) { foreach ($records as $row) { - /// Change the data object into a numerically indexed array. - ///*** Because of the way the following code works, we need to remove the non-numeric keys of the array. - ///*** The problem is that the Moodle db calls returns hask and numeric keys for each value (2 per). + $newrow = array(); + $row = (array)$row; - $qid = array_shift($row); - foreach ($row as $key => $val) { - if (!is_numeric($key)) unset($row[$key]); - } - $c = count($row); - $val = $row[$c - 2]; - if (ereg('^!other', $val)) - $row[$c - 1] = 'other_' . $row[$c - 1]; - else - settype($row[$c - 1], 'integer'); - $values[$qid] = $row; + $qid = $row['id']; + + + $newrow[0] = $row['content']; + $newrow[1] = $row['ccontent']; + + if (ereg('^!other', $row['ccontent'])){ + $newrow[3] = 'other_' . $row['cid']; + }else{ + $newrow[3] = $row['cid']; + } + + $values[$qid] = $newrow; } } @@ -1639,33 +1641,32 @@ $tmp = null; if ($records = get_records_sql($sql)) { foreach ($records as $row) { - /// Change the data object into a numerically indexed array. - ///*** Because of the way the following code works, we need to remove the non-numeric keys of the array. - ///*** The problem is that the Moodle db calls returns hask and numeric keys for each value (2 per). + + $newrow = array(); $row = (array)$row; - array_shift($row); // get rid of the answer id. - $qid = array_shift($row); - foreach ($row as $key => $val) { - if (!is_numeric($key)) unset($row[$key]); - } - $c = count($row); - $val = $row[$c - 2]; - if (ereg('^!other', $val)) - $row[$c - 1] = 'other_' . $row[$c - 1]; - else - settype($row[$c - 1], 'integer'); + + $qid = $row['qid']; + $newrow[0] = $row['content']; + $newrow[1] = $row['ccontent']; + + if (ereg('^!other', $row['ccontent'])){ + $newrow[3] = 'other_' . $row['cid']; + }else{ + $newrow[3] = $row['cid']; + } if($tmp == $qid) { - $arr[] = $row; + $arr[] = $newrow; continue; } if($tmp != null) $values["$tmp"]=$arr; $tmp = $qid; - $arr = array($row); + $arr = array($newrow); } } if($tmp != null) $values["$tmp"]=$arr; + unset($arr); unset($tmp); unset($row); @@ -1678,17 +1679,16 @@ 'ORDER BY a.question_id,c.id'; if ($records = get_records_sql($sql)) { foreach ($records as $row) { - /// Change the data object into a numerically indexed array. - ///*** Because of the way the following code works, we need to remove the non-numeric keys of the array. - ///*** The problem is that the Moodle db calls returns hask and numeric keys for each value (2 per). + $newrow = array(); $row = (array)$row; - $qid = array_shift($row); - foreach ($row as $key => $val) { - if (!is_numeric($key)) unset($row[$key]); - } - $cid = array_shift($row); - array_push($row, $row[count($row) - 1]); - $values["${qid}_${cid}"] = $row; + + $newrow[0] = $row['content']; + $newrow[1] = $row['aresponse']; + $newrow[2] = $row['aresponse']; + + $idstring = $row['id'] . '_' . $row['cid']; + + $values["$idstring"] = $newrow; } } @@ -1701,23 +1701,15 @@ 'ORDER BY aid, a.question_id,c.id'; if ($records = get_records_sql($sql)) { foreach ($records as $row) { - /// Change the data object into a numerically indexed array. - ///*** Because of the way the following code works, we need to remove the non-numeric keys of the array. - ///*** The problem is that the Moodle db calls returns hash and numeric keys for each value (2 per). - $row = (array)$row; - array_shift($row); // get rid of the answer id. - - /// Next two are 'qid' and 'cid', each with numeric and hash keys. - $qid = array_shift($row); - array_shift($row); - $qid .= '_'.array_shift($row); - array_shift($row); - - foreach ($row as $key => $val) { - if (!is_numeric($key)) unset($row[$key]); - } - settype($row[count($row) - 1], 'integer'); - $values[$qid] = $row; + $newrow = array(); + $row = (array) $row; + + $newrow[0] = $row['content']; + $newrow[1] = $row['ccontent']; + $newrow[2] = $row['arank']; + + $qid = $row['qid'] . '_' . $row['cid']; + $values[$qid] = $newrow; } } @@ -1726,18 +1718,14 @@ 'FROM '.$CFG->prefix.'questionnaire_response_text a, '.$CFG->prefix.'questionnaire_question q '. 'WHERE a.response_id=\''.$rid.'\' AND a.question_id=q.id '.$qids; if ($records = get_records_sql($sql)) { - foreach ($records as $row) { - /// Change the data object into a numerically indexed array. - ///*** Because of the way the following code works, we need to remove the non-numeric keys of the array. - ///*** The problem is that the Moodle db calls returns hask and numeric keys for each value (2 per). + foreach ($records as $row) { + $newrow = array(); $row = (array)$row; - $qid = array_shift($row); - foreach ($row as $key => $val) { - if (!is_numeric($key)) unset($row[$key]); - } - $values["$qid"]=$row; - $val = array_pop($values["$qid"]); - array_push($values["$qid"], $val, $val); + + $newrow[0] = $row['content']; + $newrow[1] = $row['aresponse']; + $newrow[2] = $row['aresponse']; + $values[$row['id']] = $newrow; } } @@ -1747,17 +1735,12 @@ 'WHERE a.response_id=\''.$rid.'\' AND a.question_id=q.id '.$qids; if ($records = get_records_sql($sql)) { foreach ($records as $row) { - /// Change the data object into a numerically indexed array. - ///*** Because of the way the following code works, we need to remove the non-numeric keys of the array. - ///*** The problem is that the Moodle db calls returns hask and numeric keys for each value (2 per). + + $newrow = array(); $row = (array)$row; - $qid = array_shift($row); - foreach ($row as $key => $val) { - if (!is_numeric($key)) unset($row[$key]); - } - $values["$qid"]=$row; - $val = array_pop($values["$qid"]); - array_push($values["$qid"], $val, $val); + $newrow[0] = $row['content']; + $newrow[1] = $row['aresponse']; + $values[$row['id']] = $newrow; } } @@ -2104,7 +2087,7 @@ $counts = array(); // --------------------------------------------------------------------------- - if (!empty($guicross) && $question["result_id"] == 1){ + if (!empty($guicross) && $question->result_id == 1){ $this->mkcrossformat($counts,$qid,$question->type_id ); } else { $question->display_results($rids); @@ -2425,4 +2408,4 @@ return 0; return ($lc > $rc) ? 1 : -1; } -?> \ No newline at end of file +?>