render ( 'search', array (
'model' => $model,
'selectionLists' => $this->selectionLists,
'submitURL' => $this->submitURL
) );
} catch (\yii\base\ErrorException $e) {
Yii::$app->mailer->compose()
->setFrom('errorggbn@bgbm.org')
->setTo('p.kelbert@bgbm.org')
->setSubject('Error occured')
->setTextBody($e)
->send();
return $this->render('site/error', ["name"=>"Oooops",
"message"=>"Something went wrong.","exception"=>$e]);
}
}
public function actionBold() {
$att = Yii::$app->request->get ();
foreach ( $att as $k => $v ) {
if (! empty ( $k ))
ExploreManager::getBOLDRecord ( $k );
}
}
public function actionGbif() {
$att = Yii::$app->request->get ();
foreach ( $att as $k => $v ) {
if (! empty ( $k ))
ExploreManager::getGBIFRecord ( $k );
}
}
public function actionNcbi() {
$att = Yii::$app->request->get ();
foreach ( $att as $k => $v ) {
if (! empty ( $k ))
ExploreManager::getNCBIRecord( $k );
}
}
public function actionTree($id, $name, $rank, $kingdom, $phylum, $classis, $ordo, $family, $genus,$institution) {
$elts = Yii::$app->request->get ();
// $connection = new \yii\db\Connection ( Yii::$app->db );
// $connection->open ();
$x = ""; // the child rank
$y = $rank; // the current rank for SOLR
switch ($rank) {
case "kingdom" :
$x = $z = "phylum";
break;
case "phylum" :
$x = $z = "classis";
$z = "class";
break;
case "class" :
$x = "ordo";
$y = "classis";
$z = "order";
break;
case "order" :
$x = $z = "family";
$y = "ordo";
break;
case "family" :
$x = $z = "genus";
break;
case "genus" :
$x = "name";
$z = "species";
break;
case "species" :
$x = "name";
$z = "species";
break;
default :
$sep = "  ";
break;
}
$config = SOLRQueryManager::getConfigColTree ();
$queryTree = SOLRQueryManager::createSearchQuery ( $config );
$q = "parent_id:" . $id;
$fq = null;
// $fq="{!join from=parent_id to=taxonID fromIndex=colTree}";
$raw_responseTree = SOLRQueryManager::fillAndExecuteQuery ( $queryTree, $q, $fq, [ ], False );
$docsTree = $raw_responseTree->getDocuments ();
// $tree = "
";
$tree2 = "";
$connection = new \yii\db\Connection ( Yii::$app->db );
$connection->open ();
foreach ( $docsTree as $docTree ) {
// $tree2.="search ".$docTree->name." and rank ".$rank."
";
if (! empty ( $x )) {
$sql = "select count(distinct fullscientificname) as nbChildren,
count(distinct occurrenceid) as nbOccurrences,
FIELDS
from treeoflife
where kingdom='" . $kingdom . "'";
$groupby = [ ];
$selectFields = [ ];
if ($rank == "kingdom")
$sql .= " AND phylum='" . $docTree->name . "'";
if ($rank == "phylum")
$sql .= " AND classis='" . $docTree->name . "'";
if ($rank == "class")
$sql .= " AND ordo='" . $docTree->name . "'";
if ($rank == "order")
$sql .= " AND family='" . $docTree->name . "'";
if ($rank == "family")
$sql .= " AND genus='" . $docTree->name . "'";
if ($rank == "genus")
$sql .= " AND canonicalNameChecklist='" . $docTree->name . "'";
// $config = SOLRQueryManager::getConfigBackbone ();
// $query = SOLRQueryManager::createSearchQuery ( $config );
$value = $this->getValue ( $docTree->name, $x );
$q = $value . " AND rank:" . strtoupper ( $z );
if (! empty ( $kingdom ) && $kingdom != "null") {
$q .= " AND " . $this->getValue ( $kingdom, "kingdom" );
$groupby = [
"kingdom",
"phylum"
];
}
if (! empty ( $phylum ) && $phylum != "null") {
$q .= " AND " . $this->getValue ( $phylum, "phylum" );
$sql .= " AND " . $this->getSQLValue ( $phylum, "phylum" );
$groupby = [
"kingdom",
"phylum",
"classis"
];
}
if (! empty ( $classis ) && $classis != "null") {
$q .= " AND " . $this->getValue ( $classis, "classis" );
$sql .= " AND " . $this->getSQLValue ( $classis, "classis" );
$groupby = [
"kingdom",
"phylum",
"classis",
"ordo"
];
}
if (! empty ( $ordo ) && $ordo != "null") {
$q .= " AND " . $this->getValue ( $ordo, "ordo" );
$sql .= " AND " . $this->getSQLValue ( $ordo, "ordo" );
$groupby = [
"kingdom",
"phylum",
"classis",
"ordo",
"family"
];
}
if (! empty ( $family ) && $family != "null") {
$q .= " AND " . $this->getValue ( $family, "family" );
$sql .= " AND " . $this->getSQLValue ( $family, "family" );
$groupby = [
"kingdom",
"phylum",
"classis",
"ordo",
"family",
"genus"
];
}
if (! empty ( $genus ) && $genus != "null") {
$q .= " AND " . $this->getValue ( $genus, "genus" );
$sql .= " AND " . $this->getSQLValue ( $genus, "genus" );
$groupby = [
"kingdom",
"phylum",
"classis",
"ordo",
"family",
"genus",
"fullscientificname"
];
}
if(isset($institution) && $institution!="---")
$sql .=" AND institution='".$institution."'";
$sql .= " group by " . implode ( ", ", $groupby );
$inst="";
if(isset ($institution) && !empty($institution))
$inst="&institution=".str_ireplace("---", "", $institution);
$fields = [ ];
foreach ( $groupby as $f ) {
$fields [] = " IFNULL (" . $f . ", 'Not assigned' ) as " . $f;
}
$sql = str_ireplace ( "FIELDS", implode ( ", ", $fields ), $sql );
// echo $sql . "
";
// $tree2.=$sql;
$command = $connection->createCommand ( $sql );
$dataReader = $command->queryAll ();
$ok = false;
foreach ( $dataReader as $row ) {
$ok = true;
$nbOccurrences = $row ['nbOccurrences'];
$nbTaxChildren = $row ['nbChildren'];
$mykingdom = $row ['kingdom'];
if (isset ( $row ['phylum'] ))
$myphylum = $row ['phylum'];
else
$myphylum = "";
if (isset ( $row ['ordo'] ))
$myordo = $row ['ordo'];
else
$myordo = "";
if (isset ( $row ['classis'] ))
$myclassis = $row ['classis'];
else
$myclassis = "";
if (isset ( $row ['family'] ))
$myfamily = $row ['family'];
else
$myfamily = "";
if (isset ( $row ['phylum'] ))
$myphylum = $row ['phylum'];
else
$myphylum = "";
if (isset ( $row ['genus'] ))
$mygenus = $row ['genus'];
else
$mygenus = "";
$currentName = $docTree->name;
$cl = "col_absent";
$butterfly = "";
if ($docTree->total_species_extant == 0) {
if ($nbOccurrences > 0) {
$cl = "col_present";
$butterfly = "name) . "&parentName=" . trim($name) . "&parentRank=" . $rank .$inst."'>";
}
$tree2 .= "- " . $docTree->name . "" . $butterfly . "
";
} else {
if ($nbOccurrences > 0) {
$cl = "col_present";
$butterfly = "name . "&parentName=" . trim($name) . "&parentRank=" . $rank .$inst."'>";
}
$tree2 .= "- " . $docTree->name . " (" . $nbTaxChildren . " / " . $nbOccurrences . " )" . $butterfly . "
";
}
}
if (! $ok) {
$cl = "col_absent";
$butterfly = "";
if ($docTree->total_species_extant == 0) {
$tree2 .= "- " . $docTree->name . "
";
} else
$tree2 .= "- " . $docTree->name . " (0 / 0)
";
}
Yii::$app->db->close ();
// $fq = null;
// $raw_response = SOLRQueryManager::fillAndExecuteQuery ( $query, $q, $fq, [ ], False );
// $nbHits = $raw_response->getNumFound ();
// $docs = $raw_response->getDocuments ();
// $nbOccurrences = 0;
// $nbTaxChildren = 0;
// if ($nbHits > 0) {
// foreach ( $docs as $doc ) {
// $nbOccurrences = 0;
// $nbTaxChildren = 0;
// $nbOccurrences = $doc->occurrenceCount;
// if (empty ( $nbOccurrences ))
// $nbOccurrences = 0;
// $nbTaxChildren = $doc->childrenCount;
// if (empty ( $nbTaxChildren ))
// $nbTaxChildren = 0;
// $cl = "col_absent";
// $butterfly = "";
// if ($docTree->total_species_extant == 0) {
// if ($nbOccurrences > 0) {
// $cl = "col_present";
// $butterfly = "";
// }
// $tree .= "- " . $docTree->name . "" . $butterfly . "
";
// } else {
// if ($nbOccurrences > 0) {
// $cl = "col_present";
// $butterfly = "";
// }
// $tree .= "- " . $docTree->name . " (" . $nbTaxChildren . " / " . $nbOccurrences . " )" . $butterfly . "
";
// }
// }
// } else {
// $cl = "col_absent";
// $butterfly = "";
// if ($docTree->total_species_extant == 0) {
// $tree .= "- " . $docTree->name . "
";
// } else
// $tree .= "- " . $docTree->name . " (0 / 0)
";
// }
}
}
Yii::$app->db->close ();
// $tree .= "
";
$tree2 .= "
";
echo $tree2;
}
private function getValue($value, $field) {
$valuep = str_replace ( " ", "\ ", $value );
if ($value == "Not assigned") {
$valuep = " ( " . $field . ":" . $valuep . " OR N/A OR null ) ";
} else
$valuep = $field . ':' . $valuep;
return $valuep;
}
private function getSQLValue($value, $field) {
if ($value == "Not assigned") {
$value = " ( " . $field . "='" . $value . "' OR " . $field . "='N/A' OR " . $field . " is null ) ";
} else
$value = $field . "='" . $value . "'";
return $value;
}
}