]> git.mjollnir.org Git - moodle.git/commitdiff
Now the show=concept|alias
authorstronk7 <stronk7>
Thu, 13 May 2004 19:27:52 +0000 (19:27 +0000)
committerstronk7 <stronk7>
Thu, 13 May 2004 19:27:52 +0000 (19:27 +0000)
has been decoupled into 2 sql statements to make it works
under every MySQL version.
Hope this close Bug 985 forever...

mod/glossary/sql.php

index 4e766355288eea84a149d1f23c81545a3bfe0210..5321d769dc3cdac7acd9008ffcc30d4034d3e723 100644 (file)
@@ -9,6 +9,8 @@
 
 /// Creating the SQL statements
 
+    $calculatedrows = array();
+
 /// Pivot is the field that set the break by groups (category, initial, author name, etc)
 
 /// fullpivot indicate if the whole pivot should be compared agasint the db or just the first letter
         break;
         
         case 'term': 
+            //Here we are going to use two selects to do the work and then mix the results
+            //due to differences about the left join implementation in some versions of MySQL
+            //When MySQL 4.1 become the minimum to Moodle, we must change this again
+            //to use the UNION operator!!
+
+            $concepts = get_records_sql("$sqlselect
+                         FROM {$CFG->prefix}glossary_entries ge
+                         WHERE (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) AND
+                               (ge.approved != 0 $userid) AND
+                               (ge.concept = '$hook')");
+
+            if (empty($concepts)) {
+                $concepts = get_records_sql("$sqlselect
+                         FROM {$CFG->prefix}glossary_entries ge,
+                              {$CFG->prefix}glossary_alias al
+                         WHERE (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) AND
+                               (ge.approved != 0 $userid) AND
+                               (ge.id = al.entryid) AND
+                               (al.alias = '$hook')");
+            }
+
+            if (!empty($concepts)) {
+                foreach ($concepts as $concept) {
+                    $calculatedrows[] = $concept;
+                    break;
+                }
+            }
+
             $printpivot = 0;
-            $sqlfrom .= " left join {$CFG->prefix}glossary_alias ga on ge.id = ga.entryid ";
-            $where = "AND (ge.concept = '$hook' OR ga.alias = '$hook' )
-                     ";
+
+            //Here I leave previous code left join. Someday code above will be deleted and code below
+            //wil be changed to a standard UNION statement. No it's only executed if $calculatedrows is empty
+            if (empty($calculatedrows)) {
+                $sqlfrom .= " left join {$CFG->prefix}glossary_alias ga on ge.id = ga.entryid ";
+                $where = "AND (ge.concept = '$hook' OR ga.alias = '$hook' )
+                        ";
+            }
         break;
 
         case 'entry': 
         break;
         }
     break;
-    } 
-    $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
+    }
+    //If there are calculatedrows, use them
+    if (!empty ($calculatedrows)) {
+        $count = count($calculatedrows);
+    } else { //Execute the query
+        $count = count_records_sql("select count(*) $sqlfrom $sqlwhere");
+    }
 
     $sqllimit = '';
     
         }    
     }
 
-    $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
+    //If there are calculatedrows, use them
+    if (!empty ($calculatedrows)) {
+        $allentries = $calculatedrows;
+    } else { //Execute the query
+        $allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
+    }
 ?>