Permalink
Browse files

MDL-9376, disallow student to see the other users posts in max editin…

…g time, credits to Vlas Voloshin and Charles Fulton MOODLE_19_STABLE
  • Loading branch information...
1 parent 1c712d9 commit a6df2c2e5f30ca2b73b9732c91a6fdb84dfc89fb @dcai dcai committed Mar 11, 2011
Showing with 28 additions and 3 deletions.
  1. +1 −1 lang/en_utf8/forum.php
  2. +27 −2 mod/forum/lib.php
View
@@ -94,7 +94,7 @@
$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)';
View
@@ -380,6 +380,12 @@ function forum_cron() {
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
$userfrom = $users[$post->userid];
@@ -4637,6 +4643,7 @@ function forum_user_can_see_discussion($forum, $discussion, $context, $user=NULL
*/
function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NULL) {
global $USER;
+ global $CFG;
// retrieve objects (yuk)
if (is_numeric($forum)) {
@@ -4697,9 +4704,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;
@@ -6937,4 +6945,21 @@ function forum_get_extra_capabilities() {
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames', 'moodle/site:trustcontent');
}
+/**
+ * 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 $CFG;
+
+ $posttime = get_field('forum_posts', 'MIN(created)', 'userid', $userid, 'discussion', $did);
+ if (empty($posttime)) {
+ return false;
+ }
+ return $posttime;
+}
+
?>

0 comments on commit a6df2c2

Please sign in to comment.