Skip to content

Commit

Permalink
MDL-28615 mod_forum: Fixed the users page that shows all of the users…
Browse files Browse the repository at this point in the history
… posts
  • Loading branch information
Sam Hemelryk committed Sep 29, 2011
1 parent 228d24f commit 4b71542
Show file tree
Hide file tree
Showing 5 changed files with 723 additions and 168 deletions.
58 changes: 57 additions & 1 deletion lib/enrollib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -263,6 +263,62 @@ function enrol_sharing_course($user1, $user2) {
return $DB->record_exists_sql($sql, $params); return $DB->record_exists_sql($sql, $params);
} }


/**
* Returns any courses shared by the two users
*
* The courses has to be visible and enrolments has to be active,
* timestart and timeend restrictions are ignored.
*
* @param stdClass|int $user1
* @param stdClass|int $user2
* @return array An array of courses that both users are enrolled in
*/
function enrol_get_shared_courses($user1, $user2, $preloadcontexts = false) {
global $DB, $CFG;

$user1 = !empty($user1->id) ? $user1->id : $user1;
$user2 = !empty($user2->id) ? $user2->id : $user2;

if (empty($user1) or empty($user2)) {
return false;
}

if (!$plugins = explode(',', $CFG->enrol_plugins_enabled)) {
return false;
}

list($plugins, $params) = $DB->get_in_or_equal($plugins, SQL_PARAMS_NAMED, 'ee');
$params['enabled'] = ENROL_INSTANCE_ENABLED;
$params['active1'] = ENROL_USER_ACTIVE;
$params['active2'] = ENROL_USER_ACTIVE;
$params['user1'] = $user1;
$params['user2'] = $user2;

$ctxselect = '';
$ctxjoin = '';
if ($preloadcontexts) {
list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
}

$sql = "SELECT c.* $ctxselect
FROM {course} c
JOIN (
SELECT DISTINCT c.id
FROM {enrol} e
JOIN {user_enrolments} ue1 ON (ue1.enrolid = e.id AND ue1.status = :active1 AND ue1.userid = :user1)
JOIN {user_enrolments} ue2 ON (ue2.enrolid = e.id AND ue2.status = :active2 AND ue2.userid = :user2)
JOIN {course} c ON (c.id = e.courseid AND c.visible = 1)
WHERE e.status = :enabled AND e.enrol $plugins
) ec ON ec.id = c.id
$ctxjoin";
$courses = $DB->get_records_sql($sql, $params);
if ($preloadcontexts) {
array_map('context_instance_preload', $courses);
}

return $courses;
}

