Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple files #47

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ContributionPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function hookInstall()
`item_type_id` INT UNSIGNED NOT NULL,
`display_name` VARCHAR(255) NOT NULL,
`file_permissions` ENUM('Disallowed', 'Allowed', 'Required') NOT NULL DEFAULT 'Disallowed',
`multiple_files` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `item_type_id` (`item_type_id`)
) ENGINE=MyISAM;";
Expand Down Expand Up @@ -259,6 +260,12 @@ public function hookUpgrade($args)
set_option('contribution_open', get_option('contribution_simple'));
delete_option('contribution_simple');
}

if (version_compare($oldVersion, '3.1.1', '<')) {
$db = $this->_db;
$sql = "ALTER TABLE `$db->ContributionType` ADD COLUMN `multiple_files` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0'";
$db->query($sql);
}
}

public function hookUninstallMessage()
Expand Down
33 changes: 20 additions & 13 deletions controllers/ContributionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function _setupContributeSubmit($typeId)

/**
* Creates the reCAPTCHA object and returns it.
*
*
* @return Zend_Captcha_Recaptcha|null
*/
protected function _setupCaptcha()
Expand Down Expand Up @@ -244,7 +244,8 @@ protected function _processForm($post)
$itemMetadata['collection_id'] = (int) $collectionId;
}

$fileMetadata = $this->_processFileUpload($contributionType);
// TODO Check if there is at least one file if one file or more is required and remove the catch below.
$fileMetadata = $this->_processFilesUpload($contributionType);

