@@ -98,10 +98,11 @@ class subscriptions {
98
98
*
99
99
* @return bool
100
100
*/
101
- public static function is_subscribed ($ userid , $ moodleoverflow , $ discussionid = null ) {
101
+ public static function is_subscribed ($ userid , $ moodleoverflow , $ context , $ discussionid = null ) {
102
102
103
103
// Is the user forced to be subscribed to the moodleoverflow?
104
- if (self ::is_forcesubscribed ($ moodleoverflow )) {
104
+ if (self ::is_forcesubscribed ($ moodleoverflow ) &&
105
+ has_capability ('mod/moodleoverflow:allowforcesubscribe ' , $ context , $ userid )) {
105
106
return true ;
106
107
}
107
108
@@ -539,13 +540,7 @@ public static function get_subscribed_users($moodleoverflow, $context, $fields =
539
540
u.picture, u.timezone, u.theme, u.lang, u.trackforums, u.mnethostid " ;
540
541
}
541
542
542
- // Check if the user is forced to e subscribed to a moodleoverflow.
543
- if (self ::is_forcesubscribed ($ moodleoverflow )) {
544
-
545
- // Find the list of potential subscribers.
546
- $ results = self ::get_potential_subscribers ($ context , $ fields , 'u.email ASC ' );
547
-
548
- } else if (self ::subscription_disabled ($ moodleoverflow )) {
543
+ if (self ::subscription_disabled ($ moodleoverflow )) {
549
544
$ results = [];
550
545
} else {
551
546
@@ -588,6 +583,12 @@ public static function get_subscribed_users($moodleoverflow, $context, $fields =
588
583
589
584
// Fetch the data.
590
585
$ results = $ DB ->get_records_sql ($ sql , $ params );
586
+
587
+ if (self ::is_forcesubscribed ($ moodleoverflow )) {
588
+ foreach (self ::get_potential_subscribers ($ context , $ fields , 'u.email ASC ' ) as $ id => $ user ) {
589
+ $ results [$ id ] = $ user ;
590
+ }
591
+ }
591
592
}
592
593
593
594
// Remove all guest users from the results. They should never be subscribed to a moodleoverflow.
@@ -647,7 +648,7 @@ public static function subscribe_user($userid, $moodleoverflow, $context, $userr
647
648
global $ DB ;
648
649
649
650
// Check if the user is already subscribed.
650
- if (self ::is_subscribed ($ userid , $ moodleoverflow )) {
651
+ if (self ::is_subscribed ($ userid , $ moodleoverflow, $ context )) {
651
652
return true ;
652
653
}
653
654
@@ -914,7 +915,7 @@ public static function unsubscribe_user_from_discussion($userid, $discussion, $c
914
915
* Generate and return the subscribe or unsubscribe link for a moodleoverflow.
915
916
*
916
917
* @param object $moodleoverflow the moodleoverflow. Fields used are $moodleoverflow->id and $moodleoverflow->forcesubscribe.
917
- * @param object $context the context object for this moodleoverflow.
918
+ * @param \context $context the context object for this moodleoverflow.
918
919
* @param array $messages text used for the link in its various states
919
920
* (subscribed, unsubscribed, forcesubscribed or cantsubscribe).
920
921
* Any strings not passed in are taken from the $defaultmessages array
@@ -953,7 +954,7 @@ public static function moodleoverflow_get_subscribe_link($moodleoverflow, $conte
953
954
}
954
955
955
956
// Check whether the user is subscribed.
956
- $ issubscribed = self ::is_subscribed ($ USER ->id , $ moodleoverflow );
957
+ $ issubscribed = self ::is_subscribed ($ USER ->id , $ moodleoverflow, $ context );
957
958
958
959
// Define the text of the link depending on the subscription state.
959
960
if ($ issubscribed ) {
@@ -984,7 +985,7 @@ public static function moodleoverflow_get_subscribe_link($moodleoverflow, $conte
984
985
* @param object $fromform The submitted form
985
986
* @param \stdClass $moodleoverflow The moodleoverflow record
986
987
* @param \stdClass $discussion The discussion record
987
- * @param \context_course $modulecontext The context of the module
988
+ * @param \context_module $modulecontext The context of the module
988
989
*
989
990
* @return bool
990
991
*/
@@ -996,15 +997,15 @@ public static function moodleoverflow_post_subscription($fromform, $moodleoverfl
996
997
$ disabled = self ::subscription_disabled ($ moodleoverflow );
997
998
998
999
// Do not continue if the user is already forced to be subscribed.
999
- if ($ force ) {
1000
+ if ($ force && has_capability ( ' mod/moodleoverflow:allowforcesubscribe ' , $ modulecontext ) ) {
1000
1001
return false ;
1001
1002
}
1002
1003
1003
1004
// Do not continue if subscriptions are disabled.
1004
1005
if ($ disabled ) {
1005
1006
1006
1007
// If the user is subscribed, unsubscribe him.
1007
- $ subscribed = self ::is_subscribed ($ USER ->id , $ moodleoverflow );
1008
+ $ subscribed = self ::is_subscribed ($ USER ->id , $ moodleoverflow, $ modulecontext );
1008
1009
$ coursecontext = \context_course::instance ($ moodleoverflow ->course );
1009
1010
$ canmanage = has_capability ('moodle/course:manageactivities ' , $ coursecontext , $ USER ->id );
1010
1011
if ($ subscribed AND !$ canmanage ) {
@@ -1025,18 +1026,19 @@ public static function moodleoverflow_post_subscription($fromform, $moodleoverfl
1025
1026
* Return the markup for the discussion subscription toggling icon.
1026
1027
*
1027
1028
* @param object $moodleoverflow The forum moodleoverflow.
1029
+ * @param \context $context
1028
1030
* @param int $discussionid The discussion to create an icon for.
1029
1031
*
1030
1032
* @return string The generated markup.
1031
1033
*/
1032
- public static function get_discussion_subscription_icon ($ moodleoverflow , $ discussionid ) {
1034
+ public static function get_discussion_subscription_icon ($ moodleoverflow , $ context , $ discussionid ) {
1033
1035
global $ OUTPUT , $ PAGE , $ USER ;
1034
1036
1035
1037
// Set the url to return to.
1036
1038
$ returnurl = $ PAGE ->url ->out ();
1037
1039
1038
1040
// Check if the discussion is subscrived.
1039
- $ status = self ::is_subscribed ($ USER ->id , $ moodleoverflow , $ discussionid );
1041
+ $ status = self ::is_subscribed ($ USER ->id , $ moodleoverflow , $ context , $ discussionid );
1040
1042
1041
1043
// Create a link to subscribe or unsubscribe to the discussion.
1042
1044
$ array = array (
0 commit comments