Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Important changes about how view.php (and print.php) retrieve records

from BD to be displayed. Some SQL statements have been modified to
get target records, avoiding a lot of post-processing causing some
bugs like Bug 1912
(http://moodle.org/bugs/bug.php?op=show&bugid=1912)
  • Loading branch information...
commit d7d8758184e85f9db1558f2716607232082153bd 1 parent bef692c
stronk7 authored
Showing with 81 additions and 153 deletions.
  1. +17 −63 mod/glossary/print.php
  2. +23 −2 mod/glossary/sql.php
  3. +41 −88 mod/glossary/view.php
View
80 mod/glossary/print.php
@@ -155,74 +155,28 @@
$pivot = $pivot[0];
}
- ///
- /// Validating special cases not covered by the SQL statement
- ///
-
- /// if we're browsing by alphabet and the current concept does not begin with
- /// the letter we are look for.
- $showentry = 1;
- if ( $mode == 'letter' and $hook != 'SPECIAL' and $hook != 'ALL' ) {
- if ( substr($entry->concept, 0, strlen($hook)) != $hook ) {
- $showentry = 0;
- }
- }
-
- /// if we're browsing for letter, looking for special characters not covered
- /// in the alphabet
- if ( $showentry and $hook == 'SPECIAL' ) {
- $initial = $entry->concept[0];
- for ($i = 0; $i < count($alphabet); $i++) {
- $curletter = $alphabet[$i];
- if ( $curletter == $initial ) {
-
- $showentry = 0;
- break;
+ if ( $currentpivot != strtoupper($pivot) ) {
+ // print the group break if apply
+ if ( $printpivot ) {
+ $currentpivot = strtoupper($pivot);
+
+ $pivottoshow = $currentpivot;
+ if ( isset($entry->uid) ) {
+ $user = get_record("user","id",$entry->uid);
+ $pivottoshow = fullname($user, isteacher($course->id));
}
+
+ echo "<p align=\"center\"><strong><i>$pivottoshow</i></strong></p>" ;
}
- }
-
- /// if we're browsing categories, looking for entries not categorised.
- if ( $showentry and $mode == 'cat' and $hook == GLOSSARY_SHOW_NOT_CATEGORISED ) {
- if ( record_exists("glossary_entries_categories", "entryid", $entry->id)) {
- $showentry = 0;
- }
- }
-
- /// if the entry is not approved, deal with it based on the current view and
- /// user.
- if ( $showentry and $mode != 'approval' ) {
- if ( !$entry->approved and isteacher($course->id, $entry->userid) ) {
- $showentry = 0;
- }
}
+
+ echo '<b>'. strip_tags($entry->concept) . ': </b>';
+ $options->para = false;
+ $definition = format_text('<nolink>' . strip_tags($entry->definition) . '</nolink>', $entry->format,$options);
- /// ok, if it's a valid entry.. Print it.
- if ( $showentry ) {
-
- if ( $currentpivot != strtoupper($pivot) ) {
- // print the group break if apply
- if ( $printpivot ) {
- $currentpivot = strtoupper($pivot);
-
- $pivottoshow = $currentpivot;
- if ( isset($entry->uid) ) {
- $user = get_record("user","id",$entry->uid);
- $pivottoshow = fullname($user, isteacher($course->id));
- }
-
- echo "<p align=\"center\"><strong><i>$pivottoshow</i></strong></p>" ;
- }
- }
-
- echo '<b>'. strip_tags($entry->concept) . ': </b>';
- $options->para = false;
- $definition = format_text('<nolink>' . strip_tags($entry->definition) . '</nolink>', $entry->format,$options);
+ echo ($definition);
- echo ($definition);
-
- echo '<br><br>';
- }
+ echo '<br><br>';
}
}
View
25 mod/glossary/sql.php
@@ -57,9 +57,10 @@
$printpivot = 0;
$sqlselect = "SELECT ge.*, concept $as pivot";
- $sqlfrom = "FROM {$CFG->prefix}glossary_entries ge";
+ $sqlfrom = "FROM {$CFG->prefix}glossary_entries ge LEFT JOIN {$CFG->prefix}glossary_entries_categories gec
+ ON ge.id = gec.entryid";
$sqlwhere = "WHERE (glossaryid = '$glossary->id' OR sourceglossaryid = '$glossary->id') AND
- (ge.approved != 0 $userid)";
+ (ge.approved != 0 $userid) AND gec.entryid IS NULL";
$sqlorderby = ' ORDER BY concept';
@@ -195,6 +196,25 @@
break;
}
}
+ if ($hook == 'SPECIAL') {
+ //Create appropiate IN contents
+ $alphabet = explode(",", get_string("alphabet"));
+ $sqlalphabet = '';
+ for ($i = 0; $i < count($alphabet); $i++) {
+ if ($i != 0) {
+ $sqlalphabet .= ',';
+ }
+ $sqlalphabet .= '\''.$alphabet[$i].'\'';
+ }
+ switch ($CFG->dbtype) {
+ case 'postgres7':
+ $where = 'AND substr(ucase(concept),1,1) NOT IN (' . strtoupper($sqlalphabet) . ')';
+ break;
+ case 'mysql':
+ $where = 'AND left(ucase(concept),1) NOT IN (' . strtoupper($sqlalphabet) . ')';
+ break;
+ }
+ }
break;
}
@@ -229,4 +249,5 @@
}
$allentries = get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby $sqllimit");
+
?>
View
129 mod/glossary/view.php
@@ -288,10 +288,9 @@
$currentpivot = '';
$ratingsmenuused = NULL;
$paging = NULL;
- if ( $hook == 'SPECIAL' ) {
- $alphabet = explode(",", get_string("alphabet"));
- }
+
if ($allentries) {
+
/// printing the paging links
$paging = get_string("allentries","glossary");
@@ -300,7 +299,7 @@
} else {
$paging = "<a href=\"view.php?id=$id&mode=$mode&hook=$hook&offset=-1&sortkey=$sortkey&sortorder=$sortorder&fullsearch=$fullsearch\">" . $paging . '</a>';
}
- if ($count > $entriesbypage ) {
+ if ($count > $entriesbypage ) {
for ($i = 0; ($i*$entriesbypage) < $count ; $i++ ) {
if ( $paging != '' ) {
if ($i % 20 == 0 and $i) {
@@ -340,103 +339,57 @@
}
foreach ($allentries as $entry) {
- /// Setting the pivot for the current entry
+
+ /// Setting the pivot for the current entry
$pivot = $entry->pivot;
if ( !$fullpivot ) {
$pivot = $pivot[0];
}
- ///
- /// Validating special cases not covered by the SQL statement
- ///
-
- /// if we're browsing by alphabet and the current concept does not begin with
- /// the letter we are look for.
- $showentry = 1;
- $num = 0;
- if ( $mode == 'letter' and $hook != 'SPECIAL' and $hook != 'ALL' ) {
- if ( strtoupper(substr($entry->concept, 0, strlen($hook))) != strtoupper($hook) ) {
- $showentry = 0;
- }
- }
-
- /// if we're browsing for letter, looking for special characters not covered
- /// in the alphabet
- if ( $showentry and $hook == 'SPECIAL' ) {
- $initial = $entry->concept[0];
- for ($i = 0; $i < count($alphabet); $i++) {
- $curletter = $alphabet[$i];
- if ( $curletter == $initial ) {
-
- $showentry = 0;
- break;
+ /// if there's a group break
+ if ( $currentpivot != strtoupper($pivot) ) {
+
+ // print the group break if apply
+ if ( $printpivot ) {
+ $currentpivot = strtoupper($pivot);
+
+ echo '<p>';
+ echo '<table width="95%" border="0" class="generaltabselected" bgcolor="' . $THEME->cellheading2 . '">';
+
+ echo '<tr>';
+ $pivottoshow = $currentpivot;
+ if ( isset($entry->uid) ) {
+ // printing the user icon if defined (only when browsing authors)
+ echo '<td align="left">';
+
+ $user = get_record("user","id",$entry->uid);
+ print_user_picture($user->id, $course->id, $user->picture);
+ $pivottoshow = fullname($user, isteacher($course->id));;
+ } else {
+ echo '<td align="center">';
}
- }
- }
- /// if we're browsing categories, looking for entries not categorised.
- if ( $showentry and $mode == 'cat' and $hook == GLOSSARY_SHOW_NOT_CATEGORISED ) {
- if ( record_exists("glossary_entries_categories", "entryid", $entry->id)) {
- $showentry = 0;
- }
- }
+ echo "<strong> $pivottoshow</strong>" ;
+ echo '</td></tr></table>';
- /// if the entry is not approved, deal with it based on the current view and
- /// user.
- if ( $showentry and $mode != 'approval' ) {
- if ( !$entry->approved and $USER->id != $entry->userid ) {
- $showentry = 0;
- }
+ }
}
-
- /// ok, if it's a valid entry.. Print it.
- if ( $showentry ) {
- /// if there's a group break
- if ( $currentpivot != strtoupper($pivot) ) {
-
- // print the group break if apply
- if ( $printpivot ) {
- $currentpivot = strtoupper($pivot);
-
- echo '<p>';
- echo '<table width="95%" border="0" class="generaltabselected" bgcolor="' . $THEME->cellheading2 . '">';
-
- echo '<tr>';
- $pivottoshow = $currentpivot;
- if ( isset($entry->uid) ) {
- // printing the user icon if defined (only when browsing authors)
- echo '<td align="left">';
-
- $user = get_record("user","id",$entry->uid);
- print_user_picture($user->id, $course->id, $user->picture);
- $pivottoshow = fullname($user, isteacher($course->id));;
- } else {
- echo '<td align="center">';
- }
-
- echo "<strong> $pivottoshow</strong>" ;
- echo '</td></tr></table>';
+ $concept = $entry->concept;
+ $definition = $entry->definition;
- }
- }
-
- $concept = $entry->concept;
- $definition = $entry->definition;
-
- /// highlight the term if necessary
- if ($mode == 'search') {
- $entry->highlight = $hook;
- }
-
- /// and finally print the entry.
-
- if ( glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,$ratings) ) {
- $ratingsmenuused = true;
- }
+ /// highlight the term if necessary
+ if ($mode == 'search') {
+ $entry->highlight = $hook;
+ }
- $entriesshown++;
+ /// and finally print the entry.
+
+ if ( glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,$ratings) ) {
+ $ratingsmenuused = true;
}
+
+ $entriesshown++;
}
}
if ( !$entriesshown ) {
Please sign in to comment.
Something went wrong with that request. Please try again.