-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Debian
committed
Apr 10, 2023
1 parent
bbcd9ed
commit 9a4c943
Showing
6 changed files
with
158 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,133 @@ | ||
<?php | ||
$translate = $this->plugin('translate'); | ||
$escape = $this->plugin('escapeHtml'); | ||
use Laminas\Form\Element\Select; | ||
|
||
$fragment = 'item-linked'; | ||
if ('Omeka\Api\Representation\ItemSetRepresentation' === get_class($objectResource)) { | ||
$fragment = 'item-set-linked'; | ||
} | ||
// Set up pagination. | ||
$pagination = $this->pagination(null, $totalCount, $page, $perPage); | ||
$fragment = 'resources-linked'; | ||
$pagination->setFragment($fragment); | ||
$showAltLabel = false; | ||
|
||
// Set up locale. | ||
$lang = null; | ||
$filterLocale = false; | ||
if ($this->status()->isSiteRequest()) { | ||
$lang = $this->lang(); | ||
$filterLocale = (bool) $this->siteSetting('filter_locale_values'); | ||
} | ||
|
||
// Set up resource property select. | ||
$labelMap = [ | ||
'items' => 'Items', // @translate | ||
'item_sets' => 'Item sets', // @translate | ||
'media' => 'Media', // @translate | ||
]; | ||
$resourcePropertiesSelect = new Select('resource_property'); | ||
$resourcePropertiesSelect->setValue($resourceProperty); | ||
$resourcePropertiesSelect->setAttributes([ | ||
'id' => 'resource-property-select', | ||
'class' => 'form-control', | ||
'data-url' => $this->url(null, [], true), | ||
'data-fragment' => $fragment, | ||
]); | ||
$valueOptions = []; | ||
foreach ($resourcePropertiesAll as $type => $resourceProperties) { | ||
if (!$resourceProperties) { | ||
continue; | ||
} | ||
$valueOptions[$type] = [ | ||
'label' => $labelMap[$type], | ||
'options' => [sprintf('%s:', $type) => sprintf('%s: All', $labelMap[$type])], | ||
]; | ||
foreach ($resourceProperties as $resourceProperty) { | ||
$key = sprintf('%s:%s', $type, $resourceProperty['id_concat']); | ||
$value = $resourceProperty['property_alternate_label'] | ||
? $this->translate($resourceProperty['property_alternate_label']) | ||
: $this->translate($resourceProperty['property_label']); | ||
$valueOptions[$type]['options'][$key] = sprintf('%s: %s', $labelMap[$type], $value); | ||
} | ||
} | ||
$resourcePropertiesSelect->setValueOptions($valueOptions); | ||
?> | ||
<div id="linked-resources"> | ||
|
||
<div class="linked-header"> | ||
<div id="linked-filter" class="mb-4"> | ||
<div class="form-group row"> | ||
<label for="staticEmail" class="col-sm-4 col-form-label"><?php echo $translate('Filter by property'); ?></label> | ||
<label class="col-sm-4 col-form-label"> | ||
<?php echo $this->translate('Filter by resource type and property:'); ?> | ||
</label> | ||
<div class="col-sm-8"> | ||
<select id="filter-property" class="form-control" name="property" data-url="<?php echo $escape($this->url(null, [], true)); ?>" data-fragment="<?php echo $escape($fragment); ?>"> | ||
<option value=""><?php echo $translate('All'); ?></option> | ||
<?php foreach ($properties as $prop): ?> | ||
<option value="<?php echo $escape($prop->id()); ?>"<?php echo $prop->id() == $property ? ' selected="selected"' : ''; ?>><?php echo $escape(sprintf('%s (%s)', $prop->label(), $prop->term())); ?></option> | ||
<?php endforeach; ?> | ||
</select> | ||
|
||
<?php echo $this->formElement($resourcePropertiesSelect); ?> | ||
</div> | ||
</div> | ||
</div> | ||
<!-- | ||
<div id="linked-filter"> | ||
<label> | ||
<?php echo $this->translate('Filter by resource type and property:'); ?> | ||
<?php echo $this->formElement($resourcePropertiesSelect); ?> | ||
</label> | ||
</div> | ||
--> | ||
<?php echo ($totalCount > $perPage) ? $pagination : ''; ?> | ||
</div> | ||
|
||
<?php foreach ($subjectValues as $term => $values): ?> | ||
<?php foreach ($subjectValues as $values): ?> | ||
|
||
<?php | ||
$caption = sprintf( | ||
$this->translate('%s with "%s: %s"'), | ||
$this->translate($labelMap[$resourceType]), | ||
$values[0]['property_alternate_label'] ?? $this->translate($values[0]['property_label']), | ||
$objectResource->displayTitle() | ||
); | ||
?> | ||
|
||
<div class="card my-4"> | ||
<div class="card-header"> | ||
<?php echo $escape($this->translate($values[0]->property()->label())); ?> | ||
<?php echo $this->escapeHtml($caption); ?> | ||
</div> | ||
<div class="card-body"> | ||
|
||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th><?php echo $translate('Title'); ?></th> | ||
<?php if ($showAltLabel): ?> | ||
<th width="40%"><?php echo $translate('Alternate label'); ?></th> | ||
<?php endif; ?> | ||
<th width="20%"><?php echo $translate('Class'); ?></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($values as $value): ?> | ||
<?php | ||
$template = $value->resource()->resourceTemplate(); | ||
$templateProperty = $template ? $template->resourceTemplateProperty($value->property()->id()) : null; | ||
$altLabel = $templateProperty ? $templateProperty->alternateLabel() : null; | ||
?> | ||
<tr class="linked-resource"> | ||
<td><?php echo $value->resource()->linkPretty(); ?></td> | ||
<?php if ($showAltLabel): ?> | ||
<td width="40%"> | ||
<?php if ($altLabel): ?> | ||
<span class="alternate-label"><?php echo $this->escapeHtml($altLabel); ?></span> | ||
<?php endif; ?> | ||
<!-- <caption class="linked-resource-property"><?php echo $this->escapeHtml($caption); ?></caption> --> | ||
<thead> | ||
<tr> | ||
<th><?php echo $this->translate('Title'); ?></th> | ||
<th><?php echo $this->translate('Class'); ?></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($values as $value): ?> | ||
<tr class="linked-resource"> | ||
<td><?php echo $value['val']->resource()->linkPretty('square', null, null, null, ($filterLocale ? $lang : null)); ?></td> | ||
<td> | ||
<?php if ($value['val']->resource()->resourceClass()): ?> | ||
<span class="resource-class"><?php echo $this->escapeHtml($this->translate($value['val']->resource()->resourceClass()->label())); ?></span> | ||
<?php endif; ?> | ||
</td> | ||
<?php endif; ?> | ||
<td width="20%"> | ||
<?php if ($value->resource()->resourceClass()): ?> | ||
<span class="resource-class"><?php echo $this->escapeHtml($value->resource()->resourceClass()->label()); ?></span> | ||
<?php endif; ?> | ||
</td> | ||
</tr> | ||
<?php endforeach; ?> | ||
</tbody> | ||
</tr> | ||
<?php endforeach; ?> | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
</div> | ||
|
||
<?php endforeach; ?> | ||
|
||
<?php echo ($totalCount > $perPage) ? '<div class="linked-footer">' . $pagination . '</div>' : ''; ?> | ||
|
||
</div> | ||
|
||
<script> | ||
$('#filter-property').on('change', function(e) { | ||
var thisSelect = $(this); | ||
var property = thisSelect.find(':selected').val(); | ||
var url = thisSelect.data('url'); | ||
var fragment = thisSelect.data('fragment'); | ||
window.location = url + '?' + $.param({property: property}) + '#' + fragment; | ||
const propertySelect = $('#resource-property-select'); | ||
const url = propertySelect.data('url'); | ||
const fragment = propertySelect.data('fragment'); | ||
propertySelect.on('change', function(e) { | ||
const selectedOption = propertySelect.find(':selected'); | ||
const resourceProperty = selectedOption.val(); | ||
window.location = url + '?' + $.param({resource_property: resourceProperty}) + '#' + fragment; | ||
}); | ||
</script> |
29 changes: 29 additions & 0 deletions
29
view/common/resource-page-block-layout/linked-resources.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
$translate = $this->plugin('translate'); | ||
$options = [ | ||
'page' => $this->params()->fromQuery('page', 1), | ||
'perPage' => 25, | ||
'resourceProperty' => $this->params()->fromQuery('resource_property'), | ||
]; | ||
if ($this->siteSetting('exclude_resources_not_in_site')) { | ||
$options['siteId'] = $this->currentSite()->id(); | ||
} | ||
$subjectValues = $resource->displaySubjectValues($options); | ||
?> | ||
<?php if ($subjectValues): ?> | ||
|
||
<div class="card my-5"> | ||
<div class="card-header"> | ||
<?php echo $translate('Linked resources'); ?> | ||
</div> | ||
<div class="card-body"> | ||
|
||
<div id="resources-linked"> | ||
<!-- <h3><?php echo $this->translate('Linked resources'); ?></h3> --> | ||
<?php echo $subjectValues; ?> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
|
||
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
$resourceMedia = $resource->media(); | ||
?> | ||
<?php if (false && $resourceMedia): ?> | ||
<div class="media-embeds"> | ||
<?php foreach ($resourceMedia as $media): ?> | ||
<?php echo $media->render(); ?> | ||
<?php endforeach; ?> | ||
</div> | ||
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
$options = []; | ||
if ($this->siteSetting('exclude_resources_not_in_site')) { | ||
$options['siteId'] = $this->currentSite()->id(); | ||
} | ||
echo $resource->displayValues($options); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters