From 70c476a79eaa629ef398fd996e1604c85e88c44f Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 3 Oct 2002 11:15:50 +0000 Subject: [PATCH] Fixes bug 112 Changes to expand "open" option in forums. Now have a choice between three options: new discussions and new replies, new replies only and no new discussions or new replies. Three new options in lang/forum.php and I changed "allowdiscussions". --- lang/en/forum.php | 6 ++-- lang/en/help/forum/allowdiscussions.html | 19 +++++++--- lang/en/moodle.php | 2 +- mod/forum/db/mysql.sql | 3 +- mod/forum/lib.php | 46 +++++++++++++++--------- mod/forum/mod.html | 14 ++++---- mod/forum/version.php | 8 ++++- 7 files changed, 65 insertions(+), 33 deletions(-) diff --git a/lang/en/forum.php b/lang/en/forum.php index 80906b5009..92eb0f51b3 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -7,13 +7,12 @@ $string['modulenameplural'] = "Forums"; $string['addanewdiscussion'] = "Add a new discussion topic"; $string['allowchoice'] = "Allow everyone to choose"; -$string['allowdiscussions'] = "Can a \$a start new discussions?"; +$string['allowdiscussions'] = "Can a \$a post to this forum?"; $string['allowratings'] = "Allow posts to be rated?"; $string['allowsdiscussions'] = "This forum allows each person to start one discussion topic."; $string['anyfile'] = "Any file"; $string['attachment'] = "Attachment"; $string['bynameondate'] = "by \$a->name - \$a->date"; -$string['canstudentsstart'] = "Can a \$a start new discussions?"; $string['couldnotadd'] = "Could not add your post due to an unknown error"; $string['couldnotdeleteratings'] = "Sorry, that cannot be deleted as people have already rated it"; $string['couldnotdeletereplies'] = "Sorry, that cannot be deleted as people have already responded to it"; @@ -65,6 +64,9 @@ $string['nownotsubscribed'] = "\$a->name will NOT receive copies of '\$a->forum' $string['nowsubscribed'] = "\$a->name will receive copies of '\$a->forum' by email."; $string['numposts'] = "\$a posts"; $string['olderdiscussions'] = "Older discussions"; +$string['openmode0'] = "No discussions, no replies"; +$string['openmode1'] = "No discussions, but replies are allowed"; +$string['openmode2'] = "Discussions and replies are allowed"; $string['parentofthispost'] = "Parent of this post"; $string['postadded'] = "Your post was successfully added.

You have \$a to edit it if you want to make any changes."; $string['postmailinfo'] = "This is a copy of a message posted on the \$a website. diff --git a/lang/en/help/forum/allowdiscussions.html b/lang/en/help/forum/allowdiscussions.html index 204980988a..fac7554c56 100644 --- a/lang/en/help/forum/allowdiscussions.html +++ b/lang/en/help/forum/allowdiscussions.html @@ -1,9 +1,20 @@ -

Allowing new discussions

+

Allowing new posts

-

For most forums you will want to allow non-teachers to start new - discussion topics (threads). +

This option allows you to restrict students from posting + new content in this forum. + +

For most forums you will want to leave students unrestricted + and choose the first option to allow them to start new discussion + topics (threads), and also to post replies within those threads.

Sometimes, however, you will want to disable this ability. For example, this is useful for the News forum when you only want teachers to post new items that appear on the course main page. - Students will still be able to REPLY to existing posts though. + In this case you might choose the third option "No discussions, no replies". + +

