1. in ContentOutputParser, skip attribute value "clsid:..." in <object>
authorCindy Li <cli@ocad.ca>
Wed, 20 Oct 2010 19:55:44 +0000 (19:55 -0000)
committerCindy Li <cli@ocad.ca>
Wed, 20 Oct 2010 19:55:44 +0000 (19:55 -0000)
2. apply alternatives to the content by default
3. fix the bug that when using alternative tool bar to switch, the alternative always append to the primary even though the user preference is set to replace.

docs/home/classes/ContentUtility.class.php
docs/home/course/content.php
docs/include/classes/ContentOutputParser.class.php

index f3b66a3..1582343 100644 (file)
@@ -795,15 +795,8 @@ class ContentUtility {
                }\r
         \r
                // get all relations between primary resources and their alternatives\r
-        $sql = "SELECT DISTINCT c.content_path, pr.resource, ";\r
-        \r
-        // ignore primary resource type if the request is on particular secondary type.\r
-        // otherwise, if the primary resource is defined with multiple primary types, \r
-        // the primary resource would be replaced/appended multiple times.\r
-        if ($only_on_secondary_type == 0) {\r
-            $sql .= "prt.type_id primary_type, ";\r
-        }\r
-        $sql .= "sr.secondary_resource, srt.type_id secondary_type\r
+        $sql = "SELECT DISTINCT c.content_path, pr.resource, , prt.type_id primary_type,\r
+                       sr.secondary_resource, srt.type_id secondary_type\r
                          FROM ".TABLE_PREFIX."primary_resources pr, ".\r
                                 TABLE_PREFIX."primary_resources_types prt,".\r
                                 TABLE_PREFIX."secondary_resources sr,".\r
@@ -830,8 +823,29 @@ class ContentUtility {
                        }\r
                }\r
                \r
+               $primary_resource_names = array();\r
                foreach ($rows as $row) {\r
-            $alternative_rows[] = $row;\r
+                       // if the primary resource is defined with multiple resource type,\r
+                       // the primary resource would be replaced/appended multiple times.\r
+                       // This is what we want at applying alternatives by default, but\r
+                       // not when only one secondary type is chosen to apply.\r
+                       // This fix is to remove the duplicates on the same primary resource.\r
+                       // A dilemma of this fix is, for example, if the primary resource type\r
+                       // is "text" and "visual", but\r
+                       // $_SESSION['prefs']['PREF_ALT_TO_TEXT_APPEND_OR_REPLACE'] == 'replace'\r
+                       // $_SESSION['prefs']['PREF_ALT_TO_VISUAL_APPEND_OR_REPLACE'] == 'append'\r
+                       // so, should replace happen or append happen? With this fix, whichever\r
+                       // the first in the sql return gets preserved in the array and processed.\r
+                       // The further improvement is requried to keep rows based on the selected\r
+                       // secondary type (http://www.atutor.ca/atutor/mantis/view.php?id=4598). \r
+                       if ($only_on_secondary_type > 0) {\r
+                               if (in_array($row['resource'], $primary_resource_names)) {\r
+                                       continue;\r
+                               } else {\r
+                                       $primary_resource_names[] = $row['resource'];\r
+                               }\r
+                       }\r
+                       $alternative_rows[] = $row;\r
             \r
             $youtube_playURL = ContentUtility::convertYoutubeWatchURLToPlayURL($row['resource']);\r
             \r
index dc19d6d..cfe0165 100644 (file)
@@ -203,7 +203,7 @@ if ($content_row['text'] == '' && empty($content_test_ids)){
        if (intval($_GET['alternative']) > 0) {
                $content = ContentUtility::applyAlternatives($cid, $content_row['text'], false, intval($_GET['alternative']));
        } else {
-               $content = $content_row['text'];
+               $content = ContentUtility::applyAlternatives($cid, $content_row['text']);
        }
 
     $content = ContentUtility::formatContent($content, $content_row['formatting']);
index b756030..a15d6a8 100644 (file)
@@ -60,7 +60,11 @@ class ContentOutputParser {
                                                        $my_files[] = trim($file);
                                                }
                                        } else {
-                                               $my_files[] = $attrs[$item];
+                                               $file = trim($attrs[$item]);
+                                               // filter our classid="clsid:..."
+                                               if (!strpos($file, "clsid:")) {
+                                                       $my_files[] = $file;
+                                               }
                                        }
                                }
                        }