MDL-49682 mod_forum: Build forum email templates
[moodle.git] / mod / forum / deprecatedlib.php
blob3be31b986e7519ca3eafa1fac3516ab41d2fd303
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * @package mod_forum
19 * @copyright 2014 Andrew Robert Nicols <andrew@nicols.co.uk>
20 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 defined('MOODLE_INTERNAL') || die();
25 // Deprecated a very long time ago.
27 /**
28 * How many posts by other users are unrated by a given user in the given discussion?
30 * @param int $discussionid
31 * @param int $userid
32 * @return mixed
33 * @deprecated since Moodle 1.1 - please do not use this function any more.
35 function forum_count_unrated_posts($discussionid, $userid) {
36 global $CFG, $DB;
37 debugging('forum_count_unrated_posts() is deprecated and will not be replaced.', DEBUG_DEVELOPER);
39 $sql = "SELECT COUNT(*) as num
40 FROM {forum_posts}
41 WHERE parent > 0
42 AND discussion = :discussionid
43 AND userid <> :userid";
44 $params = array('discussionid' => $discussionid, 'userid' => $userid);
45 $posts = $DB->get_record_sql($sql, $params);
46 if ($posts) {
47 $sql = "SELECT count(*) as num
48 FROM {forum_posts} p,
49 {rating} r
50 WHERE p.discussion = :discussionid AND
51 p.id = r.itemid AND
52 r.userid = userid AND
53 r.component = 'mod_forum' AND
54 r.ratingarea = 'post'";
55 $rated = $DB->get_record_sql($sql, $params);
56 if ($rated) {
57 if ($posts->num > $rated->num) {
58 return $posts->num - $rated->num;
59 } else {
60 return 0; // Just in case there was a counting error
62 } else {
63 return $posts->num;
65 } else {
66 return 0;
71 // Since Moodle 1.5.
73 /**
74 * Returns the count of records for the provided user and discussion.
76 * @global object
77 * @global object
78 * @param int $userid
79 * @param int $discussionid
80 * @return bool
81 * @deprecated since Moodle 1.5 - please do not use this function any more.
83 function forum_tp_count_discussion_read_records($userid, $discussionid) {
84 debugging('forum_tp_count_discussion_read_records() is deprecated and will not be replaced.', DEBUG_DEVELOPER);
86 global $CFG, $DB;
88 $cutoffdate = isset($CFG->forum_oldpostdays) ? (time() - ($CFG->forum_oldpostdays*24*60*60)) : 0;
90 $sql = 'SELECT COUNT(DISTINCT p.id) '.
91 'FROM {forum_discussions} d '.
92 'LEFT JOIN {forum_read} r ON d.id = r.discussionid AND r.userid = ? '.
93 'LEFT JOIN {forum_posts} p ON p.discussion = d.id '.
94 'AND (p.modified < ? OR p.id = r.postid) '.
95 'WHERE d.id = ? ';
97 return ($DB->count_records_sql($sql, array($userid, $cutoffdate, $discussionid)));
101 * Get all discussions started by a particular user in a course (or group)
103 * @global object
104 * @global object
105 * @param int $courseid
106 * @param int $userid
107 * @param int $groupid
108 * @return array
109 * @deprecated since Moodle 1.5 - please do not use this function any more.
111 function forum_get_user_discussions($courseid, $userid, $groupid=0) {
112 debugging('forum_get_user_discussions() is deprecated and will not be replaced.', DEBUG_DEVELOPER);
114 global $CFG, $DB;
115 $params = array($courseid, $userid);
116 if ($groupid) {
117 $groupselect = " AND d.groupid = ? ";
118 $params[] = $groupid;
119 } else {
120 $groupselect = "";
123 $allnames = get_all_user_name_fields(true, 'u');
124 return $DB->get_records_sql("SELECT p.*, d.groupid, $allnames, u.email, u.picture, u.imagealt,
125 f.type as forumtype, f.name as forumname, f.id as forumid
126 FROM {forum_discussions} d,
127 {forum_posts} p,
128 {user} u,
129 {forum} f
130 WHERE d.course = ?
131 AND p.discussion = d.id
132 AND p.parent = 0
133 AND p.userid = u.id
134 AND u.id = ?
135 AND d.forum = f.id $groupselect
136 ORDER BY p.created DESC", $params);
140 // Since Moodle 1.6.
143 * Returns the count of posts for the provided forum and [optionally] group.
144 * @global object
145 * @global object
146 * @param int $forumid
147 * @param int|bool $groupid
148 * @return int
149 * @deprecated since Moodle 1.6 - please do not use this function any more.
151 function forum_tp_count_forum_posts($forumid, $groupid=false) {
152 debugging('forum_tp_count_forum_posts() is deprecated and will not be replaced.', DEBUG_DEVELOPER);
154 global $CFG, $DB;
155 $params = array($forumid);
156 $sql = 'SELECT COUNT(*) '.
157 'FROM {forum_posts} fp,{forum_discussions} fd '.
158 'WHERE fd.forum = ? AND fp.discussion = fd.id';
159 if ($groupid !== false) {
160 $sql .= ' AND (fd.groupid = ? OR fd.groupid = -1)';
161 $params[] = $groupid;
163 $count = $DB->count_records_sql($sql, $params);
166 return $count;
170 * Returns the count of records for the provided user and forum and [optionally] group.
171 * @global object
172 * @global object
173 * @param int $userid
174 * @param int $forumid
175 * @param int|bool $groupid
176 * @return int
177 * @deprecated since Moodle 1.6 - please do not use this function any more.
179 function forum_tp_count_forum_read_records($userid, $forumid, $groupid=false) {
180 debugging('forum_tp_count_forum_read_records() is deprecated and will not be replaced.', DEBUG_DEVELOPER);
182 global $CFG, $DB;
184 $cutoffdate = time() - ($CFG->forum_oldpostdays*24*60*60);
186 $groupsel = '';
187 $params = array($userid, $forumid, $cutoffdate);
188 if ($groupid !== false) {
189 $groupsel = "AND (d.groupid = ? OR d.groupid = -1)";
190 $params[] = $groupid;
193 $sql = "SELECT COUNT(p.id)
194 FROM {forum_posts} p
195 JOIN {forum_discussions} d ON d.id = p.discussion
196 LEFT JOIN {forum_read} r ON (r.postid = p.id AND r.userid= ?)
197 WHERE d.forum = ?
198 AND (p.modified < $cutoffdate OR (p.modified >= ? AND r.id IS NOT NULL))
199 $groupsel";
201 return $DB->get_field_sql($sql, $params);
205 // Since Moodle 1.7.
208 * Returns array of forum open modes.
210 * @return array
211 * @deprecated since Moodle 1.7 - please do not use this function any more.
213 function forum_get_open_modes() {
214 debugging('forum_get_open_modes() is deprecated and will not be replaced.', DEBUG_DEVELOPER);
215 return array();
219 // Since Moodle 1.9.
222 * Gets posts with all info ready for forum_print_post
223 * We pass forumid in because we always know it so no need to make a
224 * complicated join to find it out.
226 * @global object
227 * @global object
228 * @param int $parent
229 * @param int $forumid
230 * @return array
231 * @deprecated since Moodle 1.9 MDL-13303 - please do not use this function any more.
233 function forum_get_child_posts($parent, $forumid) {
234 debugging('forum_get_child_posts() is deprecated.', DEBUG_DEVELOPER);
236 global $CFG, $DB;
238 $allnames = get_all_user_name_fields(true, 'u');
239 return $DB->get_records_sql("SELECT p.*, $forumid AS forum, $allnames, u.email, u.picture, u.imagealt
240 FROM {forum_posts} p
241 LEFT JOIN {user} u ON p.userid = u.id
242 WHERE p.parent = ?
243 ORDER BY p.created ASC", array($parent));
247 * Gets posts with all info ready for forum_print_post
248 * We pass forumid in because we always know it so no need to make a
249 * complicated join to find it out.
251 * @global object
252 * @global object
253 * @return mixed array of posts or false
254 * @deprecated since Moodle 1.9 MDL-13303 - please do not use this function any more.
256 function forum_get_discussion_posts($discussion, $sort, $forumid) {
257 debugging('forum_get_discussion_posts() is deprecated.', DEBUG_DEVELOPER);
259 global $CFG, $DB;
261 $allnames = get_all_user_name_fields(true, 'u');
262 return $DB->get_records_sql("SELECT p.*, $forumid AS forum, $allnames, u.email, u.picture, u.imagealt
263 FROM {forum_posts} p
264 LEFT JOIN {user} u ON p.userid = u.id
265 WHERE p.discussion = ?
266 AND p.parent > 0 $sort", array($discussion));
270 // Since Moodle 2.0.
273 * Returns a list of ratings for a particular post - sorted.
275 * @param stdClass $context
276 * @param int $postid
277 * @param string $sort
278 * @return array Array of ratings or false
279 * @deprecated since Moodle 2.0 MDL-21657 - please do not use this function any more.
281 function forum_get_ratings($context, $postid, $sort = "u.firstname ASC") {
282 debugging('forum_get_ratings() is deprecated.', DEBUG_DEVELOPER);
283 $options = new stdClass;
284 $options->context = $context;
285 $options->component = 'mod_forum';
286 $options->ratingarea = 'post';
287 $options->itemid = $postid;
288 $options->sort = "ORDER BY $sort";
290 $rm = new rating_manager();
291 return $rm->get_all_ratings_for_item($options);
295 * Generate and return the track or no track link for a forum.
297 * @global object
298 * @global object
299 * @global object
300 * @param object $forum the forum. Fields used are $forum->id and $forum->forcesubscribe.
301 * @param array $messages
302 * @param bool $fakelink
303 * @return string
304 * @deprecated since Moodle 2.0 MDL-14632 - please do not use this function any more.
306 function forum_get_tracking_link($forum, $messages=array(), $fakelink=true) {
307 debugging('forum_get_tracking_link() is deprecated.', DEBUG_DEVELOPER);
309 global $CFG, $USER, $PAGE, $OUTPUT;
311 static $strnotrackforum, $strtrackforum;
313 if (isset($messages['trackforum'])) {
314 $strtrackforum = $messages['trackforum'];
316 if (isset($messages['notrackforum'])) {
317 $strnotrackforum = $messages['notrackforum'];
319 if (empty($strtrackforum)) {
320 $strtrackforum = get_string('trackforum', 'forum');
322 if (empty($strnotrackforum)) {
323 $strnotrackforum = get_string('notrackforum', 'forum');
326 if (forum_tp_is_tracked($forum)) {
327 $linktitle = $strnotrackforum;
328 $linktext = $strnotrackforum;
329 } else {
330 $linktitle = $strtrackforum;
331 $linktext = $strtrackforum;
334 $link = '';
335 if ($fakelink) {
336 $PAGE->requires->js('/mod/forum/forum.js');
337 $PAGE->requires->js_function_call('forum_produce_tracking_link', Array($forum->id, $linktext, $linktitle));
338 // use <noscript> to print button in case javascript is not enabled
339 $link .= '<noscript>';
341 $url = new moodle_url('/mod/forum/settracking.php', array(
342 'id' => $forum->id,
343 'sesskey' => sesskey(),
345 $link .= $OUTPUT->single_button($url, $linktext, 'get', array('title'=>$linktitle));
347 if ($fakelink) {
348 $link .= '</noscript>';
351 return $link;
355 * Returns the count of records for the provided user and discussion.
357 * @global object
358 * @global object
359 * @param int $userid
360 * @param int $discussionid
361 * @return int
362 * @deprecated since Moodle 2.0 MDL-14113 - please do not use this function any more.
364 function forum_tp_count_discussion_unread_posts($userid, $discussionid) {
365 debugging('forum_tp_count_discussion_unread_posts() is deprecated.', DEBUG_DEVELOPER);
366 global $CFG, $DB;
368 $cutoffdate = isset($CFG->forum_oldpostdays) ? (time() - ($CFG->forum_oldpostdays*24*60*60)) : 0;
370 $sql = 'SELECT COUNT(p.id) '.
371 'FROM {forum_posts} p '.
372 'LEFT JOIN {forum_read} r ON r.postid = p.id AND r.userid = ? '.
373 'WHERE p.discussion = ? '.
374 'AND p.modified >= ? AND r.id is NULL';
376 return $DB->count_records_sql($sql, array($userid, $discussionid, $cutoffdate));
380 * Converts a forum to use the Roles System
382 * @deprecated since Moodle 2.0 MDL-23479 - please do not use this function any more.
384 function forum_convert_to_roles() {
385 debugging('forum_convert_to_roles() is deprecated and will not be replaced.', DEBUG_DEVELOPER);
389 * Returns all records in the 'forum_read' table matching the passed keys, indexed
390 * by userid.
392 * @global object
393 * @param int $userid
394 * @param int $postid
395 * @param int $discussionid
396 * @param int $forumid
397 * @return array
398 * @deprecated since Moodle 2.0 MDL-14113 - please do not use this function any more.
400 function forum_tp_get_read_records($userid=-1, $postid=-1, $discussionid=-1, $forumid=-1) {
401 debugging('forum_tp_get_read_records() is deprecated and will not be replaced.', DEBUG_DEVELOPER);
403 global $DB;
404 $select = '';
405 $params = array();
407 if ($userid > -1) {
408 if ($select != '') $select .= ' AND ';
409 $select .= 'userid = ?';
410 $params[] = $userid;
412 if ($postid > -1) {
413 if ($select != '') $select .= ' AND ';
414 $select .= 'postid = ?';
415 $params[] = $postid;
417 if ($discussionid > -1) {
418 if ($select != '') $select .= ' AND ';
419 $select .= 'discussionid = ?';
420 $params[] = $discussionid;
422 if ($forumid > -1) {
423 if ($select != '') $select .= ' AND ';
424 $select .= 'forumid = ?';
425 $params[] = $forumid;
428 return $DB->get_records_select('forum_read', $select, $params);
432 * Returns all read records for the provided user and discussion, indexed by postid.
434 * @global object
435 * @param inti $userid
436 * @param int $discussionid
437 * @deprecated since Moodle 2.0 MDL-14113 - please do not use this function any more.
439 function forum_tp_get_discussion_read_records($userid, $discussionid) {
440 debugging('forum_tp_get_discussion_read_records() is deprecated and will not be replaced.', DEBUG_DEVELOPER);
442 global $DB;
443 $select = 'userid = ? AND discussionid = ?';
444 $fields = 'postid, firstread, lastread';
445 return $DB->get_records_select('forum_read', $select, array($userid, $discussionid), '', $fields);
448 // Deprecated in 2.3.
451 * This function gets run whenever user is enrolled into course
453 * @deprecated since Moodle 2.3 MDL-33166 - please do not use this function any more.
454 * @param stdClass $cp
455 * @return void
457 function forum_user_enrolled($cp) {
458 debugging('forum_user_enrolled() is deprecated. Please use forum_user_role_assigned instead.', DEBUG_DEVELOPER);
459 global $DB;
461 // NOTE: this has to be as fast as possible - we do not want to slow down enrolments!
462 // Originally there used to be 'mod/forum:initialsubscriptions' which was
463 // introduced because we did not have enrolment information in earlier versions...
465 $sql = "SELECT f.id
466 FROM {forum} f
467 LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)
468 WHERE f.course = :courseid AND f.forcesubscribe = :initial AND fs.id IS NULL";
469 $params = array('courseid'=>$cp->courseid, 'userid'=>$cp->userid, 'initial'=>FORUM_INITIALSUBSCRIBE);
471 $forums = $DB->get_records_sql($sql, $params);
472 foreach ($forums as $forum) {
473 \mod_forum\subscriptions::subscribe_user($cp->userid, $forum);
478 // Deprecated in 2.4.
481 * Checks to see if a user can view a particular post.
483 * @deprecated since Moodle 2.4 use forum_user_can_see_post() instead
485 * @param object $post
486 * @param object $course
487 * @param object $cm
488 * @param object $forum
489 * @param object $discussion
490 * @param object $user
491 * @return boolean
493 function forum_user_can_view_post($post, $course, $cm, $forum, $discussion, $user=null){
494 debugging('forum_user_can_view_post() is deprecated. Please use forum_user_can_see_post() instead.', DEBUG_DEVELOPER);
495 return forum_user_can_see_post($forum, $discussion, $post, $user, $cm);
499 // Deprecated in 2.6.
502 * FORUM_TRACKING_ON - deprecated alias for FORUM_TRACKING_FORCED.
503 * @deprecated since 2.6
505 define('FORUM_TRACKING_ON', 2);
508 * @deprecated since Moodle 2.6
509 * @see shorten_text()
511 function forum_shorten_post($message) {
512 throw new coding_exception('forum_shorten_post() can not be used any more. Please use shorten_text($message, $CFG->forum_shortpost) instead.');
515 // Deprecated in 2.8.
518 * @global object
519 * @param int $userid
520 * @param object $forum
521 * @return bool
522 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::is_subscribed() instead
524 function forum_is_subscribed($userid, $forum) {
525 global $DB;
526 debugging("forum_is_subscribed() has been deprecated, please use \\mod_forum\\subscriptions::is_subscribed() instead.",
527 DEBUG_DEVELOPER);
529 // Note: The new function does not take an integer form of forum.
530 if (is_numeric($forum)) {
531 $forum = $DB->get_record('forum', array('id' => $forum));
534 return mod_forum\subscriptions::is_subscribed($userid, $forum);
538 * Adds user to the subscriber list
540 * @param int $userid
541 * @param int $forumid
542 * @param context_module|null $context Module context, may be omitted if not known or if called for the current module set in page.
543 * @param boolean $userrequest Whether the user requested this change themselves. This has an effect on whether
544 * discussion subscriptions are removed too.
545 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::subscribe_user() instead
547 function forum_subscribe($userid, $forumid, $context = null, $userrequest = false) {
548 global $DB;
549 debugging("forum_subscribe() has been deprecated, please use \\mod_forum\\subscriptions::subscribe_user() instead.",
550 DEBUG_DEVELOPER);
552 // Note: The new function does not take an integer form of forum.
553 $forum = $DB->get_record('forum', array('id' => $forumid));
554 \mod_forum\subscriptions::subscribe_user($userid, $forum, $context, $userrequest);
558 * Removes user from the subscriber list
560 * @param int $userid
561 * @param int $forumid
562 * @param context_module|null $context Module context, may be omitted if not known or if called for the current module set in page.
563 * @param boolean $userrequest Whether the user requested this change themselves. This has an effect on whether
564 * discussion subscriptions are removed too.
565 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::unsubscribe_user() instead
567 function forum_unsubscribe($userid, $forumid, $context = null, $userrequest = false) {
568 global $DB;
569 debugging("forum_unsubscribe() has been deprecated, please use \\mod_forum\\subscriptions::unsubscribe_user() instead.",
570 DEBUG_DEVELOPER);
572 // Note: The new function does not take an integer form of forum.
573 $forum = $DB->get_record('forum', array('id' => $forumid));
574 \mod_forum\subscriptions::unsubscribe_user($userid, $forum, $context, $userrequest);
578 * Returns list of user objects that are subscribed to this forum.
580 * @param stdClass $course the course
581 * @param stdClass $forum the forum
582 * @param int $groupid group id, or 0 for all.
583 * @param context_module $context the forum context, to save re-fetching it where possible.
584 * @param string $fields requested user fields (with "u." table prefix)
585 * @param boolean $considerdiscussions Whether to take discussion subscriptions and unsubscriptions into consideration.
586 * @return array list of users.
587 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::fetch_subscribed_users() instead
589 function forum_subscribed_users($course, $forum, $groupid = 0, $context = null, $fields = null) {
590 debugging("forum_subscribed_users() has been deprecated, please use \\mod_forum\\subscriptions::fetch_subscribed_users() instead.",
591 DEBUG_DEVELOPER);
593 \mod_forum\subscriptions::fetch_subscribed_users($forum, $groupid, $context, $fields);
597 * Determine whether the forum is force subscribed.
599 * @param object $forum
600 * @return bool
601 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::is_forcesubscribed() instead
603 function forum_is_forcesubscribed($forum) {
604 debugging("forum_is_forcesubscribed() has been deprecated, please use \\mod_forum\\subscriptions::is_forcesubscribed() instead.",
605 DEBUG_DEVELOPER);
607 global $DB;
608 if (!isset($forum->forcesubscribe)) {
609 $forum = $DB->get_field('forum', 'forcesubscribe', array('id' => $forum));
612 return \mod_forum\subscriptions::is_forcesubscribed($forum);
616 * Set the subscription mode for a forum.
618 * @param int $forumid
619 * @param mixed $value
620 * @return bool
621 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::set_subscription_mode() instead
623 function forum_forcesubscribe($forumid, $value = 1) {
624 debugging("forum_forcesubscribe() has been deprecated, please use \\mod_forum\\subscriptions::set_subscription_mode() instead.",
625 DEBUG_DEVELOPER);
627 return \mod_forum\subscriptions::set_subscription_mode($forumid, $value);
631 * Get the current subscription mode for the forum.
633 * @param int|stdClass $forumid
634 * @param mixed $value
635 * @return bool
636 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_subscription_mode() instead
638 function forum_get_forcesubscribed($forum) {
639 debugging("forum_get_forcesubscribed() has been deprecated, please use \\mod_forum\\subscriptions::get_subscription_mode() instead.",
640 DEBUG_DEVELOPER);
642 global $DB;
643 if (!isset($forum->forcesubscribe)) {
644 $forum = $DB->get_field('forum', 'forcesubscribe', array('id' => $forum));
647 return \mod_forum\subscriptions::get_subscription_mode($forumid, $value);
651 * Get a list of forums in the specified course in which a user can change
652 * their subscription preferences.
654 * @param stdClass $course The course from which to find subscribable forums.
655 * @return array
656 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::is_subscribed in combination wtih
657 * \mod_forum\subscriptions::fill_subscription_cache_for_course instead.
659 function forum_get_subscribed_forums($course) {
660 debugging("forum_get_subscribed_forums() has been deprecated, please see " .
661 "\\mod_forum\\subscriptions::is_subscribed::() " .
662 " and \\mod_forum\\subscriptions::fill_subscription_cache_for_course instead.",
663 DEBUG_DEVELOPER);
665 global $USER, $CFG, $DB;
666 $sql = "SELECT f.id
667 FROM {forum} f
668 LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = ?)
669 WHERE f.course = ?
670 AND f.forcesubscribe <> ".FORUM_DISALLOWSUBSCRIBE."
671 AND (f.forcesubscribe = ".FORUM_FORCESUBSCRIBE." OR fs.id IS NOT NULL)";
672 if ($subscribed = $DB->get_records_sql($sql, array($USER->id, $course->id))) {
673 foreach ($subscribed as $s) {
674 $subscribed[$s->id] = $s->id;
676 return $subscribed;
677 } else {
678 return array();
683 * Returns an array of forums that the current user is subscribed to and is allowed to unsubscribe from
685 * @return array An array of unsubscribable forums
686 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_unsubscribable_forums() instead
688 function forum_get_optional_subscribed_forums() {
689 debugging("forum_get_optional_subscribed_forums() has been deprecated, please use \\mod_forum\\subscriptions::get_unsubscribable_forums() instead.",
690 DEBUG_DEVELOPER);
692 return \mod_forum\subscriptions::get_unsubscribable_forums();
696 * Get the list of potential subscribers to a forum.
698 * @param object $forumcontext the forum context.
699 * @param integer $groupid the id of a group, or 0 for all groups.
700 * @param string $fields the list of fields to return for each user. As for get_users_by_capability.
701 * @param string $sort sort order. As for get_users_by_capability.
702 * @return array list of users.
703 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_potential_subscribers() instead
705 function forum_get_potential_subscribers($forumcontext, $groupid, $fields, $sort = '') {
706 debugging("forum_get_potential_subscribers() has been deprecated, please use \\mod_forum\\subscriptions::get_potential_subscribers() instead.",
707 DEBUG_DEVELOPER);
709 \mod_forum\subscriptions::get_potential_subscribers($forumcontext, $groupid, $fields, $sort);
713 * Builds and returns the body of the email notification in plain text.
715 * @uses CONTEXT_MODULE
716 * @param object $course
717 * @param object $cm
718 * @param object $forum
719 * @param object $discussion
720 * @param object $post
721 * @param object $userfrom
722 * @param object $userto
723 * @param boolean $bare
724 * @param string $replyaddress The inbound address that a user can reply to the generated e-mail with. [Since 2.8].
725 * @return string The email body in plain text format.
726 * @deprecated since Moodle 3.0 use \mod_forum\output\forum_post_email instead
728 function forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfrom, $userto, $bare = false, $replyaddress = null) {
729 global $PAGE;
730 $renderable = new \mod_forum\output\forum_post_email(
731 $course,
732 $cm,
733 $forum,
734 $discussion,
735 $post,
736 $userfrom,
737 $userto,
738 forum_user_can_post($forum, $discussion, $userto, $cm, $course)
741 $modcontext = context_module::instance($cm->id);
742 $renderable->viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
744 if ($bare) {
745 $renderer = $PAGE->get_renderer('mod_forum', 'emaildigestfull', 'textemail');
746 } else {
747 $renderer = $PAGE->get_renderer('mod_forum', 'email', 'textemail');
750 debugging("forum_make_mail_text() has been deprecated, please use the \mod_forum\output\forum_post_email renderable instead.",
751 DEBUG_DEVELOPER);
753 return $renderer->render($renderable);
757 * Builds and returns the body of the email notification in html format.
759 * @param object $course
760 * @param object $cm
761 * @param object $forum
762 * @param object $discussion
763 * @param object $post
764 * @param object $userfrom
765 * @param object $userto
766 * @param string $replyaddress The inbound address that a user can reply to the generated e-mail with. [Since 2.8].
767 * @return string The email text in HTML format
768 * @deprecated since Moodle 3.0 use \mod_forum\output\forum_post_email instead
770 function forum_make_mail_html($course, $cm, $forum, $discussion, $post, $userfrom, $userto, $replyaddress = null) {
771 return forum_make_mail_post($course,
772 $cm,
773 $forum,
774 $discussion,
775 $post,
776 $userfrom,
777 $userto,
778 forum_user_can_post($forum, $discussion, $userto, $cm, $course)
783 * Given the data about a posting, builds up the HTML to display it and
784 * returns the HTML in a string. This is designed for sending via HTML email.
786 * @param object $course
787 * @param object $cm
788 * @param object $forum
789 * @param object $discussion
790 * @param object $post
791 * @param object $userfrom
792 * @param object $userto
793 * @param bool $ownpost
794 * @param bool $reply
795 * @param bool $link
796 * @param bool $rate
797 * @param string $footer
798 * @return string
799 * @deprecated since Moodle 3.0 use \mod_forum\output\forum_post_email instead
801 function forum_make_mail_post($course, $cm, $forum, $discussion, $post, $userfrom, $userto,
802 $ownpost=false, $reply=false, $link=false, $rate=false, $footer="") {
803 global $PAGE;
804 $renderable = new \mod_forum\output\forum_post_email(
805 $course,
806 $cm,
807 $forum,
808 $discussion,
809 $post,
810 $userfrom,
811 $userto,
812 $reply);
814 $modcontext = context_module::instance($cm->id);
815 $renderable->viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
817 // Assume that this is being used as a standard forum email.
818 $renderer = $PAGE->get_renderer('mod_forum', 'email', 'htmlemail');
820 debugging("forum_make_mail_post() has been deprecated, please use the \mod_forum\output\forum_post_email renderable instead.",
821 DEBUG_DEVELOPER);
823 return $renderer->render($renderable);