From 4f5c5e11a5364350c42a9a80cc42e52444b852a8 Mon Sep 17 00:00:00 2001 From: willcast Date: Tue, 30 Sep 2003 04:01:34 +0000 Subject: [PATCH] - Multiwords concepts are now shown as a single link when they are dinymically linked. KNOWN BUG: When a concept is contained inside another concept (i.e. HOUSE and DOLL HOUSE) only the smaller concept is shown. Any help would be appreciated. --- mod/glossary/dynalink.php | 65 +++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/mod/glossary/dynalink.php b/mod/glossary/dynalink.php index 86410fce97..e5ada0aeab 100644 --- a/mod/glossary/dynalink.php +++ b/mod/glossary/dynalink.php @@ -3,23 +3,52 @@ function glossary_dynamic_link($courseid, $text,$glossaryid = NULL) { global $CFG; static $entries; - if ( !$glossaryid ) { - $glossary = get_record("glossary","course",$courseid,"mainglossary",1); + static $glossary; + if ( !$glossary ) { + $PermissionGranted = 1; + } elseif ( $glossaryid ) { + if ( $glossary->id != $glossaryid ) { + $PermissionGranted = 1; + } else { + } } else { - $glossary = get_record("glossary","course",$courseid,"id",$glossaryid); + $PermissionGranted = 1; + } + if ( $PermissionGranted ) { + if ( !$glossaryid ) { + $glossary = get_record("glossary","course",$courseid,"mainglossary",1); + } else { + $glossary = get_record("glossary","course",$courseid,"id",$glossaryid); + } } if ( $glossary ) { if ( !$entries ) { - $entries = get_records("glossary_entries","glossaryid",$glossary->id,"concept ASC"); + // char_lenght is compatible with PostGreSQL and MySQL. Other DBMS must be implemented + if ($CFG->dbtype == "postgres7" or $CFG->dbtype == "mysql") { + $ORDER_BY = "CHAR_LENGTH(concept) DESC"; + } else { + $ORDER_BY = "concept ASC"; + } + + $ownentries = get_records("glossary_entries", "glossaryid", $glossary->id,$ORDER_BY); + $importedentries = get_records("glossary_entries", "sourceglossaryid", $glossary->id,$ORDER_BY); + + if ( $ownentries and $importedentries ) { + $entries = array_merge($ownentries, $importedentries); + usort($entries, glossary_sort_entries_by_lenght); + } elseif ( $importedentries ) { + $entries = $importedentries; + } elseif ( $ownentries ) { + $entries = $ownentries; + } } if ( $entries ) { foreach ( $entries as $entry ) { - $href_tag_begin = "name: $entry->concept") ."\" href=\"$CFG->wwwroot/mod/glossary/showentry.php?courseid=$courseid&concept=$entry->concept\" ". "onClick=\"return openpopup('/mod/glossary/showentry.php?courseid=$courseid&concept=$entry->concept', 'entry', 'menubar=0,location=0,scrollbars,resizable,width=600,height=450', 0);\">"; $concept = trim(strip_tags($entry->concept)); - + $text = glossary_link_concepts($text,$concept,$href_tag_begin); } } @@ -29,14 +58,7 @@ } function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "") { - $list_of_words = eregi_replace("[^-a-zA-Z0-9&']", " ", $concept); - $list_array = explode(" ", $list_of_words); - for ($i=0; $i$value) { $final['<|'.$key.'|>'] = $value; } - + $text = str_replace($final,array_keys($final),$text); - $list_of_words_cp = eregi_replace(" +", "|", $list_of_words_cp); if ($list_of_words_cp{0}=="|") { $list_of_words_cp{0} = ""; @@ -58,9 +79,19 @@ $list_of_words_cp = "(".trim($list_of_words_cp).")"; $text = eregi_replace("$list_of_words_cp", "$href_tag_begin"."\\1"."$href_tag_end", $text); - $text = str_replace(array_keys($final),$final,$text); return stripslashes($text); } + + function glossary_sort_entries_by_lenght ( $entry0, $entry1 ) { + if ( strlen(trim($entry0->concept)) < strlen(trim($entry1->concept)) ) { + return -1; + } elseif ( strlen(trim($entry0->concept)) > strlen(trim($entry1->concept)) ) { + return 1; + } else { + return 0; + } + } + ?> -- 2.39.5