MDL-14722 Added new maxattachments setting at admin and forum level to

set the maximum number of attachments for forum posts.   Default: 1.

Works, but still needs a bit of polishing to deal with re-editing posts (to stop people going above maxattachments)

Also fixed documentation for attachments.
This commit is contained in:
moodler 2008-09-08 05:46:42 +00:00
parent 757f30a20c
commit 30a9aff589
10 changed files with 111 additions and 28 deletions

View file

@ -441,11 +441,14 @@
}
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!isset($forum->maxattachments)) { // TODO - delete this once we add a field to the forum table
$forum->maxattachments = 3;
}
$mform_post = new mod_forum_post_form('post.php', array('course'=>$course, 'cm'=>$cm, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
if ($fromform = $mform_post->get_data()) {
require_login($course, false, $cm);
if (empty($SESSION->fromurl)) {
@ -753,6 +756,26 @@
$subscribe = !empty($USER->autosubscribe);
}
$defaultattachments = array();
if ($forum->maxattachments) {
for ($i=0; $i<$forum->maxattachments; $i++) {
$defaultattachments['attachment'.$i] = '';
}
if (!empty($post->attachment)) { // We already have some attachments, so show them
$fs = get_file_storage();
$i = 0;
if ($files = $fs->get_area_files($modcontext->id, 'forum_attachment', $post->id, "timemodified ASC", false)) {
foreach ($files as $file) {
$defaultattachments['attachment'.$i] = $file->get_filename();
$i++;
}
}
}
}
// HACK ALERT: this is very wrong, the defaults should be always initialized before calling $mform->get_data() !!!
$mform_post->set_data(array( 'general'=>$heading,
'subject'=>$post->subject,
@ -762,9 +785,11 @@
'userid'=>$post->userid,
'parent'=>$post->parent,
'discussion'=>$post->discussion,
'course'=>$course->id)+
'course'=>$course->id) +
$page_params+
$defaultattachments +
$page_params +
(isset($post->format)?array(
'format'=>$post->format):