Sometimes you might want to only allow teachers to start new + discussions, but still allow students to reply within those + threads (for example within the news forum on the site home page). + In this case you would choose the second option, "No discussions, but + replies are allowed". + diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 22d81cbada..4f278df9da 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -216,7 +216,7 @@ $string['listofallpeople'] = "List of all people"; $string['license'] = "GPL License"; $string['livelogs'] = "Live logs from the past hour"; $string['location'] = "Location"; -$string['loggedinas'] = "You are logged in as \$a."; +$string['loggedinas'] = "You are logged in as \$a "; $string['loggedinnot'] = "You are not logged in."; $string['login'] = "Login"; $string['loginas'] = "Login as"; diff --git a/mod/forum/db/mysql.sql b/mod/forum/db/mysql.sql index d3680b2111..3227e42dd2 100644 --- a/mod/forum/db/mysql.sql +++ b/mod/forum/db/mysql.sql @@ -8,7 +8,8 @@ CREATE TABLE forum ( type enum('single','news','general','social','eachuser','teacher') NOT NULL default 'general', name varchar(255) NOT NULL default '', intro text NOT NULL, - open tinyint(1) unsigned NOT NULL default '0', + opendiscuss tinyint(1) unsigned NOT NULL default '1', + openpost tinyint(1) unsigned NOT NULL default '1', assessed tinyint(1) unsigned NOT NULL default '0', forcesubscribe tinyint(1) unsigned NOT NULL default '0', timemodified int(10) unsigned NOT NULL default '0', diff --git a/mod/forum/lib.php b/mod/forum/lib.php index b6a8c34392..a427cffdd6 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -20,6 +20,10 @@ $FORUM_POST_RATINGS = array ("3" => get_string("postrating3", "forum"), "2" => get_string("postrating2", "forum"), "1" => get_string("postrating1", "forum") ); +$FORUM_OPEN_MODES = array ("2" => get_string("openmode2", "forum"), + "1" => get_string("openmode1", "forum"), + "0" => get_string("openmode0", "forum") ); + $FORUM_SHORT_POST = 300; // Less than this is "short" $FORUM_LONG_POST = 600; // More than this is "long" @@ -43,21 +47,21 @@ function forum_get_course_forum($courseid, $type) { case "news": $forum->name = get_string("namenews", "forum"); $forum->intro = get_string("intronews", "forum"); - $forum->open = 0; + $forum->open = 1; // 0 - no, 1 - posts only, 2 - discuss and post $forum->assessed = 0; $forum->forcesubscribe = 1; break; case "social": $forum->name = get_string("namesocial", "forum"); $forum->intro = get_string("introsocial", "forum"); - $forum->open = 1; + $forum->open = 2; // 0 - no, 1 - posts only, 2 - discuss and post $forum->assessed = 0; $forum->forcesubscribe = 0; break; case "teacher": $forum->name = get_string("nameteacher", "forum"); $forum->intro = get_string("introteacher", "forum"); - $forum->open = 0; + $forum->open = 0; // 0 - no, 1 - posts only, 2 - discuss and post $forum->assessed = 0; $forum->forcesubscribe = 0; break; @@ -1045,10 +1049,22 @@ function forum_user_can_post_discussion($forum) { } else if (isteacher($forum->course)) { return true; } else { - return $forum->open; + return ($forum->open == 2); } } +function forum_user_can_post($forum) { +// $forum is an object + global $USER; + + if ($forum->type == "teacher") { + return isteacher($forum->course); + } else if (isteacher($forum->course)) { + return true; + } else { + return $forum->open; + } +} function forum_get_discussions($forum="0", $forum_sort="DESC", $user=0) { if ($user) { @@ -1148,8 +1164,9 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) { global $USER; $ownpost = ($USER->id == $post->user); + $reply = forum_user_can_post($forum); - forum_print_post($post, $course->id, $ownpost, $reply=true, $link=false, $rate=false); + forum_print_post($post, $course->id, $ownpost, $reply, $link=false, $rate=false); forum_print_mode_form($discussion->id, $mode); @@ -1171,16 +1188,16 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) { case -1 : // Flat descending default: echo "

"; break; case 2 : // Threaded - forum_print_posts_threaded($post->id, $course->id, 0, $forum->assessed); + forum_print_posts_threaded($post->id, $course->id, 0, $forum->assessed, $reply); break; case 3 : // Nested - forum_print_posts_nested($post->id, $course->id, $forum->assessed); + forum_print_posts_nested($post->id, $course->id, $forum->assessed, $reply); break; } @@ -1192,10 +1209,9 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) { } } -function forum_print_posts_flat($discussion, $course, $direction, $assessed) { +function forum_print_posts_flat($discussion, $course, $direction, $assessed, $reply) { global $USER; - $reply = true; $link = false; if ($direction < 0) { @@ -1217,10 +1233,9 @@ function forum_print_posts_flat($discussion, $course, $direction, $assessed) { } } -function forum_print_posts_threaded($parent, $course, $depth, $assessed) { +function forum_print_posts_threaded($parent, $course, $depth, $assessed, $reply) { global $USER; - $reply = true; $link = false; if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture @@ -1242,7 +1257,7 @@ function forum_print_posts_threaded($parent, $course, $depth, $assessed) { echo "

"; } - forum_print_posts_threaded($post->id, $course, $depth-1, $assessed); + forum_print_posts_threaded($post->id, $course, $depth-1, $assessed, $reply); echo "\n"; } } else { @@ -1250,10 +1265,9 @@ function forum_print_posts_threaded($parent, $course, $depth, $assessed) { } } -function forum_print_posts_nested($parent, $course, $assessed) { +function forum_print_posts_nested($parent, $course, $assessed, $reply) { global $USER; - $reply = true; $link = false; if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture @@ -1268,7 +1282,7 @@ function forum_print_posts_nested($parent, $course, $assessed) { echo "\n"; } } else { diff --git a/mod/forum/mod.html b/mod/forum/mod.html index cb3f0a723b..d206ee08b0 100644 --- a/mod/forum/mod.html +++ b/mod/forum/mod.html @@ -32,27 +32,25 @@ -

student") ?>:

+

student")) ?>:

- - open == 1) echo "CHECKED"; ?> > - open == 0) echo "CHECKED"; ?> > + open, ""); ?> +

:

- assessed == 1) echo "CHECKED"; ?> > - assessed == 0) echo "CHECKED"; ?> > + + assessed, ""); ?>

:

- forcesubscribe == 1) echo "CHECKED"; ?> > - forcesubscribe == 0) echo "CHECKED"; ?> > + forcesubscribe, ""); ?> diff --git a/mod/forum/version.php b/mod/forum/version.php index 3f256e3e97..9baedd3a90 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 = 2002091000; +$module->version = 2002100300; $module->cron = 60; function forum_upgrade($oldversion) { @@ -49,6 +49,12 @@ function forum_upgrade($oldversion) { } } + if ($oldversion < 2002100300) { + execute_sql(" ALTER TABLE `forum` CHANGE `open` `open` TINYINT(2) UNSIGNED DEFAULT '2' NOT NULL "); + execute_sql(" UPDATE `forum` SET `open` = 2 WHERE `open` = 1 "); + execute_sql(" UPDATE `forum` SET `open` = 1 WHERE `open` = 0 "); + } + return true; } -- 2.39.5