n@1107: id = $id; n@1108: $this->comments = array(); n@1108: } n@1108: function addComment($str) { n@1108: array_push($this->comments,$str); n@1108: } n@1108: } n@1107: n@1108: class testPage { n@1108: function __construct($id) { n@1108: $this->id = $id; n@1108: $this->elements = array(); n@1108: } n@1108: } n@1107: // XML Saves location - assumes it will be saves/ n@1107: $saves = glob("../saves/*.xml"); n@1108: $comment_struct = array(); n@1107: if (is_array($saves)) n@1107: { n@1107: foreach($saves as $filename) { n@1107: $xml_string = file_get_contents($filename, FILE_TEXT); n@1107: $xml_object = simplexml_load_string($xml_string); n@1107: if ($xml_object == false) { n@1107: echo "

FATAL

could not parse file ".$filename.": "; n@1107: foreach(libxml_get_errors() as $error) { n@1107: echo "
", $error->message; n@1107: } n@1107: } else { n@1107: // Iterate over each audioHolder node n@1107: foreach($xml_object->page as $pageInstance) n@1107: { n@1108: // Find the page in the comment_struct n@1108: $page_struct = null; n@1274: if($pageInstance['state'] == "complete") { n@1274: foreach($comment_struct as $comment_struct_page) n@1108: { n@1274: if ($pageInstance['ref'] == $comment_struct_page->id) n@1108: { n@1274: $page_struct = $comment_struct_page; n@1108: break; n@1108: } n@1108: } n@1274: if ($page_struct == null) { n@1274: array_push($comment_struct,new testPage($pageInstance['ref'])); n@1274: $page_struct = $comment_struct[count($comment_struct)-1]; n@1108: } n@1274: // Get the audioelements of the page n@1274: foreach($pageInstance->audioelement as $fragment) n@1274: { n@1274: // Find the page in the comment_struct n@1274: $element_struct = null; n@1274: foreach($page_struct->elements as $page_struct_element) n@1274: { n@1274: if ($fragment['name'] == $page_struct_element->id) n@1274: { n@1274: $element_struct = $page_struct_element; n@1274: break; n@1274: } n@1274: } n@1274: if ($element_struct == null) { n@1274: array_push($page_struct->elements,new audioElement($fragment['name'])); n@1274: $element_struct = $page_struct->elements[count($page_struct->elements)-1]; n@1274: } n@1274: $element_struct->addComment($fragment->comment->response); n@1274: } n@1107: } n@1107: } n@1107: } n@1107: } n@1274: // Now we have a structure containing all comment data n@1108: switch($_GET['format']) { n@1108: case "XML": n@1108: // Convert to an XML n@1108: $doc_struct = new SimpleXMLElement(''); n@1108: foreach($comment_struct as $page_struct) n@1108: { n@1108: $doc_page = $doc_struct->addChild("page"); n@1108: $doc_page->addAttribute("id",$page_struct->id); n@1108: foreach($page_struct->elements as $element_struct) n@1108: { n@1108: $doc_element = $doc_page->addChild("audioelement"); n@1108: $doc_element->addAttribute("id",$element_struct->id); n@1108: foreach($element_struct->comments as $comment) n@1108: { n@1108: $doc_comment = $doc_element->addChild("comment",$comment); n@1108: } n@1108: } n@1108: } n@1108: echo $doc_struct->asXML(); n@1108: break; n@1108: case "JSON": n@1108: // Convert to JSON n@1108: $doc_string = '{ "pages": ['; n@1108: for($page_index = 0; $page_index < count($comment_struct); $page_index++ ) n@1108: { n@1108: $page_struct = $comment_struct[$page_index]; n@1108: $doc_page = '{"id": "'.$page_struct->id.'", "elements": ['; n@1108: for($element_index = 0; $element_index < count($page_struct->elements); $element_index++ ) n@1108: { n@1108: $element_struct = $page_struct->elements[$element_index]; n@1108: $doc_element = '{"id": "'.$element_struct->id.'", "comments": ['; n@1108: for($comment_index = 0; $comment_index < count($element_struct->comments); $comment_index++ ) n@1108: { n@1108: $doc_comment = '"'.$element_struct->comments[$comment_index].'"'; n@1108: if ($comment_index < count($element_struct->comments)-1) { n@1108: $doc_comment = $doc_comment.','; n@1108: } n@1108: $doc_element = $doc_element.$doc_comment; n@1108: } n@1108: $doc_element = $doc_element.']}'; n@1108: if ($element_index < count($page_struct->elements)-1) { n@1108: $doc_element = $doc_element.','; n@1108: } n@1108: $doc_page = $doc_page.$doc_element; n@1108: } n@1108: $doc_page = $doc_page.']}'; n@1108: if ($page_index < count($comment_struct)-1) { n@1108: $doc_page = $doc_page.','; n@1108: } n@1108: $doc_string = $doc_string.$doc_page; n@1108: } n@1108: $doc_string = $doc_string."]}"; n@1108: echo $doc_string; n@1108: break; n@1108: case "CSV": n@1108: // Conver to CSV n@1108: // The CSV has three columns: page, element, comment n@1108: $doc_string = "page,element,comment"."\r\n"; n@1108: foreach($comment_struct as $page_struct) n@1108: { n@1108: foreach($page_struct->elements as $element_struct) n@1108: { n@1108: foreach($element_struct->comments as $comment) n@1108: { n@1108: $doc_string = $doc_string.$page_struct->id.",".$element_struct->id.",".$comment."\r\n"; n@1108: } n@1108: } n@1108: } n@1108: echo $doc_string; n@1108: } n@1107: } else { n@1107: echo "FATAL - No saved XML files discovered"; n@1107: } n@1107: ?>