MDL-64820 forum: convert user.php to user new rendering
[moodle.git] / mod / forum / deprecatedlib.php
CommitLineData
39de876c
AN
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.
13//
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/>.
16
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
21 */
22
23defined('MOODLE_INTERNAL') || die();
24
25// Deprecated a very long time ago.
26
27/**
39de876c
AN
28 * @deprecated since Moodle 1.1 - please do not use this function any more.
29 */
d16185fd
AN
30function forum_count_unrated_posts() {
31 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
32}
33
34
35// Since Moodle 1.5.
36
37/**
39de876c
AN
38 * @deprecated since Moodle 1.5 - please do not use this function any more.
39 */
d16185fd
AN
40function forum_tp_count_discussion_read_records() {
41 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
42}
43
44/**
39de876c
AN
45 * @deprecated since Moodle 1.5 - please do not use this function any more.
46 */
d16185fd
AN
47function forum_get_user_discussions() {
48 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
49}
50
51
52// Since Moodle 1.6.
53
54/**
39de876c
AN
55 * @deprecated since Moodle 1.6 - please do not use this function any more.
56 */
d16185fd
AN
57function forum_tp_count_forum_posts() {
58 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
59}
60
61/**
39de876c
AN
62 * @deprecated since Moodle 1.6 - please do not use this function any more.
63 */
d16185fd
AN
64function forum_tp_count_forum_read_records() {
65 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
66}
67
68
69// Since Moodle 1.7.
70
71/**
39de876c
AN
72 * @deprecated since Moodle 1.7 - please do not use this function any more.
73 */
74function forum_get_open_modes() {
d16185fd 75 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
76}
77
78
79// Since Moodle 1.9.
80
81/**
39de876c
AN
82 * @deprecated since Moodle 1.9 MDL-13303 - please do not use this function any more.
83 */
d16185fd
AN
84function forum_get_child_posts() {
85 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
86}
87
88/**
39de876c
AN
89 * @deprecated since Moodle 1.9 MDL-13303 - please do not use this function any more.
90 */
d16185fd
AN
91function forum_get_discussion_posts() {
92 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
93}
94
95
96// Since Moodle 2.0.
97
98/**
39de876c
AN
99 * @deprecated since Moodle 2.0 MDL-21657 - please do not use this function any more.
100 */
d16185fd
AN
101function forum_get_ratings() {
102 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
103}
104
105/**
39de876c
AN
106 * @deprecated since Moodle 2.0 MDL-14632 - please do not use this function any more.
107 */
d16185fd
AN
108function forum_get_tracking_link() {
109 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
110}
111
112/**
39de876c
AN
113 * @deprecated since Moodle 2.0 MDL-14113 - please do not use this function any more.
114 */
d16185fd
AN
115function forum_tp_count_discussion_unread_posts() {
116 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
117}
118
119/**
39de876c
AN
120 * @deprecated since Moodle 2.0 MDL-23479 - please do not use this function any more.
121 */
122function forum_convert_to_roles() {
d16185fd 123 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
124}
125
126/**
39de876c
AN
127 * @deprecated since Moodle 2.0 MDL-14113 - please do not use this function any more.
128 */
d16185fd
AN
129function forum_tp_get_read_records() {
130 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
131}
132
133/**
39de876c
AN
134 * @deprecated since Moodle 2.0 MDL-14113 - please do not use this function any more.
135 */
d16185fd
AN
136function forum_tp_get_discussion_read_records() {
137 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
138}
139
140// Deprecated in 2.3.
141
142/**
39de876c 143 * @deprecated since Moodle 2.3 MDL-33166 - please do not use this function any more.
39de876c 144 */
d16185fd
AN
145function forum_user_enrolled() {
146 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
147}
148
149
150// Deprecated in 2.4.
151
152/**
39de876c 153 * @deprecated since Moodle 2.4 use forum_user_can_see_post() instead
39de876c 154 */
d16185fd
AN
155function forum_user_can_view_post() {
156 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
39de876c
AN
157}
158
159
160// Deprecated in 2.6.
161
162/**
163 * FORUM_TRACKING_ON - deprecated alias for FORUM_TRACKING_FORCED.
164 * @deprecated since 2.6
165 */
166define('FORUM_TRACKING_ON', 2);
167
168/**
39de876c
AN
169 * @deprecated since Moodle 2.6
170 * @see shorten_text()
39de876c
AN
171 */
172function forum_shorten_post($message) {
d16185fd
AN
173 throw new coding_exception(__FUNCTION__ . '() can not be used any more. '
174 . 'Please use shorten_text($message, $CFG->forum_shortpost) instead.');
39de876c 175}
59075a43
AN
176
177// Deprecated in 2.8.
178
179/**
59075a43
AN
180 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::is_subscribed() instead
181 */
d16185fd
AN
182function forum_is_subscribed() {
183 throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
59075a43
AN
184}
185
186/**
59075a43
AN
187 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::subscribe_user() instead
188 */
d16185fd
AN
189function forum_subscribe() {
190 throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
191 . \mod_forum\subscriptions::class . '::subscribe_user() instead');
59075a43
AN
192}
193
194/**
59075a43
AN
195 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::unsubscribe_user() instead
196 */
d16185fd
AN
197function forum_unsubscribe() {
198 throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
199 . \mod_forum\subscriptions::class . '::unsubscribe_user() instead');
59075a43
AN
200}
201
202/**
59075a43
AN
203 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::fetch_subscribed_users() instead
204 */
d16185fd
AN
205function forum_subscribed_users() {
206 throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
207 . \mod_forum\subscriptions::class . '::fetch_subscribed_users() instead');
59075a43
AN
208}
209
210/**
211 * Determine whether the forum is force subscribed.
212 *
59075a43
AN
213 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::is_forcesubscribed() instead
214 */
215function forum_is_forcesubscribed($forum) {
d16185fd
AN
216 throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
217 . \mod_forum\subscriptions::class . '::is_forcesubscribed() instead');
59075a43
AN
218}
219
220/**
59075a43
AN
221 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::set_subscription_mode() instead
222 */
223function forum_forcesubscribe($forumid, $value = 1) {
d16185fd
AN
224 throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
225 . \mod_forum\subscriptions::class . '::set_subscription_mode() instead');
59075a43
AN
226}
227
228/**
59075a43
AN
229 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_subscription_mode() instead
230 */
231function forum_get_forcesubscribed($forum) {
d16185fd
AN
232 throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
233 . \mod_forum\subscriptions::class . '::set_subscription_mode() instead');
59075a43
AN
234}
235
236/**
59075a43
AN
237 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::is_subscribed in combination wtih
238 * \mod_forum\subscriptions::fill_subscription_cache_for_course instead.
239 */
d16185fd
AN
240function forum_get_subscribed_forums() {
241 throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
242 . \mod_forum\subscriptions::class . '::is_subscribed(), and '
243 . \mod_forum\subscriptions::class . '::fill_subscription_cache_for_course() instead');
59075a43
AN
244}
245
246/**
59075a43
AN
247 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_unsubscribable_forums() instead
248 */
249function forum_get_optional_subscribed_forums() {
d16185fd
AN
250 throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
251 . \mod_forum\subscriptions::class . '::get_unsubscribable_forums() instead');
59075a43
AN
252}
253
254/**
59075a43
AN
255 * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_potential_subscribers() instead
256 */
d16185fd
AN
257function forum_get_potential_subscribers() {
258 throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
259 . \mod_forum\subscriptions::class . '::get_potential_subscribers() instead');
59075a43 260}
31793839
AN
261
262/**
263 * Builds and returns the body of the email notification in plain text.
264 *
265 * @uses CONTEXT_MODULE
266 * @param object $course
267 * @param object $cm
268 * @param object $forum
269 * @param object $discussion
270 * @param object $post
271 * @param object $userfrom
272 * @param object $userto
273 * @param boolean $bare
274 * @param string $replyaddress The inbound address that a user can reply to the generated e-mail with. [Since 2.8].
275 * @return string The email body in plain text format.
276 * @deprecated since Moodle 3.0 use \mod_forum\output\forum_post_email instead
277 */
278function forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfrom, $userto, $bare = false, $replyaddress = null) {
279 global $PAGE;
280 $renderable = new \mod_forum\output\forum_post_email(
281 $course,
282 $cm,
283 $forum,
284 $discussion,
285 $post,
286 $userfrom,
287 $userto,
288 forum_user_can_post($forum, $discussion, $userto, $cm, $course)
289 );
290
291 $modcontext = context_module::instance($cm->id);
292 $renderable->viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
293
294 if ($bare) {
295 $renderer = $PAGE->get_renderer('mod_forum', 'emaildigestfull', 'textemail');
296 } else {
297 $renderer = $PAGE->get_renderer('mod_forum', 'email', 'textemail');
298 }
299
300 debugging("forum_make_mail_text() has been deprecated, please use the \mod_forum\output\forum_post_email renderable instead.",
301 DEBUG_DEVELOPER);
302
303 return $renderer->render($renderable);
304}
305
306/**
307 * Builds and returns the body of the email notification in html format.
308 *
309 * @param object $course
310 * @param object $cm
311 * @param object $forum
312 * @param object $discussion
313 * @param object $post
314 * @param object $userfrom
315 * @param object $userto
316 * @param string $replyaddress The inbound address that a user can reply to the generated e-mail with. [Since 2.8].
317 * @return string The email text in HTML format
318 * @deprecated since Moodle 3.0 use \mod_forum\output\forum_post_email instead
319 */
320function forum_make_mail_html($course, $cm, $forum, $discussion, $post, $userfrom, $userto, $replyaddress = null) {
321 return forum_make_mail_post($course,
322 $cm,
323 $forum,
324 $discussion,
325 $post,
326 $userfrom,
327 $userto,
328 forum_user_can_post($forum, $discussion, $userto, $cm, $course)
329 );
330}
331
332/**
333 * Given the data about a posting, builds up the HTML to display it and
334 * returns the HTML in a string. This is designed for sending via HTML email.
335 *
336 * @param object $course
337 * @param object $cm
338 * @param object $forum
339 * @param object $discussion
340 * @param object $post
341 * @param object $userfrom
342 * @param object $userto
343 * @param bool $ownpost
344 * @param bool $reply
345 * @param bool $link
346 * @param bool $rate
347 * @param string $footer
348 * @return string
349 * @deprecated since Moodle 3.0 use \mod_forum\output\forum_post_email instead
350 */
351function forum_make_mail_post($course, $cm, $forum, $discussion, $post, $userfrom, $userto,
352 $ownpost=false, $reply=false, $link=false, $rate=false, $footer="") {
353 global $PAGE;
354 $renderable = new \mod_forum\output\forum_post_email(
355 $course,
356 $cm,
357 $forum,
358 $discussion,
359 $post,
360 $userfrom,
361 $userto,
362 $reply);
363
364 $modcontext = context_module::instance($cm->id);
365 $renderable->viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
366
367 // Assume that this is being used as a standard forum email.
368 $renderer = $PAGE->get_renderer('mod_forum', 'email', 'htmlemail');
369
370 debugging("forum_make_mail_post() has been deprecated, please use the \mod_forum\output\forum_post_email renderable instead.",
371 DEBUG_DEVELOPER);
372
373 return $renderer->render($renderable);
374}
4459ad29
AN
375
376/**
377 * Removes properties from user record that are not necessary for sending post notifications.
378 *
379 * @param stdClass $user
380 * @return void, $user parameter is modified
381 * @deprecated since Moodle 3.7
382 */
383function forum_cron_minimise_user_record(stdClass $user) {
384 debugging("forum_cron_minimise_user_record() has been deprecated and has not been replaced.",
385 DEBUG_DEVELOPER);
386
387 // We store large amount of users in one huge array,
388 // make sure we do not store info there we do not actually need
389 // in mail generation code or messaging.
390
391 unset($user->institution);
392 unset($user->department);
393 unset($user->address);
394 unset($user->city);
395 unset($user->url);
396 unset($user->currentlogin);
397 unset($user->description);
398 unset($user->descriptionformat);
399}
400
401/**
402 * Function to be run periodically according to the scheduled task.
403 *
404 * Finds all posts that have yet to be mailed out, and mails them out to all subscribers as well as other maintance
405 * tasks.
406 *
407 * @deprecated since Moodle 3.7
408 */
409function forum_cron() {
410 debugging("forum_cron() has been deprecated and replaced with new tasks. Please uses these instead.",
411 DEBUG_DEVELOPER);
412}