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)

Merged from MOODLE_14_STABLE
This commit is contained in:
stronk7 2004-09-09 18:31:50 +00:00
parent 797ba17e78
commit 539f698d73
3 changed files with 81 additions and 153 deletions

View File

@ -155,51 +155,6 @@
$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 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;
}
}
/// ok, if it's a valid entry.. Print it.
if ( $showentry ) {
if ( $currentpivot != strtoupper($pivot) ) {
// print the group break if apply
if ( $printpivot ) {
@ -224,7 +179,6 @@
echo '<br><br>';
}
}
}
echo '</body></html>';
?>

View File

@ -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 File

@ -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");
@ -340,58 +339,13 @@
}
foreach ($allentries as $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 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 $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) ) {
@ -438,7 +392,6 @@
$entriesshown++;
}
}
}
if ( !$entriesshown ) {
print_simple_box('<center>' . get_string("noentries","glossary") . '</center>',"center","95%");
}