nicholas@2249: = poolSize. nicholas@2249: nicholas@2249: // The reference will always point to the original master XML file. nicholas@2249: nicholas@2249: include 'rel2abs.php'; nicholas@2249: nicholas@2249: // MODIFY THE FOLLOWING LINE TO POINT TO YOUR TEST FILE nicholas@2249: $master_file = "../tests/pool.xml"; nicholas@2249: // Note this is relative to the PHP location nicholas@2249: nicholas@2249: // First set up the store with all the test page key nodes nicholas@2283: $pages = array(); nicholas@2249: $master_xml = simplexml_load_string(file_get_contents($master_file, FILE_TEXT)); nicholas@2249: if ($master_xml) { nicholas@2249: if (!isset($master_xml->setup["poolSize"])) nicholas@2249: { nicholas@2249: echo file_get_contents($master_file, FILE_TEXT); nicholas@2249: return; nicholas@2249: } nicholas@2249: $poolSize = $master_xml->setup["poolSize"]; nicholas@2249: foreach($master_xml->page as $pageInstance) { nicholas@2249: $id = (string)$pageInstance['id']; nicholas@2249: $pages[$id] = 0; nicholas@2249: } nicholas@2249: } nicholas@2249: nicholas@2249: $waet_url = rel2abs("pool.php","http://".$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); nicholas@2249: nicholas@3120: $saveLocation = getSaveLocation(); nicholas@3120: $saves = glob($saveLocation."*.xml"); nicholas@2249: if (is_array($saves)) nicholas@2249: { nicholas@2249: foreach($saves as $filename) { nicholas@2249: $xml_object = simplexml_load_string(file_get_contents($filename, FILE_TEXT)); nicholas@2249: if($xml_object) { nicholas@2249: // First we must check the saves match the master URL nicholas@2249: $waet = $xml_object->waet[0]; nicholas@2249: if (urldecode($waet["url"])==$waet_url) { nicholas@2249: // This save is a save from the master XML nicholas@2249: // Count which pages have been added nicholas@2249: foreach($xml_object->page as $page) { nicholas@2249: $id = (string)$page['ref']; nicholas@2249: $pages[$id] = $pages[$id] + 1; nicholas@2249: } nicholas@2249: } nicholas@2249: } nicholas@2249: } nicholas@2249: } nicholas@2249: nicholas@2249: // Now we have a list of pages, sorted from low to high nicholas@2249: // Create the new prototype tree nicholas@2249: $orig_doc = new DOMDocument; nicholas@2249: $orig_doc->loadXML(file_get_contents($master_file, FILE_TEXT)); nicholas@2249: $orig_doc->schemaValidate("../xml/test-schema.xsd"); nicholas@2249: $new_doc = new DOMDocument; nicholas@2249: $new_doc->formatOutput = true; nicholas@2249: // nicholas@2249: $root = $new_doc->createElement('waet'); nicholas@2249: $root->setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); nicholas@2249: $root->setAttribute("xsi:noNamespaceSchemaLocation","test-schema.xsd"); nicholas@2249: $root = $new_doc->appendChild($root); nicholas@2249: nicholas@2249: // Copy over the node nicholas@2249: $dom_setup = $new_doc->importNode(dom_import_simplexml($master_xml->setup),true); nicholas@2249: $root->appendChild($dom_setup); nicholas@2249: nicholas@2249: // We must now extract the number which have been performed the least nicholas@2283: $rot_pages = array(); nicholas@2249: foreach($pages as $key => $var) nicholas@2249: if(array_key_exists($var,$rot_pages)) { nicholas@2249: array_push($rot_pages[$var],$key); nicholas@2249: } else { nicholas@2283: $rot_pages[$var] = array($key); nicholas@2249: } nicholas@2249: ksort($rot_pages); nicholas@2249: $Keys = array_keys($rot_pages); nicholas@2249: nicholas@2249: // Pages are grouped into an array based on the number of page initiations ($rot_pages) nicholas@2249: // $Keys is an array of the sorted key maps nicholas@2249: $pageList = $new_doc->getElementsByTagName("page"); nicholas@2249: $iter = 0; nicholas@2249: while ($pageList->length < $poolSize) { nicholas@2249: if ($iter > 0) { nicholas@2249: // We are adding more than one set of pages, make all current always include nicholas@2249: foreach($pageList as $page) { nicholas@2249: $page->setAttribute("alwaysInclude","true"); nicholas@2249: } nicholas@2249: } nicholas@2249: foreach($rot_pages[$Keys[$iter]] as $pageId) { nicholas@2249: // We have the pages to add as a $pageId nicholas@2249: // Now COPY nicholas@2249: $dom_page = $orig_doc->getElementById($pageId); nicholas@2249: $dom_page = $new_doc->importNode($dom_page,true); nicholas@2249: $root->appendChild($dom_page); nicholas@2249: } nicholas@2249: $iter++; nicholas@2249: $pageList = $new_doc->getElementsByTagName("page"); nicholas@2249: } nicholas@2249: nicholas@2249: echo $new_doc->saveXML(); nicholas@2249: nicholas@2538: ?>