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 "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, family,
FIELDS
from treeoflife t
join identification i on t.fullscientificname = i.fullScientificName
join occurrence o on i.fk_occurrenceid = o.occurrenceid
where family='" . $family . "'";
$groupby = [ ];
$selectFields = [ ];
if ($origin == "wild")
$sql .= " AND o.establishmentMeans != 'cultivated' ";
if ($origin == "cultivated")
$sql .= " AND o.establishmentMeans = 'cultivated' ";
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 );
$groupby = [
"family"
];
if (! empty ( $family ) && $family != "null") {
$q .= " AND " . $this->getValue ( $family, "family" );
$sql .= " AND " . $this->getSQLValue ( $family, "family" );
$groupby = [
"family",
"genus"
];
}
if (! empty ( $genus ) && $genus != "null") {
$q .= " AND " . $this->getValue ( $genus, "genus" );
$sql .= " AND " . $this->getSQLValue ( $genus, "genus" );
$groupby = [
"family",
"genus",
"fullscientificname"
];
}
$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'];
$myfamily = $row ['family'];
if (isset ( $row ['family'] ))
$myfamily = $row ['family'];
else
$myfamily = "";
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 = "";
}
$tree2 .= "- " . $docTree->name . "" . $butterfly . "
";
} else {
if ($nbOccurrences > 0) {
$cl = "col_present";
$butterfly = "";
}
$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 ();
}
}
Yii::$app->db->close ();
// $tree .= "
";
$tree2 .= "
";
echo $tree2;
}
}