Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:collectiveaccess/pawtucket2 into…
Browse files Browse the repository at this point in the history
… develop
  • Loading branch information
mariamotorina committed Jul 6, 2023
2 parents 522c816 + c166cb2 commit 7127a05
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 85 deletions.
42 changes: 26 additions & 16 deletions app/lib/Browse/BrowseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* ----------------------------------------------------------------------
*
* Software by Whirl-i-Gig (http://www.whirl-i-gig.com)
* Copyright 2009-2020 Whirl-i-Gig
* Copyright 2009-2023 Whirl-i-Gig
*
* For more information visit http://www.CollectiveAccess.org
*
Expand Down Expand Up @@ -1691,9 +1691,11 @@ public function execute($pa_options=null) {
}

$vs_container_sql = '';
if (!caGetOption('multiple', $va_facet_info, false) && is_array($va_element_code) && (sizeof($va_element_code) == 1) && is_array($va_container_ids[$va_element_code[0]]) && sizeof($va_container_ids[$va_element_code[0]])) {

$container_element_code = (sizeof($va_element_code) >= 1) ? (ca_metadata_elements::getElementID($e = $va_element_code[sizeof($va_element_code) - 1]) ? $e : null) : null;
if (!caGetOption('multiple', $va_facet_info, false) && $container_element_code && sizeof($va_container_ids[$container_element_code] ?? [])) {
$vs_container_sql = " AND ca_attributes.attribute_id IN (?)";
$va_attr_values[] = $va_container_ids[$va_element_code[0]];
$va_attr_values[] = $va_container_ids[$container_element_code];
}

$vs_where_sql = '';
Expand Down Expand Up @@ -1723,8 +1725,8 @@ public function execute($pa_options=null) {

if (is_array($va_element_code) && sizeof($va_element_code) == 1) {
// is sub-element in container
$va_container_ids[$va_element_code[0]] = array_unique($qr_res->getAllFieldValues('attribute_id'));
$this->opo_ca_browse_cache->setParameter('container_ids', $va_container_ids[$va_element_code[0]]);
$va_container_ids[$container_element_code] = array_unique($qr_res->getAllFieldValues('attribute_id'));
$this->opo_ca_browse_cache->setParameter('container_ids', $va_container_ids[$container_element_code]);
}
if (!caGetOption('multiple', $va_facet_info, false)) {
$vn_i++;
Expand Down Expand Up @@ -1791,10 +1793,12 @@ public function execute($pa_options=null) {

if ($vb_is_element) {
$vs_container_sql = '';
$container_element_code = (sizeof($va_element_code) >= 1) ? (ca_metadata_elements::getElementID($e = $va_element_code[sizeof($va_element_code) - 1]) ? $e : null) : null;

$va_attr_values = null;
if (is_array($va_element_code) && (sizeof($va_element_code) == 1) && is_array($va_container_ids[$va_element_code[0]]) && sizeof($va_container_ids[$va_element_code[0]])) {
if (is_array($va_element_code) && $container_element_code && sizeof($va_container_ids[$container_element_code] ?? [])) {
$vs_container_sql = " AND ca_attributes.attribute_id IN (?)";
$va_attr_values = $va_container_ids[$va_element_code[0]];
$va_attr_values = $va_container_ids[$container_element_code];
}

$filter_join = $filter_where = null;
Expand Down Expand Up @@ -1896,7 +1900,7 @@ public function execute($pa_options=null) {

if ($vb_is_element && is_array($va_element_code) && (sizeof($va_element_code) == 1)) {
// is sub-element in container
$va_container_ids[$va_element_code[0]] = array_unique($qr_res->getAllFieldValues('attribute_id'));
$va_container_ids[$container_element_code] = array_unique($qr_res->getAllFieldValues('attribute_id'));
$this->opo_ca_browse_cache->setParameter('container_ids', $va_container_ids);
}

Expand Down Expand Up @@ -1964,9 +1968,11 @@ public function execute($pa_options=null) {

$va_params = [intval($vs_target_browse_table_num), $vn_element_id, $vn_start_in_meters, $vn_end_in_meters];
$vs_container_sql = '';
if (is_array($va_element_code) && (sizeof($va_element_code) == 1) && is_array($va_container_ids[$va_element_code[0]]) && sizeof($va_container_ids[$va_element_code[0]])) {
$container_element_code = (sizeof($va_element_code) >= 1) ? (ca_metadata_elements::getElementID($e = $va_element_code[sizeof($va_element_code) - 1]) ? $e : null) : null;

if (is_array($va_element_code) && $container_element_code && sizeof($va_container_ids[$container_element_code] ?? [])) {
$vs_container_sql = " AND ca_attributes.attribute_id IN (?)";
$va_params[] = $va_container_ids[$va_element_code[0]];
$va_params[] = $va_container_ids[$container_element_code];
}

$vs_sql = "
Expand All @@ -1987,7 +1993,7 @@ public function execute($pa_options=null) {

if ($vb_is_element && is_array($va_element_code) && (sizeof($va_element_code) == 1)) {
// is sub-element in container
$va_container_ids[$va_element_code[0]] = array_unique($qr_res->getAllFieldValues('attribute_id'));
$va_container_ids[$container_element_code] = array_unique($qr_res->getAllFieldValues('attribute_id'));
$this->opo_ca_browse_cache->setParameter('container_ids', $va_container_ids);
}

Expand Down Expand Up @@ -2053,9 +2059,11 @@ public function execute($pa_options=null) {

$va_params = [intval($vs_target_browse_table_num), $vn_element_id, $vn_start_in_meters, $vn_end_in_meters];
$vs_container_sql = '';
if (is_array($va_element_code) && (sizeof($va_element_code) == 1) && is_array($va_container_ids[$va_element_code[0]]) && sizeof($va_container_ids[$va_element_code[0]])) {
$container_element_code = (sizeof($va_element_code) >= 1) ? (ca_metadata_elements::getElementID($e = $va_element_code[sizeof($va_element_code) - 1]) ? $e : null) : null;

if (is_array($va_element_code) && sizeof($va_container_ids[$container_element_code] ?? [])) {
$vs_container_sql = " AND ca_attributes.attribute_id IN (?)";
$va_params[] = $va_container_ids[$va_element_code[0]];
$va_params[] = $va_container_ids[$container_element_code];
}

$vs_sql = "
Expand All @@ -2076,7 +2084,7 @@ public function execute($pa_options=null) {

if ($vb_is_element && is_array($va_element_code) && (sizeof($va_element_code) == 1)) {
// is sub-element in container
$va_container_ids[$va_element_code[0]] = array_unique($qr_res->getAllFieldValues('attribute_id'));
$va_container_ids[$container_element_code] = array_unique($qr_res->getAllFieldValues('attribute_id'));
$this->opo_ca_browse_cache->setParameter('container_ids', $va_container_ids);
}

Expand Down Expand Up @@ -7389,10 +7397,12 @@ protected function doGetResults($po_result=null, $pa_options=null) {
$sort_tmp = explode('.', $vs_sort);
if(Datamodel::isRelationship($sort_tmp[0])) {
$criteria = $this->getCriteria();

$t_rel = Datamodel::getInstance($sort_tmp[0], true);
$rel_tables = [$t_rel->getLeftTableName(), $t_rel->getRightTableName()];
foreach($criteria as $facet => $values) {
$fi = $this->getInfoForFacet($facet);
if(is_array($fi) && ($fi['type'] === 'authority') && ($fi['table'] ?? null) && (sizeof($values) === 1)) {

if(is_array($fi) && ($fi['type'] === 'authority') && ($fi['table'] ?? null) && in_array($fi['table'], $rel_tables, true) && (sizeof($values) === 1)) {
// use first found authority facet as context, but only if a single value is set
$v = array_shift(array_keys($values));
$opts['context'] = [$sort_tmp[0] => [Datamodel::primaryKey($fi['table']) => $v]];
Expand Down
Loading

0 comments on commit 7127a05

Please sign in to comment.