diff --git a/mod/forum/deprecatedlib.php b/mod/forum/deprecatedlib.php new file mode 100644 index 0000000000000..eb75ff80ee567 --- /dev/null +++ b/mod/forum/deprecatedlib.php @@ -0,0 +1,523 @@ +. + +/** + * @package mod_forum + * @copyright 2014 Andrew Robert Nicols + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +// Deprecated a very long time ago. + +/** + * How many posts by other users are unrated by a given user in the given discussion? + * + * @param int $discussionid + * @param int $userid + * @return mixed + * @deprecated since Moodle 1.1 - please do not use this function any more. + */ +function forum_count_unrated_posts($discussionid, $userid) { + global $CFG, $DB; + debugging('forum_count_unrated_posts() is deprecated and will not be replaced.', DEBUG_DEVELOPER); + + $sql = "SELECT COUNT(*) as num + FROM {forum_posts} + WHERE parent > 0 + AND discussion = :discussionid + AND userid <> :userid"; + $params = array('discussionid' => $discussionid, 'userid' => $userid); + $posts = $DB->get_record_sql($sql, $params); + if ($posts) { + $sql = "SELECT count(*) as num + FROM {forum_posts} p, + {rating} r + WHERE p.discussion = :discussionid AND + p.id = r.itemid AND + r.userid = userid AND + r.component = 'mod_forum' AND + r.ratingarea = 'post'"; + $rated = $DB->get_record_sql($sql, $params); + if ($rated) { + if ($posts->num > $rated->num) { + return $posts->num - $rated->num; + } else { + return 0; // Just in case there was a counting error + } + } else { + return $posts->num; + } + } else { + return 0; + } +} + + +// Since Moodle 1.5. + +/** + * Returns the count of records for the provided user and discussion. + * + * @global object + * @global object + * @param int $userid + * @param int $discussionid + * @return bool + * @deprecated since Moodle 1.5 - please do not use this function any more. + */ +function forum_tp_count_discussion_read_records($userid, $discussionid) { + debugging('forum_tp_count_discussion_read_records() is deprecated and will not be replaced.', DEBUG_DEVELOPER); + + global $CFG, $DB; + + $cutoffdate = isset($CFG->forum_oldpostdays) ? (time() - ($CFG->forum_oldpostdays*24*60*60)) : 0; + + $sql = 'SELECT COUNT(DISTINCT p.id) '. + 'FROM {forum_discussions} d '. + 'LEFT JOIN {forum_read} r ON d.id = r.discussionid AND r.userid = ? '. + 'LEFT JOIN {forum_posts} p ON p.discussion = d.id '. + 'AND (p.modified < ? OR p.id = r.postid) '. + 'WHERE d.id = ? '; + + return ($DB->count_records_sql($sql, array($userid, $cutoffdate, $discussionid))); +} + +/** + * Get all discussions started by a particular user in a course (or group) + * + * @global object + * @global object + * @param int $courseid + * @param int $userid + * @param int $groupid + * @return array + * @deprecated since Moodle 1.5 - please do not use this function any more. + */ +function forum_get_user_discussions($courseid, $userid, $groupid=0) { + debugging('forum_get_user_discussions() is deprecated and will not be replaced.', DEBUG_DEVELOPER); + + global $CFG, $DB; + $params = array($courseid, $userid); + if ($groupid) { + $groupselect = " AND d.groupid = ? "; + $params[] = $groupid; + } else { + $groupselect = ""; + } + + $allnames = get_all_user_name_fields(true, 'u'); + return $DB->get_records_sql("SELECT p.*, d.groupid, $allnames, u.email, u.picture, u.imagealt, + f.type as forumtype, f.name as forumname, f.id as forumid + FROM {forum_discussions} d, + {forum_posts} p, + {user} u, + {forum} f + WHERE d.course = ? + AND p.discussion = d.id + AND p.parent = 0 + AND p.userid = u.id + AND u.id = ? + AND d.forum = f.id $groupselect + ORDER BY p.created DESC", $params); +} + + +// Since Moodle 1.6. + +/** + * Returns the count of posts for the provided forum and [optionally] group. + * @global object + * @global object + * @param int $forumid + * @param int|bool $groupid + * @return int + * @deprecated since Moodle 1.6 - please do not use this function any more. + */ +function forum_tp_count_forum_posts($forumid, $groupid=false) { + debugging('forum_tp_count_forum_posts() is deprecated and will not be replaced.', DEBUG_DEVELOPER); + + global $CFG, $DB; + $params = array($forumid); + $sql = 'SELECT COUNT(*) '. + 'FROM {forum_posts} fp,{forum_discussions} fd '. + 'WHERE fd.forum = ? AND fp.discussion = fd.id'; + if ($groupid !== false) { + $sql .= ' AND (fd.groupid = ? OR fd.groupid = -1)'; + $params[] = $groupid; + } + $count = $DB->count_records_sql($sql, $params); + + + return $count; +} + +/** + * Returns the count of records for the provided user and forum and [optionally] group. + * @global object + * @global object + * @param int $userid + * @param int $forumid + * @param int|bool $groupid + * @return int + * @deprecated since Moodle 1.6 - please do not use this function any more. + */ +function forum_tp_count_forum_read_records($userid, $forumid, $groupid=false) { + debugging('forum_tp_count_forum_read_records() is deprecated and will not be replaced.', DEBUG_DEVELOPER); + + global $CFG, $DB; + + $cutoffdate = time() - ($CFG->forum_oldpostdays*24*60*60); + + $groupsel = ''; + $params = array($userid, $forumid, $cutoffdate); + if ($groupid !== false) { + $groupsel = "AND (d.groupid = ? OR d.groupid = -1)"; + $params[] = $groupid; + } + + $sql = "SELECT COUNT(p.id) + FROM {forum_posts} p + JOIN {forum_discussions} d ON d.id = p.discussion + LEFT JOIN {forum_read} r ON (r.postid = p.id AND r.userid= ?) + WHERE d.forum = ? + AND (p.modified < $cutoffdate OR (p.modified >= ? AND r.id IS NOT NULL)) + $groupsel"; + + return $DB->get_field_sql($sql, $params); +} + + +// Since Moodle 1.7. + +/** + * Returns array of forum open modes. + * + * @deprecated since + * @return array + * @deprecated since Moodle 1.7 - please do not use this function any more. + */ +function forum_get_open_modes() { + debugging('forum_get_open_modes() is deprecated and will not be replaced.', DEBUG_DEVELOPER); + return array(); +} + + +// Since Moodle 1.9. + +/** + * Gets posts with all info ready for forum_print_post + * We pass forumid in because we always know it so no need to make a + * complicated join to find it out. + * + * @global object + * @global object + * @param int $parent + * @param int $forumid + * @return array + * @deprecated since Moodle 1.9 MDL-13303 - please do not use this function any more. + */ +function forum_get_child_posts($parent, $forumid) { + debugging('forum_get_child_posts() is deprecated.', DEBUG_DEVELOPER); + + global $CFG, $DB; + + $allnames = get_all_user_name_fields(true, 'u'); + return $DB->get_records_sql("SELECT p.*, $forumid AS forum, $allnames, u.email, u.picture, u.imagealt + FROM {forum_posts} p + LEFT JOIN {user} u ON p.userid = u.id + WHERE p.parent = ? + ORDER BY p.created ASC", array($parent)); +} + +/** + * Gets posts with all info ready for forum_print_post + * We pass forumid in because we always know it so no need to make a + * complicated join to find it out. + * + * @global object + * @global object + * @return mixed array of posts or false + * @deprecated since Moodle 1.9 MDL-13303 - please do not use this function any more. + */ +function forum_get_discussion_posts($discussion, $sort, $forumid) { + debugging('forum_get_discussion_posts() is deprecated.', DEBUG_DEVELOPER); + + global $CFG, $DB; + + $allnames = get_all_user_name_fields(true, 'u'); + return $DB->get_records_sql("SELECT p.*, $forumid AS forum, $allnames, u.email, u.picture, u.imagealt + FROM {forum_posts} p + LEFT JOIN {user} u ON p.userid = u.id + WHERE p.discussion = ? + AND p.parent > 0 $sort", array($discussion)); +} + + +// Since Moodle 2.0. + +/** + * Returns a list of ratings for a particular post - sorted. + * + * @param stdClass $context + * @param int $postid + * @param string $sort + * @return array Array of ratings or false + * @deprecated since Moodle 2.0 MDL-21657 - please do not use this function any more. + */ +function forum_get_ratings($context, $postid, $sort = "u.firstname ASC") { + debugging('forum_get_ratings() is deprecated.', DEBUG_DEVELOPER); + $options = new stdClass; + $options->context = $context; + $options->component = 'mod_forum'; + $options->ratingarea = 'post'; + $options->itemid = $postid; + $options->sort = "ORDER BY $sort"; + + $rm = new rating_manager(); + return $rm->get_all_ratings_for_item($options); +} + +/** + * Generate and return the track or no track link for a forum. + * + * @global object + * @global object + * @global object + * @param object $forum the forum. Fields used are $forum->id and $forum->forcesubscribe. + * @param array $messages + * @param bool $fakelink + * @return string + * @deprecated since Moodle 2.0 MDL-14632 - please do not use this function any more. + */ +function forum_get_tracking_link($forum, $messages=array(), $fakelink=true) { + debugging('forum_get_tracking_link() is deprecated.', DEBUG_DEVELOPER); + + global $CFG, $USER, $PAGE, $OUTPUT; + + static $strnotrackforum, $strtrackforum; + + if (isset($messages['trackforum'])) { + $strtrackforum = $messages['trackforum']; + } + if (isset($messages['notrackforum'])) { + $strnotrackforum = $messages['notrackforum']; + } + if (empty($strtrackforum)) { + $strtrackforum = get_string('trackforum', 'forum'); + } + if (empty($strnotrackforum)) { + $strnotrackforum = get_string('notrackforum', 'forum'); + } + + if (forum_tp_is_tracked($forum)) { + $linktitle = $strnotrackforum; + $linktext = $strnotrackforum; + } else { + $linktitle = $strtrackforum; + $linktext = $strtrackforum; + } + + $link = ''; + if ($fakelink) { + $PAGE->requires->js('/mod/forum/forum.js'); + $PAGE->requires->js_function_call('forum_produce_tracking_link', Array($forum->id, $linktext, $linktitle)); + // use