Skip to content

Commit

Permalink
Merge pull request egbot#66 from BioKIC/master
Browse files Browse the repository at this point in the history
Merge various Symbiota-light developments into bryo-lichen code repositories
  • Loading branch information
egbot authored Apr 2, 2021
2 parents 41798c2 + 422f65f commit 525a47b
Show file tree
Hide file tree
Showing 33 changed files with 1,047 additions and 433 deletions.
5 changes: 5 additions & 0 deletions classes/DwcArchiverCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,7 @@ private function writeOccurrenceFile(){
$dwcOccurManager = new DwcArchiverOccurrence($this->conn);
$dwcOccurManager->setSchemaType($this->schemaType);
$dwcOccurManager->setExtended($this->extended);
$dwcOccurManager->setHarvestExsiccatae();
$dwcOccurManager->setIncludePaleo($this->hasPaleo);
if(!$this->occurrenceFieldArr) $this->occurrenceFieldArr = $dwcOccurManager->getOccurrenceArr($this->schemaType, $this->extended);
//Output records
Expand Down Expand Up @@ -1662,6 +1663,10 @@ private function writeOccurrenceFile(){
elseif($this->schemaType == 'backup') unset($r['collid']);

if($ocnStr = $dwcOccurManager->getAdditionalCatalogNumberStr($r['occid'])) $r['otherCatalogNumbers'] = $ocnStr;
if($exsStr = $dwcOccurManager->getExsiccateStr($r['occid'])){
if(isset($r['occurrenceRemarks']) && $r['occurrenceRemarks']) $exsStr = $r['occurrenceRemarks'].'; '.$exsStr;
$r['occurrenceRemarks'] = $exsStr;
}
if($assocOccurStr = $dwcOccurManager->getAssociationStr($r['occid'])) $r['t_associatedOccurrences'] = $assocOccurStr;
if($assocTaxa = $dwcOccurManager->getAssocTaxa($r['occid'])) $r['associatedTaxa'] = $assocTaxa;
//$dwcOccurManager->appendUpperTaxonomy($r);
Expand Down
27 changes: 27 additions & 0 deletions classes/DwcArchiverOccurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class DwcArchiverOccurrence{
private $schemaType;
private $extended = false;
private $includePaleo = false;
private $harvestExsiccatae = false;
private $relationshipArr;
private $upperTaxonomy = array();
private $taxonRankArr = array();
Expand Down Expand Up @@ -358,6 +359,32 @@ public function getAdditionalCatalogNumberStr($occid){
return $retStr;
}

public function setHarvestExsiccatae(){
$sql = 'SELECT occid FROM omexsiccatiocclink LIMIT 1';
$rs = $this->conn->query($sql);
if($rs->num_rows) $this->harvestExsiccatae = true;
$rs->free();
}

public function getExsiccateStr($occid){
$retStr = '';
$sql = 'SELECT t.title, t.abbreviation, t.editor, t.exsrange, n.exsnumber, l.notes '.
'FROM omexsiccatiocclink l INNER JOIN omexsiccatinumbers n ON l.omenid = n.omenid '.
'INNER JOIN omexsiccatititles t ON n.ometid = t.ometid '.
'WHERE l.occid = '.$occid;
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
$retStr = $r->title;
if($r->abbreviation) $retStr .= ' ['.$r->abbreviation.']';
if($r->exsrange) $retStr .= ', '.$r->exsrange;
if($r->editor) $retStr .= ', '.$r->editor;
$retStr .= ', exs #: '.$r->exsnumber;
if($r->notes) $retStr .= ' ('.$r->notes.')';
}
$rs->free();
return $retStr;
}

public function getAssociationStr($occid){
$retStr = '';
if($occid){
Expand Down
119 changes: 68 additions & 51 deletions classes/KeyDataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class KeyDataManager extends Manager {
private $charArr = Array();
private $taxaCount;
private $lang;
private $commonDisplay = false;
private $displayMode;
private $displayCommon = false;
private $pid;
private $dynClid;

Expand All @@ -35,16 +36,12 @@ public function __destruct(){
//$returns an Array of ("chars" => $charArray, "taxa" => $taxaArray)
//In coming attrs are in the form of: (cid => array of cs)
public function getData(){
$charArray = array();
$taxaArray = array();
$retArr = array();
if(($this->clid && $this->taxonFilter) || $this->dynClid){
$this->setTaxaListSQL();
$taxaArray = $this->getTaxaList();
$charArray = $this->getCharList();
$retArr['taxa'] = $this->getTaxaList();
$retArr['chars'] = $this->getCharList();
}
$returnArray["chars"] = $charArray;
$returnArray["taxa"] = $taxaArray;
return $returnArray;
return $retArr;
}

//returns map: HeadingId => Array(
Expand Down Expand Up @@ -182,36 +179,51 @@ public function getCharList(){
return $returnArray;
}

//return an array: family => array(TID => DisplayName)
public function getTaxaArr(){
$this->setTaxaListSQL();
$retArr = array();
$rs = $this->conn->query($this->sql);
$this->taxaCount = 0;
$taxaArr = array();
while($r = $rs->fetch_object()){
$this->taxaCount++;
$retArr[$r->family][$r->tid] = $r->sciname;
$taxaArr[$r->tid] = $r->family;
}
$rs->free();
if($this->displayCommon){
$sql = 'SELECT tid, vernacularName FROM taxavernaculars WHERE langid = 1 AND SortSequence = 1 AND tid IN('.implode(',',array_keys($taxaArr)).')';
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
$retArr[$taxaArr[$r->tid]][$r->tid]['vern'] = $r->vernacularName;
}
$rs->free();
}
return $retArr;
}

public function getTaxaList(){
$taxaList[] = null;
unset($taxaList);
$sqlTaxa = "";
if($this->commonDisplay){
$sqlTaxa = "SELECT innert.tid, innert.Family, IFNULL(v.VernacularName, innert.DisplayName) AS DisplayName, innert.ParentTID ".
"FROM (".$this->sql.") innert LEFT JOIN (SELECT tid, VernacularName FROM taxavernaculars WHERE langid = 1 AND SortSequence = 1) v ON innert.tid = v.tid ";
//Delete after current modifications are approved
$this->setTaxaListSQL();
$retArr = array();
$rs = $this->conn->query($this->sql);
$this->taxaCount = 0;
$taxaArr = array();
while($r = $rs->fetch_object()){
$this->taxaCount++;
$retArr[$r->family][$r->tid] = $r->sciname;
$taxaArr[$r->tid] = $r->family;
}
else{
$sqlTaxa = $this->sql;
$rs->free();
if($this->displayMode){
$sql = 'SELECT tid, vernacularName FROM taxavernaculars WHERE langid = 1 AND SortSequence = 1 AND tid IN('.implode(',',array_keys($taxaArr)).')';
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
$retArr[$taxaArr[$r->tid]][$r->tid] = $r->vernacularName;
}
$rs->free();
}
//echo $sqlTaxa.'<br/>';
$result = $this->conn->query($sqlTaxa);
$returnArray = array();
$sppArr = array();
$count = 0;
while ($row = $result->fetch_object()){
$count++;
$family = $row->Family;
$tid = $row->tid;
$displayName = $row->DisplayName;
unset($sppArr);
if(array_key_exists($family, $returnArray)) $sppArr = $returnArray[$family];
$sppArr[$tid] = $displayName;
$returnArray[$family] = $sppArr;
}
$this->taxaCount = $count;
$result->close();
return $returnArray;
return $retArr;
}

public function setTaxaListSQL(){
Expand Down Expand Up @@ -262,7 +274,7 @@ public function setTaxaListSQL(){
$sqlWhere.=' AND (D'.$count.'.CID='.$cid.') AND ('.$stateStr.')';
}
}
$this->sql = 'SELECT DISTINCT t.tid, ts.Family, t.SciName AS DisplayName, ts.ParentTID '.$sqlFromBase.$sqlWhere;
$this->sql = 'SELECT DISTINCT t.tid, ts.family, t.sciname '.$sqlFromBase.$sqlWhere;
//echo $this->sql;
}
}
Expand Down Expand Up @@ -293,29 +305,28 @@ public function getTaxaFilterList(){
if($this->childClidArr){
$clidStr .= ','.implode(',',array_keys($this->childClidArr));
}
$sql .= 'FROM (taxstatus ts INNER JOIN taxa nt ON ts.tid = nt.tid) INNER JOIN fmchklsttaxalink cltl ON nt.TID = cltl.TID WHERE (cltl.CLID IN('.$clidStr.')) ';
$sql .= 'FROM (taxstatus ts INNER JOIN taxa nt ON ts.tid = nt.tid) INNER JOIN fmchklsttaxalink cltl ON nt.TID = cltl.TID WHERE (ts.taxauthid = 1) AND (cltl.CLID IN('.$clidStr.')) ';
}
else if($this->dynClid){
$sql .= 'FROM (taxstatus ts INNER JOIN taxa nt ON ts.tid = nt.tid) INNER JOIN fmdyncltaxalink dcltl ON nt.TID = dcltl.TID WHERE (dcltl.dynclid = '.$this->dynClid.') ';
$sql .= 'FROM (taxstatus ts INNER JOIN taxa nt ON ts.tid = nt.tid) INNER JOIN fmdyncltaxalink dcltl ON nt.TID = dcltl.TID WHERE (ts.taxauthid = 1) AND (dcltl.dynclid = '.$this->dynClid.') ';
}
else{
$sql .= "FROM (((taxstatus ts INNER JOIN taxa nt ON ts.tid = nt.tid) ".
"INNER JOIN fmchklsttaxalink cltl ON nt.TID = cltl.TID) ".
"INNER JOIN fmchecklists cl ON cltl.CLID = cl.CLID) ".
"INNER JOIN fmchklstprojlink clpl ON cl.CLID = clpl.clid ".
"WHERE (clpl.pid = ".$this->pid.") ";
$sql .= 'FROM (((taxstatus ts INNER JOIN taxa nt ON ts.tid = nt.tid) '.
'INNER JOIN fmchklsttaxalink cltl ON nt.TID = cltl.TID) '.
'INNER JOIN fmchecklists cl ON cltl.CLID = cl.CLID) '.
'INNER JOIN fmchklstprojlink clpl ON cl.CLID = clpl.clid '.
'WHERE (ts.taxauthid = 1) ';
if($this->pid) $sql .= 'AND (clpl.pid = '.$this->pid.') ';
}
$sql .= 'AND (ts.taxauthid = 1)';
//echo $sql.'<br/>'; exit;
$result = $this->conn->query($sql);
while($row = $result->fetch_object()){
$rs = $this->conn->query($sql);
while($row = $rs->fetch_object()){
$genus = $row->UnitName1;
$family = $row->Family;
if($genus) $returnArr[] = $genus;
if($family) $returnArr[] = $family;
}

$result->free();
$rs->free();
$returnArr = array_unique($returnArr);
natcasesort($returnArr);
array_unshift($returnArr,"--------------------------");
Expand Down Expand Up @@ -390,8 +401,14 @@ public function setLanguage($l){
$this->lang = $l;
}

public function setCommonDisplay($bool){
if($bool) $this->commonDisplay = true;
public function setDisplayMode($bool){
if($bool) $this->displayMode = 1;
else $this->displayMode = 0;
}

public function setDisplayCommon($bool){
if($bool) $this->displayCommon = true;
else $this->displayCommon = false;
}

public function setTaxonFilter($t){
Expand Down
130 changes: 130 additions & 0 deletions classes/OccurrenceAttributeSearch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
include_once($SERVER_ROOT.'/classes/OccurrenceAttributes.php');

class OccurrenceAttributeSearch extends OccurrenceAttributes {

//use $setAttributes = false in call to ->getTraitArr, if reverting to using OccurrenceAttributes class

//private $traitSearchArr = array();
public function __construct(){
parent::__construct('readonly');
}

public function __destruct(){
parent::__destruct();
}

public function getTraitSearchArr($traitID = null){
if($traitID) {
$traitIDArr = array_map('trim', explode(',', $traitID));
if (($key = array_search('0', $traitIDArr)) !== false) {
unset($traitIDArr[$key]);
} // this purges potential zeros from the array
$traitID = implode(',', $traitIDArr);
foreach($traitIDArr as $tid) {
if(!is_numeric($tid)) return null; // reject non-numeric IDs
}
}
unset($this->traitArr);
$this->traitArr = array();
$this->setTraitSearchArr($traitID);
$this->setTraitStates();
return $this->traitArr;
}

private function setTraitSearchArr($traitID){
$sql = 'SELECT traitid, traitname, traittype, units, description, refurl, notes, dynamicproperties FROM tmtraits WHERE traittype IN("UM","OM","TF","NU") ';
if($traitID) $sql .= 'AND (traitid IN('.$traitID.'))';
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
if(!isset($this->traitArr[$r->traitid])){
$this->traitArr[$r->traitid]['name'] = $r->traitname;
$this->traitArr[$r->traitid]['type'] = $r->traittype;
$this->traitArr[$r->traitid]['props'] = $r->dynamicproperties;
//Get dependent traits and append to return array
$this->setDependentTraits($r->traitid);
}
}
$rs->free();
return $this->traitArr;
}

public function echoTraitSearchForm($traitID){
echo $this->getTraitSearchHTML($traitID,true);
}

private function getTraitSearchHTML($traitID,$display,$classStr=''){
$controlType = '';
if($this->traitArr[$traitID]['props']){
$propArr = json_decode($this->traitArr[$traitID]['props'],true);
if(isset($propArr[0]['controlType'])) $controlType = $propArr[0]['controlType'];
}
$innerStr = '<div style="clear:both">';
if(isset($this->traitArr[$traitID]['states'])){
if($this->traitArr[$traitID]['type']=='TF'){
$innerStr .= '<div style="float:left;margin-left: 15px">'.$this->traitArr[$traitID]['name'].':</div>';
$innerStr .= '<div style="clear:both;margin-left: 25px">';
}
else $innerStr .= '<div style="float:left;">';
$attrStateArr = $this->traitArr[$traitID]['states'];
foreach($attrStateArr as $sid => $sArr){
$isCoded = false;
if(array_key_exists('coded',$sArr)){
if(is_numeric($sArr['coded'])) $isCoded = $sArr['coded'];
else $isCoded = true;
$this->stateCodedArr[$sid] = $sid;
}
$depTraitIdArr = array();
if(isset($sArr['dependTraitID']) && $sArr['dependTraitID']) $depTraitIdArr = $sArr['dependTraitID'];
if($this->traitArr[$traitID]['type']=='NU'){
$innerStr .= '<div title="'.$sArr['description'].'" style="clear:both">';
$innerStr .= $sArr['name'].
$innerStr .= ': <input name="traitid-'.$traitID.'[]" id="traitstateid-'.$sid.'" class="'.$classStr.'" type="text" value="'.$sid.'-'.($isCoded!==false?$isCoded:'').'" onchange="traitChanged(this)" style="width:50px" /> ';
if($depTraitIdArr){
foreach($depTraitIdArr as $depTraitId){
$innerStr .= $this->getTraitSearchHTML($depTraitId,$isCoded,trim($classStr.' child-'.$sid));
}
}
}
else{
if($controlType == 'checkbox' || $controlType == 'radio'){
$innerStr .= '<div title="'.$sArr['description'].'" style="clear:both">';
$innerStr .= '<input name="traitid-'.$traitID.'[]" id="traitstateid-'.$sid.'" class="'.$classStr.'" type="'.$controlType.'" value="'.$sid.'" '.($isCoded?'checked':'').' onchange="traitChanged(this)" /> ';
$innerStr .= $sArr['name'];
}
elseif($controlType == 'select'){
$innerStr .= '<option value="'.$sid.'" '.($isCoded?'selected':'').'>'.$sArr['name'].'</option>';
}
if($depTraitIdArr){
foreach($depTraitIdArr as $depTraitId){
$innerStr .= $this->getTraitSearchHTML($depTraitId,$isCoded,trim($classStr.' child-'.$sid));
}
}
if($controlType != 'select') $innerStr .= '</div>';
}
}
$innerStr .= '</div>';
}
$innerStr .= '</div>';
//Display if trait has been coded or is the first/base trait (e.g. $indend == 0)
$divClass = '';
if($classStr){
$classArr = explode(' ',$classStr);
$divClass = array_pop($classArr);
}
$outStr = '<div class="'.$divClass.'" style="margin-left:'.($classStr?'10':'').'px; display:'.($display?'block':'none').';">';
if($controlType == 'select'){
$outStr .= '<select name="stateid">';
$outStr .= '<option value="">Select State</option>';
$outStr .= '<option value="">------------------------------</option>';
$outStr .= $innerStr;
$outStr .= '</select>';
}
else{
$outStr .= $innerStr;
}
$outStr .= '</div>';
return $outStr;
}

}
Loading

0 comments on commit 525a47b

Please sign in to comment.