return $rehashed_items;
}
+/**
+ * Take out the common path within all $items['new_path'].
+ * This allows import/export repeatedly without duplicating its path
+ * @param array contains the breakdown of all resources in the XML
+ */
+function removeCommonPath($items){
+ $common_path;
+ $quit = false; //a flag that is set if it's not the first time being run.
+
+ foreach($items as $index=>$item){
+ if (isset($item['new_path']) && $item['new_path']!=''){
+ $path = $item['new_path'];
+ } else {
+ continue;
+ }
+
+ //hack
+ //check if this is a XML file; if so, skip through,
+ //cause XML most likely isn't a content resource.
+ $ext = substr($item['href'], (strrpos($item['href'], '.')+1));
+ if($ext=='xml'){
+ continue;
+ }
+
+ //if common path is empty, assign the first path to it.
+ if ($common_path=='' && $quit==false){
+ $common_path = $path;
+ $quit = true; //the next time common_path is empty, quit;
+ continue;
+ }
+ //we use '/' here instead of DIRECTORY_SEPARATOR because php would
+ //actually use '\' and return the whole string.
+ $common_array = explode('/', $common_path);
+ $path_array = explode('/', $path);
+ $intersect_array = array_intersect($common_array, $path_array);
+ $common_path = implode('/', $intersect_array);
+ }
+ return $common_path;
+}
+
/**
* This function will take the test accessment XML and add these to the database.
$order_offset = $contentDAO->getMaxOrdering($_course_id, 0);
$lti_offset = array(); //since we don't need lti tools, the ordering needs to be subtracted
//reorder the items stack
+$common_path = removeCommonPath($items);
$items = rehash($items);
//debug($items);exit;
foreach ($items as $item_id => $content_info)
$all_package_base_path = implode('/', $all_package_base_path);
}
- if ($all_package_base_path != '') {
- $content_info['new_path'] = $package_base_name . substr($content_info['new_path'], strlen($all_package_base_path));
+ if ($common_path != '') {
+ $content_info['new_path'] = $package_base_name . substr($content_info['new_path'], strlen($common_path));
} else {
$content_info['new_path'] = $package_base_name . '/' . $content_info['new_path'];
}
}
// loop through the files outside the package folder, and copy them to its relative path
+/**
if (is_dir($import_path.'resources')) {
$handler = opendir($import_path.'resources');
while ($file = readdir($handler)){
}
closedir($handler);
}
+**/
+//--- harris edit for path thing
+$file = TR_CONTENT_DIR . 'import/'.$_course_id.DIRECTORY_SEPARATOR.$common_path;
+if (is_dir($file)) {
+ rename($file, TR_CONTENT_DIR .$_course_id.'/'.$package_base_name);
+}
+//--- end
//takes care of the condition where the whole package doesn't have any contents but question banks
//also is the case of urls
if(is_array($all_package_base_path)){
$all_package_base_path = implode('/', $all_package_base_path);
-}
-if(strpos($all_package_base_path, 'http:/')===false){
- if (@rename($import_path.$all_package_base_path, TR_CONTENT_DIR .$_course_id.'/'.$package_base_name) === false) {
- if (!$msg->containsErrors()) {
- if ($oauth_import) {
- echo "error=".urlencode('Cannot move lesson directory into content directory');
- } else {
- $msg->addError('IMPORT_FAILED');
- }
- }
- }
+
+ if(strpos($all_package_base_path, 'http:/')===false){
+ if (@rename($import_path.$all_package_base_path, TR_CONTENT_DIR .$_course_id.'/'.$package_base_name) === false) {
+ if (!$msg->containsErrors()) {
+ if ($oauth_import) {
+ echo "error=".urlencode('Cannot move lesson directory into content directory');
+ } else {
+ $msg->addError('IMPORT_FAILED');
+ }
+ }
+ }
+ }
}
//check if there are still resources missing
foreach($items as $idetails){
$added_files = test_qti_export($content_test_row['test_id'], '', $zipfile);
foreach($added_files as $xml_file=>$chunk){
foreach ($chunk as $xml_filename){
- $added_files_xml .= str_replace('{FILE}', 'QTI/'.$xml_filename, $ims_template_xml['xml']);
+ $added_files_xml .= str_replace('{FILE}', 'resources/'.$xml_filename, $ims_template_xml['xml']);
}
}
//Save all the xml files in this array, and then print_organizations will add it to the manifest file.
$ims_template_xml['test']);
*/
foreach($test_files as $filename=>$realfilepath){
- $zipfile->add_file(@file_get_contents($realfilepath), 'QTI/'.$filename, filemtime($realfilepath));
+ $zipfile->add_file(@file_get_contents($realfilepath), 'resources/'.$filename, filemtime($realfilepath));
}
}
}