Commit 7c5707f2 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow multiple attachments to be uploaded with comments


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent d2248c7c
......@@ -33,7 +33,9 @@ $string['comment'] = 'comment';
$string['comments'] = 'comments';
$string['attachfile'] = "Attach file";
$string['Attachments'] = "Attachments";
$string['feedbackchangedtoprivate'] = 'Feedback changed to private';
$string['feedbackonviewbyuser'] = 'Feedback on %s by %s';
$string['feedbacksubmitted'] = 'Feedback submitted';
$string['makeprivate'] = 'Change to Private';
$string['makepublic'] = 'Make public';
......
......@@ -322,9 +322,10 @@ class ArtefactTypeComment extends ArtefactType {
'title' => get_string('makepublic', 'artefact.comment'),
);
if ($attachments) {
$form['elements']['attachment'] = array(
'type' => 'file',
'title' => get_string('attachfile', 'artefact.comment'),
$form['elements']['attachments'] = array(
'type' => 'files',
'title' => get_string('attachfile', 'artefact.comment'),
'defaultvalue' => array(),
);
}
$form['elements']['submit'] = array(
......@@ -407,48 +408,58 @@ function add_feedback_form_submit(Pieform $form, $values) {
$comment = new ArtefactTypeComment(0, $data);
$comment->commit();
if (0&&isset($values['attachment']) && is_array($values['attachment'])) {
require_once(get_config('libroot') . 'group.php');
if (!empty($values['attachments']) && is_array($values['attachments']) && !empty($data->author)) {
require_once(get_config('libroot') . 'uploadmanager.php');
safe_require('artefact', 'file');
$groupid = $view->get('submittedgroup');
if (group_user_can_assess_submitted_views($groupid, $USER->get('id'))) {
$ownerlang = empty($data->owner) ? get_config('lang') : get_user_language($data->owner);
$folderid = ArtefactTypeFolder::get_folder_id(
get_string_from_language($ownerlang, 'feedbackattachdirname', 'view'),
get_string_from_language($ownerlang, 'feedbackattachdirdesc', 'view'),
null, true, $data->owner, $data->group, $data->institution
);
$attachment = (object) array(
'owner' => $data->owner,
'group' => $data->group,
'institution' => $data->institution,
'author' => $data->author,
'allowcomments' => 0,
'parent' => $folderid,
'description' => get_string_from_language(
$ownerlang,
'feedbackonviewbyuser',
'artefact.comment',
$view->get('title'),
display_name($USER)
),
);
foreach ($values['attachments'] as $filesindex) {
$um = new upload_manager('attachment');
$um = new upload_manager($filesindex);
if ($error = $um->preprocess_file()) {
throw new UploadException($error);
}
$owner = $view->get('owner');
$ownerlang = get_user_language($owner);
$folderid = ArtefactTypeFolder::get_folder_id(
get_string_from_language($ownerlang, 'feedbackattachdirname', 'view'),
get_string_from_language($ownerlang, 'feedbackattachdirdesc', 'view'),
null, true, $owner
);
$attachment = (object) array(
'owner' => $owner,
'parent' => $folderid,
'title' => ArtefactTypeFileBase::get_new_file_title($values['attachment']['name'], $folderid, $owner),
'size' => $values['attachment']['size'],
'filetype' => $values['attachment']['type'],
'oldextensin' => $um->original_filename_extension(),
'description' => get_string_from_language(
$ownerlang,
'feedbackonviewbytutorofgroup',
'view',
$view->get('title'),
display_name($USER),
get_field('group', 'name', 'id', $groupid)
),
$attachment->title = ArtefactTypeFileBase::get_new_file_title(
$um->file['name'],
$folderid,
$data->owner,
$data->group,
$data->institution
);
$attachment->size = $um->file['size'];
$attachment->filetype = $um->file['type'];
$attachment->oldextension = $um->original_filename_extension();
try {
$data->attachment = ArtefactTypeFile::save_uploaded_file('attachment', $attachment);
$fileid = ArtefactTypeFile::save_uploaded_file($filesindex, $attachment);
}
catch (QuotaExceededException $e) {}
$comment->attach($fileid);
}
}
......
......@@ -16,9 +16,11 @@
{if $item->pubmessage}
| {$item->pubmessage|escape}{if $item->makeprivateform}{$item->makeprivateform}{/if}
{/if}
{foreach $item->attachments item=a}
| {str tag=attachment section=view}: <a href="{$WWWROOT}artefact/file/download.php?file={$a->attachid}">{$a->attachtitle|escape}</a> ({$a->attachsize|escape})
{strip}
{foreach $item->attachments item=a name=attachments}
{if $.foreach.attachments.first} | {str tag=Attachments section=artefact.comment}:{else},{/if} <a href="{$WWWROOT}artefact/file/download.php?file={$a->attachid}">{$a->attachtitle|escape}</a> ({$a->attachsize|escape})
{/foreach}
{/strip}
</div>
</td>
</tr>
......
......@@ -113,7 +113,6 @@ $string['feedbackattachdirname'] = 'assessmentfiles';
$string['feedbackattachdirdesc'] = 'Files attached to View assessments';
$string['feedbackattachmessage'] = 'The attached file has been added to your %s folder';
$string['feedbackonthisartefactwillbeprivate'] = 'Feedback on this artefact will only be visible to the owner.';
$string['feedbackonviewbytutorofgroup'] = 'Feedback on %s by %s of %s';
$string['nopublicfeedback'] = 'No public feedback';
$string['notifysiteadministrator'] = 'Notify site administrator';
$string['print'] = 'Print';
......
......@@ -58,7 +58,7 @@ function pieform_element_files_get_value(Pieform $form, $element) {
foreach ($_FILES as $k => $v) {
if (preg_match('/^' . $name . '_files_\d+$/', $k) && !empty($v['name'])) {
$value[] = $v;
$value[] = $k;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment