Permalink
Browse files

Merge branch 's7_MDL-9376_qaforum' of git://github.com/dongsheng/moodle

  • Loading branch information...
2 parents 0080118 + 67fc4f0 commit 9f091bcd45595ab18be9b95e53496e94d3f76094 @stronk7 stronk7 committed Mar 14, 2011
Showing with 28 additions and 5 deletions.
  1. +1 −1 mod/forum/lang/en/forum.php
  2. +27 −4 mod/forum/lib.php
View
2 mod/forum/lang/en/forum.php
@@ -146,7 +146,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
31 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;

0 comments on commit 9f091bc

Please sign in to comment.