/** * makeTeamMakerXML * * @param mixed $questions questions for make groups * @param mixed $responses user responses * @param mixed $numGroups number of groups * @param mixed $weight weight * * @access public * @return void */ function makeTeamMakerXML($questions, $responses, $numGroups, $weight) { if (phpversion() < 5) { $appendChildFunc = 'append_child'; $setAttributeFunc = 'set_attribute'; $createElementFunc = 'create_element'; $doc = domxml_new_doc('1.0'); } else { $appendChildFunc = 'appendChild'; $setAttributeFunc = 'setAttribute'; $createElementFunc = 'createElement'; $doc = new DOMDocument('1.0'); } $this->SurveyInput = new SurveyInput(); $this->Response = new Response(); //docroot $team_input = $doc->{$createElementFunc}('team_input'); $team_input->{$setAttributeFunc}('num_groups', $numGroups); $doc->{$appendChildFunc}($team_input); foreach ($questions as $q) { //questions $question = $doc->{$createElementFunc}('question'); $question->{$setAttributeFunc}('id', $q['id']); $question->{$setAttributeFunc}('type', $q['type'] == 'C' ? 'CAO' : 'MC'); $question->{$setAttributeFunc}('title', $q['prompt']); $team_input->{$appendChildFunc}($question); //weight $element_weight = $doc->{$createElementFunc}('weight'); $element_weight->{$setAttributeFunc}('value', $weight[$q['id']]); $question->{$appendChildFunc}($element_weight); } foreach ($responses as $user) { //students $student = $doc->{$createElementFunc}('student'); $student->{$setAttributeFunc}('username', $user['User']['id']); $team_input->{$appendChildFunc}($student); foreach ($questions as $q) { //response $response = $doc->{$createElementFunc}('response'); $response->{$setAttributeFunc}('q_id', $q['id']); $response->{$setAttributeFunc}('type', $q['type'] == 'C' ? 'CAO' : 'MC'); $student->{$appendChildFunc}($response); // TODO: handle CAO (checkbox questions. See the example xml in teammaker // source directory $responses = Set::extract($user, '/SurveyInput[question_id=' . $q['id'] . ']'); if (!empty($responses)) { foreach ($responses as $resp) { $response_tmp = $resp['SurveyInput']; //response/answer $value = $doc->{$createElementFunc}('value'); $value->{$setAttributeFunc}('id', $response_tmp['response_id'] == null ? '' : $response_tmp['response_id']); //$value->$setAttributeFunc('answer', 1); $response->{$appendChildFunc}($value); } } else { if ('M' == $q['type']) { $value = $doc->{$createElementFunc}('value'); $value->{$setAttributeFunc}('id', ''); $response->{$appendChildFunc}($value); } } } } if (phpversion() < 5) { return $doc->dump_mem(true); } else { return $doc->saveXML(); } }
function exportPhp5($db, $dbname, $tables) { $doc = new DOMDocument('1.0'); // create root node = database name $dbname_element = $doc->createElement($dbname); // create a new element for each table foreach($tables as $table) { // get all rows $table_rows = getRows($db, $table); foreach($table_rows as $row) { $table_element = $doc->createElement($table); foreach($row as $fieldname => $value) { $row_element = $doc->createElement($fieldname); $row_element->appendChild($doc->createTextNode($value)); $table_element->appendChild($row_element); } $dbname_element->appendChild($table_element); } } $doc->appendChild($dbname_element); $xml_content=$doc->dump_mem(FORMAT_XML); $xml_filename="ipeer_dump.xml"; $xml_filesize=strlen($xml_content); header("HTTP/1.1 200 OK"); header("Content-Disposition: attachment; filename=$xml_filename"); header("Content-Length: $xml_filesize"); header("Content-Type: application/force-download"); header("Content-Transfer-Encoding: binary"); header("Pragma: no-cache"); header("Expires: 0"); echo $xml_content; }