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

Delete contribution #52

Open
wants to merge 3 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
11 changes: 10 additions & 1 deletion ContributionPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function hookInstall()
`item_id` INT UNSIGNED NOT NULL,
`public` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`anonymous` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`deleted` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `item_id` (`item_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.3', '<')) {
$db = $this->_db;
$sql = "ALTER TABLE `$db->ContributionContributedItem` ADD COLUMN `deleted` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' AFTER `anonymous`";
$db->query($sql);
}
}

public function hookUninstallMessage()
Expand Down Expand Up @@ -714,7 +721,9 @@ private function _adminBaseInfo($args)

$publicMessage = '';
if (is_allowed($item, 'edit')) {
if ($contributedItem->public) {
if ($contributedItem->deleted) {
$publicMessage = __('This item has been deleted by user. It cannot be made public.');
} elseif ($contributedItem->public) {
$publicMessage = __("This item can be made public.");
} else {
$publicMessage = __("This item cannot be made public.");
Expand Down
23 changes: 14 additions & 9 deletions controllers/ContributionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@ public function myContributionsAction()
if(!empty($_POST)) {
foreach($_POST['contribution_public'] as $id=>$value) {
$contribItem = $contribItemTable->find($id);
if($value) {
$contribItem->public = true;
} else {
$contribItem->makeNotPublic();
}
$contribItem->public = $value;
$contribItem->anonymous = $_POST['contribution_anonymous'][$id];
$contribItem->public = (integer) $value;
$contribItem->anonymous = (integer) $_POST['contribution_anonymous'][$id];
$contribItem->deleted = (integer) $_POST['contribution_deleted'][$id];

if($contribItem->save()) {
$this->_helper->flashMessenger( __('Your contributions have been updated.'), 'success');
} else {
$this->_helper->flashMessenger($contribItem->getErrors());
}

$contribItems[] = $contribItem;
// Clean list for next view.
if (!$contribItem->deleted) {
$contribItems[] = $contribItem;
}
}
} else {
$contribItems = $contribItemTable->findBy(array('contributor'=>$user->id));
$contribItems = $contribItemTable->findBy(array(
'contributor' => $user->id,
'deleted' => false,
));
}
$this->view->contrib_items = $contribItems;
}
Expand Down Expand Up @@ -260,6 +262,7 @@ protected function _processForm($post)
$item = update_item($item, $itemMetadata, array(), $fileMetadata);
} catch(Omeka_Validator_Exception $e) {
$this->flashValidatonErrors($e);
$item->delete();
return false;
} catch (Omeka_File_Ingest_InvalidException $e) {
// Copying this cruddy hack
Expand All @@ -268,9 +271,11 @@ protected function _processForm($post)
} else {
$this->_helper->flashMessenger($e->getMessage());
}
$item->delete();
return false;
} catch (Exception $e) {
$this->_helper->flashMessenger($e->getMessage());
$item->delete();
return false;
}
$this->_addElementTextsToItem($item, $post['Elements']);
Expand Down
14 changes: 14 additions & 0 deletions helpers/ThemeHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,17 @@ function contribution_contribute_url($actionName = null)
return get_view()->url($options, $route, array(), true);
}

/**
* Get a URL to the public contribution remove page.
*
* @param Record|integer $contributedItem.
* @return string URL
*/
function contribution_remove_url($contributedItem)
{
$basePath = get_option('contribution_page_path');
$string = $basePath ? $basePath : 'contribution';
$string .= '/remove/';
$string .= is_object($contributedItem) ? $contributedItem->id : (integer) $contributedItem;
return url($string);
}
43 changes: 33 additions & 10 deletions models/ContributionContributedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ContributionContributedItem extends Omeka_Record_AbstractRecord
public $item_id;
public $public;
public $anonymous;

public $deleted = 0;

protected $_related = array(
'Item' => 'getItem',
'Contributor' => 'getContributor'
Expand All @@ -28,15 +29,6 @@ public function getItem()
return $this->getDb()->getTable('Item')->find($this->item_id);
}

public function makeNotPublic()
{
$this->public = false;
$item = $this->Item;
$item->public = false;
$item->save();
release_object($item);
}

public function getContributor()
{
$owner = $this->Item->getOwner();
Expand All @@ -57,4 +49,35 @@ public function getContributor()
}
return $owner;
}

/**
* Before-save hook.
*
* @param array $args
*/
protected function beforeSave($args)
{
// Delete a contributed item. In fact, for security reason, make it
// private and invisible to contributor.
if ($this->deleted) {
$this->public = false;
}
}

/**
* After-save hook.
*
* @param array $args
*/
protected function afterSave($args)
{
if (!$this->public) {
$item = $this->Item;
if ($item->public) {
$item->public = false;
$item->save(false);
}
release_object($item);
}
}
}
2 changes: 2 additions & 0 deletions views/admin/common/contribution-quick-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<li><a href="<?php echo url('contribution/items', array('status' => 'public')); ?>"><?php echo __('Public'); ?></a></li>
<li><a href="<?php echo url('contribution/items', array('status' => 'private')); ?>"><?php echo __('Private'); ?></a></li>
<li><a href="<?php echo url('contribution/items', array('status' => 'review')); ?>"><?php echo __('Needs review'); ?></a></li>
<li><a href="<?php echo url('contribution/items', array('deleted' => true)); ?>"><?php echo __('Deleted by User'); ?></a></li>
<li><a href="<?php echo url('contribution/items', array('deleted' => false)); ?>"><?php echo __('Not Deleted by User'); ?></a></li>
</ul>
</li>
</ul>
14 changes: 8 additions & 6 deletions views/admin/contributors/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
<?php endif; ?>

<div id='contribution-user-contributions'>
<?php foreach($items as $item): ?>
<?php set_current_record('item', $item->Item); ?>
<?php foreach($items as $contributedItem): ?>
<?php set_current_record('item', $contributedItem->Item); ?>
<section class="seven columns omega contribution">
<?php
if ($item->Item->public) {
<?php
if ($contributedItem->deleted) {
$status = __('User Deleted');
} elseif ($contributedItem->Item->public) {
$status = __('Public');
} else {
if($item->public) {
if($contributedItem->public) {
$status = __('Needs review');
} else {
$status = __('Private contribution');
Expand All @@ -45,7 +47,7 @@
?>

<h2><?php echo link_to_item(null, array(), 'edit'); ?></h2>
<p><?php echo $status;?> <?php echo (boolean) $item->anonymous ? " | " . __('Anonymous') : ""; ?></p>
<p><?php echo $status;?> <?php echo (boolean) $contributedItem->anonymous ? " | " . __('Anonymous') : ""; ?></p>
<?php
echo item_image_gallery(
array('linkWrapper' => array('class' => 'admin-thumb panel')),
Expand Down
4 changes: 3 additions & 1 deletion views/admin/items/browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@
<?php endif; ?>
</td>
<td class="contribution-status">
<?php if ($allowToManage && ($status != 'private')): ?>
<?php if ($contributedItem->deleted): ?>
<span class="contribution deleted"><?php echo __('User Deleted'); ?></span>
<?php elseif ($allowToManage && ($status != 'private')): ?>
<a href="<?php echo ADMIN_BASE_URL; ?>" id="contribution-<?php echo $contributedItem->id; ?>" class="contribution toggle-status status <?php echo $status; ?>"><?php echo $statusText; ?></a>
<?php else: ?>
<span class="contribution toggle-status status <?php echo $status; ?>"><?php echo $statusText; ?></span>
Expand Down
13 changes: 7 additions & 6 deletions views/public/contribution/my-contributions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@
<th><?php echo __('Public'); ?></th>
<th><?php echo __('Anonymous'); ?></th>
<th><?php echo __('Item'); ?></th>
<th><?php echo __('Remove'); ?></th>
<th><?php echo __('Added'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach(loop('contrib_items') as $contribItem): ?>
<?php $item = $contribItem->Item; ?>
<tr>
<td><?php echo $this->formCheckbox("contribution_public[{$contribItem->id}]", null, array('checked'=>$contribItem->public) ); ?>
</td>
<td><?php echo $this->formCheckbox("contribution_anonymous[{$contribItem->id}]", null, array('checked'=>$contribItem->anonymous) ); ?>
</td>
<td><?php echo $this->formCheckbox("contribution_public[{$contribItem->id}]",
null, array('checked' => $contribItem->public)); ?></td>
<td><?php echo $this->formCheckbox("contribution_anonymous[{$contribItem->id}]",
null, array('checked' => $contribItem->anonymous)); ?></td>
<td><?php echo link_to($item, 'show', metadata($item, array('Dublin Core', 'Title'))); ?></td>
<td><?php echo $this->formCheckbox("contribution_deleted[{$contribItem->id}]",
null, array('checked' => false)); ?></td>
<td><?php echo metadata($item, 'added'); ?></td>

</tr>

<?php endforeach; ?>
</tbody>
</table>
Expand Down