1. in ContentOutputParser, skip attribute value "clsid:..." in <object>
[acontent.git] / docs / home / classes / ContentUtility.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