]> git.mjollnir.org Git - moodle.git/commitdiff
search MDL-19822 Upgraded deprecated calls and added set_url calls
authorsamhemelryk <samhemelryk>
Thu, 15 Oct 2009 07:37:29 +0000 (07:37 +0000)
committersamhemelryk <samhemelryk>
Thu, 15 Oct 2009 07:37:29 +0000 (07:37 +0000)
search/documents/chat_document.php
search/documents/data_document.php
search/documents/forum_document.php
search/documents/lesson_document.php
search/documents/wiki_document.php
search/indexersplash.php
search/query.php
search/querylib.php
search/stats.php

index dd8962242b062ae2dc4536b22c351d82e79d2bf2..1296b6a3c353072e5e16bbd080aaa66ba2863f2a 100644 (file)
@@ -77,7 +77,7 @@ function chat_make_link($cm_id, $start, $end) {
 /**
 * fetches all the records for a given session and assemble them as a unique track
 * we revamped here the code of report.php for making sessions, but without any output.
-* note that we should collect sessions "by groups" if groupmode() is SEPARATEGROUPS.
+* note that we should collect sessions "by groups" if $groupmode is SEPARATEGROUPS.
 * @param int $chat_id the database
 * @param int $fromtime
 * @param int $totime
@@ -91,7 +91,11 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
     $course = $DB->get_record('course', array('id' => $chat->course));
     $coursemodule = $DB->get_field('modules', 'id', array('name' => 'data'));
     $cm = $DB->get_record('course_modules', array('course' => $course->id, 'module' => $coursemodule, 'instance' => $chat->id));
-    $groupmode = groupmode($course, $cm);
+    if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
+        $groupmode =  $cm->groupmode;
+    } else {
+        $groupmode = $course->groupmode;
+    }
 
     $fromtimeclause = ($fromtime) ? "AND timestamp >= {$fromtime}" : ''; 
     $totimeclause = ($totime) ? "AND timestamp <= {$totime}" : ''; 
@@ -283,7 +287,12 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
     //group consistency check : checks the following situations about groups
     // trap if user is not same group and groups are separated
     $course = $DB->get_record('course', array('id' => $chat->course));
-    if ((groupmode($course, $cm) == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){ 
+    if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
+        $groupmode =  $cm->groupmode;
+    } else {
+        $groupmode = $course->groupmode;
+    }
+    if (($groupmode == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){
         if (!empty($CFG->search_access_debug)) echo "search reject : chat element is in separated group ";
         return false;
     }
index 8fafd52233f9420e4750ac2699e4cc720b2f778c..236a672f9e80e60098fa031f69a0ecf368f2e98f 100644 (file)
@@ -371,7 +371,12 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
     //group consistency check : checks the following situations about groups
     // trap if user is not same group and groups are separated
     $course = $DB->get_record('course', 'id', $data->course);
-    if ((groupmode($course, $cm) == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){ 
+    if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
+        $groupmode =  $cm->groupmode;
+    } else {
+        $groupmode = $course->groupmode;
+    }
+    if (($groupmode == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){
         if (!empty($CFG->search_access_debug)) echo "search reject : separated group owned resource ";
         return false;
     }
index 8e5c939c009e215d8a5435746acf64fa29db2828..adfa6a5f027df078b61531a2d84558aceee1c87b 100644 (file)
@@ -177,15 +177,25 @@ function forum_db_names() {
 * @param int $forum_id a forum identifier
 * @uses $CFG, $USER, $DB
 * @return an array of posts
-* @todo get rid of old isteacher() call
 */
 function forum_get_discussions_fast($forum_id) {
     global $CFG, $USER, $DB;
     
     $timelimit='';
     if (!empty($CFG->forum_enabletimedposts)) {
-        if (!((has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))
-          && !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) {
+
+        $courseid = $DB->get_field('forum', 'course', array('id'=>$forum_id));
+
+        if ($courseid) {
+            $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
+            $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+        } else {
+            $coursecontext = get_context_instance(CONTEXT_SYSTEM);
+            $systemcontext = $coursecontext;
+        }
+
+        if (!((has_capability('moodle/site:doanything', $systemcontext) && !empty($CFG->admineditalways))
+                || has_any_capability(array('moodle/legacy:teacher', 'moodle/legacy:editingteacher', 'moodle/legacy:admin'), $coursecontext, $userid, false))) {
             $now = time();
             $timelimit = " AND ((d.timestart = 0 OR d.timestart <= '$now') AND (d.timeend = 0 OR d.timeend > '$now')";
             if (!empty($USER->id)) {
@@ -283,7 +293,7 @@ function forum_get_child_posts_fast($parent, $forum_id) {
 * @return true if access is allowed, false elsewhere
 */
 function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
-    global $CFG, $USER, $DB;
+    global $CFG, $USER, $DB, $SESSION;
     
     include_once("{$CFG->dirroot}/{$path}/lib.php");
 
@@ -307,9 +317,25 @@ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $
     }
 
     // group check : entries should be in accessible groups
-    $current_group = get_current_group($discussion->course);
+    if (isset($SESSION->currentgroup[$discussion->course])) {
+        $current_group =  $SESSION->currentgroup[$discussion->course];
+    } else {
+        $current_group = groups_get_all_groups($discussion->course, $USER->id);
+        if (is_array($current_group)) {
+            $current_group = array_shift(array_keys($current_group));
+            $SESSION->currentgroup[$discussion->course] = $current_group;
+        } else {
+            $current_group = 0;
+        }
+    }
+
     $course = $DB->get_record('course', array('id' => $discussion->course));
-    if ($group_id >= 0 && (groupmode($course, $cm)  == SEPARATEGROUPS) && ($group_id != $current_group) && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context)){
+    if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
+        $groupmode =  $cm->groupmode;
+    } else {
+        $groupmode = $course->groupmode;
+    }
+    if ($group_id >= 0 && ($groupmode  == SEPARATEGROUPS) && ($group_id != $current_group) && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context)){
         if (!empty($CFG->search_access_debug)) echo "search reject : separated grouped forum item";
         return false;
     }
index 54759a942802ae43f341359ffd4b81d491cf5a93..f1c105bbcd760b6659109caeadb427c5bd357440 100644 (file)
@@ -203,7 +203,8 @@ function lesson_check_text_access($path, $itemtype, $this_id, $user, $group_id,
     }
     
     // the user have it seen yet ? did he tried one time at least
-    $attempt = get_record('lesson_attempts', 'lessonid', $lesson->id, 'pageid', $page->id, 'userid', $USER->id);
+    $attempt = $DB->get_record('lesson_attempts', array('lessonid'=>$lesson->id,'pageid'=>$page->id, 'userid'=>$USER->id));
+
     if (!$attempt && !$lessonsuperuser){
         if (!empty($CFG->search_access_debug)) echo "search reject : never tried this lesson ";
         return false;
index 5e4f36c169609e37e5fb9c4122156c7c3fa55e4b..02c7628a2393bec72c6d7ca23988046cc73da9fe 100644 (file)
@@ -257,7 +257,7 @@ function wiki_db_names() {
 * @return true if access is allowed, false elsewhere
 */
 function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
-    global $CFG, $DB;
+    global $CFG, $DB, $SESSION;
     
     // get the wiki object and all related stuff
     $page = $DB->get_record('wiki_pages', array('id' => $this_id));
@@ -275,8 +275,24 @@ function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
     
     //group consistency check : checks the following situations about groups
     // trap if user is not same group and groups are separated
-    $current_group = get_current_group($course->id);
-    if ((groupmode($course) == SEPARATEGROUPS) && $group_id != $current_group && !has_capability('moodle/site:accessallgroups', $context)) {
+    if (isset($SESSION->currentgroup[$course->id])) {
+        $current_group =  $SESSION->currentgroup[$course->id];
+    } else {
+        $current_group = groups_get_all_groups($course->id, $USER->id);
+        if (is_array($current_group)) {
+            $current_group = array_shift(array_keys($current_group));
+            $SESSION->currentgroup[$course->id] = $current_group;
+        } else {
+            $current_group = 0;
+        }
+    }
+
+    if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
+        $groupmode =  $cm->groupmode;
+    } else {
+        $groupmode = $course->groupmode;
+    }
+    if (($groupmode == SEPARATEGROUPS) && $group_id != $current_group && !has_capability('moodle/site:accessallgroups', $context)) {
         if (!empty($CFG->search_access_debug)) echo "search reject : separated group owner wiki ";
         return false;
     }
index 94c8c296202d670e75b83b99e192684ecf918bde..c2715d7031c27fb6f7ac5b057692d6ec44c31f93 100644 (file)
@@ -47,6 +47,7 @@
         // print page header
         $site = get_site();
 
+        $PAGE->set_url(new moodle_url($CFG->wwwroot.'/search/indexersplash.php'));
         $PAGE->navbar->add($strsearch, new moodle_url($CFG->wwwroot.'/search/index.php'));
         $PAGE->navbar->add($strquery, new moodle_url($CFG->wwwroot.'/search/stats.php'));
         $PAGE->navbar->add(get_string('runindexer','search'));
index 6182fd169776ae058e2eea3879d2cbf94a81e65d..1c95442b3473924891185b359539a070f3cd0c03 100644 (file)
     $advanced     = (optional_param('a', '0', PARAM_INT) == '1') ? true : false;
     $query_string = stripslashes(optional_param('query_string', '', PARAM_CLEAN));
 
+    $url = new moodle_url($CFG->wwwroot.'/search/query.php');
+    if ($page_number !== -1) {
+        $url->param('page', $page_number);
+    }
+    if ($advanced) {
+        $url->param('a', '1');
+    }
+    $PAGE->set_url($url);
+
 /// discard harmfull searches
 
     if (!isset($CFG->block_search_utf8dir)){
index c5f4e318f086b24c8293fe6a7510f2761f8bb2c0..0899b5ed07e98d6919042bbad0129604c60fb368 100644 (file)
@@ -402,7 +402,7 @@ class SearchQuery {
         $unenroled = !in_array($course_id, array_keys($myCourses));
         
         // if guests are allowed, logged guest can see
-        $isallowedguest = (isguest()) ? $DB->get_field('course', 'guest', array('id' => $course_id)) : false ;
+        $isallowedguest = (isguestuser()) ? $DB->get_field('course', 'guest', array('id' => $course_id)) : false ;
         
         if ($unenroled && !$isallowedguest){
             return false;
index 88bc62c17c6aa1a21eed5a30ad1381e2472ff173..1f84c950ca554f77926ecbcd9b2deb41b6f9e822 100644 (file)
@@ -46,6 +46,7 @@ require_once($CFG->dirroot.'/search/lib.php');
 
     $site = get_site();
 
+    $PAGE->set_url($CFG->wwwroot.'/search/stats.php');
     $PAGE->navbar->add($strsearch, new moodle_url($CFG->wwwroot.'/search/index.php'));
     $PAGE->navbar->add($strquery, new moodle_url($CFG->wwwroot.'/search/stats.php'));
     $PAGE->set_title($strsearch);
@@ -125,7 +126,6 @@ require_once($CFG->dirroot.'/search/lib.php');
 
         echo $OUTPUT->table($admin_table);
         echo $OUTPUT->spacer($spacer) . '<br />';
-        print_spacer(20);
     }
 
 /// this is the standard summary table for normal users, shows document counts