Skip to content

Commit

Permalink
Merge pull request #140 from UIUCLibrary/issue_138
Browse files Browse the repository at this point in the history
Issue 138
  • Loading branch information
alexdryden authored Sep 18, 2023
2 parents c4febdd + 9843732 commit a131f38
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 169 deletions.
22 changes: 22 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,21 @@ public function filterByTeam(Event $event)
}
}

public function getOrphans(Event $event)
{
$request = $event->getParam('request')->getContent();
if(array_key_exists('orphans', $request)){
$qb = $event->getParam('queryBuilder');
$sub = $this->getServiceLocator()->get('Omeka\EntityManager')
->createQueryBuilder()
->select('tr')
->from('Teams\Entity\TeamResource', 'tr');
$q = $sub->getQuery()->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
$resource_ids = array_column($q,'tr_resource_id');
$qb->andWhere($qb->expr()->notIn('omeka_root.id', $resource_ids));
}
}

//Handle Users
public function filterByTeamUser(Event $event)
{
Expand Down Expand Up @@ -2537,8 +2552,15 @@ public function attachListeners(SharedEventManagerInterface $sharedEventManager)
'api.search.query',
[$this, 'filterByTeam']
);

endforeach;

$sharedEventManager->attach(
ItemAdapter::class,
'api.search.query',
[$this, 'getOrphans']
);

