Skip to content

Commit

Permalink
Merge pull request #26 from BioKIC/master
Browse files Browse the repository at this point in the history
Merge Symbiota-light developments into CCH2 code repository
  • Loading branch information
egbot committed Nov 20, 2020
2 parents 2ecccab + a4b335e commit 65c50c7
Show file tree
Hide file tree
Showing 26 changed files with 499 additions and 459 deletions.
14 changes: 7 additions & 7 deletions classes/DwcArchiverCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,9 @@ public function addCondition($field, $cond, $value = ''){
if($field){
if($this->overrideConditionLimit || in_array(strtolower($field),$this->condAllowArr)){
if(!$cond) $cond = 'EQUALS';
if($value || ($cond == 'NULL' || $cond == 'NOTNULL')){
if(is_array($value)){
$this->conditionArr[$field][$cond] = $this->cleanInArray($value);
}
else{
$this->conditionArr[$field][$cond][] = $this->cleanInStr($value);
}
if($value != '' || ($cond == 'NULL' || $cond == 'NOTNULL')){
if(is_array($value)) $this->conditionArr[$field][$cond] = $this->cleanInArray($value);
else $this->conditionArr[$field][$cond][] = $this->cleanInStr($value);
}
}
}
Expand Down Expand Up @@ -276,6 +272,10 @@ private function applyConditions(){
$taxaManager->setTaxonRequestVariable($taxaArr);
$sqlFrag .= $taxaManager->getTaxonWhereFrag();
}
elseif($field == 'cultivationStatus'){
if(current(current($condArr)) === '0') $sqlFrag .= 'AND (o.cultivationStatus = 0 OR o.cultivationStatus IS NULL) ';
else $sqlFrag .= 'AND (o.cultivationStatus = 1) ';
}
else{
if($field == 'datelastmodified') $field = 'IFNULL(o.modified,o.datelastmodified)';
else $field = 'o.'.$field;
Expand Down
30 changes: 12 additions & 18 deletions classes/DwcArchiverOccurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function getOccurrenceArr(){
'kingdom','phylum','class','order','genus','specificEpithet','infraSpecificEpithet',
'recordedBy','recordNumber','eventDate','year','month','day','fieldNumber','country','stateProvince','county','municipality',
'locality','localitySecurity','geodeticDatum','decimalLatitude','decimalLongitude','verbatimCoordinates',
'minimumElevationInMeters','maximumElevationInMeters','verbatimElevation','maximumDepthInMeters','minimumDepthInMeters',
'minimumElevationInMeters','maximumElevationInMeters','verbatimElevation','maximumDepthInMeters','minimumDepthInMeters','establishmentMeans','cultivationStatus',
'sex','occurrenceRemarks','preparationType','individualCount','dateEntered','dateLastModified','recordId','references','collId');
$this->occurDefArr[$k] = array_intersect_key($vArr,array_flip($targetArr));
}
Expand Down Expand Up @@ -379,7 +379,7 @@ public function appendUpperTaxonomy(&$targetArr){
}

public function appendUpperTaxonomy2(&$r){
$target = $r['taxonID'];
$target = (isset($r['taxonID'])?$r['taxonID']:false);
if(!$target) $target = ucfirst($r['family']);
if($target){
if(array_key_exists($target, $this->upperTaxonomy)){
Expand All @@ -393,15 +393,9 @@ public function appendUpperTaxonomy2(&$r){
}
else{
$higherStr = '';
$sql = 'SELECT t.tid, t.sciname, t.rankid '.
'FROM taxaenumtree e INNER JOIN taxa t ON e.parentTid = t.tid '.
'WHERE e.taxauthid = 1 AND e.tid = '.$r['taxonID'].' ORDER BY t.rankid';
if(!is_numeric($target)){
$sql = 'SELECT t.tid, t.sciname, t.rankid '.
'FROM taxaenumtree e INNER JOIN taxa t ON e.parentTid = t.tid '.
'INNER JOIN taxa t2 ON e.tid = t2.tid '.
'WHERE e.taxauthid = 1 AND t2.sciname = "'.$this->cleanInStr($target).'" ORDER BY t.rankid';
}
$sql = 'SELECT t.tid, t.sciname, t.rankid FROM taxaenumtree e INNER JOIN taxa t ON e.parentTid = t.tid ';
if(!is_numeric($target)) $sql .= 'INNER JOIN taxa t2 ON e.tid = t2.tid WHERE e.taxauthid = 1 AND t2.sciname = "'.$this->cleanInStr($target).'" ORDER BY t.rankid';
else $sql .= 'WHERE e.taxauthid = 1 AND e.tid = '.$target.' ORDER BY t.rankid';
$rs = $this->conn->query($sql);
while($row = $rs->fetch_object()){
if($row->rankid == 10) $r['t_kingdom'] = $row->sciname;
Expand All @@ -415,13 +409,13 @@ public function appendUpperTaxonomy2(&$r){
$rs->free();
if($higherStr) $r['t_higherClassification'] = trim($higherStr,'| ');
if(count($this->upperTaxonomy)<1000 || !is_numeric($target)){
if($r['t_kingdom']) $this->upperTaxonomy[$target]['k'] = $r['t_kingdom'];
if($r['t_phylum']) $this->upperTaxonomy[$target]['p'] = $r['t_phylum'];
if($r['t_class']) $this->upperTaxonomy[$target]['c'] = $r['t_class'];
if($r['t_order']) $this->upperTaxonomy[$target]['o'] = $r['t_order'];
if($r['family']) $this->upperTaxonomy[$target]['f'] = $r['family'];
if($r['t_subgenus']) $this->upperTaxonomy[$target]['s'] = $r['t_subgenus'];
if($r['t_higherClassification']) $this->upperTaxonomy[$target]['u'] = $r['t_higherClassification'];
if(isset($r['t_kingdom'])) $this->upperTaxonomy[$target]['k'] = $r['t_kingdom'];
if(isset($r['t_phylum'])) $this->upperTaxonomy[$target]['p'] = $r['t_phylum'];
if(isset($r['t_class'])) $this->upperTaxonomy[$target]['c'] = $r['t_class'];
if(isset($r['t_order'])) $this->upperTaxonomy[$target]['o'] = $r['t_order'];
if(isset($r['family'])) $this->upperTaxonomy[$target]['f'] = $r['family'];
if(isset($r['t_subgenus'])) $this->upperTaxonomy[$target]['s'] = $r['t_subgenus'];
if(isset($r['t_higherClassification'])) $this->upperTaxonomy[$target]['u'] = $r['t_higherClassification'];
}
}
}
Expand Down
119 changes: 100 additions & 19 deletions classes/OccurrenceLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,25 +275,27 @@ private function setLabelFieldArr(){
public function getLabelBlock($blockArr,$occArr){
$outStr = '';
foreach($blockArr as $bArr){
if(array_key_exists('divElem', $bArr)){
$outStr .= $this->getDivElem($bArr['divElem'],$occArr);
if(array_key_exists('divBlock', $bArr)){
$outStr .= $this->getDivBlock($bArr['divBlock'],$occArr);
}
elseif(array_key_exists('fields', $bArr)){
elseif(array_key_exists('fieldBlock', $bArr)){
$delimiter = (isset($bArr['delimiter'])?$bArr['delimiter']:'');
$cnt = 0;
$fieldDivStr = '';
foreach($bArr['fields'] as $fieldArr){
foreach($bArr['fieldBlock'] as $fieldArr){
$fieldName = $fieldArr['field'];
$fieldValue = trim($occArr[$fieldName]);
if($fieldValue){
if($delimiter && $cnt) $fieldDivStr .= $delimiter;
$fieldDivStr .= '<span class="'.$fieldName.'" '.(isset($fieldArr['style'])?'style="'.$fieldArr['style'].'"':'').'>';
if(isset($fieldArr['prefix']) && $fieldArr['prefix']){
$fieldDivStr .= '<span class="'.$fieldName.'Prefix" '.(isset($fieldArr['prefixStyle'])?'style="'.$fieldArr['prefixStyle'].'"':'').'>'.$fieldArr['prefix'].'</span>';
}
$fieldDivStr .= '<span class="'.$fieldName.'" '.(isset($fieldArr['style'])?'style="'.$fieldArr['style'].'"':'').'>'.$fieldValue.'</span>';
$fieldDivStr .= $fieldValue;
if(isset($fieldArr['suffix']) && $fieldArr['suffix']){
$fieldDivStr .= '<span class="'.$fieldName.'Suffix" '.(isset($fieldArr['suffixStyle'])?'style="'.$fieldArr['sufffixStyle'].'"':'').'>'.$fieldArr['suffix'].'</span>';
$fieldDivStr .= '<span class="'.$fieldName.'Suffix" '.(isset($fieldArr['suffixStyle'])?'style="'.$fieldArr['suffixStyle'].'"':'').'>'.$fieldArr['suffix'].'</span>';
}
$fieldDivStr .= '</span>';
$cnt++;
}
}
Expand All @@ -303,7 +305,7 @@ public function getLabelBlock($blockArr,$occArr){
return $outStr;
}

private function getDivElem($divArr,$occArr){
private function getDivBlock($divArr,$occArr){
if(array_key_exists('blocks', $divArr)){
if($blockStr = $this->getLabelBlock($divArr['blocks'],$occArr)){
return '<div '.(isset($divArr['className'])?'class="'.$divArr['className'].'"':'').' '.(isset($divArr['style'])?'style="'.$divArr['style'].'"':'').'>'.$blockStr.'</div>'."\n";
Expand All @@ -312,30 +314,109 @@ private function getDivElem($divArr,$occArr){
return '';
}

public function getLabelFormatArr($index){
if(is_numeric($index) && $this->collArr['dynprops']){
$dymPropArr = json_decode($this->collArr['dynprops'],true);
if(isset($dymPropArr['labelFormats'][$index])){
return $dymPropArr['labelFormats'][$index];
public function getLabelFormatArr($labelCat, $labelIndex){
if(is_numeric($labelIndex)){
if($labelCat == 'global'){
if(file_exists($GLOBALS['SERVER_ROOT'].'/content/collections/reports/labeljson.php')){
include($GLOBALS['SERVER_ROOT'].'/content/collections/reports/labeljson.php');
if(isset($LABEL_FORMAT_JSON)){
if($labelFormatArr = json_decode($LABEL_FORMAT_JSON,true)){
if(isset($labelFormatArr['labelFormats'][$labelIndex])){
return $labelFormatArr['labelFormats'][$labelIndex];
}
else $this->errorArr[] = 'ERROR returning global format: index does not exist';
}
else $this->errorArr[] = 'ERROR returning global format: issue parsing JSON string';
}
else $this->errorArr[] = 'ERROR returning global format: $LABEL_FORMAT_JSON does not exist';
}
else $this->errorArr[] = 'ERROR returning global format: /content/collections/reports/labeljson.php does not exist';
return false;
}
elseif($labelCat == 'coll'){
if($this->collArr['dynprops']){
if($dymPropArr = json_decode($this->collArr['dynprops'],true)){
if(isset($dymPropArr['labelFormats'][$labelIndex])){
return $dymPropArr['labelFormats'][$labelIndex];
}
else $this->errorArr[] = 'ERROR returning collection format: labelFormats or index does not exist';
}
else $this->errorArr[] = 'ERROR returning collection format: issue parsing JSON string';
}
else $this->errorArr[] = 'ERROR returning collection format: dynamicProperties not defined';
}
elseif($labelCat == 'user'){
$dynPropStr = '';
$sql = 'SELECT dynamicProperties FROM users WHERE uid = '.$GLOBALS['SYMB_UID'];
$rs = $this->conn->query($sql);
if($r = $rs->fetch_object()){
$dynPropStr = $r->dynamicProperties;
}
$rs->free();
if($dynPropStr){
if($dymPropArr = json_decode($dynPropStr,true)){
if(isset($dymPropArr['labelFormats'][$labelIndex])){
return $dymPropArr['labelFormats'][$labelIndex];
}
else $this->errorArr[] = 'ERROR returning user format: labelFormats or index does not exist';
}
else $this->errorArr[] = 'ERROR returning user format: issue parsing JSON string';
}
else $this->errorArr[] = 'ERROR returning user format: dynamicProperties not defined';
}
}
return false;
}

public function getLabelFormatAnnotatedArr(){
$labelFormatArr = array();
//Add global portal defined label formats
if(file_exists($GLOBALS['SERVER_ROOT'].'/content/collections/reports/labeljson.php')){
include($GLOBALS['SERVER_ROOT'].'/content/collections/reports/labeljson.php');
if(isset($LABEL_FORMAT_JSON)){
if($globalFormatArr = json_decode($LABEL_FORMAT_JSON,true)){
if(isset($globalFormatArr['labelFormats'])){
foreach($globalFormatArr['labelFormats'] as $k => $labelObj){
unset($labelObj['labelBlocks']);
$labelFormatArr['g'][$k] = $labelObj;
}
}
}
}
}
//Add collection defined label formats
if($this->collArr['dynprops']){
if($dymPropArr = json_decode($this->collArr['dynprops'],true)){
if($collFormatArr = json_decode($this->collArr['dynprops'],true)){
if(isset($collFormatArr['labelFormats'])){
foreach($collFormatArr['labelFormats'] as $k => $labelObj){
unset($labelObj['labelBlocks']);
$labelFormatArr['c'][$k] = $labelObj;
}
}
}
}
//Add label formats associated with user profile
/*
$dynPropStr = '';
$sql = 'SELECT dynamicProperties FROM users WHERE uid = '.$GLOBALS['SYMB_UID'];
$rs = $this->conn->query($sql);
if($r = $rs->fetch_object()){
$dynPropStr = $r->dynamicProperties;
}
$rs->free();
if($dynPropStr){
if($dymPropArr = json_decode($dynPropStr,true)){
if(isset($dymPropArr['labelFormats'])){
$labelFormatArr = $dymPropArr['labelFormats'];
foreach($labelFormatArr as $k => $labelObj){
unset($labelFormatArr[$k]['blocks']);
foreach($dymPropArr['labelFormats'] as $k => $labelObj){
unset($labelObj['labelBlocks']);
$labelFormatArr['u'][$k] = $labelObj;
}
if($labelFormatArr) return $labelFormatArr;
else return false;
}
}
}
return null;
*/
return $labelFormatArr;
}

//Annotation functions
Expand Down
21 changes: 13 additions & 8 deletions classes/OccurrenceUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,17 +839,22 @@ public static function occurrenceArrayCleaning($recMap){
unset($recMap['specify:qualifier_position']);
}
if(isset($recMap['specify:latitude1']) && $recMap['specify:latitude1']){
$llStr = $recMap['specify:latitude1'];
if(isset($recMap['specify:latitude2']) && $recMap['specify:latitude1'] != $recMap['specify:latitude2']){
if($recMap['specify:latitude2'] && $recMap['specify:latitude2'] != 'null') $llStr .= ' to '.$recMap['specify:latitude2'];
$verbLatLngStr = '';
if(isset($recMap['specify:latitude2']) && $recMap['specify:latitude2'] && $recMap['specify:latitude2'] != 'null' && $recMap['specify:latitude1'] != $recMap['specify:latitude2']){
$verbLatLngStr = $recMap['specify:latitude1'].' to '.$recMap['specify:latitude2'];
}
if(isset($recMap['specify:longitude1']) && $recMap['specify:longitude1']) $llStr .= '; '.$recMap['specify:longitude1'];
if(isset($recMap['specify:longitude2']) && $recMap['specify:longitude1'] != $recMap['specify:longitude2']){
if($recMap['specify:longitude2'] && $recMap['specify:longitude2'] != 'null') $llStr .= ' to '.$recMap['specify:longitude2'];
if(isset($recMap['specify:longitude2']) && $recMap['specify:longitude2'] && $recMap['specify:longitude2'] != 'null' && $recMap['specify:longitude1'] != $recMap['specify:longitude2']){
$verbLatLngStr .= '; '.$recMap['specify:longitude1'].' to '.$recMap['specify:longitude2'];
//todo: populate decimal Lat/long with mid-point and radius

}
$recMap['verbatimcoordinates'] = $llStr;
if($verbLatLngStr){
if(isset($recMap['verbatimcoordinates']) && $recMap['verbatimcoordinates']) $recMap['verbatimcoordinates'] .= '; '.$verbLatLngStr;
else $recMap['verbatimcoordinates'] = $verbLatLngStr;
}
else{
$recMap['decimallatitude'] = $recMap['specify:latitude1'];
$recMap['decimallongitude'] = $recMap['specify:longitude1'];
}
}
unset($recMap['specify:latitude1']);
unset($recMap['specify:latitude2']);
Expand Down
2 changes: 1 addition & 1 deletion classes/SpecUploadBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ protected function transferOccurrences(){
}
$transactionInterval = 1000;
$this->outputMsg('<li>Updating existing records in batches of '.$transactionInterval.'... </li>');
//Grab specimen intervals for updating reords in batches
//Grab specimen intervals for updating records in batches
$intervalArr = array();
$sql = 'SELECT occid FROM ( SELECT @row := @row +1 AS rownum, occid FROM ( SELECT @row :=0) r, uploadspectemp WHERE occid IS NOT NULL AND collid = '.
$this->collId.' ORDER BY occid) ranked WHERE rownum % '.$transactionInterval.' = 1';
Expand Down
2 changes: 1 addition & 1 deletion classes/TaxonomyUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ public function getTaxAuthorityName(){

public function getKingdomArr(){
$retArr = array();
$rs = $this->conn->query('SELECT tid, sciname FROM taxa WHERE rankid = 10');
$rs = $this->conn->query('SELECT tid, sciname FROM taxa WHERE rankid = 10 ORDER BY sciname');
while($r = $rs->fetch_object()){
$retArr[$r->tid] = $r->sciname;
}
Expand Down
Loading

0 comments on commit 65c50c7

Please sign in to comment.