mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
New feature: Embargoed Announcements
This commit is contained in:
parent
cca4a82f8c
commit
fbc21e82be
7 changed files with 130 additions and 6 deletions
|
@ -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");
|
||||
|
|
|
@ -1145,6 +1145,7 @@ 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
|
||||
|
@ -1152,6 +1153,8 @@ function forum_get_unmailed_posts($starttime, $endtime) {
|
|||
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>';
|
||||
|
|
|
@ -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") ?>) </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) ?>" />
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue