Skip to content

Commit

Permalink
Allowed to add tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Nov 8, 2014
1 parent 7b5ca06 commit e0074a1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 20 deletions.
31 changes: 17 additions & 14 deletions ContributionPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function setUp()
$this->_hooks[] = 'user_profiles_user_page';
}

if (! is_admin_theme()) {
if (!is_admin_theme()) {
//dig up all the elements being used, and add their ElementForm hook
$elementsTable = $this->_db->getTable('Element');
$select = $elementsTable->getSelect();
Expand Down Expand Up @@ -112,6 +112,7 @@ public function hookInstall()
`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',
`add_tags` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `item_type_id` (`item_type_id`)
) ENGINE=MyISAM;";
Expand Down Expand Up @@ -222,6 +223,8 @@ public function hookUpgrade($args)
$db = $this->_db;
$sql = "ALTER TABLE `$db->ContributionType` ADD COLUMN `multiple_files` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0'";
$db->query($sql);
$sql = "ALTER TABLE `$db->ContributionType` ADD COLUMN `add_tags` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0'";
$db->query($sql);
}
}

Expand Down Expand Up @@ -545,17 +548,17 @@ private function _createDefaultContributionTypes()

public function hookBeforeSaveItem($args)
{
$item = $args['record'];
if ($item->exists()) {
//prevent admins from overriding the contributer's assertion of public vs private
$contributionItem = $this->_db->getTable('ContributionContributedItem')->findByItem($item);
if ($contributionItem) {
if (!$contributionItem->public && $item->public) {
$item->public = false;
Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->addMessage("Cannot override contributor's desire to leave contribution private", 'error');
}
}
}
$item = $args['record'];
if ($item->exists()) {
//prevent admins from overriding the contributer's assertion of public vs private
$contributionItem = $this->_db->getTable('ContributionContributedItem')->findByItem($item);
if($contributionItem) {
if(!$contributionItem->public && $item->public) {
$item->public = false;
Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->addMessage(__("Cannot override contributor's desire to leave contribution private"), 'error');
}
}
}
}

public function hookAfterDeleteItem($args)
Expand All @@ -571,8 +574,8 @@ public function hookUserProfilesUserPage($args)
{
$user = $args['user'];
$contributionCount = $this->_db->getTable('ContributionContributedItem')->count(array('contributor' => $user->id));
if ($contributionCount !=0) {
echo "<a href='" . url('contribution/contributors/show/id/' . $user->id) . "'>Contributed Items ($contributionCount)";
if ($contributionCount != 0) {
echo "<a href='" . url('contribution/contributors/show/id/' . $user->id) . "'>" . __('Contributed Items (%d)', $contributionCount) . '</a>';
}
}

Expand Down
16 changes: 10 additions & 6 deletions controllers/ContributionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ protected function _setupCaptcha()
protected function _processForm($post)
{
if (!empty($post)) {

//for the "Simple" configuration, look for the user if exists by email. Log them in.
//If not, create the user and log them in.
$user = current_user();
Expand Down Expand Up @@ -233,9 +232,11 @@ protected function _processForm($post)
$this->_helper->flashMessenger(__('You must select a type for your contribution.'), 'error');
return false;
}
$itemMetadata = array('public' => false,
'featured' => false,
'item_type_id' => $itemTypeId);
$itemMetadata = array(
'public' => false,
'featured' => false,
'item_type_id' => $itemTypeId,
);

$collectionId = get_option('contribution_collection_id');
if (!empty($collectionId) && is_numeric($collectionId)) {
Expand All @@ -262,7 +263,7 @@ protected function _processForm($post)
} catch (Omeka_File_Ingest_InvalidException $e) {
// Copying this cruddy hack
if (strstr($e->getMessage(), "'contributed_file'")) {
$this->_helper->flashMessenger("You must upload a file when making a {$contributionType->display_name} contribution.", 'error');
$this->_helper->flashMessenger(__('You must upload a file when making a %s contribution.', $contributionType->display_name), 'error');
}
else {
$this->_helper->flashMessenger($e->getMessage());
Expand All @@ -273,8 +274,11 @@ protected function _processForm($post)
return false;
}
$this->_addElementTextsToItem($item, $post['Elements']);
if ($contributionType->add_tags && isset($post['tags'])) {
$item->addTags($post['tags']);
}
// 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));
fire_plugin_hook('contribution_save_form', array('contributionType' => $contributionType, 'record' => $item, 'post' => $post));
$item->save();
//if not simple and the profile doesn't process, send back false for the error
$this->_processUserProfile($post, $user);
Expand Down
1 change: 1 addition & 0 deletions models/ContributionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ContributionType extends Omeka_Record_AbstractRecord
public $display_name;
public $file_permissions = 'Disallowed';
public $multiple_files;
public $add_tags;

protected $_related = array(
'ContributionTypeElements' => 'getTypeElements',
Expand Down
12 changes: 12 additions & 0 deletions views/admin/types/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
</div>
</div>

<div class="field">
<div class="two columns alpha">
<label><?php echo __("Add Tags"); ?></label>
</div>
<div class="inputs five columns omega">
<p class="explanation"><?php echo __("Allow to add tags."); ?></p>
<div class="input-block">
<?php echo $this->formCheckbox('add_tags', null, array('checked' => $contribution_type->add_tags)); ?>
</div>
</div>
</div>

<div id="element-list" class="seven columns alpha">
<ul id="contribution-type-elements" class="sortable">
<?php
Expand Down
12 changes: 12 additions & 0 deletions views/public/contribution/type-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
}
?>

<?php if ($type->add_tags) : ?>
<div id="tag-form" class="field">
<div>
<?php echo $this->formLabel('tags', __('Add Tags')); ?>
</div>
<div>
<p id="add-tags-explanation" class="explanation"><?php echo __('Separate tags with %s', option('tag_delimiter')); ?></p>
<?php echo $this->formText('tags'); ?>
</div>
</div>
<?php endif; ?>

<?php
if (!isset($required) && $type->isFileAllowed()):
?>
Expand Down

0 comments on commit e0074a1

Please sign in to comment.