request->get (); $filter = [ ]; $filterURL = [ ]; $genus = ""; $family = ""; $classes = ""; $ordo = ""; $species = ""; foreach ( $att as $k => $v ) { $value = str_replace ( " ", "\ ", $v ); $value = str_replace ( "(", "\(", $value ); $value = str_replace ( ")", "\)", $value ); $value = str_replace ( ":", "\:", $value ); $filter [] = $k . ":" . $value; if ($k == "institution") $filterURL ["registry"] = $v; else $filterURL [$k] = $v; } // Yii::info ( "filterURL: " . implode ( "--", $filterURL ) ); $f = implode ( " AND ", $filter ); try{ $kindofunitdata = $this->getKindofunit ( $f ); } catch (\Solarium\Exception\HttpException $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"=>"The SOLR instance seems to be gone.","error"=>$e]); } $classes = $this->getHigher ( $f, "classis" ); // Yii::info ( "classes returned: " . $classes ); if (! empty ( explode ( "classis", $f, - 1 ) )) $ordo = $this->getHigher ( $f, "ordo" ); if (! empty ( explode ( "ordo", $f, - 1 ) )) $family = $this->getHigher ( $f, "family" ); if (! empty ( explode ( "family", $f, - 1 ) )) $genus = $this->getHigher ( $f, "genus" ); if (! empty ( explode ( "genus", $f, - 1 ) )) $species = $this->getHigher ( $f, "fullScientificName" ); try { $datasets = $this->getDatasets (); } catch (\yii\db\Exception $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"=>"The database server seems to be gone.","error"=>$e]); } return $this->render ( 'index', array_merge ( [ 'kindofunitdata' => $kindofunitdata, 'datasets' => $datasets [1], 'registries' => $datasets [0], 'classes' => $classes, 'orders' => $ordo, 'families' => $family, 'genera' => $genus, 'species' => $species ], $filterURL ) ) // 'kindofunits'=>$datasets[0], // 'classes'=>$datasets[2] ; } public function actionDetails() { $att = Yii::$app->request->get (); $filter = [ ]; $filterURL = [ ]; $genus = ""; $family = ""; $classes = ""; $ordo = ""; $species = ""; $basisofrecordstxt = "- all basis of records included -"; foreach ( $att as $k => $v ) { $value = str_replace ( " ", "\ ", $v ); $value = str_replace ( "(", "\(", $value ); $value = str_replace ( ")", "\)", $value ); $value = str_replace ( ":", "\:", $value ); $filter [] = $k . ":" . $value; if ($k == "institution") $filterURL ["registry"] = $v; else { $filterURL [$k] = $v; if ($k != "registry") $basisofrecordstxt = ""; } } // Yii::info ( "filterURL: " . implode ( "--", $filterURL ) ); $f = implode ( " AND ", $filter ); $kindofunitdata = $this->getKindofunit ( $f ); $classes = $this->getHigher ( $f, "classis" ); if (! empty ( explode ( "classis", $f, - 1 ) )) $ordo = $this->getHigher ( $f, "ordo" ); if (! empty ( explode ( "ordo", $f, - 1 ) )) $family = $this->getHigher ( $f, "family" ); if (! empty ( explode ( "family", $f, - 1 ) )) $genus = $this->getHigher ( $f, "genus" ); if (! empty ( explode ( "genus", $f, - 1 ) )) $species = $this->getHigher ( $f, "fullScientificName" ); return $this->render ( 'details', array_merge ( [ 'kindofunits' => $kindofunitdata, 'classes' => $classes, 'orders' => $ordo, 'families' => $family, 'genera' => $genus, 'species' => $species, 'basisofrecordstxt' => $basisofrecordstxt ], $filterURL ) ); } public function getKindofunit($filter) { // Yii::info ( "getKindofunit " . $filter ); $config = SOLRQueryManager::getConfigStats (); // create a client instance $client = new Solarium\Client ( $config ); // set the adapter to http $client->setAdapter ( 'Solarium\Core\Client\Adapter\Http' ); // get a select query instance $query = $client->createSelect (); // set fields to fetch (this overrides the default setting 'all fields') $query->setFields ( [ "[]" ] ); $q = "sampletype:*"; if (! empty ( $filter )) $q .= " AND " . $filter; $q = str_replace ( "registry", "institution", $q ); $query->setQuery ( $q ); // Yii::info ( "TETE DE QUERY: " . $q ); // get the facetset component $facetSet = $query->getFacetSet (); $facetSet->setLimit ( - 1 ); $facetSet->setMinCount ( 1 ); $facetSet->setSort ( "false" ); // create a facet field instance and set options $facetSet->createFacetField ( "sampletype" )->setField ( "sampletype" ); // this executes the query and returns the result $raw_response = $client->select ( $query ); $result = $raw_response->getFacetSet ()->getFacet ( "sampletype" ); $data = [ ]; foreach ( $result as $doc => $count ) { $data [] = '["' . $doc . ' (' . $count . ')",' . $count . ']'; // Yii::info("SUBLIST: ".$doc); } return "[" . implode ( ",", $data ) . "]"; } public function getHigher($filter, $rank) { // Yii::info ( "getHigher " . $filter . " " . $rank ); // echo "getHigher ".$rank."
"; $config = SOLRQueryManager::getConfigStats (); // create a client instance $client = new Solarium\Client ( $config ); // set the adapter to http $client->setAdapter ( 'Solarium\Core\Client\Adapter\Http' ); // get a select query instance $query = $client->createSelect (); // set fields to fetch (this overrides the default setting 'all fields') $query->setFields ( [ "[]" ] ); $q = $rank . ":*"; $query->setQuery ( $q ); $fq = [ ]; if ($filter != "") { $filter = str_replace ( "registry", "institution", $filter ); $query->createFilterQuery ( 'myfilter' )->setQuery ( $filter ); } // get the facetset component $facetSet = $query->getFacetSet (); $facetSet->setLimit ( - 1 ); $facetSet->setMinCount ( 1 ); $facetSet->setSort ( "false" ); // create a facet field instance and set options $facetSet->createFacetField ( $rank )->setField ( $rank ); // this executes the query and returns the result $raw_response = $client->select ( $query ); $result = $raw_response->getFacetSet ()->getFacet ( $rank ); $data = [ ]; foreach ( $result as $doc => $count ) { $data [] = '["' . $doc . ' (' . $count . ')",' . $count . ']'; // Yii::info("SUBLIST: ".$doc); } return "[" . implode ( ",", $data ) . "]"; } public function getDatasets() { $connection = new \yii\db\Connection ( Yii::$app->db ); $connection->open (); // only DNA / tissue /enviro $query = 'SELECT count(occurrenceid) as cnt, concat(Institution,", ",City) as reg from occurrence join bio_datasource on fk_datasourceid=id join unitkind on fk_kindofunitid=unitkindid where kindofunit_clean in (\'DNA\',\'tissue\',\'environmental sample\') group by reg order by reg'; // use lowest unit for having the same numbers as in the search formular $query = "SELECT count(distinct occurrenceid) as cnt, concat(Institution,', ',City) as reg from occurrence o join bio_datasource on fk_datasourceid=id join lowerOccurrence l on l.fk_tripleidstoreid=o.fk_tripleidstoreid group by reg order by reg"; $command = $connection->createCommand ($query); $dataReader = $command->queryAll (); $data = [ ]; $datapie = [ ]; $labels = [ ]; $kindofunitDatasets = [ ]; foreach ( $dataReader as $row ) { $labels[]=$row["reg"]; $data[]=$row["cnt"]; $datapie[]='["'.$row["reg"].' ('.$row["cnt"].')",'.$row["cnt"].']'; // $kindofunitDatasets[$row["reg"]]=$this->getKindofunit($row["reg"]); // $classesDatasets[$row["reg"]]=$this->getClasses($row["reg"]); } Yii::$app->db->close(); // Yii::info("getCounts: ".$counts); return [ $labels, "[".implode(",", $datapie)."]"]; // return [$kindofunitDatasets,"[".implode(",",$datapie)."]",$classesDatasets]; } }