diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 6985b4eaf78..ad6051adde3 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -146,7 +146,7 @@ $string['forum'] = 'Forum'; $string['forum:addnews'] = 'Add news'; $string['forumauthorhidden'] = 'Author (hidden)'; $string['forumblockingalmosttoomanyposts'] = 'You are approaching the posting threshold. You have posted {$a->numposts} times in the last {$a->blockperiod} and the limit is {$a->blockafter} posts.'; -$string['forumbodyhidden'] = 'This post cannot be viewed by you, probably because you have not posted in the discussion yet.'; +$string['forumbodyhidden'] = 'This post cannot be viewed by you, probably because you have not posted in the discussion or the maximum editing time hasn\'t passed yet.'; $string['forum:createattachment'] = 'Create attachments'; $string['forum:deleteanypost'] = 'Delete any posts (anytime)'; $string['forum:deleteownpost'] = 'Delete own posts (within deadline)'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 92220f75de3..3900fffd54c 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -526,6 +526,11 @@ function forum_cron() { // oops - this user should not receive anything from this course continue; } + // Don't send email if the forum is Q&A and the user has not posted + if ($forum->type == 'qanda' && !forum_get_user_posted_time($discussion->id, $userto->id)) { + mtrace('Did not email '.$userto->id.' because user has not posted in discussion'); + continue; + } // Get info about the sending user if (array_key_exists($post->userid, $users)) { // we might know him/her already @@ -4640,8 +4645,25 @@ function forum_user_has_posted($forumid, $did, $userid) { WHERE p.userid = :userid AND d.forum = :forumid"; return $DB->record_exists_sql($sql, array('forumid'=>$forumid,'userid'=>$userid)); } else { - return $DB->record_exists('forum_posts', array('discussion'=>$did,'userid'=>$userid)); + return $DB->record_exists('forum_posts', array('discussion'=>$did,'userid'=>$userid)); + } } + +/** + * Returns creation time of the first user's post in given discussion + * @global object $DB + * @param int $did Discussion id + * @param int $userid User id + * @return int|bool post creation time stamp or return false + */ +function forum_get_user_posted_time($did, $userid) { + global $DB; + + $posttime = $DB->get_field('forum_posts', 'MIN(created)', array('userid'=>$userid, 'discussion'=>$did)); + if (empty($posttime)) { + return false; + } + return $posttime; } /** @@ -4893,7 +4915,7 @@ function forum_user_can_see_discussion($forum, $discussion, $context, $user=NULL * @return bool */ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NULL) { - global $USER, $DB; + global $CFG, $USER, $DB; // retrieve objects (yuk) if (is_numeric($forum)) { @@ -4954,9 +4976,10 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL if ($forum->type == 'qanda') { $firstpost = forum_get_firstpost_from_discussion($discussion->id); $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); + $userfirstpost = forum_get_user_posted_time($discussion->id, $user->id); - return (forum_user_has_posted($forum->id,$discussion->id,$user->id) || - $firstpost->id == $post->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, false)); } return true;