Skip to content

Commit

Permalink
fix types for taxa id-related prepared statements to match sqls expec… (
Browse files Browse the repository at this point in the history
#1426)

* fix types for taxa id-related prepared statements to match sqls expectation of integer types as well as make some cosmetic fixes to spacing for code readbility

* change result to statement for close
  • Loading branch information
Atticus29 authored Jun 12, 2024
1 parent 78b2200 commit a78afb0
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions classes/RpcTaxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,37 +110,37 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc
$sql = 'SELECT MIN(t.RankId) AS RankId FROM taxa t INNER JOIN taxstatus ts ON t.tid = ts.tid WHERE (t.rankid != 0) AND (ts.taxauthid = ?) LIMIT 1 ';
//echo $sql.'<br>';
if ($statement = $this->conn->prepare($sql)) {
$statement->bind_param("s", $this->taxAuthID);
$statement->bind_param("i", $this->taxAuthID);
$statement->execute();
$result = $statement->get_result();
while($row = $result->fetch_object()){
$lowestRank = $row->RankId;
}
$result->free();
$result->close();
$statement->close();
}
$sql1 = 'SELECT DISTINCT t.tid, t.sciname, t.author, t.rankid FROM taxa t LEFT JOIN taxstatus ts ON t.tid = ts.tid WHERE ts.taxauthid = ? AND t.RankId = ? ';
//echo "<div>".$sql1."</div>";

if ($statement1 = $this->conn->prepare($sql1)) {
$i = 0;
$statement1->bind_param("ss", $this->taxAuthID, $lowestRank);
$statement1->bind_param("ii", $this->taxAuthID, $lowestRank);
$statement1->execute();
$result1 = $statement1->get_result();
while($row1 = $result1->fetch_object()){
$rankName = (isset($taxonUnitArr[$row1->rankid])?$taxonUnitArr[$row1->rankid]:'Unknown');
$label = '2-'.$row1->rankid.'-'.$rankName.'-'.$row1->sciname;
$rankName = (isset($taxonUnitArr[$row1->rankid]) ? $taxonUnitArr[$row1->rankid] : 'Unknown');
$label = '2-' . $row1->rankid . '-' . $rankName.'-' . $row1->sciname;
$sciName = $row1->sciname;
if($row1->tid == $targetId) $sciName = '<b>'.$sciName.'</b>';
$sciName = "<span style='font-size:75%;'>".$rankName.":</span> ".$sciName.($displayAuthor?" ".$row1->author:"");
if($row1->tid == $targetId) $sciName = '<b>' . $sciName . '</b>';
$sciName = "<span style='font-size:75%;'>" . $rankName . ":</span> " . $sciName . ($displayAuthor ? " " . $row1->author : "");
$childArr[$i]['id'] = $row1->tid;
$childArr[$i]['label'] = $label;
$childArr[$i]['name'] = $sciName;
$childArr[$i]['url'] = $urlPrefix.$row1->tid;
$sql3 = 'SELECT tid FROM taxaenumtree WHERE taxauthid = ? AND parenttid = ? LIMIT 1 ';
//echo "<div>".$sql3."</div>";
if ($statement3 = $this->conn->prepare($sql3)) {
$statement3->bind_param("ss", $this->taxAuthID, $row1->tid);
$statement3->bind_param("ii", $this->taxAuthID, $row1->tid);
$statement3->execute();
$result3 = $statement3->get_result();
if($row3 = $result3->fetch_object()){
Expand All @@ -150,7 +150,7 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc
$sql4 = 'SELECT DISTINCT tid, tidaccepted FROM taxstatus WHERE (taxauthid = ?) AND (tidaccepted = ?) ';
//echo "<div>".$sql4."</div>";
if ($statement4 = $this->conn->prepare($sql4)) {
$statement4->bind_param("ss", $this->taxAuthID, $row1->tid);
$statement4->bind_param("ii", $this->taxAuthID, $row1->tid);
$statement4->execute();
$result4 = $statement4->get_result();
while($row4 = $result4->fetch_object()){
Expand Down Expand Up @@ -179,17 +179,17 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc
$sql .= 'WHERE (ts.taxauthid = ?) AND (ts.tid = ts.tidaccepted) AND ((ts.parenttid = ?) OR (t.tid = ?)) ';
//echo $sql.'<br>';
if ($statement = $this->conn->prepare($sql)) {
$statement->bind_param("sss", $this->taxAuthID, $objId, $objId);
$statement->bind_param("iii", $this->taxAuthID, $objId, $objId);
$statement->execute();
$result = $statement->get_result();
$i = 0;
while($r = $result->fetch_object()){
$rankName = (isset($taxonUnitArr[$r->rankid])?$taxonUnitArr[$r->rankid]:'Unknown');
$rankName = (isset($taxonUnitArr[$r->rankid]) ? $taxonUnitArr[$r->rankid] : 'Unknown');
$label = '2-'.$r->rankid.'-'.$rankName.'-'.$r->sciname;
$sciName = $r->sciname;
if($r->rankid >= 180) $sciName = '<i>'.$sciName.'</i>';
if($r->tid == $targetId) $sciName = '<b>'.$sciName.'</b>';
$sciName = "<span style='font-size:75%;'>".$rankName.":</span> ".$sciName.($displayAuthor?" ".$r->author:"");
if($r->rankid >= 180) $sciName = '<i>' . $sciName . '</i>';
if($r->tid == $targetId) $sciName = '<b>' . $sciName . '</b>';
$sciName = "<span style='font-size:75%;'>" . $rankName . ":</span> " . $sciName . ($displayAuthor ? " " . $r->author : "");
if($r->tid == $objId){
$retArr['id'] = $r->tid;
$retArr['label'] = $label;
Expand All @@ -205,7 +205,7 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc
$sql3 = 'SELECT tid FROM taxaenumtree WHERE taxauthid = ? AND parenttid = ? LIMIT 1 ';
//echo 'sql3: '.$sql3.'<br/>';
if ($statement3 = $this->conn->prepare($sql3)) {
$statement3->bind_param("ss", $this->taxAuthID, $r->tid);
$statement3->bind_param("ii", $this->taxAuthID, $r->tid);
$statement3->execute();
$result3 = $statement3->get_result();
if($row3 = $result3->fetch_object()){
Expand All @@ -215,7 +215,7 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc
$sql4 = 'SELECT DISTINCT tid, tidaccepted FROM taxstatus WHERE taxauthid = ? AND tidaccepted = ? ';
//echo 'sql4: '.$sql4.'<br/>';
if ($statement4 = $this->conn->prepare($sql4)) {
$statement4->bind_param("ss", $this->taxAuthID, $r->tid);
$statement4->bind_param("ii", $this->taxAuthID, $r->tid);
$statement4->execute();
$result4 = $statement4->get_result();
while($row4 = $result4->fetch_object()){
Expand Down Expand Up @@ -243,16 +243,16 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc
'WHERE (ts.tid <> ts.tidaccepted) AND (ts.taxauthid = ?) AND (ts.tidaccepted = ?)';
//echo 'syn: '.$sqlSyns.'<br/>';
if ($statementSyns = $this->conn->prepare($sqlSyns)) {
$statementSyns->bind_param("ss", $this->taxAuthID, $objId);
$statementSyns->bind_param("ii", $this->taxAuthID, $objId);
$statementSyns->execute();
$resultSyns = $statementSyns->get_result();
while($row = $resultSyns->fetch_object()){
$rankName = (isset($taxonUnitArr[$row->rankid])?$taxonUnitArr[$row->rankid]:'Unknown');
$label = '1-'.$row->rankid.'-'.$rankName.'-'.$row->sciname;
$rankName = (isset($taxonUnitArr[$row->rankid]) ? $taxonUnitArr[$row->rankid] : 'Unknown');
$label = '1-' . $row->rankid . '-' . $rankName . '-' . $row->sciname;
$sciName = $row->sciname;
if($row->rankid >= 180) $sciName = '<i>'.$sciName.'</i>';
if($row->tid == $targetId) $sciName = '<b>'.$sciName.'</b>';
$sciName = '['.$sciName.']'.($displayAuthor?' '.$row->author:'');
if($row->rankid >= 180) $sciName = '<i>' . $sciName . '</i>';
if($row->tid == $targetId) $sciName = '<b>' . $sciName . '</b>';
$sciName = '[' . $sciName . ']' . ($displayAuthor ? ' ' . $row->author : '');
$childArr[$i]['id'] = $row->tid;
$childArr[$i]['label'] = $label;
$childArr[$i]['name'] = $sciName;
Expand Down Expand Up @@ -281,4 +281,4 @@ public function isValidApiCall(){
return true;
}
}
?>
?>

0 comments on commit a78afb0

Please sign in to comment.