// This is a hack to allow the file upload job to succeed
// even with the synchronous job dispatcher.
Expand All @@ -263,8 +264,13 @@ protected function _processForm($post)
return false;
} catch (Omeka_File_Ingest_InvalidException $e) {
// Copying this cruddy hack
if (strstr($e->getMessage(), "'contributed_file'")) {
if (strstr($e->getMessage(), "'file'")) {
$this->_helper->flashMessenger("You must upload a file when making a {$contributionType->display_name} contribution.", 'error');
}
// Check multiple files.
elseif (strstr($e->getMessage(), "file_")) {
$this->_helper->flashMessenger(__('One or more files have not been uploaded.')
. ' ' . __('You must upload a file when making a %s contribution.', $contributionType->display_name), 'error');
} else {
$this->_helper->flashMessenger($e->getMessage());
}
Expand All @@ -273,6 +279,7 @@ protected function _processForm($post)
$this->_helper->flashMessenger($e->getMessage());
return false;
}

$this->_addElementTextsToItem($item, $post['Elements']);
// Allow plugins to deal with the inputs they may have added to the form.
fire_plugin_hook('contribution_save_form', array('contributionType'=>$contributionType,'record'=>$item, 'post'=>$post));
Expand Down Expand Up @@ -310,21 +317,21 @@ protected function _processUserProfile($post, $user)
/**
* Deals with files specified on the contribution form.
*
* @todo Check if multiple files are allowed.
* @todo Error when option is required and when multiple files are allowed: an empty contributed_file input generate an error.
*
* @param ContributionType $contributionType Type of contribution.
* @return array File upload array.
* @return array Files upload array.
*/
protected function _processFileUpload($contributionType) {
protected function _processFilesUpload($contributionType)
{
if ($contributionType->isFileAllowed()) {
$options = array();
if ($contributionType->isFileRequired()) {
$options['ignoreNoFile'] = false;
} else {
$options['ignoreNoFile'] = true;
}
$options['ignoreNoFile'] = !$contributionType->isFileRequired();

$fileMetadata = array(
'file_transfer_type' => 'Upload',
'files' => 'contributed_file',
'files' => 'file',
'file_ingest_options' => $options
);

Expand Down Expand Up @@ -385,13 +392,13 @@ protected function _addElementTextsToItem($item, $elements)
*/
protected function _validateContribution($post)
{

// ReCaptcha ignores the first argument.
if ($this->_captcha and !$this->_captcha->isValid(null, $_POST)) {
$this->_helper->flashMessenger(__('Your CAPTCHA submission was invalid, please try again.'), 'error');
return false;
}

if ($post['terms-agree'] == 0) {
$this->_helper->flashMessenger(__('You must agree to the Terms and Conditions.'), 'error');
return false;
Expand Down
17 changes: 10 additions & 7 deletions models/ContributionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ class ContributionType extends Omeka_Record_AbstractRecord
public $item_type_id;
public $display_name;
public $file_permissions = 'Disallowed';

protected $_related = array('ContributionTypeElements' => 'getTypeElements',
'ItemType' => 'getItemType');
public $multiple_files = 0;

protected $_related = array(
'ContributionTypeElements' => 'getTypeElements',
'ItemType' => 'getItemType',
);

protected function filterPostData($post)
{
Expand All @@ -34,7 +37,7 @@ protected function filterPostData($post)
}
return $post;
}

protected function _validate()
{
if(empty($this->item_type_id)) {
Expand All @@ -47,7 +50,7 @@ protected function _initializeMixins()
$this->_mixins[] = new Mixin_ContributionOrder($this,
'ContributionTypeElement', 'type_id', 'Elements');
}

/**
* Get the type elements associated with this type.
*
Expand All @@ -57,7 +60,7 @@ public function getTypeElements()
{
return $this->_db->getTable('ContributionTypeElement')->findByType($this);
}

/**
* Get the item type associated with this type.
*
Expand Down Expand Up @@ -173,7 +176,7 @@ public function getPossibleTypeElements()
}
return $options;
}

public function getRecordUrl($action = 'show')
{
return url("contribution/types/$action/id/{$this->id}");
Expand Down
2 changes: 1 addition & 1 deletion plugin.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ link="http://omeka.org/codex/Plugins/Contribution_2.0"
support_link="http://omeka.org/forums/forum/plugins"
omeka_minimum_version="2.3"
omeka_target_version="2.3"
version="3.1.0"
version="3.1.1"
tags="social, items"
license="GPLv3"
required_plugins="GuestUser"
Expand Down
28 changes: 19 additions & 9 deletions views/admin/types/form.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php
$itemTypeOptions = get_db()->getTable('ContributionType')->getPossibleItemTypes();
$itemTypeOptions = array('' => 'Select an Item Type') + $itemTypeOptions;
?>
<form method='post'>
<form method='post'>
<section class='seven columns alpha'>
<?php if($action == 'add'): ?>
<div class="field">
Expand Down Expand Up @@ -42,17 +42,27 @@
<?php echo $this->formSelect('file_permissions', $contribution_type->file_permissions, array(), ContributionType::getPossibleFilePermissions()); ?>
</div>
</div>
</div>

</div>

<div class="field">
<div class="two columns alpha">
<label><?php echo __("Allow Multiple File Upload"); ?></label>
</div>
<div class="inputs five columns omega">
<p class="explanation"><?php echo __("Allow to upload multiple files for one item."); ?></p>
<div class="input-block">
<?php echo $this->formCheckbox("multiple_files", null, array('checked' => $contribution_type->multiple_files)); ?>
</div>
</div>
</div>


<div id="element-list" class="seven columns alpha">
<ul id="contribution-type-elements" class="sortable">
<?php
foreach ($contributionTypeElements as $contributionElement):
if ($contributionElement):
?>

<li class="element">
<div class="sortable-item">
<strong><?php echo html_escape($contributionElement->Element->name); ?></strong><span class='prompt'><?php echo __('Prompt'); ?></span>
Expand All @@ -65,7 +75,7 @@
<a id="remove-element-link-<?php echo html_escape($contributionElement->id); ?>" href="" class="delete-element"><?php echo __('Remove'); ?></a>
<?php endif; ?>
</div>

<div class="drawer-contents">
<div class="element-description"><?php echo html_escape($contributionElement->Element->description); ?></div>
</div>
Expand Down Expand Up @@ -96,7 +106,7 @@
?>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; // end for each $elementInfos ?>
<?php endforeach; // end for each $elementInfos ?>
<li>
<div class="add-new">
<?php echo __('Add Element'); ?>
Expand All @@ -112,7 +122,7 @@

<section class='three columns omega'>
<div id='save' class='panel'>

<input type="submit" class="big green button" value="<?php echo __('Save Changes');?>" id="submit" name="submit">
<?php if($contribution_type->exists()): ?>
<?php echo link_to($contribution_type, 'delete-confirm', __('Delete'), array('class' => 'big red button delete-confirm')); ?>
Expand Down
20 changes: 16 additions & 4 deletions views/public/contribution/contribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* @package Contribution
*/

queue_js_file('contribution-public-form');
$contributionPath = get_option('contribution_page_path');
if(!$contributionPath) {
$contributionPath = 'contribution';
}
queue_css_file('form');

queue_js_file('contribution-public-form');
//load user profiles js and css if needed
if(get_option('contribution_user_profile_type') && plugin_is_active('UserProfiles') ) {
queue_js_file('admin-globals');
Expand All @@ -32,7 +32,7 @@

<div id="primary">
<?php echo flash(); ?>

<h1><?php echo $head['title']; ?></h1>

<?php if(! ($user = current_user() )
Expand All @@ -42,7 +42,7 @@
<?php $session = new Zend_Session_Namespace;
$session->redirect = absolute_url();
?>
<p>You must <a href='<?php echo url('guest-user/user/register'); ?>'>create an account</a> or <a href='<?php echo url('guest-user/user/login'); ?>'>log in</a> before contributing. You can still leave your identity to site visitors anonymous.</p>
<p>You must <a href='<?php echo url('guest-user/user/register'); ?>'>create an account</a> or <a href='<?php echo url('guest-user/user/login'); ?>'>log in</a> before contributing. You can still leave your identity to site visitors anonymous.</p>
<?php else: ?>
<form method="post" action="" enctype="multipart/form-data">
<fieldset id="contribution-item-metadata">
Expand All @@ -54,7 +54,19 @@
<input type="submit" name="submit-type" id="submit-type" value="Select" />
</div>
<div id="contribution-type-form">
<?php if(isset($type)) { include('type-form.php'); }?>
<?php if (isset($type)) {
$partialOptions = array();
$partialOptions['preset'] = true;
$partialOptions['type'] = $type;
$partialOptions['item'] = $item;
if (isset($profileType)) {
$partialOptions['profileType'] = $profileType;
}
if (isset($profile)) {
$partialOptions['profile'] = $profile;
}
echo $this->partial('contribution/type-form.php', $partialOptions);
}?>
</div>
</fieldset>

Expand Down
62 changes: 39 additions & 23 deletions views/public/contribution/type-form.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@

<?php if (!$type): ?>
<p><?php echo __('You must choose a contribution type to continue.'); ?></p>
<?php else: ?>
<?php else:
$isRequired = $type->isFileRequired();
$isAllowed = $type->isFileAllowed();
$allowMultipleFiles = $isAllowed && $type->multiple_files;
?>
<h2><?php echo __('Contribute a %s', $type->display_name); ?></h2>

<?php
if ($type->isFileRequired()):
$required = true;
?>

<div class="field">
// When a file is required, the upload element is displayed before other ones.
if ($isRequired): ?>
<div id="files-form" class="field drawer-contents">
<div class="two columns alpha">
<?php echo $this->formLabel('contributed_file', __('Upload a file')); ?>
<?php echo $this->formLabel('file', __('Upload a file')); ?>
</div>
<div class="inputs five columns omega">
<?php echo $this->formFile('contributed_file', array('class' => 'fileinput')); ?>
<div id="files-metadata" class="inputs five columns omega">
<div id="upload-files" class="files">
<?php echo $this->formFile($allowMultipleFiles ? 'file[0]' : 'file', array('class' => 'fileinput button')); ?>
<p class="explanation"><?php echo __('The maximum file size is %s.', max_file_size()); ?></p>
</div>
</div>
</div>

<?php endif; ?>

<?php
Expand All @@ -26,26 +29,39 @@
}
?>

<?php
if (!isset($required) && $type->isFileAllowed()):
?>
<div class="field">
<div class="two columns alpha">
<?php echo $this->formLabel('contributed_file', __('Upload a file (Optional)')); ?>
</div>
<div class="inputs five columns omega">
<?php echo $this->formFile('contributed_file', array('class' => 'fileinput')); ?>
<?php if (!$isRequired && $isAllowed): ?>
<div id="files-form" class="field drawer-contents">
<div class="two columns alpha">
<?php echo $this->formLabel('file', __('Upload a file (Optional)')); ?>
</div>
<div id="files-metadata" class="inputs five columns omega">
<div id="upload-files" class="files">
<?php echo $this->formFile($allowMultipleFiles ? 'file[0]' : 'file', array('class' => 'fileinput button')); ?>
<p class="explanation"><?php echo __('The maximum file size is %s.', max_file_size()); ?></p>
</div>
</div>
</div>
<?php endif; ?>

<?php if ($allowMultipleFiles): ?>
<script type="text/javascript" charset="utf-8">
<?php if (!empty($preset)): ?>
jQuery(window).load(function () {
Omeka.Items.enableAddFiles(<?php echo js_escape(__('Add Another File')); ?>);
});
<?php else: ?>
Omeka.Items.enableAddFiles(<?php echo js_escape(__('Add Another File')); ?>);
<?php endif; ?>
</script>
<?php endif; ?>

<?php $user = current_user(); ?>
<?php if(( get_option('contribution_open') || get_option('contribution_strict_anonymous') ) && !$user) : ?>
<div class="field">
<div class="two columns alpha">
<?php
if (get_option('contribution_strict_anonymous')) {
echo $this->formLabel('contribution_email', __('Email (Optional)'));
echo $this->formLabel('contribution_email', __('Email (Optional)'));
} else {
echo $this->formLabel('contribution_email', __('Email (Required)'));
}
Expand Down Expand Up @@ -90,7 +106,7 @@
<div class='contribution-userprofile <?php echo $profile->exists() ? "exists" : "" ?>'>
<p class="user-profiles-profile-description"><?php echo $profileType->description; ?></p>
<fieldset name="user-profiles">
<?php
<?php
foreach($profileType->Elements as $element) {
echo $this->profileElementForm($element, $profile);
}
Expand All @@ -104,4 +120,4 @@
// on a type-by-type basis).
fire_plugin_hook('contribution_type_form', array('type'=>$type, 'view'=>$this));
?>
<?php endif; ?>
<?php endif;
Loading