1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-07 09:23:31 +02:00

MDL-71144 mod_forum: Deprecate forum_get_completion_state()

This commit is contained in:
Jun Pataleta 2021-03-30 09:56:10 +08:00 committed by Shamim Rezaie
parent c10dfd7583
commit c9fa4f9cd7
2 changed files with 68 additions and 63 deletions

@ -1690,3 +1690,71 @@ function forum_get_user_grades($forum, $userid = 0) {
$rm = new rating_manager();
return $rm->get_user_grades($ratingoptions);
}
/**
* Obtains the automatic completion state for this forum based on any conditions
* in forum settings.
*
* @deprecated since Moodle 3.11
* @todo MDL-71196 Final deprecation in Moodle 4.3
* @see \mod_forum\completion\custom_completion
* @global object
* @global object
* @param object $course Course
* @param object $cm Course-module
* @param int $userid User ID
* @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
* @return bool True if completed, false if not. (If no conditions, then return
* value depends on comparison type)
*/
function forum_get_completion_state($course, $cm, $userid, $type) {
global $DB;
// No need to call debugging here. Deprecation debugging notice already being called in \completion_info::internal_get_state().
// Get forum details.
if (!($forum = $DB->get_record('forum', array('id' => $cm->instance)))) {
throw new Exception("Can't find forum {$cm->instance}");
}
$result = $type; // Default return value.
$postcountparams = array('userid' => $userid, 'forumid' => $forum->id);
$postcountsql = "
SELECT
COUNT(1)
FROM
{forum_posts} fp
INNER JOIN {forum_discussions} fd ON fp.discussion=fd.id
WHERE
fp.userid=:userid AND fd.forum=:forumid";
if ($forum->completiondiscussions) {
$value = $forum->completiondiscussions <=
$DB->count_records('forum_discussions', array('forum' => $forum->id, 'userid' => $userid));
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
if ($forum->completionreplies) {
$value = $forum->completionreplies <=
$DB->get_field_sql($postcountsql . ' AND fp.parent<>0', $postcountparams);
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
if ($forum->completionposts) {
$value = $forum->completionposts <= $DB->get_field_sql($postcountsql, $postcountparams);
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
return $result;
}

@ -373,69 +373,6 @@ function forum_supports($feature) {
}
}
/**
* Obtains the automatic completion state for this forum based on any conditions
* in forum settings.
*
* @global object
* @global object
* @param object $course Course
* @param object $cm Course-module
* @param int $userid User ID
* @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
* @return bool True if completed, false if not. (If no conditions, then return
* value depends on comparison type)
*/
function forum_get_completion_state($course,$cm,$userid,$type) {
global $CFG,$DB;
// Get forum details
if (!($forum=$DB->get_record('forum',array('id'=>$cm->instance)))) {
throw new Exception("Can't find forum {$cm->instance}");
}
$result=$type; // Default return value
$postcountparams=array('userid'=>$userid,'forumid'=>$forum->id);
$postcountsql="
SELECT
COUNT(1)
FROM
{forum_posts} fp
INNER JOIN {forum_discussions} fd ON fp.discussion=fd.id
WHERE
fp.userid=:userid AND fd.forum=:forumid";
if ($forum->completiondiscussions) {
$value = $forum->completiondiscussions <=
$DB->count_records('forum_discussions',array('forum'=>$forum->id,'userid'=>$userid));
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
if ($forum->completionreplies) {
$value = $forum->completionreplies <=
$DB->get_field_sql( $postcountsql.' AND fp.parent<>0',$postcountparams);
if ($type==COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
if ($forum->completionposts) {
$value = $forum->completionposts <= $DB->get_field_sql($postcountsql,$postcountparams);
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
return $result;
}
/**
* Create a message-id string to use in the custom headers of forum notification emails
*