Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvanbreda committed Mar 26, 2024
2 parents bf32a52 + f2282ce commit 176b44d
Show file tree
Hide file tree
Showing 23 changed files with 619 additions and 742 deletions.
126 changes: 81 additions & 45 deletions ElasticsearchProxyHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ private static function applyGroupFilter(array $readAuth, $groupFilter, array &$
* @param array $bool
* ES bool query definintion.
*/
private static function applyFilterDef(array $readAuth, array $definition, array &$bool) {
public static function applyFilterDef(array $readAuth, array $definition, array &$bool) {
self::convertLocationListToSearchArea($definition, $readAuth);
self::applyUserFiltersTaxonGroupList($definition, $bool);
self::applyUserFiltersTaxaTaxonList($definition, $bool, $readAuth);
Expand Down Expand Up @@ -1420,16 +1420,25 @@ private static function convertLocationListToSearchArea(array &$definition, arra
'location_id',
]);
if (!empty($filter)) {
require_once 'report_helper.php';
$boundaryData = report_helper::get_report_data([
'dataSource' => '/library/locations/locations_combined_boundary_transformed',
'extraParams' => [
'location_ids' => $filter['value'],
],
'readAuth' => $readAuth,
'caching' => TRUE,
]);
$definition['searchArea'] = $boundaryData[0]['geom'];
if (defined('KOHANA')) {
// Use direct access as on warehouse.
$polygon = warehouseEsFilters::getCombinedBoundaryData($filter['value']);
}
else {
// API access as on client.
require_once 'report_helper.php';
$boundaryData = report_helper::get_report_data([
'dataSource' => '/library/locations/locations_combined_boundary_transformed',
'extraParams' => [
'location_ids' => $filter['value'],
],
'readAuth' => $readAuth,
'caching' => TRUE,
'cachePerUser' => FALSE,
]);
$polygon = $boundaryData[0]['geom'];
}
$definition['searchArea'] = $polygon;
}
}

Expand Down Expand Up @@ -1467,14 +1476,21 @@ private static function applyUserFiltersTaxonGroupList(array $definition, array
*/
private static function applyTaxonomyFilter(array &$bool, array $readAuth, $filterField, $filterValues) {
// Convert the IDs to external keys, stored in ES as taxon_ids.
$taxonData = helper_base::get_population_data([
'report' => 'library/taxa/convert_ids_to_external_keys',
'extraParams' => [
$filterField => $filterValues,
'master_checklist_id' => hostsite_get_config_value('iform', 'master_checklist_id', 0),
] + $readAuth,
'cachePerUser' => FALSE,
]);
if (defined('KOHANA')) {
// Use direct access as on warehouse.
$taxonData = warehouseEsFilters::taxonIdsToExternalKeys($filterField, $filterValues);
}
else {
// API access as on client.
$taxonData = helper_base::get_population_data([
'report' => 'library/taxa/convert_ids_to_external_keys',
'extraParams' => [
$filterField => $filterValues,
'master_checklist_id' => hostsite_get_config_value('iform', 'master_checklist_id', 0),
] + $readAuth,
'cachePerUser' => FALSE,
]);
}
$keys = [];
foreach ($taxonData as $taxon) {
$keys[] = $taxon['external_key'];
Expand Down Expand Up @@ -1680,16 +1696,23 @@ private static function applyUserFiltersIndexedLocationTypeList(array $definitio
if (!empty($filter)) {
// Convert the location type IDs to terms that are used in the ES
// document.
$typeRows = helper_base::get_population_data([
'table' => 'termlists_term',
'extraParams' => [
'id' => $filter,
'view' => 'cache',
] + $readAuth,
]);
if (defined('KOHANA')) {
// Use direct access as on warehouse.
$typeTerms = warehouseEsFilters::getTermsFromIds($filter);
}
else {
// API access as on client.
$typeTerms = helper_base::get_population_data([
'table' => 'termlists_term',
'extraParams' => [
'id' => $filter,
'view' => 'cache',
] + $readAuth,
]);
}
$types = [];
foreach ($typeRows as $typeRow) {
$types[] = $typeRow['term'];
foreach ($typeTerms as $typeTermRow) {
$types[] = $typeTermRow['term'];
}
if (count($types) > 0) {
$bool['must'][] = [
Expand Down Expand Up @@ -2371,12 +2394,19 @@ private static function getLicenceCodes(array $readAuth) {
'open' => [],
'restricted' => [],
];
$licences = helper_base::get_population_data([
'table' => 'licence',
'extraParams' => $readAuth,
'columns' => 'code,open',
'cachePerUser' => FALSE,
]);
if (defined('KOHANA')) {
// Direct access as on warehouse.
$licences = warehouseEsFilters::getLicences();
}
else {
// API access as on client.
$licences = helper_base::get_population_data([
'table' => 'licence',
'extraParams' => $readAuth,
'columns' => 'code,open',
'cachePerUser' => FALSE,
]);
}
foreach ($licences as $licence) {
$r[$licence['open'] === 't' ? 'open' : 'restricted'][] = $licence['code'];
}
Expand Down Expand Up @@ -2512,7 +2542,6 @@ private static function applyUserFiltersLicences(array $definition, array &$bool
*/
private static function applyUserFiltersCoordinatePrecision(array $definition, array &$bool) {
$filter = self::getDefinitionFilter($definition, ['coordinate_precision']);
\Drupal::logger('iform')->notice(var_export($filter, TRUE));
if (!empty($filter)) {
// Default is same as or better than.
$filter['op'] = $filter['op'] ?? '<=';
Expand Down Expand Up @@ -2654,16 +2683,23 @@ private static function applyUserFiltersTaxaScratchpadList(array $definition, ar
'taxa_scratchpad_list_id',
]);
if (!empty($filter)) {
require_once 'report_helper.php';
// Convert the IDs to external keys, stored in ES as taxon_ids.
$taxonData = report_helper::get_report_data([
'dataSource' => '/library/taxa/external_keys_for_scratchpad',
'extraParams' => [
'scratchpad_list_id' => $filter['value'],
],
'readAuth' => $readAuth,
'caching' => TRUE,
]);
if (defined('KOHANA')) {
// Direct access as on warehouse.
$taxonData = warehouseEsFilters::getExternalKeysForTaxonScratchpad($filter['value']);
}
else {
require_once 'report_helper.php';
// Convert the IDs to external keys, stored in ES as taxon_ids.
$taxonData = report_helper::get_report_data([
'dataSource' => '/library/taxa/external_keys_for_scratchpad',
'extraParams' => [
'scratchpad_list_id' => $filter['value'],
],
'readAuth' => $readAuth,
'caching' => TRUE,
'cachePerUser' => FALSE,
]);
}
$keys = [];
foreach ($taxonData as $taxon) {
$keys[] = $taxon['external_key'];
Expand Down
52 changes: 31 additions & 21 deletions ElasticsearchReportHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,16 @@ public static function download(array $options) {
/**
* Integrates the page with groups (activities).
*
* @param bool $checkPage
* Set to false to disable checking that the current page path is an iform
* page linked to the group.
*
* @link https://indicia-docs.readthedocs.io/en/latest/site-building/iform/helpers/elasticsearch-report-helper.html#elasticsearchreporthelper-groupintegration
*
* @return string
* Control HTML
*/
public static function groupIntegration(array $options) {
public static function groupIntegration(array $options, $checkPage = TRUE) {
$options = array_merge([
'missingGroupIdBehaviour' => 'error',
'showGroupSummary' => FALSE,
Expand All @@ -693,7 +697,7 @@ public static function groupIntegration(array $options) {
return '';
}
require_once 'prebuilt_forms/includes/groups.php';
$member = group_authorise_group_id($group_id, $options['readAuth']);
$member = group_authorise_group_id($group_id, $options['readAuth'], $checkPage);
$output = '';
if (!empty($group_id)) {
// Apply filtering by group.
Expand Down Expand Up @@ -723,21 +727,21 @@ public static function groupIntegration(array $options) {
$output .= self::getGroupPageLinks($group, $options, $member);
}
}
}
$filterBoundaries = helper_base::get_population_data([
'report' => 'library/groups/group_boundary_transformed',
'extraParams' => $options['readAuth'] + ['group_id' => $group_id],
'cachePerUser' => FALSE,
]);
if (count($filterBoundaries) > 0) {
helper_base::$indiciaData['reportBoundaries'] = [];
foreach ($filterBoundaries as $boundary) {
helper_base::$indiciaData['reportBoundaries'][] = $boundary['boundary'];
}
helper_base::$late_javascript .= <<<JS
$filterBoundaries = helper_base::get_population_data([
'report' => 'library/groups/group_boundary_transformed',
'extraParams' => $options['readAuth'] + ['group_id' => $group_id],
'cachePerUser' => FALSE,
]);
if (count($filterBoundaries) > 0) {
helper_base::$indiciaData['reportBoundaries'] = [];
foreach ($filterBoundaries as $boundary) {
helper_base::$indiciaData['reportBoundaries'][] = $boundary['boundary'];
}
helper_base::$late_javascript .= <<<JS
indiciaFns.loadReportBoundaries();
JS;
}
}
return $output;
}
Expand Down Expand Up @@ -839,6 +843,8 @@ private static function internalLocationSelect(array $options, $addGeomHiddenInp
}
if ($idx > 0) {
$options['parentControlId'] = "$baseId-" . ($idx - 1);
// We don't want the query to apply to the child drop-downs ($idx > 0), as the query can't apply to both parent/child, as they are very different.
unset($options['extraParams']['query']);
if ($idx === 1) {
$options['parentControlLabel'] = $options['label'];
$options['filterField'] = 'parent_id';
Expand Down Expand Up @@ -919,7 +925,7 @@ public static function leafletMap(array $options) {
}
}
}
// Override map position from URL if needed.
// Override map position from URL if needed.
// (e.g. this allows control via an iFrame).
if (!empty($_GET['initialLat'])) {
$options['initialLat'] = $_GET['initialLat'];
Expand Down Expand Up @@ -2360,9 +2366,11 @@ private static function applySourceModeDefaultsTermAggregation(array &$options)
* Options passed to the [source]. Will be modified as appropriate.
*/
private static function applySourceModeDefaults(array &$options) {
$method = 'applySourceModeDefaults' . ucfirst($options['mode']);
if (method_exists('ElasticsearchReportHelper', $method)) {
self::$method($options);
if (!empty($options['mode'])) {
$method = 'applySourceModeDefaults' . ucfirst($options['mode']);
if (method_exists('ElasticsearchReportHelper', $method)) {
self::$method($options);
}
}
}

Expand Down Expand Up @@ -2472,9 +2480,10 @@ private static function convertValueToFilterList($report, array $params, $output
* @param string $controlName
* Control type name (e.g. source, dataGrid).
* @param array $options
* Options passed to the control. If the control's @containerElement option
* Options passed to the control. If the control's containerElement option
* is set then sets the required JavaScript to make the control inject
* itself into the existing element instead.
* itself into the existing element instead. Can include an option for the
* id and class to assign to the container if not using containerElement.
* @param string $dataOptions
* Options to store in the HTML data-idc-config attribute on the container.
* These are made available to configure the JS behaviour of the control.
Expand All @@ -2500,8 +2509,9 @@ private static function getControlContainer($controlName, array $options, $dataO
$('#$options[id]').$initFn({});
JS;
$class = "idc-control idc-$controlName" . (empty($options['class']) ? '' : ' ' . $options['class']);
return <<<HTML
<div id="$options[id]" class="idc-control idc-$controlName" data-idc-class="$initFn" data-idc-config="$dataOptions">
<div id="$options[id]" class="$class" data-idc-class="$initFn" data-idc-config="$dataOptions">
$content
</div>
Expand Down
Loading

0 comments on commit 176b44d

Please sign in to comment.