Merge branch 'MDL-41191-duplicaterecords' of git://github.com/danpoltawski/moodle
This commit is contained in:
+11
-10
@@ -8104,16 +8104,18 @@ function forum_get_courses_user_posted_in($user, $discussionsonly = false, $incl
|
||||
// table and join to the userid there. If we are looking for posts then we need
|
||||
// to join to the forum_posts table.
|
||||
if (!$discussionsonly) {
|
||||
$joinsql = 'JOIN {forum_discussions} fd ON fd.course = c.id
|
||||
JOIN {forum_posts} fp ON fp.discussion = fd.id';
|
||||
$wheresql = 'fp.userid = :userid';
|
||||
$params = array('userid' => $user->id);
|
||||
$subquery = "(SELECT DISTINCT fd.course
|
||||
FROM {forum_discussions} fd
|
||||
JOIN {forum_posts} fp ON fp.discussion = fd.id
|
||||
WHERE fp.userid = :userid )";
|
||||
} else {
|
||||
$joinsql = 'JOIN {forum_discussions} fd ON fd.course = c.id';
|
||||
$wheresql = 'fd.userid = :userid';
|
||||
$params = array('userid' => $user->id);
|
||||
$subquery= "(SELECT DISTINCT fd.course
|
||||
FROM {forum_discussions} fd
|
||||
WHERE fd.userid = :userid )";
|
||||
}
|
||||
|
||||
$params = array('userid' => $user->id);
|
||||
|
||||
// Join to the context table so that we can preload contexts if required.
|
||||
if ($includecontexts) {
|
||||
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||
@@ -8126,11 +8128,10 @@ function forum_get_courses_user_posted_in($user, $discussionsonly = false, $incl
|
||||
|
||||
// Now we need to get all of the courses to search.
|
||||
// All courses where the user has posted within a forum will be returned.
|
||||
$sql = "SELECT DISTINCT c.* $ctxselect
|
||||
$sql = "SELECT c.* $ctxselect
|
||||
FROM {course} c
|
||||
$joinsql
|
||||
$ctxjoin
|
||||
WHERE $wheresql";
|
||||
WHERE c.id IN ($subquery)";
|
||||
$courses = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
|
||||
if ($includecontexts) {
|
||||
array_map('context_helper::preload_from_record', $courses);
|
||||
|
||||
@@ -99,13 +99,25 @@ class mod_forum_lib_testcase extends advanced_testcase {
|
||||
$record->course = $course3->id;
|
||||
$forum3 = $this->getDataGenerator()->create_module('forum', $record);
|
||||
|
||||
// Add discussions to course 1 and 2 started by user1.
|
||||
// Add a second forum in course 1.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$forum4 = $this->getDataGenerator()->create_module('forum', $record);
|
||||
|
||||
// Add discussions to course 1 started by user1.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $user1->id;
|
||||
$record->forum = $forum1->id;
|
||||
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $user1->id;
|
||||
$record->forum = $forum4->id;
|
||||
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
// Add discussions to course2 started by user1.
|
||||
$record = new stdClass();
|
||||
$record->course = $course2->id;
|
||||
$record->userid = $user1->id;
|
||||
|
||||
Reference in New Issue
Block a user