From c17a81a32775049afa1931c3fcb04c92163896ce Mon Sep 17 00:00:00 2001 From: Cindy Li Date: Wed, 20 Oct 2010 19:55:44 +0000 Subject: [PATCH] 1. in ContentOutputParser, skip attribute value "clsid:..." in 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 | 34 +++++++++++++------ docs/home/course/content.php | 2 +- .../classes/ContentOutputParser.class.php | 6 +++- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/docs/home/classes/ContentUtility.class.php b/docs/home/classes/ContentUtility.class.php index f3b66a3..1582343 100644 --- a/docs/home/classes/ContentUtility.class.php +++ b/docs/home/classes/ContentUtility.class.php @@ -795,15 +795,8 @@ class ContentUtility { } // get all relations between primary resources and their alternatives - $sql = "SELECT DISTINCT c.content_path, pr.resource, "; - - // ignore primary resource type if the request is on particular secondary type. - // otherwise, if the primary resource is defined with multiple primary types, - // the primary resource would be replaced/appended multiple times. - if ($only_on_secondary_type == 0) { - $sql .= "prt.type_id primary_type, "; - } - $sql .= "sr.secondary_resource, srt.type_id secondary_type + $sql = "SELECT DISTINCT c.content_path, pr.resource, , prt.type_id primary_type, + sr.secondary_resource, srt.type_id secondary_type FROM ".TABLE_PREFIX."primary_resources pr, ". TABLE_PREFIX."primary_resources_types prt,". TABLE_PREFIX."secondary_resources sr,". @@ -830,8 +823,29 @@ class ContentUtility { } } + $primary_resource_names = array(); foreach ($rows as $row) { - $alternative_rows[] = $row; + // if the primary resource is defined with multiple resource type, + // the primary resource would be replaced/appended multiple times. + // This is what we want at applying alternatives by default, but + // not when only one secondary type is chosen to apply. + // This fix is to remove the duplicates on the same primary resource. + // A dilemma of this fix is, for example, if the primary resource type + // is "text" and "visual", but + // $_SESSION['prefs']['PREF_ALT_TO_TEXT_APPEND_OR_REPLACE'] == 'replace' + // $_SESSION['prefs']['PREF_ALT_TO_VISUAL_APPEND_OR_REPLACE'] == 'append' + // so, should replace happen or append happen? With this fix, whichever + // the first in the sql return gets preserved in the array and processed. + // The further improvement is requried to keep rows based on the selected + // secondary type (http://www.atutor.ca/atutor/mantis/view.php?id=4598). + if ($only_on_secondary_type > 0) { + if (in_array($row['resource'], $primary_resource_names)) { + continue; + } else { + $primary_resource_names[] = $row['resource']; + } + } + $alternative_rows[] = $row; $youtube_playURL = ContentUtility::convertYoutubeWatchURLToPlayURL($row['resource']); diff --git a/docs/home/course/content.php b/docs/home/course/content.php index dc19d6d..cfe0165 100644 --- a/docs/home/course/content.php +++ b/docs/home/course/content.php @@ -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']); diff --git a/docs/include/classes/ContentOutputParser.class.php b/docs/include/classes/ContentOutputParser.class.php index b756030..a15d6a8 100644 --- a/docs/include/classes/ContentOutputParser.class.php +++ b/docs/include/classes/ContentOutputParser.class.php @@ -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; + } } } } -- 2.17.1