Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…g time, credits to Vlas Voloshin and Charles Fulton
  • Loading branch information...
commit 67fc4f0025199cd0ecab6e9444883edbf2e411c8 1 parent c096042
Dongsheng Cai dongsheng authored

Showing 2 changed files with 28 additions and 5 deletions. Show diff stats Hide diff stats

  1. +1 1  mod/forum/lang/en/forum.php
  2. +27 4 mod/forum/lib.php
2  mod/forum/lang/en/forum.php
@@ -146,7 +146,7 @@
146 146 $string['forum:addnews'] = 'Add news';
147 147 $string['forumauthorhidden'] = 'Author (hidden)';
148 148 $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.';
149   -$string['forumbodyhidden'] = 'This post cannot be viewed by you, probably because you have not posted in the discussion yet.';
  149 +$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.';
150 150 $string['forum:createattachment'] = 'Create attachments';
151 151 $string['forum:deleteanypost'] = 'Delete any posts (anytime)';
152 152 $string['forum:deleteownpost'] = 'Delete own posts (within deadline)';
31 mod/forum/lib.php
@@ -526,6 +526,11 @@ function forum_cron() {
526 526 // oops - this user should not receive anything from this course
527 527 continue;
528 528 }
  529 + // Don't send email if the forum is Q&A and the user has not posted
  530 + if ($forum->type == 'qanda' && !forum_get_user_posted_time($discussion->id, $userto->id)) {
  531 + mtrace('Did not email '.$userto->id.' because user has not posted in discussion');
  532 + continue;
  533 + }
529 534
530 535 // Get info about the sending user
531 536 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) {
4640 4645 WHERE p.userid = :userid AND d.forum = :forumid";
4641 4646 return $DB->record_exists_sql($sql, array('forumid'=>$forumid,'userid'=>$userid));
4642 4647 } else {
4643   - return $DB->record_exists('forum_posts', array('discussion'=>$did,'userid'=>$userid));
  4648 + return $DB->record_exists('forum_posts', array('discussion'=>$did,'userid'=>$userid));
  4649 + }
4644 4650 }
  4651 +
  4652 +/**
  4653 + * Returns creation time of the first user's post in given discussion
  4654 + * @global object $DB
  4655 + * @param int $did Discussion id
  4656 + * @param int $userid User id
  4657 + * @return int|bool post creation time stamp or return false
  4658 + */
  4659 +function forum_get_user_posted_time($did, $userid) {
  4660 + global $DB;
  4661 +
  4662 + $posttime = $DB->get_field('forum_posts', 'MIN(created)', array('userid'=>$userid, 'discussion'=>$did));
  4663 + if (empty($posttime)) {
  4664 + return false;
  4665 + }
  4666 + return $posttime;
4645 4667 }
4646 4668
4647 4669 /**
@@ -4893,7 +4915,7 @@ function forum_user_can_see_discussion($forum, $discussion, $context, $user=NULL
4893 4915 * @return bool
4894 4916 */
4895 4917 function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NULL) {
4896   - global $USER, $DB;
  4918 + global $CFG, $USER, $DB;
4897 4919
4898 4920 // retrieve objects (yuk)
4899 4921 if (is_numeric($forum)) {
@@ -4954,9 +4976,10 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL
4954 4976 if ($forum->type == 'qanda') {
4955 4977 $firstpost = forum_get_firstpost_from_discussion($discussion->id);
4956 4978 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
  4979 + $userfirstpost = forum_get_user_posted_time($discussion->id, $user->id);
4957 4980
4958   - return (forum_user_has_posted($forum->id,$discussion->id,$user->id) ||
4959   - $firstpost->id == $post->id ||
  4981 + return (($userfirstpost !== false && (time() - $userfirstpost >= $CFG->maxeditingtime)) ||
  4982 + $firstpost->id == $post->id || $post->userid == $user->id || $firstpost->userid == $user->id ||
4960 4983 has_capability('mod/forum:viewqandawithoutposting', $modcontext, $user->id, false));
4961 4984 }
4962 4985 return true;

0 comments on commit 67fc4f0

Please sign in to comment.
Something went wrong with that request. Please try again.