Skip to content

Commit

Permalink
Add setting for default item sites for users
Browse files Browse the repository at this point in the history
(fix #1594)
  • Loading branch information
zerocrates committed Sep 14, 2020
1 parent 8a6c1af commit a37d4b3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
22 changes: 20 additions & 2 deletions application/src/Form/UserForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Omeka\Form;

use Omeka\Form\Element\ResourceSelect;
use Omeka\Form\Element\SiteSelect;
use Omeka\Permissions\Acl;
use Omeka\Settings\Settings;
use Omeka\Settings\UserSettings;
Expand Down Expand Up @@ -122,7 +123,9 @@ public function init()
if (null === $locale) {
$locale = $this->settings->get('locale');
}
$this->get('user-settings')->add([

$settingsFieldset = $this->get('user-settings');
$settingsFieldset->add([
'name' => 'locale',
'type' => 'Omeka\Form\Element\LocaleSelect',
'options' => [
Expand All @@ -135,7 +138,7 @@ public function init()
'id' => 'locale',
],
]);
$this->get('user-settings')->add([
$settingsFieldset->add([
'name' => 'default_resource_template',
'type' => ResourceSelect::class,
'attributes' => [
Expand All @@ -158,6 +161,21 @@ public function init()
],
],
]);
$settingsFieldset->add([
'name' => 'default_item_sites',
'type' => SiteSelect::class,
'attributes' => [
'value' => $userId ? $this->userSettings->get('default_item_sites', null, $userId) : [],
'class' => 'chosen-select',
'data-placeholder' => 'Select sites', // @translate
'multiple' => true,
'id' => 'default_sites',
],
'options' => [
'label' => 'Default sites for items', // @translate
'empty_option' => '',
],
]);

if ($this->getOption('include_password')) {
if ($this->getOption('current_password')) {
Expand Down
30 changes: 20 additions & 10 deletions application/view/omeka/admin/item/manage-sites.phtml
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
<?php
$siteRepresentations = $item
? $item->sites()
: $this->api()->search('sites', ['assign_new_items' => true])->getContent();
if ($item) {
$siteRepresentations = $item->sites();
} else {
$siteRepresentations = $this->api()->search('sites', ['assign_new_items' => true])->getContent();

$userDefaultSites = $this->userSetting('default_item_sites');
if (is_array($userDefaultSites)) {
$userDefaultSiteRepresentations = $this->api()->search('sites', ['id' => $userDefaultSites])->getContent();
$siteRepresentations = array_merge($siteRepresentations, $userDefaultSiteRepresentations);
}
}

$sites = [];
foreach ($siteRepresentations as $siteRepresentation) {
$sites[] = [
'id' => $siteRepresentation->id(),
'title' => $siteRepresentation->title(),
'email' => $siteRepresentation->owner(),
];
$id = $siteRepresentation->id();
$sites[$id] = [
'id' => $id,
'title' => $siteRepresentation->title(),
'email' => $siteRepresentation->owner(),
];
}

$siteTemplate = '
Expand All @@ -23,7 +33,7 @@ $siteTemplate = '
</td>
</tr>';
?>
<table id="item-sites" data-existing-rows="<?php echo $this->escapeHtml(json_encode($sites)); ?>" data-row-template="<?php echo $this->escapeHtml($siteTemplate); ?>" data-tablesaw-mode="stack" class="selector-table tablesaw tablesaw-stack <?php echo ($item && (count($sites) > 0)) ? '' : 'empty'; ?>">
<table id="item-sites" data-existing-rows="<?php echo $this->escapeHtml(json_encode(array_values($sites))); ?>" data-row-template="<?php echo $this->escapeHtml($siteTemplate); ?>" data-tablesaw-mode="stack" class="selector-table tablesaw tablesaw-stack <?php echo ($item && (count($sites) > 0)) ? '' : 'empty'; ?>">
<thead>
<tr>
<th><?php echo $this->translate('Title'); ?></th>
Expand All @@ -44,4 +54,4 @@ $siteTemplate = '

<script>
Omeka.initializeSelector('#item-sites', '#site-selector');
</script>
</script>

0 comments on commit a37d4b3

Please sign in to comment.