]> git.mjollnir.org Git - moodle.git/commitdiff
- Multiwords concepts are now shown as a single link when they are dinymically linked.
authorwillcast <willcast>
Tue, 30 Sep 2003 04:01:34 +0000 (04:01 +0000)
committerwillcast <willcast>
Tue, 30 Sep 2003 04:01:34 +0000 (04:01 +0000)
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

index 86410fce97385d197c03454fc43fbac70de24bf0..e5ada0aeabd8514eff719dba3f4044c1323035e6 100644 (file)
@@ -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);
                 }
             }
     }
     
     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 @@
         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} = "";
         $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;
+        }
+    }
+
 ?>