From 098d27d46ed846cdc35d8d0621c5ef6438b6ab11 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Mon, 16 Jan 2006 04:57:48 +0000 Subject: [PATCH] New forum type: question and answer: requires students to post their answer before being able to view other posts. After initial post, students can view & respond normally --- lang/en/forum.php | 11 +++ lang/en/help/forum/forumtype.html | 6 ++ mod/forum/db/mysql.php | 4 + mod/forum/db/mysql.sql | 2 +- mod/forum/db/postgres7.php | 5 ++ mod/forum/db/postgres7.sql | 2 +- mod/forum/discuss.php | 4 + mod/forum/index.php | 6 +- mod/forum/lib.php | 124 +++++++++++++++++++++++++++++- mod/forum/mod.html | 1 + mod/forum/post.html | 4 +- mod/forum/post.php | 22 +++++- mod/forum/search.php | 2 + mod/forum/subscribe.php | 3 + mod/forum/version.php | 2 +- mod/forum/view.php | 8 ++ 16 files changed, 196 insertions(+), 10 deletions(-) diff --git a/lang/en/forum.php b/lang/en/forum.php index 61f9547f71e..1e44b5d1ae9 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -4,6 +4,7 @@ $string['addanewdiscussion'] = 'Add a new discussion topic'; +$string['addanewquestion'] = 'Add a new question'; $string['addanewtopic'] = 'Add a new topic'; $string['advancedsearch'] = 'Advanced search'; $string['allforums'] = 'All forums'; @@ -41,6 +42,8 @@ $string['digestmailheader'] = 'This is your daily digest of new posts from the $ $string['digestmailprefs'] = 'your user profile'; $string['digestmailsubject'] = '$a: forum digest'; $string['digestsentusers'] = 'Email digests successfully sent to $a users.'; +$string['disallowsubscribe'] = 'Subscriptions not allowed'; +$string['disallowsubscribeteacher'] = 'Subscriptions not allowed (except for teachers)'; $string['discussion'] = 'Discussion'; $string['discussionmoved'] = 'This discussion has been moved to \'$a\'.'; $string['discussionname'] = 'Discussion name'; @@ -66,6 +69,9 @@ $string['forumintro'] = 'Forum introduction'; $string['forumname'] = 'Forum name'; $string['forumposts'] = 'Forum posts'; $string['forums'] = 'Forums'; +$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)'; $string['forumtype'] = 'Forum type'; $string['generalforum'] = 'Standard forum for general use'; $string['generalforums'] = 'General forums'; @@ -105,6 +111,7 @@ $string['nomorepostscontaining'] = 'No more posts containing \'$a\' were found'; $string['nonews'] = 'No news has been posted yet'; $string['noposts'] = 'No posts'; $string['nopostscontaining'] = 'No posts containing \'$a\' were found'; +$string['noquestions'] = 'There are no questions yet in this forum'; $string['nosubscribers'] = 'There are no subscribers yet for this forum'; $string['nothingnew'] = 'Nothing new for $a'; $string['notingroup'] = 'Sorry, but you need to be part of a group to see this forum.'; @@ -143,6 +150,9 @@ $string['processingpost'] = 'Processing post $a'; $string['prune'] = 'Split'; $string['prunedpost'] = 'A new discussion has been created from that post'; $string['pruneheading'] = 'Split the discussion and move this post to a new discussion'; +$string['qandaforum'] = 'Q and A forum'; +$string['qandanotify'] = 'This is a Question and Answer forum. In order to see other responses to these Questions, you must first post your Answer'; +$string['cannotviewpostyet'] = 'You cannot read other students questions in this discussion yet because you haven\'t posted'; $string['rate'] = 'Rate'; $string['rating'] = 'Rating'; $string['ratingeveryone'] = 'Everyone can rate posts'; @@ -212,6 +222,7 @@ $string['yesforever'] = 'Yes, forever'; $string['yesinitially'] = 'Yes, initially'; $string['youratedthis'] = 'You rated this'; $string['yournewtopic'] = 'Your new discussion topic'; +$string['yournewquestion'] = 'Your new question'; $string['yourreply'] = 'Your reply'; ?> diff --git a/lang/en/help/forum/forumtype.html b/lang/en/help/forum/forumtype.html index feca4331b98..fdf65b8c6e0 100644 --- a/lang/en/help/forum/forumtype.html +++ b/lang/en/help/forum/forumtype.html @@ -13,4 +13,10 @@ new discussion topic (everyone can reply to them though). This is useful when you want each student to start a discussion about, say, their reflections on the week's topic, and everyone else responds to these.

