]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14018 fixed ##more## icon regression, thanks Robert Allerstorfer for all the...
authorskodak <skodak>
Sat, 19 Apr 2008 21:02:10 +0000 (21:02 +0000)
committerskodak <skodak>
Sat, 19 Apr 2008 21:02:10 +0000 (21:02 +0000)
mod/data/view.php

index e67ede258d874b8c824638b1fe348398f85401be..acdeb0593ed54be3c65632adfb050dfded8d5340 100755 (executable)
 
             $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname';
             $count = ' COUNT(DISTINCT c.recordid) ';
-            $rids  = ' DISTINCT c.recordid ';
             $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content cs, '.$CFG->prefix.'user u ';
             $where =  'WHERE c.recordid = r.id
                          AND r.dataid = '.$data->id.'
 
             $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname, c.'.$sortcontent.', '.$sortcontentfull.' AS _order ';
             $count = ' COUNT(DISTINCT c.recordid) ';
-            $rids  = ' DISTINCT c.recordid ';
             $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content cs, '.$CFG->prefix.'user u ';
             $where =  'WHERE c.recordid = r.id
                          AND c.fieldid = '.$sort.'
         } else if ($search) {
             $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
             $count = ' COUNT(DISTINCT c.recordid) ';
-            $rids  = ' DISTINCT c.recordid ';
             $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
             $where =  'WHERE c.recordid = r.id
                          AND r.userid = u.id
         } else {
             $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
             $count = ' COUNT(r.id) ';
-            $rids  = ' COUNT(r.id) ';
             $tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
             $where =  'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id ';
             $sortorder = ' ORDER BY r.timecreated '.$order. ' ';
         $fromsql    = "FROM $tables $where $groupselect $approveselect $searchselect";
         $sqlselect  = "SELECT $what $fromsql $sortorder";
         $sqlcount   = "SELECT $count $fromsql";   // Total number of records when searching
-        $sqlrids    = "SELECT $rids $fromsql";
+        $sqlrids    = "SELECT tmp.id FROM ($sqlselect) tmp";
         $sqlmax     = "SELECT $count FROM $tables $where $groupselect $approveselect"; // number of all recoirds user may see
 
     /// Work out the paging numbers and counts
             $mode = 'single';
 
             $page = 0;
-            if ($allrecords = get_records_sql($sqlrids)) {      // Kludgey but accurate at least!          
-                foreach ($allrecords as $key => $unused) {
-                    if ($key == $record->id) {
-                        break;
-                    }
-                    $page++;
-                }
-                unset($allrecords);
+            if ($allrecordids = get_records_sql($sqlrids)) {
+                $allrecordids = array_keys($allrecordids);
+                $page = (int)array_search($record->id, $allrecordids);
+                unset($allrecordids);
             }
 
         } else if ($mode == 'single') {  // We rely on ambient $page settings