From a4f495bf86526921d38bdeff41107a78be71a48f Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Mon, 16 Jan 2006 08:42:09 +0000 Subject: [PATCH] Introducing: managed posted forums. Optional ability to 'throttle' forums by adding three new settings: warnafter, blockafter and blockperiod. Useful for tutors with big courses with some dominant students. --- lang/en/error.php | 1 + lang/en/forum.php | 6 ++++ lang/en/help/forum/manageposts.html | 13 +++++++++ lang/en/moodle.php | 7 +++++ mod/forum/backuplib.php | 3 ++ mod/forum/db/mysql.php | 6 ++++ mod/forum/db/mysql.sql | 3 ++ mod/forum/db/postgres7.php | 6 ++++ mod/forum/db/postgres7.sql | 5 +++- mod/forum/discuss.php | 6 ++++ mod/forum/lib.php | 45 +++++++++++++++++++++++++++++ mod/forum/mod.html | 38 ++++++++++++++++++++++++ mod/forum/post.php | 2 ++ mod/forum/version.php | 2 +- mod/forum/view.php | 6 ++++ 15 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 lang/en/help/forum/manageposts.html diff --git a/lang/en/error.php b/lang/en/error.php index b120231c9cb..f469164f21c 100755 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -12,6 +12,7 @@ $string['errorcreatingfile'] = 'Error creating file \"$a\"'; $string['errorreadingfile'] = 'Error reading file \"$a\"'; $string['erroronline'] = 'Error on line $a'; $string['errorunzippingfiles'] = 'Error unzipping files'; +$string['forumblockingtoomanyposts'] = 'You have exceeded the posting threshold set for this forum.'; $string['fieldrequired'] = '\"$a\" is a required field'; $string['filenotfound'] = 'Sorry, the requested file could not be found'; $string['groupalready'] = 'User already belongs to group $a'; diff --git a/lang/en/forum.php b/lang/en/forum.php index 1e44b5d1ae9..98610d404b2 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -16,6 +16,9 @@ $string['allsubscribe'] = 'Subscribe to all forums'; $string['allunsubscribe'] = 'Unsubscribe from all forums'; $string['anyfile'] = 'Any file'; $string['attachment'] = 'Attachment'; +$string['blockafter'] = 'Post threshold for blocking'; +$string['blockperiod'] = 'Time period for blocking'; +$string['blockperioddisabled'] = 'Don\'t block'; $string['bynameondate'] = 'by $a->name - $a->date'; $string['configcleanreadtime'] = 'The hour of the day to clean old posts from the \'read\' table.'; $string['configdisplaymode'] = 'The default display mode for discussions if one isn\'t set.'; @@ -69,6 +72,7 @@ $string['forumintro'] = 'Forum introduction'; $string['forumname'] = 'Forum name'; $string['forumposts'] = 'Forum posts'; $string['forums'] = 'Forums'; +$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['forumauthorhidden'] = 'Author (hidden)'; $string['forumsubjecthidden'] = 'Subject (hidden)'; @@ -204,6 +208,7 @@ $string['subscribestart'] = 'Send me email copies of posts to this forum'; $string['subscribestop'] = 'I don\'t want email copies of posts to this forum'; $string['subscription'] = 'Subscription'; $string['subscriptions'] = 'Subscriptions'; +$string['thisforumisthrottled'] = 'This forum has a limit to the number of forum postings you can make in a given time period - this is currently set at $a->blockafter posting(s) in $a->blockperiod'; $string['timestartenderror'] = 'Display end date cannot be earlier than the start date'; $string['trackforum'] = 'Track unread messages'; $string['tracking'] = 'Track'; @@ -218,6 +223,7 @@ $string['unreadpostsone'] = '1 unread post'; $string['unsubscribe'] = 'Unsubscribe from this forum'; $string['unsubscribed'] = 'Unsubscribed'; $string['unsubscribeshort'] = 'Unsubscribe'; +$string['warnafter'] = 'Post threshold for warning'; $string['yesforever'] = 'Yes, forever'; $string['yesinitially'] = 'Yes, initially'; $string['youratedthis'] = 'You rated this'; diff --git a/lang/en/help/forum/manageposts.html b/lang/en/help/forum/manageposts.html new file mode 100644 index 00000000000..bb84035868a --- /dev/null +++ b/lang/en/help/forum/manageposts.html @@ -0,0 +1,13 @@ +

