apply the changes in atutor to fix the issue that the export puts the items into...
authorCindy Li <cli@ocad.ca>
Mon, 23 Aug 2010 17:26:47 +0000 (17:26 -0000)
committerCindy Li <cli@ocad.ca>
Mon, 23 Aug 2010 17:26:47 +0000 (17:26 -0000)
Also fix:
http://www.atutor.ca/atutor/mantis/view.php?id=4498
http://www.atutor.ca/atutor/mantis/view.php?id=4499

docs/home/ims/ims_import.php
docs/home/imscc/include/ims_template.inc.php
docs/include/classes/Weblinks/WeblinksExport.class.php
docs/include/classes/Weblinks/WeblinksParser.class.php

index 9a66f19..33d3d24 100644 (file)
@@ -372,6 +372,46 @@ function rehash($items){
        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.
@@ -1111,6 +1151,7 @@ if ($xml_base_path) {
 $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) 
@@ -1343,8 +1384,8 @@ 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'];
        }
@@ -1527,6 +1568,7 @@ if (!is_dir($course_dir)) {
 }
 
 // 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)){
@@ -1537,21 +1579,29 @@ if (is_dir($import_path.'resources')) {
        }
        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){
index 5b6d7d4..ad32171 100644 (file)
@@ -231,7 +231,7 @@ function print_organizations($parent_id,
                                        $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.
@@ -244,7 +244,7 @@ function print_organizations($parent_id,
                                                                                                $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));
                                        }
                                }
                        }
index 05226b3..628adff 100644 (file)
@@ -42,7 +42,7 @@ class WeblinksExport {
                //assign all the neccessarily values to the template.
                $savant->assign('title', htmlentities($wl->getTitle(), ENT_QUOTES, 'UTF-8'));
                $url = $wl->getUrl();
-               $savant->assign('url_href', htmlentities($url['href'], ENT_QUOTES, 'UTF-8'));
+               $savant->assign('url_href', urlencode($url['href']));
                $savant->assign('url_target', $url['target']);
                //TODO: not supported yet
                //$savant->assign('url_window_features', $url['window_features']);
index 015b592..8e0a004 100644 (file)
@@ -95,7 +95,7 @@ class WeblinksParser {
                return $this->title;
        }
        function getUrl(){
-               return $this->url;
+               return urldecode($this->url);
        }
 }