Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvanbreda committed Nov 29, 2024
2 parents 3f43331 + 65d0d8f commit e01c51f
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 22 deletions.
58 changes: 55 additions & 3 deletions ElasticsearchProxyHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public static function callMethod($method, $nid) {
case 'runcustomruleset':
return self::proxyRunCustomRuleset($nid);

case 'getLocationBoundaryGeom':
return self::getLocationBoundaryGeom($nid);

default:
throw new ElasticsearchProxyAbort('Method not found', 404);
}
Expand Down Expand Up @@ -283,7 +286,10 @@ private static function proxyDoesUserSeeNotifications($nid) {
iform_load_helpers(['VerificationHelper']);
$conn = iform_get_connection_details($nid);
$readAuth = helper_base::get_read_auth($conn['website_id'], $conn['password']);
return ['msg' => VerificationHelper::doesUserSeeNotifications($readAuth, $_GET['user_id'])];
return [
'message' => 'OK',
'result' => VerificationHelper::doesUserSeeNotifications($readAuth, $_GET['user_id']),
];
}

/**
Expand Down Expand Up @@ -657,7 +663,8 @@ private static function proxyVerificationQueryEmail() {
$success = hostsite_send_email($_POST['to'], $_POST['subject'], $emailBody);

return [
'status' => $success ? 'OK' : 'Fail',
'message' => $success ? 'OK' : 'Fail',
'code' => $success ? 200 : 500,
];
}

Expand Down Expand Up @@ -2885,7 +2892,7 @@ private static function proxyBulkEditAll($nid) {
return $response;
}

/**
/**
* Bulk edit a list of selected records.
*
* @param int $nid
Expand Down Expand Up @@ -3222,4 +3229,49 @@ private static function proxyRunCustomRuleset($nid) {
return self::curlPost($url, $query);
}

/**
* Proxy method for fetching a locations' boundary geom.
*
* Used when the `locationBoundaryId` option is set for a `leafletMap`
* control. The response is cached.
*
* @param int $nid
* Node ID.
*
* @return array
* Array containing HTTP status and response message, plus boundary_geom
* if it worked.
*/
private static function getLocationBoundaryGeom($nid) {
if (empty($_GET['location_id']) || !preg_match('/^\d+$/', $_GET['location_id'])) {
http_response_code(400);
return ['code' => 400, 'message' => 'Bad Request'];
}
iform_load_helpers(['report_helper']);
$conn = iform_get_connection_details($nid);
$readAuth = helper_base::get_read_auth($conn['website_id'], $conn['password']);

$response = report_helper::get_report_data([
'dataSource' => '/library/locations/locations_combined_boundary_transformed',
'extraParams' => [
'location_ids' => $_GET['location_id'],
],
'readAuth' => $readAuth,
'caching' => TRUE,
'cachePerUser' => FALSE,
]);
if (empty($response)) {
http_response_code(404);
return ['code' => 404, 'message' => 'Not Found'];
}
return [
'message' => 'OK',
'boundary_geom' => $response[0]['geom'],
'#cache' => [
'max-age' => 3600,
'contexts' => ['route'],
],
];
}

}
1 change: 1 addition & 0 deletions ElasticsearchReportHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ public static function leafletMap(array $options) {
}
$dataOptions = helper_base::getOptionsForJs($options, [
'baseLayerConfig',
'boundaryLocationId',
'cookies',
'initialLat',
'initialLng',
Expand Down
23 changes: 21 additions & 2 deletions data_entry_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5066,6 +5066,7 @@ public static function preload_species_checklist_occurrences($sampleId, $readAut
data_entry_helper::$entity_to_load['sc:' . $idx . ':' . $subSample['id'] . ':sample:geom'] = $subSample['wkt'];
data_entry_helper::$entity_to_load['sc:' . $idx . ':' . $subSample['id'] . ':sample:wkt'] = $subSample['wkt'];
data_entry_helper::$entity_to_load['sc:' . $idx . ':' . $subSample['id'] . ':sample:location_id'] = $subSample['location_id'];
data_entry_helper::$entity_to_load['sc:' . $idx . ':' . $subSample['id'] . ':sample:location_name'] = $subSample['location_name'];
data_entry_helper::$entity_to_load['sc:' . $idx . ':' . $subSample['id'] . ':sample:entered_sref'] = $subSample['entered_sref'];
data_entry_helper::$entity_to_load['sc:' . $idx . ':' . $subSample['id'] . ':sample:entered_sref_system'] = $subSample['entered_sref_system'];
if ($spatialRefPrecisionAttrId) {
Expand Down Expand Up @@ -6042,6 +6043,8 @@ public static function get_species_checklist_clonable_row(array $options, array
* the default. Options same as sampleOnClusterButtonContents.
* * **samplePhotos** - set to true to add a photos upload control for each
* sub-sample.
* * **location_name** - set to true to add a location name input control for
* each sub-sample.
*/
public static function multiple_places_species_checklist($options) {
if (empty($options['spatialSystem'])) {
Expand Down Expand Up @@ -6074,7 +6077,14 @@ public static function multiple_places_species_checklist($options) {
$attr['fieldname'] = "sc:n::$attr[fieldname]";
$attr['id'] = "sc:n::$attr[id]";
}
$sampleCtrls = get_attribute_html($sampleAttrs, [], ['extraParams' => $options['readAuth']], NULL, $attrOptions);
$sampleCtrls = '';
if (!empty($options['locationName'])) {
$sampleCtrls .= self::text_input([
'label' => lang::get('Location name at this position'),
'fieldname' => "sc:n::sample:location_name",
]);
}
$sampleCtrls .= get_attribute_html($sampleAttrs, [], ['extraParams' => $options['readAuth']], NULL, $attrOptions);
// Add a template for the form section for a new subsample.
$r .= "<div id=\"$options[id]-subsample-ctrls\" style=\"display: none\" class=\"subsample-ctrl-cntr\">$sampleCtrls</div>";
}
Expand Down Expand Up @@ -6269,7 +6279,16 @@ private static function getMultiplePlacesSpeciesChecklistButtons($options) {
$attr['id'] = "sc:$a[1]:$a[2]:$attr[id]";
}
$attrOptions = self::getAttrSpecificOptions($options);
$sampleCtrls = get_attribute_html($sampleAttrs, [], ['extraParams' => $options['readAuth']], NULL, $attrOptions);
$sampleCtrls = '';
if (!empty($options['locationName'])) {
$locationName = data_entry_helper::$entity_to_load["$a[0]:$a[1]:$sampleId:sample:location_name"] ?? '';
$sampleCtrls .= self::text_input([
'label' => lang::get('Location name at this position'),
'fieldname' => "$a[0]:$a[1]:$sampleId:sample:location_name",
'default' => $locationName,
]);
}
$sampleCtrls .= get_attribute_html($sampleAttrs, [], ['extraParams' => $options['readAuth']], NULL, $attrOptions);
$blocks .= <<<HTML
<div class="subsample-ctrl-cntr">
$sampleCtrls
Expand Down
1 change: 1 addition & 0 deletions helper_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -3581,6 +3581,7 @@ public static function getCachedGenericCall($url, array $get, array $post, array
];
if (isset($options['cachePerUser']) && !$options['cachePerUser']) {
$excludedParams[] = 'user_id';
$excludedParams[] = 'currentUser';
}
$cacheOpts = array_diff_key(array_merge($get, $post), array_combine($excludedParams, $excludedParams));
$cacheOpts['serviceCallPath'] = self::$base_url . $url;
Expand Down
Loading

0 comments on commit e01c51f

Please sign in to comment.