open($tmp_file); if ($res === TRUE) { $zip->extractTo($dir); $zip->close(); //$result = $this->readZipContents(); return $result; } } return false; } function readZipContents($dir) { if ($handle = opendir($dir)) { $this->setManifestFile(); if ($this->manifest_dom) { $result = $this->readManifestFile(); } if (is_dir($dir)) { $this->delete_directory($dir); } return $result; } return false; } function getManifestFileDOM($dir) { if ($handle = opendir($dir)) { while (false !== ($f = readdir($handle))) { if (!substr_compare($f, ".xml", -4, 4)) { $fc = file_get_contents($dir."/".$f); if (!empty($fc)) { $manifest = isManifestFile($fc); if ($manifest) { return $manifest; break; } } } } closedir($handle); } } function isManifestFile($xml) { $dom = new DOMDocument(); $dom->loadXML($xml); $dom->preserveWhiteSpace = false; $dom->normalizeDocument(); $manifest = $dom->getElementsByTagName("manifest"); if ($manifest->length != 0) { return $dom; } return false; } function readManifestFile($dir, $manifest_dom) { $success = true; $resources = $manifest_dom->getElementsByTagName("resource"); for ($i=0; $i<$resources->length; $i++) { $resource = $resources->item($i); $item_href = $resource->getAttribute("href"); $fc = file_get_contents($dir."/".$item_href); if (!empty($fc)) { $obj_id = readItemXML($resource, $fc); if (!$obj_id) { $success = false; } } } return $success; } function readItemXML($resource, $xml) { $dom = new DOMDocument(); $dom->loadXML($xml); $dom->preserveWhiteSpace = false; $dom->normalizeDocument(); $assessmentItem = $dom->getElementsByTagName("assessmentItem"); if ($assessmentItem->length != 0) { $choiceInteraction = $assessmentItem->item(0)->getElementsByTagName("choiceInteraction"); if ($choiceInteraction->length != 0) { importChoiceInteraction($resource, $dom); } $extendedTextInteraction = $assessmentItem->item(0)->getElementsByTagName("extendedTextInteraction"); if ($extendedTextInteraction->length != 0) { createDigiMinaItemExtendedText($resource, $dom); } } return true; } function importChoiceInteraction($resource, $dom) { $responseDeclaration = $dom->getElementsByTagName("responseDeclaration"); $cardinality = $responseDeclaration->item(0)->getAttribute("cardinality"); if ($cardinality == "single") { createDigiMinaItemMultipleChoice($resource, $dom); } else if ($cardinality == "multiple") { createDigiMinaItemMultipleResponse($resource, $dom); } return false; } function createDigiMinaItemMultipleChoice($resource_dom, $item_dom) { $item = new DigiMinaItemMultipleChoice(); $item->buildFromXML($resource_dom, $item_dom); $item->save(); } function createDigiMinaItemMultipleResponse($resource_dom, $item_dom) { $item = new DigiMinaItemMultipleResponse(); $item->buildFromXML($resource_dom, $item_dom); $item->save(); } function createDigiMinaItemExtendedText($resource_dom, $item_dom) { $item = new DigiMinaItemExtendedText(); $item->buildFromXML($resource_dom, $item_dom); $item->save(); }