Managed Postings Forums

+ +

The concept of managed postings is very simple. Users +will be blocked from posting after a given number +of posts in a given period, and as they approach + that number, they'll be warned that they are +approaching the threshold.

+ +

Setting either the warn threshold to 0 will disable warnings, +and setting the block threshhold to 0 will disable blocking. +If blocking is disabled, warnings will automatically be disabled.

+ +

None of these settings affect teachers posting

\ No newline at end of file diff --git a/lang/en/moodle.php b/lang/en/moodle.php index f1656b77b6d..de5ae504598 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1072,6 +1072,13 @@ $string['searchhelp'] = 'You can search for multiple words at once.

w $string['searchresults'] = 'Search results'; $string['sec'] = 'sec'; $string['secs'] = 'secs'; +$string['secondstotime86400'] = '1 day'; +$string['secondstotime172800'] = '2 days'; +$string['secondstotime259200'] = '3 days'; +$string['secondstotime345600'] = '4 days'; +$string['secondstotime432000'] = '5 days'; +$string['secondstotime518400'] = '6 days'; +$string['secondstotime604800'] = '1 Week'; $string['section'] = 'Section'; $string['sections'] = 'Sections'; $string['seealsostats'] = 'See also: stats'; diff --git a/mod/forum/backuplib.php b/mod/forum/backuplib.php index 5ef3640129f..1dfc2f407f4 100644 --- a/mod/forum/backuplib.php +++ b/mod/forum/backuplib.php @@ -83,6 +83,9 @@ fwrite ($bf,full_tag("RSSTYPE",4,false,$forum->rsstype)); fwrite ($bf,full_tag("RSSARTICLES",4,false,$forum->rssarticles)); fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$forum->timemodified)); + fwrite ($bf,full_tag("WARNAFTER",4,false,$forum->warnafter)); + fwrite ($bf,full_tag("BLOCKAFTER",4,false,$forum->blockafter)); + fwrite ($bf,full_tag("BLOCKPERIOD",4,false,$forum->blockperiod)); //if we've selected to backup users info, then execute backup_forum_suscriptions and //backup_forum_discussions diff --git a/mod/forum/db/mysql.php b/mod/forum/db/mysql.php index bdcd3c5f3a9..4b2fac97aaa 100644 --- a/mod/forum/db/mysql.php +++ b/mod/forum/db/mysql.php @@ -214,6 +214,12 @@ function forum_upgrade($oldversion) { execute_sql("alter table ".$CFG->prefix."forum change column type type enum('single','news','general','social','eachuser','teacher','qanda') not null default 'general'"); } + if ($oldversion < 2006011601) { + table_column('forum','','warnafter'); + table_column('forum','','blockafter'); + table_column('forum','','blockperiod'); + } + return true; } diff --git a/mod/forum/db/mysql.sql b/mod/forum/db/mysql.sql index 92b188bf915..490ea97bd0d 100644 --- a/mod/forum/db/mysql.sql +++ b/mod/forum/db/mysql.sql @@ -20,6 +20,9 @@ CREATE TABLE prefix_forum ( rsstype tinyint(2) unsigned NOT NULL default '0', rssarticles tinyint(2) unsigned NOT NULL default '0', timemodified int(10) unsigned NOT NULL default '0', + warnafter int(10) unsigned NOT NULL default '0', + blockafter int(10) unsigned NOT NULL default '0', + blockperiod int(10) unsigned NOT NULL default '0', PRIMARY KEY (id), UNIQUE KEY id (id), KEY course (course) diff --git a/mod/forum/db/postgres7.php b/mod/forum/db/postgres7.php index d67c0d94bbf..8bec1be6117 100644 --- a/mod/forum/db/postgres7.php +++ b/mod/forum/db/postgres7.php @@ -160,6 +160,12 @@ function forum_upgrade($oldversion) { execute_sql("ALTER TABLE {$CFG->prefix}forum ADD CONSTRAINT {$CFG->prefix}forum_type CHECK (type IN ('single','news','general','social','eachuser','teacher','qanda')) "); } + if ($oldversion < 2006011601) { + table_column('forum','','warnafter'); + table_column('forum','','blockafter'); + table_column('forum','','blockperiod'); + } + return true; } diff --git a/mod/forum/db/postgres7.sql b/mod/forum/db/postgres7.sql index dec23ed0768..3a5d13d28d5 100644 --- a/mod/forum/db/postgres7.sql +++ b/mod/forum/db/postgres7.sql @@ -19,7 +19,10 @@ CREATE TABLE prefix_forum ( trackingtype integer NOT NULL default '1', rsstype integer NOT NULL default '0', rssarticles integer NOT NULL default '0', - timemodified integer NOT NULL default '0' + timemodified integer NOT NULL default '0', + warnafter integer NOT NULL default '0', + blockafter integer NOT NULL default '0', + blockperiod integer NOT NULL default '0' ); CREATE INDEX prefix_forum_course_idx ON prefix_forum (course); diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index 03faa17b92a..9061b61734f 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -218,6 +218,12 @@ } echo ""; + if (!empty($forum->blockafter) && !empty($forum->blockperiod)) { + $a->blockafter = $forum->blockafter; + $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); + notify(get_string('thisforumisthrottled','forum',$a)); + } + if ($forum->type == 'qanda' && !isteacher($forum->course) && !forum_user_has_posted($forum->id,$discussion->id,$USER->id)) { notify(get_string('qandanotify','forum')); } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 4b72e5cb185..3b080bb43c1 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3884,4 +3884,49 @@ function forum_get_separate_modules($courseid) { } +function forum_check_throttling($forum) { + global $USER,$CFG; + + if (is_numeric($forum)) { + $forum = get_record('forum','id',$forum); + } + if (!is_object($forum)) { + return false; // this is broken. + } + + if (empty($forum->blockafter)) { + return true; + } + + if (empty($forum->blockperiod)) { + return true; + } + + if (isteacher($forum->course)) { + return true; + } + + // get the number of posts in the last period we care about + $timenow = time(); + $timeafter = $timenow - $forum->blockperiod; + + $numposts = count_records_sql('SELECT COUNT(p.id) FROM '.$CFG->prefix.'forum_posts p' + .' JOIN '.$CFG->prefix.'forum_discussions d' + .' ON p.discussion = d.id WHERE d.forum = '.$forum->id + .' AND p.userid = '.$USER->id.' AND p.created > '.$timeafter); + + $a->blockafter = $forum->blockafter; + $a->numposts = $numposts; + $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); + + if ($forum->blockafter <= $numposts) { + error(get_string('forumblockingtoomanyposts','error',$a),$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id); + } + if ($forum->warnafter <= $numposts) { + notify(get_string('forumblockingalmosttoomanyposts','forum',$a)); + } + + +} + ?> diff --git a/mod/forum/mod.html b/mod/forum/mod.html index c6dee0fc624..324a4ff2961 100644 --- a/mod/forum/mod.html +++ b/mod/forum/mod.html @@ -43,6 +43,16 @@ if (!isset($form->trackingtype)) { $form->trackingtype = FORUM_TRACKING_OPTIONAL; } + if (!isset($form->warnafter)) { + $form->warnafter = 0; + } + if (!isset($form->blockafter)) { + $form->blockafter = 0; + } + if (!isset($form->blockperiod)) { + $form->blockperiod = 0; + } + ?>
@@ -287,6 +297,34 @@ ?> + + + + + + + + + + + +
: +
: +
:blockperiod,''); + helpbutton('manageposts', get_string('blockperiod', 'forum'),'forum'); ?> +
diff --git a/mod/forum/post.php b/mod/forum/post.php index 2fc3bdacabd..17315f35407 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -636,6 +636,8 @@ notify(get_string('qandanotify','forum')); } + forum_check_throttling($forum); + if (!empty($parent)) { forum_print_post($parent, $course->id, $ownpost=false, $reply=false, $link=false); if (empty($post->edit)) { diff --git a/mod/forum/version.php b/mod/forum/version.php index 4a906346deb..bbf80d0009f 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2006011600; +$module->version = 2006011601; $module->requires = 2005031000; // Requires this Moodle version $module->cron = 60; diff --git a/mod/forum/view.php b/mod/forum/view.php index dbb852e3778..94afe312a97 100644 --- a/mod/forum/view.php +++ b/mod/forum/view.php @@ -219,6 +219,12 @@ echo ''; + if (!empty($forum->blockafter) && !empty($forum->blockperiod)) { + $a->blockafter = $forum->blockafter; + $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); + notify(get_string('thisforumisthrottled','forum',$a)); + } + if ($forum->type == 'qanda' && !isteacher($forum->course)) { notify(get_string('qandanotify','forum')); }