/** /**
* This function adds necessary enrol plugins UI into the course edit form. * This function adds necessary enrol plugins UI into the course edit form.
* *
Expand Down Expand Up @@ -1566,4 +1622,4 @@ public function has_bulk_operations() {
public function get_bulk_operations() { public function get_bulk_operations() {
return array(); return array();
} }
} }
10 changes: 9 additions & 1 deletion mod/forum/lang/en/forum.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
$string['cannotunsubscribe'] = 'Could not unsubscribe you from that forum'; $string['cannotunsubscribe'] = 'Could not unsubscribe you from that forum';
$string['cannotupdatepost'] = 'You can not update this post'; $string['cannotupdatepost'] = 'You can not update this post';
$string['cannotviewpostyet'] = 'You cannot read other students questions in this discussion yet because you haven\'t posted'; $string['cannotviewpostyet'] = 'You cannot read other students questions in this discussion yet because you haven\'t posted';
$string['cannotviewusersposts'] = 'There are no posts made by this user that you are able to view.';
$string['cleanreadtime'] = 'Mark old posts as read hour'; $string['cleanreadtime'] = 'Mark old posts as read hour';
$string['completiondiscussions'] = 'Student must create discussions:'; $string['completiondiscussions'] = 'Student must create discussions:';
$string['completiondiscussionsgroup'] = 'Require discussions'; $string['completiondiscussionsgroup'] = 'Require discussions';
Expand Down Expand Up @@ -122,6 +123,7 @@
$string['discussions'] = 'Discussions'; $string['discussions'] = 'Discussions';
$string['discussionsstartedby'] = 'Discussions started by {$a}'; $string['discussionsstartedby'] = 'Discussions started by {$a}';
$string['discussionsstartedbyrecent'] = 'Discussions recently started by {$a}'; $string['discussionsstartedbyrecent'] = 'Discussions recently started by {$a}';
$string['discussionsstartedbyuserincourse'] = 'Discussions started by {$a->fullname} in {$a->coursename}';
$string['discussthistopic'] = 'Discuss this topic'; $string['discussthistopic'] = 'Discuss this topic';
$string['displayend'] = 'Display end'; $string['displayend'] = 'Display end';
$string['displayend_help'] = 'This setting specifies whether a forum post should be hidden after a certain date. Note that administrators can always view forum posts.'; $string['displayend_help'] = 'This setting specifies whether a forum post should be hidden after a certain date. Note that administrators can always view forum posts.';
Expand All @@ -136,6 +138,7 @@
$string['emptymessage'] = 'Something was wrong with your post. Perhaps you left it blank, or the attachment was too big. Your changes have NOT been saved.'; $string['emptymessage'] = 'Something was wrong with your post. Perhaps you left it blank, or the attachment was too big. Your changes have NOT been saved.';
$string['erroremptymessage'] = 'Post message cannot be empty'; $string['erroremptymessage'] = 'Post message cannot be empty';
$string['erroremptysubject'] = 'Post subject cannot be empty.'; $string['erroremptysubject'] = 'Post subject cannot be empty.';
$string['errorenrolmentrequired'] = 'You must be enrolled in this course to access this content';
$string['errorwhiledelete'] = 'An error occurred while deleting record.'; $string['errorwhiledelete'] = 'An error occurred while deleting record.';
$string['everyonecanchoose'] = 'Everyone can choose to be subscribed'; $string['everyonecanchoose'] = 'Everyone can choose to be subscribed';
$string['everyonecannowchoose'] = 'Everyone can now choose to be subscribed'; $string['everyonecannowchoose'] = 'Everyone can now choose to be subscribed';
Expand Down Expand Up @@ -240,7 +243,8 @@
$string['newforumposts'] = 'New forum posts'; $string['newforumposts'] = 'New forum posts';
$string['noattachments'] = 'There are no attachments to this post'; $string['noattachments'] = 'There are no attachments to this post';
$string['nodiscussions'] = 'There are no discussion topics yet in this forum'; $string['nodiscussions'] = 'There are no discussion topics yet in this forum';
$string['nodiscussionsstartedby'] = 'No discussions started by this user'; $string['nodiscussionsstartedby'] = '{$a} has not started any discussions';
$string['nodiscussionsstartedbyyou'] = 'You haven\'t started any discussions yet';
$string['noguestpost'] = 'Sorry, guests are not allowed to post.'; $string['noguestpost'] = 'Sorry, guests are not allowed to post.';
$string['noguesttracking'] = 'Sorry, guests are not allowed to set tracking options.'; $string['noguesttracking'] = 'Sorry, guests are not allowed to set tracking options.';
$string['nomorepostscontaining'] = 'No more posts containing \'{$a}\' were found'; $string['nomorepostscontaining'] = 'No more posts containing \'{$a}\' were found';
Expand All @@ -250,6 +254,8 @@
$string['nopermissiontoview'] = 'You do not have permissions to view this post'; $string['nopermissiontoview'] = 'You do not have permissions to view this post';
$string['nopostforum'] = 'Sorry, you are not allowed to post to this forum'; $string['nopostforum'] = 'Sorry, you are not allowed to post to this forum';
$string['noposts'] = 'No posts'; $string['noposts'] = 'No posts';
$string['nopostsmadebyuser'] = '{$a} has made no posts';
$string['nopostsmadebyyou'] = 'You haven\'t made any posts';
$string['nopostscontaining'] = 'No posts containing \'{$a}\' were found'; $string['nopostscontaining'] = 'No posts containing \'{$a}\' were found';
$string['noquestions'] = 'There are no questions yet in this forum'; $string['noquestions'] = 'There are no questions yet in this forum';
$string['nosubscribers'] = 'There are no subscribers yet for this forum'; $string['nosubscribers'] = 'There are no subscribers yet for this forum';
Expand Down Expand Up @@ -294,6 +300,8 @@
$string['postrating2'] = 'Separate and connected'; $string['postrating2'] = 'Separate and connected';
$string['postrating3'] = 'Mostly connected knowing'; $string['postrating3'] = 'Mostly connected knowing';
$string['posts'] = 'Posts'; $string['posts'] = 'Posts';
$string['postsmadebyuser'] = 'Posts made by {$a}';
$string['postsmadebyuserincourse'] = 'Posts made by {$a->fullname} in {$a->coursename}';
$string['posttoforum'] = 'Post to forum'; $string['posttoforum'] = 'Post to forum';
$string['postupdated'] = 'Your post was updated'; $string['postupdated'] = 'Your post was updated';
$string['potentialsubscribers'] = 'Potential subscribers'; $string['potentialsubscribers'] = 'Potential subscribers';
Expand Down
Loading

0 comments on commit 4b71542

Please sign in to comment.