Permalink
Browse files

New feature: Embargoed Announcements

  • Loading branch information...
1 parent cca4a82 commit fbc21e82be3fb729c2246199df2f3c5807dcf6c9 patrickslee committed Nov 10, 2005
View
@@ -46,6 +46,9 @@
$string['discussionsstartedby'] = 'Discussions started by $a';
$string['discussionsstartedbyrecent'] = 'Discussions recently started by $a';
$string['discussthistopic'] = 'Discuss this topic';
+$string['displayend'] = 'Display end';
+$string['displayperiod'] = 'Display Period';
+$string['displaystart'] = 'Display start';
$string['eachuserforum'] = 'Each person posts one discussion';
$string['edit'] = 'Edit';
$string['editedby'] = 'Edited by $a->name - $a->date';
@@ -187,6 +190,7 @@
$string['subscribestop'] = 'I don\'t want email copies of posts to this forum';
$string['subscription'] = 'Subscription';
$string['subscriptions'] = 'Subscriptions';
+$string['timestartenderror'] = 'Display end date cannot be earlier than the start date';
$string['trackforum'] = 'Track unread messages';
$string['tracking'] = 'Track';
$string['trackingon'] = 'On';
@@ -0,0 +1,8 @@
+<p align="center"><b>Forum Display Period</b></p>
+
+<p>You can choose whether your forum posting is displayed from a certain date, expires on a
+certain date or is only displayed over a given period.</p>
+
+<p>Deselect the Disable option(s) to activate a display start and/or end date.</p>
+
+<p>Note that users with Admin access will see messages before their release date and after their expiry date.</p>
@@ -18,5 +18,7 @@
<li><a href="help.php?module=forum&amp;file=subscription.html">Subscription</a></li>
+ <li><a href="help.php?module=forum&amp;file=displayperiod.html">Display Period</a></li>
+
</ul>
View
@@ -32,6 +32,15 @@
error("You must be a $course->teacher to view this forum");
}
+ } elseif ($forum->type == "news") {
+ if (!((isadmin() and !empty($CFG->admineditalways))
+ || isteacher($course->id)
+ || $USER->id == $discussion->userid
+ || (($discussion->timestart == 0 || $discussion->timestart <= time())
+ && ($discussion->timeend == 0 || $discussion->timeend > time())))) {
+ error('Discussion ID was incorrect or no longer exists', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
+ }
+
} else {
if (! $cm = get_coursemodule_from_instance("forum", $discussion->forum, $course->id)) {
error("Course Module ID was incorrect");
View
@@ -1145,13 +1145,16 @@ function forum_get_ratings($postid, $sort="u.firstname ASC") {
function forum_get_unmailed_posts($starttime, $endtime) {
/// Returns a list of all new posts that have not been mailed yet
global $CFG;
+ $now = time();
return get_records_sql("SELECT p.*, d.course
FROM {$CFG->prefix}forum_posts p,
{$CFG->prefix}forum_discussions d
WHERE p.mailed = 0
AND p.created >= '$starttime'
AND p.created < '$endtime'
AND p.discussion = d.id
+ AND ((d.timestart = 0 OR d.timestart <= '$now')
+ AND (d.timeend = 0 OR d.timeend > '$now'))
ORDER BY p.modified ASC");
}
@@ -1298,7 +1301,18 @@ function forum_count_unrated_posts($discussionid, $userid) {
function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
$user=0, $fullpost=true, $visiblegroups=-1, $limit=0, $userlastmodified=false) {
/// Get all discussions in a forum
- global $CFG;
+ global $CFG, $USER;
+
+ if ((isadmin() and !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum))) {
+ $timelimit = '';
+ } else {
+ $now = time();
+ $timelimit = " AND ((d.timestart = 0 OR d.timestart <= '$now') AND (d.timeend = 0 OR d.timeend > '$now')";
+ if (!empty($USER->id)) {
+ $timelimit .= " OR d.userid = '$USER->id'";
+ }
+ $timelimit .= ')';
+ }
if ($user) {
$userselect = " AND u.id = '$user' ";
@@ -1345,7 +1359,7 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
$umtable
WHERE d.forum = '$forum'
AND p.parent = 0
- $groupselect $userselect
+ $timelimit $groupselect $userselect
ORDER BY $forumsort $limit");
} else {
return get_records_sql("SELECT $postdata, d.name, d.timemodified, d.usermodified, d.groupid,
@@ -1357,7 +1371,8 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
WHERE d.forum = '$forum'
AND p.discussion = d.id
AND p.parent = 0
- AND p.userid = u.id $groupselect $userselect
+ AND p.userid = u.id
+ $timelimit $groupselect $userselect
ORDER BY $forumsort $limit");
}
}
@@ -1750,6 +1765,12 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
}
$age = time() - $post->created;
+ /// Hack for allow to edit news posts those are not displayed yet until they are displayed
+ if (!$post->parent
+ && get_field('forum', 'type', 'id', $post->forum) == 'news'
+ && get_field_sql("SELECT id FROM {$CFG->prefix}forum_discussions WHERE id = $post->discussion AND timestart > ".time())) {
+ $age = 0;
+ }
if ($ownpost or $adminedit) {
if (($age < $CFG->maxeditingtime) or $adminedit) {
$commands[] = '<a href="'.$CFG->wwwroot.'/mod/forum/post.php?edit='.$post->id.'">'.$stredit.'</a>';
View
@@ -92,6 +92,41 @@
<?php } ?>
+<?php if ($forum->type == 'news' && !$post->parent) { // This is the first post of a discussion in news forum ?>
+
+<tr valign="top">
+ <td align="right"><b><?php print_string("displayperiod", "forum") ?>:<br />(<?php print_string("optional") ?>)&nbsp;</b></td>
+ <td>
+ <table cellpadding="0" cellspacing="0">
+ <tr>
+ <td align="right"><?php print_string('displaystart', "forum") ?>: </td>
+ <td><?php
+ print_date_selector("timestartday", "timestartmonth", "timestartyear", $discussion->timestart);
+ print_string('disable');
+ echo ': ';
+ print_checkbox('timestartdisabled', 1, empty($discussion->timestart));
+ helpbutton("displayperiod", get_string("displayperiod", "forum"), "forum");
+ ?></td>
+ </tr>
+ <tr>
+ <td height="18" colspan="2"> </td>
+ </tr>
+ <tr>
+ <td align="right"><?php print_string('displayend', "forum") ?>: </td>
+ <td><?php
+ print_date_selector("timeendday", "timeendmonth", "timeendyear", $discussion->timeend);
+ print_string('disable');
+ echo ': ';
+ print_checkbox('timeenddisabled', 1, empty($discussion->timeend));
+ ?></td>
+ </tr>
+ </table>
+ </td>
+</tr>
+
+<?php } ?>
+
+
<tr>
<td align="center" colspan="2">
<input type="hidden" name="course" value="<?php p($post->course) ?>" />
View
@@ -95,6 +95,26 @@
} else if ($post->edit) { // Updating a post
$post->id = $post->edit;
$message = '';
+ if (get_field('forum', 'type', 'id', $forum) == 'news' && !$post->parent) {
+ $updatediscussion->id = $post->discussion;
+ if (empty($post->timestartdisabled)) {
+ $updatediscussion->timestart = make_timestamp($post->timestartyear, $post->timestartmonth, $post->timestartday);
+ } else {
+ $updatediscussion->timestart = 0;
+ }
+ if (empty($post->timeenddisabled)) {
+ $updatediscussion->timeend = make_timestamp($post->timeendyear, $post->timeendmonth, $post->timeendday);
+ } else {
+ $updatediscussion->timeend = 0;
+ }
+ if (empty($post->timeenddisabled) && $updatediscussion->timeend <= $updatediscussion->timestart) {
+ $post->error = get_string('timestartenderror', 'forum');
+ } elseif (!update_record('forum_discussions', $updatediscussion)) {
+ error(get_string("couldnotupdate", "forum"), $errordestination);
+ }
+ }
+ if (!isset($post->error)) {
+
if (forum_update_post($post,$message)) {
add_to_log($course->id, "forum", "update post",
@@ -116,6 +136,7 @@
}
exit;
+ }
} else if ($post->discussion) { // Adding a new post to an existing discussion
$message = '';
if ($post->id = forum_add_new_post($post,$message)) {
@@ -144,6 +165,24 @@
$discussion = $post;
$discussion->name = $post->subject;
$discussion->intro = $post->message;
+ $newstopic = false;
+ if (get_field('forum', 'type', 'id', $forum) == 'news' && !$post->parent) {
+ $newstopic = true;
+ }
+ if ($newstopic && empty($post->timestartdisabled)) {
+ $discussion->timestart = make_timestamp($post->timestartyear, $post->timestartmonth, $post->timestartday);
+ } else {
+ $discussion->timestart = 0;
+ }
+ if ($newstopic && empty($post->timeenddisabled)) {
+ $discussion->timeend = make_timestamp($post->timeendyear, $post->timeendmonth, $post->timeendday);
+ } else {
+ $discussion->timeend = 0;
+ }
+ if ($newstopic && empty($post->timeenddisabled) && $discussion->timeend <= $discussion->timestart) {
+ $post->error = get_string('timestartenderror', 'forum');
+ } else {
+
$message = '';
if ($discussion->id = forum_add_discussion($discussion,$message)) {
@@ -165,7 +204,9 @@
} else {
error(get_string("couldnotadd", "forum"), $errordestination);
}
+
exit;
+ }
}
}
@@ -297,9 +338,6 @@
if (($post->userid <> $USER->id) and !$adminedit) {
error("You can't edit other people's posts!");
}
- if (((time() - $post->created) > $CFG->maxeditingtime) and !$adminedit) {
- error( get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime)) );
- }
if ($post->parent) {
if (! $parent = forum_get_post_full($post->parent)) {
error("Parent post ID was incorrect ($post->parent)");
@@ -311,6 +349,11 @@
if (! $forum = get_record("forum", "id", $discussion->forum)) {
error("The forum number was incorrect ($discussion->forum)");
}
+ if (!($forum->type == 'news' && !$post->parent && $discussion->timestart > time())) {
+ if (((time() - $post->created) > $CFG->maxeditingtime) and !$adminedit) {
+ error( get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime)) );
+ }
+ }
if (! $course = get_record("course", "id", $discussion->course)) {
error("The course number was incorrect ($discussion->course)");
}
@@ -456,6 +499,8 @@
$newdiscussion->groupid = $discussion->groupid;
$newdiscussion->assessed = $discussion->assessed;
$newdiscussion->usermodified = $post->userid;
+ $newdiscussion->timestart = $discussion->timestart;
+ $newdiscussion->timeend = $discussion->timeend;
if (!$newid = insert_record('forum_discussions', $newdiscussion)) {
error('Could not create new discussion');

0 comments on commit fbc21e8

Please sign in to comment.