mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
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:
parent
757f30a20c
commit
30a9aff589
10 changed files with 111 additions and 28 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue