Skip to content
Browse files

Merge branch 's7_MDL-9376_qaforum_m19' of git://github.com/dongsheng/…

…moodle into MOODLE_19_STABLE
  • Loading branch information...
2 parents 7e06e9f + a6df2c2 commit fb7abd481b286dde388c174656af59c0dab18652 @stronk7 stronk7 committed Mar 14, 2011
Showing with 28 additions and 3 deletions.
  1. +1 −1 lang/en_utf8/forum.php
  2. +27 −2 mod/forum/lib.php
View
2 lang/en_utf8/forum.php
@@ -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
29 mod/forum/lib.php
@@ -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 fb7abd4

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