$sharedEventManager->attach(
UserAdapter::class,
'api.search.query',
Expand Down
52 changes: 15 additions & 37 deletions src/Controller/TrashController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function createNamedParameter(

public function indexAction()
{
$qb = $this->entityManager->createQueryBuilder();

if ($this->request->isPost()) {
if ($this->identity()->getRole() == 'global_admin') {
Expand Down Expand Up @@ -70,42 +69,17 @@ public function indexAction()
}
}
}
$params = $this->params();
if ($params()->fromQuery('sort_order') === 'asc') {
$order = 'asc';
} else {
$order = 'desc';
}
$sort_options = [
'title' => 'title',
'id' => 'id',
'resource_class_label' => 'class',
'owner_name' => 'owner',
'created' => 'created',
];
if (key_exists($params->fromQuery('sort_by'), $sort_options)) {
$sort = $sort_options[$params->fromQuery('sort_by')];
} else {
$sort = 'created';
}
$this->browse()->setDefaults('items');
$params = $this->params()->fromQuery();
$params['orphans'] = true;
$params['bypass_team_filter'] = true;
$response = $this->api()->search('items', $params);
$this->paginator($response->getTotalResults());

$orphans = $response->getContent();
$returnQuery = $this->params()->fromQuery();
unset($returnQuery['page']);

$qb->select('r_trash')
->from('Omeka\Entity\Item ', 'r_trash')
->leftJoin(
'Teams\Entity\TeamResource',
'tr_trash',
\Doctrine\ORM\Query\Expr\Join::WITH,
'r_trash.id = tr_trash.resource'
)
->where('tr_trash.team is NULL')
->orderBy('r_trash.' . $sort, $order);

$orphans = $qb->getQuery()->getResult();
$this->paginator(count($orphans));

$page = $this->params()->fromQuery('page');
$offset = ($page * 10) - 10;
$orphans = array_slice($orphans, $offset, 10);
$formDeleteSelected = $this->getForm(ConfirmForm::class);
$formDeleteSelected->setAttribute('action', $this->url()->fromRoute('admin/trash', ['action' => 'batch-delete'], true));
$formDeleteSelected->setButtonLabel('Delete Selected'); // @translate
Expand All @@ -118,9 +92,13 @@ public function indexAction()
$formDeleteAll->get('submit')->setAttribute('disabled', true);

$view = new ViewModel;
$view->setVariable('orphan', $orphans);
$view->setVariable('items', $orphans);
$view->setVariable('formDeleteSelected', $formDeleteSelected);
$view->setVariable('formDeleteAll', $formDeleteAll);
$view->setVariable('resources', $orphans);
$view->setVariable('formDeleteSelected', $formDeleteSelected);
$view->setVariable('formDeleteAll', $formDeleteAll);
$view->setVariable('returnQuery', $returnQuery);

return $view;
}
Expand Down
208 changes: 76 additions & 132 deletions view/teams/trash/index.phtml
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
<?php

$items = array();
foreach ($this->orphan as $item):
$items[] = $this->api()->read('items', $item->getId())->getContent();
endforeach;
?>
<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$this->htmlElement('body')->appendAttribute('class', 'items browse');
$sortHeadings = [
[
'label' => $translate('Title'),
'value' => 'title'
],
[
'label' => $translate('Identifier'),
'value' => 'dcterms:identifier'
],
[
'label' => $translate('Class'),
'value' => 'resource_class_label'
],
[
'label' => $translate('Owner'),
'value' => 'owner_name'
],
[
'label' => $translate('Created'),
'value' => 'created'
],
];
?>

<?php echo $this->pageTitle($translate('Orphaned Items')); ?>
Expand All @@ -39,105 +10,77 @@ $sortHeadings = [

<div class="browse-controls">
<?php echo $this->pagination(); ?>
<!-- --><?php //echo $this->hyperlink($translate('Advanced search'), $this->url(null, ['action' => 'search'], ['query' => $this->params()->fromQuery()], true), ['class' => 'advanced-search']);?>
<?php echo $this->sortSelector($sortHeadings); ?>
<?php echo $this->browse()->renderSortSelector('items'); ?>
</div>

<div id="page-actions">

</div>
<?php $this->trigger('view.browse.before'); ?>
<?php if ($items): ?>
<form method="post" id="batch-form" class="disable-unsaved-warning">
<?php if ($this->userIsAllowed('Teams\Controller\Trash', 'perm_delete')): ?>
<div class="batch-inputs">
<select class="batch-actions-select" aria-label="<?php echo $translate('Batch actions'); ?>">
<option value="default"><?php echo $translate('Batch actions'); ?></option>
<option value="delete-selected" disabled="true"><?php echo $translate('Delete selected'); ?></option>
<option value="delete-all"><?php echo $translate('Delete all'); ?></option>
</select>
<div class="batch-actions">
<button type="button" class="default active" disabled="true"><?php echo $translate('Go'); ?></button>
<input type="hidden" name="query" class="batch-query" value="<?php echo $escape(json_encode($this->params()->fromQuery())); ?>">
<a class="delete button sidebar-content delete-selected" data-sidebar-selector="#sidebar-delete-selected"><?php echo $translate('Go'); ?></a>
<a class="delete button sidebar-content delete-all" data-sidebar-selector="#sidebar-delete-all"><?php echo $translate('Go'); ?></a>
</div>
</div>
<?php endif; ?>


<table class="tablesaw batch-edit" data-tablesaw-mode="stack">
<thead>
<tr>
<th><input type="checkbox" class="select-all" aria-label="<?php echo $translate('Select all'); ?>"><?php echo $translate('Title'); ?></th>
<th><?php echo $translate('Class'); ?></th>
<th><?php echo $translate('Owner'); ?></th>
<th><?php echo $translate('Created'); ?></th>
<th><?php echo $translate('Last Modified'); ?></th>

</tr>
</thead>
<tbody>
<?php foreach ($items as $item): ?>
<?php
if ($owner = $item->owner()) {
$ownerText = $this->hyperlink(
$owner->name(),
$this->url(
'admin/id',
[
'controller' => 'user',
'action' => 'show',
'id' => $owner->id()]
)
);
} else {
$ownerText = $translate('[no owner]');
}
?>
<tr>
<td>
<?php if ($item->userIsAllowed('update') || $item->userIsAllowed('delete')): ?>
<input type="checkbox" name="resource_ids[]" value="<?php echo $item->id(); ?>" aria-label="<?php echo $translate('Select item'); ?>">
<?php endif; ?>
<?php echo $item->linkPretty(); ?>
<?php if (!$item->isPublic()): ?>
<span class="o-icon-private" aria-label="<?php echo $translate('Private'); ?>"></span>
<?php endif; ?>
<ul class="actions">
<?php if ($item->userIsAllowed('update')): ?>
<li><?php echo $item->link('', 'edit', [
'class' => 'o-icon-edit',
'title' => $translate('Edit'),
]); ?></li>
<form method="post" id="batch-form" class="disable-unsaved-warning">
<?php if ($this->userIsAllowed('Omeka\Api\Adapter\ItemAdapter', 'batch_update')): ?>
<div class="batch-inputs">
<select class="batch-actions-select" aria-label="<?php echo $translate('Batch actions'); ?>">
<option value="default"><?php echo $translate('Batch actions'); ?></option>
<option value="update-selected" disabled="true"><?php echo $translate('Edit selected'); ?></option>
<?php if ($this->userIsAllowed('Omeka\Api\Adapter\ItemAdapter', 'batch_update_all')): ?>
<option value="update-all"><?php echo $translate('Edit all'); ?></option>
<?php endif; ?>
<!-- --><?php //if ($item->userIsAllowed('delete')):?>
<!-- <li>--><?php //echo $this->hyperlink('', '#', [
// 'data-sidebar-selector' => '#sidebar',
// 'data-sidebar-content-url' => $item->url('perm-delete-confirm'),
// 'class' => 'o-icon-delete sidebar-content',
// 'title' => $translate('Delete'),
// ]);?><!--</li>-->
<!-- --><?php //endif;?>
<li><?php echo $this->hyperlink('', '#', [
'data-sidebar-selector' => '#sidebar',
'data-sidebar-content-url' => $item->url('show-details'),
'class' => 'o-icon-more sidebar-content',
'title' => $translate('Details'),
]); ?></li>
</ul>
</td>
<td><?php echo $escape($translate($item->displayResourceClassLabel())); ?></td>
<td><?php echo $ownerText; ?></td>
<td><?php echo $escape($this->i18n()->dateFormat($item->created())); ?></td>
<td><?php echo $escape($this->i18n()->dateFormat($item->modified())); ?></td>

</tr>
<?php endforeach; ?>
</tbody>
</table>

</form>
<option value="delete-selected" disabled="true"><?php echo $translate('Delete selected'); ?></option>
<?php if ($this->userIsAllowed('Omeka\Api\Adapter\ItemAdapter', 'batch_delete_all')): ?>
<option value="delete-all"><?php echo $translate('Delete all'); ?></option>
<?php endif; ?>
</select>
<div class="batch-actions">
<button type="button" class="default active" disabled="true"><?php echo $translate('Go'); ?></button>
<input type="submit" class="update-selected" name="update_selected" value="<?php echo $translate('Go'); ?>" formaction="<?php echo $escape($this->url(null, ['action' => 'batch-edit'], ['query' => $returnQuery], true)); ?>">
<input type="submit" class="update-all" name="update_all" value="<?php echo $translate('Go'); ?>" formaction="<?php echo $escape($this->url(null, ['action' => 'batch-edit-all'], ['query' => $returnQuery], true)); ?>">
<input type="hidden" name="query" class="batch-query" value="<?php echo $escape(json_encode($this->params()->fromQuery())); ?>">
<a class="delete button sidebar-content delete-selected" data-sidebar-selector="#sidebar-delete-selected"><?php echo $translate('Go'); ?></a>
<a class="delete button sidebar-content delete-all" data-sidebar-selector="#sidebar-delete-all"><?php echo $translate('Go'); ?></a>
</div>
</div>
<?php endif; ?>


<table class="tablesaw batch-edit" data-tablesaw-mode="stack">
<thead>
<tr>
<th><input type="checkbox" class="select-all" aria-label="<?php echo $translate('Select all'); ?>"><?php echo $translate('Title'); ?></th>
<?php echo $this->browse()->renderHeaderRow('items'); ?>
</tr>
</thead>
<tbody>
<?php foreach ($items as $item): ?>
<tr>
<td>
<?php if ($this->userIsAllowed('Omeka\Api\Adapter\ItemAdapter', 'batch_update') && ($item->userIsAllowed('update') || $item->userIsAllowed('delete'))): ?>
<input type="checkbox" name="resource_ids[]" value="<?php echo $item->id(); ?>" aria-label="<?php echo $translate('Select item'); ?>">
<?php endif; ?>
<?php echo $item->linkPretty(); ?>
<?php if (!$item->isPublic()): ?>
<span class="o-icon-private" aria-label="<?php echo $translate('Private'); ?>"></span>
<?php endif; ?>
<ul class="actions">
<?php if ($item->userIsAllowed('update')): ?>
<li><?php echo $item->link('', 'edit', [
'class' => 'o-icon-edit',
'title' => $translate('Edit'),
]); ?></li>
<?php endif; ?>
<li><?php echo $this->hyperlink('', '#', [
'data-sidebar-selector' => '#sidebar',
'data-sidebar-content-url' => $item->url('show-details'),
'class' => 'o-icon-more sidebar-content',
'title' => $translate('Details'),
]); ?></li>
</ul>
</td>
<?php echo $this->browse()->renderContentRow('items', $item); ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>

</form>

<?php $this->trigger('view.browse.after'); ?>
<div class="browse-controls">
Expand All @@ -161,10 +104,10 @@ $sortHeadings = [
<h3><?php echo $translate('Delete items'); ?></h3>
<p><?php echo $translate('Are you sure you would like to delete the selected items?'); ?></p>
<p class="error"><?php echo sprintf(
$translate('%1$s: this action will permanently delete %2$s items and cannot be undone.'),
sprintf('<strong>%s</strong>', $translate('Warning')),
'<strong><span id="delete-selected-count"></span></strong>'
); ?></p>
$translate('%1$s: this action will permanently delete %2$s items and cannot be undone.'),
sprintf('<strong>%s</strong>', $translate('Warning')),
'<strong><span id="delete-selected-count"></span></strong>'
); ?></p>
<?php echo $this->form($this->formDeleteSelected); ?>
</div>
</div>
Expand All @@ -179,10 +122,10 @@ $sortHeadings = [
<h3><?php echo $translate('Delete items'); ?></h3>
<p><?php echo $translate('Are you sure you would like to delete all items on all pages of this result?'); ?></p>
<p class="error"><?php echo sprintf(
$translate('%1$s: this action will permanently delete %2$s items and cannot be undone.'),
sprintf('<strong>%s</strong>', $translate('Warning')),
sprintf('<strong>%s</strong>', number_format($this->pagination()->getPaginator()->getTotalCount()))
); ?></p>
$translate('%1$s: this action will permanently delete %2$s items and cannot be undone.'),
sprintf('<strong>%s</strong>', $translate('Warning')),
sprintf('<strong>%s</strong>', number_format($this->pagination()->getPaginator()->getTotalCount()))
); ?></p>
<label><input type="checkbox" name="confirm-delete-all-check"> <?php echo $translate('Are you sure?'); ?></label>
<?php echo $this->form($this->formDeleteAll); ?>
</div>
Expand Down Expand Up @@ -217,9 +160,10 @@ $('#sidebar-delete-all').on('click', 'input[name="confirm-delete-all-check"]', f
<?php else: ?>

<div class="no-resources">
<p><?php echo $translate('Omeka could not find any items.'); ?></p>
<p><?php echo $translate('Omeka could not find any orphaned items.'); ?></p>
</div>

<?php endif; ?>



0 comments on commit a131f38

Please sign in to comment.