mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-46929 mod_forum: small fixes for post tagging
This commit is contained in:
parent
d2ba493cfe
commit
34c8585d83
@ -4434,6 +4434,10 @@ function forum_add_new_post($post, $mform, $unused = null) {
|
||||
forum_tp_mark_post_read($post->userid, $post);
|
||||
}
|
||||
|
||||
if (isset($post->tags)) {
|
||||
core_tag_tag::set_item_tags('mod_forum', 'forum_posts', $post->id, $context, $post->tags);
|
||||
}
|
||||
|
||||
// Let Moodle know that assessable content is uploaded (eg for plagiarism detection)
|
||||
forum_trigger_content_uploaded_event($post, $cm, 'forum_add_new_post');
|
||||
|
||||
@ -4495,6 +4499,10 @@ function forum_update_post($newpost, $mform, $unused = null) {
|
||||
|
||||
forum_add_attachment($post, $forum, $cm, $mform);
|
||||
|
||||
if (isset($newpost->tags)) {
|
||||
core_tag_tag::set_item_tags('mod_forum', 'forum_posts', $post->id, $context, $newpost->tags);
|
||||
}
|
||||
|
||||
if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
|
||||
forum_tp_mark_post_read($USER->id, $post);
|
||||
}
|
||||
@ -4573,6 +4581,10 @@ function forum_add_discussion($discussion, $mform=null, $unused=null, $userid=nu
|
||||
forum_add_attachment($post, $forum, $cm, $mform, $unused);
|
||||
}
|
||||
|
||||
if (isset($discussion->tags)) {
|
||||
core_tag_tag::set_item_tags('mod_forum', 'forum_posts', $post->id, context_module::instance($cm->id), $discussion->tags);
|
||||
}
|
||||
|
||||
if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
|
||||
forum_tp_mark_post_read($post->userid, $post);
|
||||
}
|
||||
@ -5308,12 +5320,16 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL
|
||||
}
|
||||
|
||||
if ($forum->type == 'qanda') {
|
||||
if (has_capability('mod/forum:viewqandawithoutposting', $modcontext, $user->id) || $post->userid == $user->id
|
||||
|| (isset($discussion->firstpost) && $discussion->firstpost == $post->id)) {
|
||||
return true;
|
||||
}
|
||||
$firstpost = forum_get_firstpost_from_discussion($discussion->id);
|
||||
if ($firstpost->userid == $user->id) {
|
||||
return true;
|
||||
}
|
||||
$userfirstpost = forum_get_user_posted_time($discussion->id, $user->id);
|
||||
|
||||
return (($userfirstpost !== false && (time() - $userfirstpost >= $CFG->maxeditingtime)) ||
|
||||
$firstpost->id == $post->id || $post->userid == $user->id || $firstpost->userid == $user->id ||
|
||||
has_capability('mod/forum:viewqandawithoutposting', $modcontext, $user->id));
|
||||
return (($userfirstpost !== false && (time() - $userfirstpost >= $CFG->maxeditingtime)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -589,7 +589,8 @@ function mod_forum_get_tagged_posts($tag, $exclusivemode = false, $fromctx = 0,
|
||||
|
||||
// Build the SQL query.
|
||||
$ctxselect = context_helper::get_preload_record_columns_sql('ctx');
|
||||
$query = "SELECT fp.id, fp.subject, fd.forum, fp.discussion, f.type, fd.timestart, fd.timeend, fd.groupid, fp.parent, fp.userid,
|
||||
$query = "SELECT fp.id, fp.subject, fd.forum, fp.discussion, f.type, fd.timestart, fd.timeend, fd.groupid, fd.firstpost,
|
||||
fp.parent, fp.userid,
|
||||
cm.id AS cmid, c.id AS courseid, c.shortname, c.fullname, $ctxselect
|
||||
FROM {forum_posts} fp
|
||||
JOIN {forum_discussions} fd ON fp.discussion = fd.id
|
||||
@ -636,8 +637,9 @@ function mod_forum_get_tagged_posts($tag, $exclusivemode = false, $fromctx = 0,
|
||||
}
|
||||
$modinfo = get_fast_modinfo($builder->get_course($courseid));
|
||||
// Set accessibility of this item and all other items in the same course.
|
||||
$builder->walk(function ($taggeditem) use ($courseid, $modinfo, $builder) {
|
||||
if ($taggeditem->courseid == $courseid) {
|
||||
$builder->walk(function ($taggeditem) use ($courseid, $modinfo, $builder, $item) {
|
||||
// Checking permission for Q&A forums performs additional DB queries, do not do them in bulk.
|
||||
if ($taggeditem->courseid == $courseid && ($taggeditem->type != 'qanda' || $taggeditem->id == $item->id)) {
|
||||
$cm = $modinfo->get_cm($taggeditem->cmid);
|
||||
$forum = (object)['id' => $taggeditem->forum,
|
||||
'course' => $taggeditem->courseid,
|
||||
@ -646,7 +648,8 @@ function mod_forum_get_tagged_posts($tag, $exclusivemode = false, $fromctx = 0,
|
||||
$discussion = (object)['id' => $taggeditem->discussion,
|
||||
'timestart' => $taggeditem->timestart,
|
||||
'timeend' => $taggeditem->timeend,
|
||||
'groupid' => $taggeditem->groupid
|
||||
'groupid' => $taggeditem->groupid,
|
||||
'firstpost' => $taggeditem->firstpost
|
||||
];
|
||||
$post = (object)['id' => $taggeditem->id,
|
||||
'parent' => $taggeditem->parent,
|
||||
|
@ -757,8 +757,6 @@ if ($mform_post->is_cancelled()) {
|
||||
$discussionurl = new moodle_url("/mod/forum/discuss.php", array('d' => $discussion->id), 'p' . $fromform->id);
|
||||
}
|
||||
|
||||
core_tag_tag::set_item_tags('mod_forum', 'forum_posts', $fromform->id, $modcontext, $fromform->tags);
|
||||
|
||||
$params = array(
|
||||
'context' => $modcontext,
|
||||
'objectid' => $fromform->id,
|
||||
@ -811,10 +809,6 @@ if ($mform_post->is_cancelled()) {
|
||||
$discussionurl = new moodle_url("/mod/forum/discuss.php", array('d' => $discussion->id), 'p'.$fromform->id);
|
||||
}
|
||||
|
||||
if (core_tag_tag::is_enabled('mod_forum', 'forum_posts') && isset($data->tags)) {
|
||||
core_tag_tag::set_item_tags('mod_forum', 'forum_posts', $fromform->id, $modcontext, $fromform->tags);
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'context' => $modcontext,
|
||||
'objectid' => $fromform->id,
|
||||
@ -942,8 +936,6 @@ if ($mform_post->is_cancelled()) {
|
||||
$completion->update_state($cm, COMPLETION_COMPLETE);
|
||||
}
|
||||
|
||||
core_tag_tag::set_item_tags('mod_forum', 'forum_posts', $fromform->firstpost, $modcontext, $fromform->tags);
|
||||
|
||||
// Redirect back to the discussion.
|
||||
redirect(
|
||||
forum_go_back_to($redirectto->out()),
|
||||
|
@ -77,7 +77,6 @@ class behat_mod_forum extends behat_base {
|
||||
|
||||
// Fill form and post.
|
||||
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', $table);
|
||||
$this->execute("behat_general::wait_until_the_page_is_ready");
|
||||
|
||||
$this->execute('behat_forms::press_button', get_string('posttoforum', 'forum'));
|
||||
$this->execute('behat_general::i_wait_to_be_redirected');
|
||||
|
Loading…
x
Reference in New Issue
Block a user