+

Q And A Forum - The Q & A forum requires students to post their +perspectives before viewing other students' postings. After the initial posting, + students can view and respond to others' postings. This feature allows equal +initial posting opportunity among all students, thus encouraging original and +independent thinking.

+

(More development to come in future versions of Moodle)

diff --git a/mod/forum/db/mysql.php b/mod/forum/db/mysql.php index cc788f67014..5bec6b50ec8 100644 --- a/mod/forum/db/mysql.php +++ b/mod/forum/db/mysql.php @@ -209,6 +209,10 @@ function forum_upgrade($oldversion) { table_column('forum_discussions','','timestart','integer'); table_column('forum_discussions','','timeend','integer'); } + + if ($oldversion < 2006011600) { + execute_sql("alter table mdl_forum change column type type enum('single','news','general','social','eachuser','teacher','qanda') not null default 'general'"); + } return true; diff --git a/mod/forum/db/mysql.sql b/mod/forum/db/mysql.sql index 6f1ccf9ba5d..92b188bf915 100644 --- a/mod/forum/db/mysql.sql +++ b/mod/forum/db/mysql.sql @@ -5,7 +5,7 @@ CREATE TABLE prefix_forum ( id int(10) unsigned NOT NULL auto_increment, course int(10) unsigned NOT NULL default '0', - type enum('single','news','general','social','eachuser','teacher') NOT NULL default 'general', + type enum('single','news','general','social','eachuser','teacher','qanda') NOT NULL default 'general', name varchar(255) NOT NULL default '', intro text NOT NULL, open tinyint(2) unsigned NOT NULL default '2', diff --git a/mod/forum/db/postgres7.php b/mod/forum/db/postgres7.php index ccc39df333a..d67c0d94bbf 100644 --- a/mod/forum/db/postgres7.php +++ b/mod/forum/db/postgres7.php @@ -155,6 +155,11 @@ function forum_upgrade($oldversion) { table_column('forum_discussions','','timeend','integer'); } + if ($oldversion < 2006011600) { + execute_sql("ALTER TABLE {$CFG->prefix}forum DROP CONSTRAINT {$CFG->prefix}forum_type"); + execute_sql("ALTER TABLE {$CFG->prefix}forum ADD CONSTRAINT {$CFG->prefix}forum_type CHECK (type IN ('single','news','general','social','eachuser','teacher','qanda')) "); + } + return true; } diff --git a/mod/forum/db/postgres7.sql b/mod/forum/db/postgres7.sql index b812944e77d..dec23ed0768 100644 --- a/mod/forum/db/postgres7.sql +++ b/mod/forum/db/postgres7.sql @@ -5,7 +5,7 @@ CREATE TABLE prefix_forum ( id SERIAL PRIMARY KEY, course integer NOT NULL default '0', - type varchar(10) CHECK (type IN ('single','news','general','social','eachuser','teacher')) NOT NULL default 'general', + type varchar(10) CHECK (type IN ('single','news','general','social','eachuser','teacher','qanda')) NOT NULL default 'general', name varchar(255) NOT NULL default '', intro text NOT NULL default '', open integer NOT NULL default '2', diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index 8c3c0454371..03faa17b92a 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -218,6 +218,10 @@ } echo ""; + if ($forum->type == 'qanda' && !isteacher($forum->course) && !forum_user_has_posted($forum->id,$discussion->id,$USER->id)) { + notify(get_string('qandanotify','forum')); + } + if (isset($discussionmoved)) { notify(get_string("discussionmoved", "forum", format_string($forum->name,true))); } diff --git a/mod/forum/index.php b/mod/forum/index.php index 24f2433a773..624eeb5a05c 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -237,7 +237,11 @@ $subscribed = $strno; $subtitle = get_string("subscribe", "forum"); } - $sublink = "id\">$subscribed"; + if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE && !isteacher($forum->course)) { + $sublink = '-'; + } else { + $sublink = "id\">$subscribed"; + } } } $row = array ($forumlink, $forum->intro, $discussionlink); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index d37834b0c3e..4b72e5cb185 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -11,6 +11,7 @@ define('FORUM_MODE_NESTED', 3); define('FORUM_FORCESUBSCRIBE', 1); define('FORUM_INITIALSUBSCRIBE', 2); +define('FORUM_DISALLOWSUBSCRIBE',3); define('FORUM_TRACKING_OFF', 0); define('FORUM_TRACKING_OPTIONAL', 1); @@ -24,7 +25,9 @@ $FORUM_LAYOUT_MODES = array ( FORUM_MODE_FLATOLDEST => get_string('modeflatoldes // These are course content forums that can be added to the course manually $FORUM_TYPES = array ('general' => get_string('generalforum', 'forum'), 'eachuser' => get_string('eachuserforum', 'forum'), - 'single' => get_string('singleforum', 'forum') ); + 'single' => get_string('singleforum', 'forum'), + 'qanda' => get_string('qandaforum', 'forum') + ); $FORUM_OPEN_MODES = array ('2' => get_string('openmode2', 'forum'), '1' => get_string('openmode1', 'forum'), @@ -328,6 +331,11 @@ function forum_cron () { } } } + + // make sure we're allowed to see it... + if (!forum_user_can_see_post($forum,$discussion,$post,$userto)) { + continue; + } if ($userto->maildigest > 0) { // This user wants the mails to be in digest form @@ -1641,12 +1649,43 @@ function forum_make_mail_post(&$post, $user, $touser, $course, function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false, $ratings=NULL, $footer="", $highlight="", $post_read=-99) { - global $USER, $CFG; + global $USER, $CFG, $SESSION; static $stredit, $strdelete, $strreply, $strparent, $strprune, $strpruneheading, $threadedmode, $isteacher, $adminedit; static $strmarkread, $strmarkunread, $istracked; + if (!forum_user_can_see_post($post->forum,$post->discussion,$post)) { + if (empty($SESSION->forum_search)) { + // just viewing, return + return; + } + echo ''; + echo ''; + echo ''; + if ($post->parent) { + echo ''; + + echo '
'; + // print_user_picture($post->userid, $courseid, $post->picture); + echo ''; + } else { + echo ''; + } + echo '
'.get_string('forumsubjecthidden','forum').'
'; + echo '
'; + print_string('forumauthorhidden','forum'); + echo '
'; + echo ' '; + + /// Actual content + + echo ''."\n"; + echo get_string('forumbodyhidden','forum'); + echo '
'; + return; + } + if (empty($stredit)) { $stredit = get_string('edit', 'forum'); $strdelete = get_string('delete', 'forum'); @@ -1969,6 +2008,7 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring="" echo ''; $usedate = (empty($post->timemodified)) ? $post->modified : $post->timemodified; // Just in case $parenturl = (empty($post->lastpostid)) ? '' : '&parent='.$post->lastpostid; + $usermodified->id = $post->usermodified; $usermodified->firstname = $post->umfirstname; $usermodified->lastname = $post->umlastname; echo ''. @@ -2616,12 +2656,18 @@ function forum_user_has_posted_discussion($forumid, $userid) { } } +function forum_user_has_posted($forumid,$did,$userid) { + return record_exists('forum_posts','discussion',$did,'userid',$userid); +} + function forum_user_can_post_discussion($forum, $currentgroup=false, $groupmode='') { // $forum is an object global $USER, $SESSION; if ($forum->type == "eachuser") { return (! forum_user_has_posted_discussion($forum->id, $USER->id)); + } else if ($forum->type == 'qanda') { + return isteacher($forum->course); } else if ($forum->type == "teacher") { return isteacher($forum->course); } else if ($currentgroup) { @@ -2705,6 +2751,70 @@ function forum_user_can_view_post($post, $course, $user=NULL){ } } +function forum_user_can_see_discussion($forum,$discussion,$user=NULL) { + global $USER; + + if (empty($user) || empty($user->id)) { + $user = $USER; + } + + // retrive objects (yuk) + if (is_numeric($forum)) { + if (!$forum = get_record('forum','id',$forum)) { + return false; + } + } + if (is_numeric($discussion)) { + if (!$discussion = get_record('forum_discussions','id',$discussion)) { + return false; + } + } + if ($forum->type == 'qanda') { + return (forum_user_has_posted($forum->id,$discussion->id,$user->id) || isteacher($forum->course)); + } + return true; +} + + +function forum_user_can_see_post($forum,$discussion,$post,$user=NULL) { + global $USER; + + if (empty($user) || empty($user->id)) { + $user = $USER; + } + + // retrive objects (yuk) + if (is_numeric($forum)) { + if (!$forum = get_record('forum','id',$forum)) { + return false; + } + } + if (isteacher($forum->course)) { + return true; + } + if (is_numeric($discussion)) { + if (!$discussion = get_record('forum_discussions','id',$discussion)) { + return false; + } + } + if (is_numeric($post)) { + if (!$post = get_record('forum_posts','id',$post)) { + return false; + } + } + + if (!isset($post->id) && isset($post->parent)) { + $post->id = $post->parent; + } + + if ($forum->type == 'qanda') { + $firstpost = forum_get_firstpost_from_discussion($discussion->id); + return (forum_user_has_posted($forum->id,$discussion->id,$user->id) || $firstpost->id == $post->id || isteacher($forum->course)); + } + return true; +} + + /** * Prints the discussion view screen for a forum. * @@ -2763,7 +2873,10 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=5, $dis echo "
wwwroot/mod/forum/post.php\">"; echo "id\" />"; echo ''; echo '
'; echo "\n"; @@ -2778,6 +2891,8 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=5, $dis echo '
'; if ($forum->type == 'news') { echo '('.get_string('nonews', 'forum').')'; + } else if ($forum->type == 'qanda') { + echo '('.get_string('noquestions','forum').')'; } else { echo '('.get_string('nodiscussions', 'forum').')'; } @@ -3077,6 +3192,9 @@ function forum_print_posts_threaded($parent, $courseid, $depth, $ratings, $reply $ratingsmenuused = true; } } else { + if (!forum_user_can_see_post($post->forum,$post->discussion,$post)) { + continue; + } $by->name = fullname($post, isteacher($courseid)); $by->date = userdate($post->modified); diff --git a/mod/forum/mod.html b/mod/forum/mod.html index 0cb4f9b42e2..c6dee0fc624 100644 --- a/mod/forum/mod.html +++ b/mod/forum/mod.html @@ -114,6 +114,7 @@ $options[0] = get_string('no'); $options[1] = get_string('yesforever', 'forum'); $options[FORUM_INITIALSUBSCRIBE] = get_string('yesinitially', 'forum'); + $options[FORUM_DISALLOWSUBSCRIBE] = get_string('disallowsubscribe','forum'); choose_from_menu($options, 'forcesubscribe', $form->forcesubscribe, ''); helpbutton('subscription2', get_string('forcesubscribeq', 'forum'), 'forum'); ?> diff --git a/mod/forum/post.html b/mod/forum/post.html index 514ca732cce..78d65143b9a 100644 --- a/mod/forum/post.html +++ b/mod/forum/post.html @@ -59,7 +59,7 @@ if (!isset($discussion->timeend)) { id)) { print_string("everyoneissubscribed", "forum"); - } else { + } else if ($forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE || isteacher($forum->course)){ unset($options); if (forum_is_subscribed($USER->id, $post->forum)) { $options[0] = get_string("subscribestart", "forum"); @@ -74,6 +74,8 @@ if (!isset($discussion->timeend)) { $options[1] = get_string("subscribestart", "forum"); choose_from_menu($options, "subscribe", $default, ""); } + } else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) { + print_string('disallowsubscribe','forum'); } helpbutton("subscription", get_string("subscription", "forum"), "forum"); ?> diff --git a/mod/forum/post.php b/mod/forum/post.php index ddd67f61445..2fc3bdacabd 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -624,6 +624,18 @@ } +// checkup + if (!empty($parent) && !forum_user_can_see_post($forum,$discussion,$post)) { + error("You cannot reply to this post"); + } + if (empty($parent) && !forum_user_can_post_discussion($forum)) { + error("You cannot start a new discussion in this forum"); + } + + if ($forum->type == 'qanda' && !isteacher($forum->course) && !forum_user_has_posted($forum->id,$discussion->id,$USER->id)) { + notify(get_string('qandanotify','forum')); + } + if (!empty($parent)) { forum_print_post($parent, $course->id, $ownpost=false, $reply=false, $link=false); if (empty($post->edit)) { @@ -632,7 +644,9 @@ } else { $user_read_array = array(); } - forum_print_posts_threaded($parent->id, $course->id, 0, false, false, $user_read_array, $discussion->forum); + if ($forum->type != 'qanda' || forum_user_can_see_discussion($forum,$discussion)) { + forum_print_posts_threaded($parent->id, $course->id, 0, false, false, $user_read_array, $discussion->forum); + } } print_heading(get_string("yourreply", "forum").':'); } else { @@ -640,7 +654,11 @@ if (!empty($forum->intro)) { print_simple_box(format_text($forum->intro), 'center'); } - print_heading(get_string('yournewtopic', 'forum')); + if ($forum->type == 'qanda') { + print_heading(get_string('yournewquestion','forum')); + } else { + print_heading(get_string('yournewtopic', 'forum')); + } } echo '
'; if (!empty($post->error)) { diff --git a/mod/forum/search.php b/mod/forum/search.php index a94dd20c603..6d8e36ce4f3 100644 --- a/mod/forum/search.php +++ b/mod/forum/search.php @@ -225,7 +225,9 @@ $fulllink = "discussion#$post->id\">".get_string("postincontext", "forum").""; //search terms already highlighted - fiedorow - 9/2/2005 + $SESSION->forum_search = true; forum_print_post($post, $course->id, false, false, false, false, $fulllink); + unset($SESSION->forum_search); echo "
"; } diff --git a/mod/forum/subscribe.php b/mod/forum/subscribe.php index 2c974e95ea4..187e4da1faf 100644 --- a/mod/forum/subscribe.php +++ b/mod/forum/subscribe.php @@ -97,6 +97,9 @@ } } else { // subscribe + if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE && !isteacher($forum->course)) { + error(get_string('disallowsubscribe'),$_SERVER["HTTP_REFERER"]); + } if (forum_subscribe($user->id, $forum->id) ) { add_to_log($course->id, "forum", "subscribe", "view.php?f=$forum->id", $forum->id, $cm->id); redirect($returnto, get_string("nowsubscribed", "forum", $info), 1); diff --git a/mod/forum/version.php b/mod/forum/version.php index a4362ab0a3a..4a906346deb 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 = 2005111100; +$module->version = 2006011600; $module->requires = 2005031000; // Requires this Moodle version $module->cron = 60; diff --git a/mod/forum/view.php b/mod/forum/view.php index c1de54df961..dbb852e3778 100644 --- a/mod/forum/view.php +++ b/mod/forum/view.php @@ -152,6 +152,10 @@ } echo ''; + } else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) { + $strsubscriptionsoff = get_string('disallowsubscribe','forum'); + echo $strsubscriptionsoff; + helpbutton("subscription", $strsubscriptionsoff, "forum"); } else { $streveryonecanchoose = get_string("everyonecanchoose", "forum"); $strforcesubscribe = get_string("forcesubscribe", "forum"); @@ -215,6 +219,10 @@ echo ''; + if ($forum->type == 'qanda' && !isteacher($forum->course)) { + notify(get_string('qandanotify','forum')); + } + $forum->intro = trim($forum->intro); switch ($forum->type) {