From: stronk7 Date: Thu, 9 Sep 2004 18:31:50 +0000 (+0000) Subject: Important changes about how view.php (and print.php) retrieve records X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=539f698d73c47b3c4930e198b40df5d8258fb585;p=moodle.git 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 --- diff --git a/mod/glossary/print.php b/mod/glossary/print.php index 35c6990725..da6c46f7ce 100644 --- a/mod/glossary/print.php +++ b/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 "

$pivottoshow

" ; } - } - - /// 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 ''. strip_tags($entry->concept) . ': '; + $options->para = false; + $definition = format_text('' . strip_tags($entry->definition) . '', $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 "

$pivottoshow

" ; - } - } - - echo ''. strip_tags($entry->concept) . ': '; - $options->para = false; - $definition = format_text('' . strip_tags($entry->definition) . '', $entry->format,$options); + echo ($definition); - echo ($definition); - - echo '

'; - } + echo '

'; } } diff --git a/mod/glossary/sql.php b/mod/glossary/sql.php index 822f6233a0..760634879d 100644 --- a/mod/glossary/sql.php +++ b/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"); + ?> diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 0cd1151fc5..16f451bd1b 100644 --- a/mod/glossary/view.php +++ b/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 = "" . $paging . ''; } - 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 '

'; + echo ''; + + echo ''; + $pivottoshow = $currentpivot; + if ( isset($entry->uid) ) { + // printing the user icon if defined (only when browsing authors) + echo '
'; + + $user = get_record("user","id",$entry->uid); + print_user_picture($user->id, $course->id, $user->picture); + $pivottoshow = fullname($user, isteacher($course->id));; + } else { + echo ''; } - } - } - /// 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 " $pivottoshow" ; + echo '
'; - /// 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 '

'; - echo ''; - - echo ''; - $pivottoshow = $currentpivot; - if ( isset($entry->uid) ) { - // printing the user icon if defined (only when browsing authors) - echo '
'; - - $user = get_record("user","id",$entry->uid); - print_user_picture($user->id, $course->id, $user->picture); - $pivottoshow = fullname($user, isteacher($course->id));; - } else { - echo ''; - } - - echo " $pivottoshow" ; - echo '
'; + $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 ) {