Hi
I am attempting to add a secondary “Collections” or itemset menu to a theme. I would like the the menu to list just those Item Sets that contain items for each particular site and to sort the item sets alphabetically.
Building on previous advice supplied on this forum I have come up with:-
<?php $siteId = $site->id(); ?>
<nav id="item-set-menu">
<ul>
<?php $itemSets = $this->api()->search('item_sets', ['site_id' => $siteId, 'sort_by' => 'title', 'sort_order' => 'asc'])->getContent(); ?>
<li>Collections:</li>
<ul>
<?php foreach ($itemSets as $itemSet):
$itemCount = $itemSet->itemCount();
if ($itemCount > 0): ?>
<li>
<?php $fullLink = $itemSet->link($itemSet->displayTitle());
$href = (string)( new SimpleXMLElement($fullLink))['href'];
$firstQuote = strpos($fullLink,'href="')+5;
$secondQuote = strpos($fullLink,'"',$firstQuote+1)+1;
$finalLink = substr($fullLink,0,$firstQuote) . $href . "?sort_by=title&sort_order=asc";
$finalLink .= substr($fullLink,$secondQuote);
echo $finalLink; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</ul>
</nav>
This works (surprisingly) but has issues:
- There must be a better way to set the default sort order for when each item set is displayed than having to muck about with the URL, appending the sort_by and sort_order parameters.
- I used the itemCount function to determine how many items are in each set, BUT this returns how many items are in the total item set pool, and not how many are associated with a particular site.
- I would like the first option in the menu to link to the same Item Set page that you get from the standard options in the navigation menu with a few improvements if possible. The standard Item Set page returns all the item sets in the site’s pool even if it is empty. Again there seems little point listing an empty item set.
One issue I have is trying to determine how to best to invoke some of the function. For example the https://omeka.org/s/docs/developer/modules/view_helpers/ page list many helpers, however few have examples, or any indications of parameters that may be passed. Attempting to find instances within the code is not helpful, for example searching the installation for “searchFilters” returns 610 hits in 51 files.
Many thanks for looking