Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Multiwords concepts are now shown as a single link when they are di…

…nymically 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.
  • Loading branch information...
commit 4f5c5e11a5364350c42a9a80cc42e52444b852a8 1 parent 99d8357
willcast authored
Showing with 48 additions and 17 deletions.
  1. +48 −17 mod/glossary/dynalink.php
65 mod/glossary/dynalink.php
View
@@ -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 = "<a target=\"entry\" title=\"" . strip_tags("$glossary->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_dynamic_link($courseid, $text,$glossaryid = NULL) {
}
function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "</a>") {
- $list_of_words = eregi_replace("[^-a-zA-Z0-9&']", " ", $concept);
- $list_array = explode(" ", $list_of_words);
- for ($i=0; $i<sizeof($list_array); $i++) {
- if (strlen($list_array[$i]) == 1) {
- $list_array[$i] = "";
- }
- }
- $list_of_words = implode(" ", $list_array);
+ $list_of_words = $concept;
$list_of_words_cp = $list_of_words;
$final = array();
@@ -45,9 +67,8 @@ function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "
foreach (array_unique($list_of_words[0]) as $key=>$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 @@ function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "
$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;
+ }
+ }
+
?>
Please sign in to comment.
Something went wrong with that request. Please try again.