mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
Merge branch 'wip-MDL-34527-m24' of git://github.com/samhemelryk/moodle
This commit is contained in:
commit
2c333485c4
1 changed files with 29 additions and 19 deletions
|
@ -8079,29 +8079,37 @@ function forum_get_courses_user_posted_in($user, $discussionsonly = false, $incl
|
||||||
function forum_get_forums_user_posted_in($user, array $courseids = null, $discussionsonly = false, $limitfrom = null, $limitnum = null) {
|
function forum_get_forums_user_posted_in($user, array $courseids = null, $discussionsonly = false, $limitfrom = null, $limitnum = null) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$where = array("m.name = 'forum'");
|
|
||||||
$params = array();
|
|
||||||
if (!is_null($courseids)) {
|
if (!is_null($courseids)) {
|
||||||
list($coursewhere, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED, 'courseid');
|
list($coursewhere, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED, 'courseid');
|
||||||
$where[] = 'f.course '.$coursewhere;
|
$coursewhere = ' AND f.course '.$coursewhere;
|
||||||
}
|
|
||||||
if (!$discussionsonly) {
|
|
||||||
$joinsql = 'JOIN {forum_discussions} fd ON fd.forum = f.id
|
|
||||||
JOIN {forum_posts} fp ON fp.discussion = fd.id';
|
|
||||||
$where[] = 'fp.userid = :userid';
|
|
||||||
} else {
|
} else {
|
||||||
$joinsql = 'JOIN {forum_discussions} fd ON fd.forum = f.id';
|
$coursewhere = '';
|
||||||
$where[] = 'fd.userid = :userid';
|
$params = array();
|
||||||
}
|
}
|
||||||
$params['userid'] = $user->id;
|
$params['userid'] = $user->id;
|
||||||
$wheresql = join(' AND ', $where);
|
$params['forum'] = 'forum';
|
||||||
|
|
||||||
$sql = "SELECT DISTINCT f.*, cm.id AS cmid
|
if ($discussionsonly) {
|
||||||
FROM {forum} f
|
$join = 'JOIN {forum_discussions} ff ON ff.forum = f.id';
|
||||||
JOIN {course_modules} cm ON cm.instance = f.id
|
} else {
|
||||||
JOIN {modules} m ON m.id = cm.module
|
$join = 'JOIN {forum_discussions} fd ON fd.forum = f.id
|
||||||
$joinsql
|
JOIN {forum_posts} ff ON ff.discussion = fd.id';
|
||||||
WHERE $wheresql";
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT f.*, cm.id AS cmid
|
||||||
|
FROM {forum} f
|
||||||
|
JOIN {course_modules} cm ON cm.instance = f.id
|
||||||
|
JOIN {modules} m ON m.id = cm.module
|
||||||
|
JOIN (
|
||||||
|
SELECT f.id
|
||||||
|
FROM {forum} f
|
||||||
|
{$join}
|
||||||
|
WHERE ff.userid = :userid
|
||||||
|
GROUP BY f.id
|
||||||
|
) j ON j.id = f.id
|
||||||
|
WHERE m.name = :forum
|
||||||
|
{$coursewhere}";
|
||||||
|
|
||||||
$courseforums = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
|
$courseforums = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
|
||||||
return $courseforums;
|
return $courseforums;
|
||||||
}
|
}
|
||||||
|
@ -8356,8 +8364,10 @@ function forum_get_posts_by_user($user, array $courses, $musthaveaccess = false,
|
||||||
$forumsearchwhere[] = "(d.forum $fullidsql)";
|
$forumsearchwhere[] = "(d.forum $fullidsql)";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare SQL to both count and search
|
// Prepare SQL to both count and search.
|
||||||
$userfields = user_picture::fields('u', null, 'userid');
|
// We alias user.id to useridx because we forum_posts already has a userid field and not aliasing this would break
|
||||||
|
// oracle and mssql.
|
||||||
|
$userfields = user_picture::fields('u', null, 'useridx');
|
||||||
$countsql = 'SELECT COUNT(*) ';
|
$countsql = 'SELECT COUNT(*) ';
|
||||||
$selectsql = 'SELECT p.*, d.forum, d.name AS discussionname, '.$userfields.' ';
|
$selectsql = 'SELECT p.*, d.forum, d.name AS discussionname, '.$userfields.' ';
|
||||||
$wheresql = implode(" OR ", $forumsearchwhere);
|
$wheresql = implode(" OR ", $forumsearchwhere);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue