Skip to content

Commit

Permalink
Merge branch 'wip-MDL-28615-m21-squashed' of git://github.com/samheme…
Browse files Browse the repository at this point in the history
…lryk/moodle into MOODLE_21_STABLE
  • Loading branch information
Aparup Banerjee committed Oct 5, 2011
2 parents f1ae261 + 82bd683 commit e153abc
Show file tree
Hide file tree
Showing 5 changed files with 722 additions and 173 deletions.
59 changes: 51 additions & 8 deletions lib/enrollib.php
Expand Up @@ -226,11 +226,35 @@ function enrol_check_plugins($user) {
* The courses has to be visible and enrolments has to be active,
* timestart and timeend restrictions are ignored.
*
* This function calls {@see enrol_get_shared_courses()} setting checkexistsonly
* to true.
*
* @param stdClass|int $user1
* @param stdClass|int $user2
* @return bool
*/
function enrol_sharing_course($user1, $user2) {
return enrol_get_shared_courses($user1, $user2, false, true);
}

/**
* 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.
*
* @global moodle_database $DB
* @param stdClass|int $user1
* @param stdClass|int $user2
* @param bool $preloadcontexts If set to true contexts for the returned courses
* will be preloaded.
* @param bool $checkexistsonly If set to true then this function will return true
* if the users share any courses and false if not.
* @return array|bool An array of courses that both users are enrolled in OR if
* $checkexistsonly set returns true if the users share any courses
* and false if not.
*/
function enrol_get_shared_courses($user1, $user2, $preloadcontexts = false, $checkexistsonly = false) {
global $DB, $CFG;

$user1 = !empty($user1->id) ? $user1->id : $user1;
Expand All @@ -251,14 +275,33 @@ function enrol_sharing_course($user1, $user2) {
$params['user1'] = $user1;
$params['user2'] = $user2;

$sql = "SELECT DISTINCT 'x'
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";
$ctxselect = '';
$ctxjoin = '';
if ($preloadcontexts) {
list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
}

return $DB->record_exists_sql($sql, $params);
$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";

if ($checkexistsonly) {
return $DB->record_exists_sql($sql, $params);
} else {
$courses = $DB->get_records_sql($sql, $params);
if ($preloadcontexts) {
array_map('context_instance_preload', $courses);
}
return $courses;
}
}

/**
Expand Down Expand Up @@ -1564,4 +1607,4 @@ public function has_bulk_operations() {
public function get_bulk_operations() {
return array();
}
}
}
10 changes: 9 additions & 1 deletion mod/forum/lang/en/forum.php
Expand Up @@ -73,6 +73,7 @@
$string['cannotunsubscribe'] = 'Could not unsubscribe you from that forum';
$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['cannotviewusersposts'] = 'There are no posts made by this user that you are able to view.';
$string['cleanreadtime'] = 'Mark old posts as read hour';
$string['completiondiscussions'] = 'Student must create discussions:';
$string['completiondiscussionsgroup'] = 'Require discussions';
Expand Down Expand Up @@ -122,6 +123,7 @@
$string['discussions'] = 'Discussions';
$string['discussionsstartedby'] = 'Discussions 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['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.';
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['erroremptymessage'] = 'Post message 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['everyonecanchoose'] = 'Everyone can 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['noattachments'] = 'There are no attachments to this post';
$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['noguesttracking'] = 'Sorry, guests are not allowed to set tracking options.';
$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['nopostforum'] = 'Sorry, you are not allowed to post to this forum';
$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['noquestions'] = 'There are no questions yet in 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['postrating3'] = 'Mostly connected knowing';
$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['postupdated'] = 'Your post was updated';
$string['potentialsubscribers'] = 'Potential subscribers';
Expand Down

0 comments on commit e153abc

Please sign in to comment.