Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvanbreda committed Oct 25, 2019
2 parents 2f19aac + e07b3de commit f33e390
Show file tree
Hide file tree
Showing 16 changed files with 1,242 additions and 330 deletions.
4 changes: 2 additions & 2 deletions application/config/config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ $config['modules'] = array
MODPATH.'demo', // Demo and test pages
MODPATH.'data_cleaner', // automatic record checks
MODPATH.'cache_builder', // build a cache for performance reporting
MODPATH.'spatial_index_builder', // index of location occurrence overlaps
// ,MODPATH.'summary_builder' // build a cache for improving the performance of reporting summary data
// MODPATH.'spatial_index_builder', // index of location occurrence overlaps
// MODPATH.'summary_builder' // build a cache for improving the performance of reporting summary data
);
4 changes: 2 additions & 2 deletions application/config/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
*
* @var string
*/
$config['version'] = '2.35.2';
$config['version'] = '2.36.0';

/**
* Version release date.
*
* @var string
*/
$config['release_date'] = '2019-10-12';
$config['release_date'] = '2019-10-14';

/**
* Link to the code repository downloads page.
Expand Down
32 changes: 31 additions & 1 deletion application/controllers/survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,39 @@ protected function prepareOtherViewData(array $values) {
$arr = array();
foreach ($websites->where('deleted','false')->orderby('title','asc')->find_all() as $website)
$arr[$website->id] = $website->title;
return array(

$otherData = array(
'websites' => $arr
);

$otherData['taxon_restrictions'] = [];
$masterListId = warehouse::getMasterTaxonListId();
if ($masterListId) {

$tmIdVals = $this->db
->select('s.auto_accept_taxa_filters')
->from('surveys AS s')
->where([
's.id' => $values['survey:id'],
])
->get()->result();

$valsCSV=trim($tmIdVals[0]->auto_accept_taxa_filters, "{}");

$ttlIds = $this->db
->select('id')
->from('cache_taxa_taxon_lists as cttl')
->in('taxon_meaning_id', explode(",", $valsCSV))
->where([
'cttl.preferred' => true
])
->get()->result();

foreach ($ttlIds as $ttlId) {
array_push($otherData['taxon_restrictions'], array("taxa_taxon_list_id" => $ttlId->id));
}
}
return $otherData;
}

/**
Expand Down
23 changes: 23 additions & 0 deletions application/models/survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,32 @@ public function validate(Validation $array, $save = FALSE) {
'owner_id',
'auto_accept',
'auto_accept_max_difficulty',
'auto_accept_taxa_filters',
'core_validation_rules',
);
return parent::validate($array, $save);
}

protected function preSubmit() {
if (!empty($_POST['has-taxon-restriction-data'])) {
$ttlIds = [];
$tmIds = [];
foreach ($_POST as $key => $value) {
if (substr($key, -8) === ':present' && $value !== '0') {
$ttlIds[] = $value;
}
}
$tmIdRecs = $this->db
->select('id, taxon_meaning_id')
->from('cache_taxa_taxon_lists')
->in('id', $ttlIds)
->get()->result();

foreach ($tmIdRecs as $tmIdRec) {
$tmIds[] = intVal($tmIdRec->taxon_meaning_id);
}
$this->submission['fields']['auto_accept_taxa_filters']=array('value' => $tmIds);
}
return parent::presubmit();
}
}
30 changes: 30 additions & 0 deletions application/views/survey/survey_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,36 @@
'helpText' => 'If Auto Accept is set, then this is the minimum identification difficulty that will be auto verified.',
));
}
if (array_key_exists('survey:auto_accept_taxa_filters', $values)) {
$masterListId = warehouse::getMasterTaxonListId();
echo <<<HTML
<div class="alert alert-info">
<p>You can use the taxon selection control below to
select one or more higher level taxa to which recorded taxa must belong in order to
quality for auto-verification. Leave the list empty for no filtering. You must also
check the Auto Accept box for these filters to take effect.</p>
</div>
<label>Taxon restrictions</label>
<input type="hidden" name="has-taxon-restriction-data" value="1" />
HTML;
require_once 'client_helpers/prebuilt_forms/includes/language_utils.php';
$speciesChecklistOptions = [
'lookupListId' => $masterListId,
'rowInclusionCheck' => 'alwaysRemovable',
'extraParams' => $readAuth,
'survey_id' => $values['survey:id'],
'language' => iform_lang_iso_639_2(kohana::config('indicia.default_lang')),
];
if (!empty($other_data['taxon_restrictions'])) {
$speciesChecklistOptions['listId'] = $masterListId;
$speciesChecklistOptions['preloadTaxa'] = [];
foreach ($other_data['taxon_restrictions'] as $restriction) {
$speciesChecklistOptions['preloadTaxa'][] = $restriction['taxa_taxon_list_id'];
}
}
echo data_entry_helper::species_checklist($speciesChecklistOptions);
echo '<br/>';
}
?>
</fieldset>
<?php if (array_key_exists('attributes', $values) && count($values['attributes']) > 0) : ?>
Expand Down
2 changes: 1 addition & 1 deletion client_helpers
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE OR REPLACE function f_add_new_survey_fields (OUT success bool)
LANGUAGE plpgsql AS
$func$
BEGIN

success := TRUE;

BEGIN
ALTER TABLE surveys ADD COLUMN auto_accept_taxa_filters INT[];

EXCEPTION
WHEN duplicate_column THEN
RAISE NOTICE 'column exists.';
success := FALSE;
END;

END
$func$;

SELECT f_add_new_survey_fields();

DROP FUNCTION f_add_new_survey_fields();

COMMENT ON COLUMN surveys.auto_accept_taxa_filters IS 'List of taxon meaning IDs to filter records qualifying for auto-verification';
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ function data_cleaner_period_within_year_data_cleaner_rules() {
and (vr.stages is null or vr.stages @> string_to_array(co.stage, ''))
SQL;
// The groupBy allows us to count the verified records at a similar time of
// year and only create messages if less than 2.
// year and only create messages if less than 6.
$groupBy = <<<SQL
group by co.id, co.date_start, co.taxa_taxon_list_external_key, co.stage,
co.verification_checks_enabled, co.record_status, vr.error_message, vr.stages
-- at least 2 similar records
having count(o2.id) < 2
-- at least 6 similar records
having count(o2.id) < 6
SQL;

return array(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-- Index for extracting deletions into feeds, e.g. Elasticsearch.
CREATE INDEX IF NOT EXISTS ix_occurrence_updated_on_deletions ON occurrences(updated_on) WHERE deleted=true;
CREATE INDEX ix_occurrence_updated_on_deletions ON occurrences(updated_on) WHERE deleted=true;
Loading

0 comments on commit f33e390

Please sign in to comment.