request->get (); $filter = [ ]; $filterURL = [ ]; $genus = ""; $family = ""; $classes = ""; $ordo = ""; $species = ""; $continents = ""; $countries = ""; $oceans = ""; $seas = ""; $kindofunitdatavouchers = [ ]; $kindofunitdatasamples = [ ]; $repositoriessamples = [ ]; $repositoriesvouchers = [ ]; foreach ( $att as $k => $v ) { $value = str_replace ( " ", "\ ", $v ); $value = str_replace ( "(", "\(", $value ); $value = str_replace ( ")", "\)", $value ); $value = str_replace ( ":", "\:", $value ); if (! empty ( $value )) { $filter [] = $k . ":" . $value; if ($k == "institution") $filterURL ["registry"] = $v; else $filterURL [$k] = $v; } } foreach ( $filterURL as $k => $v ) Yii::info ( "filterURL: " . $k . "::" . $v ); $f = implode ( " AND ", $filter ).Yii::$app->params['thematicSOLRfilterShort']; try { $kindofunitdatasamples = $this->getKindofunit ( $f, 'samples' ); } catch ( \Solarium\Exception\HttpException $e ) { Yii::$app->mailer->compose ()->setFrom ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'Error occured' )->setTextBody ( $e )->send (); return $this->render ( '/site/error', [ "name" => "Oooops", "message" => "The SOLR instance seems to be gone.".$f, "error" => $e ] ); } try { $kindofunitdatavouchers = $this->getKindofunit ( $f, 'vouchers' ); } catch ( \Solarium\Exception\HttpException $e ) { Yii::$app->mailer->compose ()->setFrom ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'Error occured' )->setTextBody ( $e )->send (); return $this->render ( '/site/error', [ "name" => "Oooops", "message" => "The SOLR instance seems to be gone.", "error" => $e ] ); } try { $repositoriesvouchers = $this->getRepositories( $f, 'vouchers' ); } catch ( \Solarium\Exception\HttpException $e ) { Yii::$app->mailer->compose ()->setFrom ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'Error occured' )->setTextBody ( $e )->send (); return $this->render ( '/site/error', [ "name" => "Oooops", "message" => "The SOLR instance seems to be gone.", "error" => $e ] ); } try { $repositoriessamples = $this->getRepositories ( $f, 'samples' ); } catch ( \Solarium\Exception\HttpException $e ) { Yii::$app->mailer->compose ()->setFrom ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'Error occured' )->setTextBody ( $e )->send (); return $this->render ( '/site/error', [ "name" => "Oooops", "message" => "The SOLR instance seems to be gone.", "error" => $e ] ); } if (! array_key_exists ( 'continent', $filterURL )) try { $continents = $this->getContinent ( $f ); } catch ( \Solarium\Exception\HttpException $e ) { Yii::$app->mailer->compose ()->setFrom ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'Error occured' )->setTextBody ( $e )->send (); return $this->render ( '/site/error', [ "name" => "Oooops", "message" => "The SOLR instance seems to be gone.", "error" => $e ] ); } else $continents = [ ]; if (array_key_exists ( 'continent', $filterURL )) { $countries = $this->getCountries ( $f ); } else $countries = [ ]; if (! array_key_exists ( 'ocean', $filterURL )) try { $oceans = $this->getOcean ( $f ); } catch ( \Solarium\Exception\HttpException $e ) { Yii::$app->mailer->compose ()->setFrom ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'Error occured' )->setTextBody ( $e )->send (); return $this->render ( '/site/error', [ "name" => "Oooops", "message" => "The SOLR instance seems to be gone.", "error" => $e ] ); } else $oceans = [ ]; if (array_key_exists ( 'ocean', $filterURL )) $seas = $this->getSeas ( $f ); else $seas = [ ]; $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, "familia" ); if (! empty ( explode ( "familia", $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 ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'Error occured' )->setTextBody ( $e )->send (); return $this->render ( '/site/error', [ "name" => "Oooops", "message" => "The database server seems to be gone.", "error" => $e ] ); } $orders = $this->getOrders (); $speciesYear = $this->getSpeciesYear ( '' ); $genusYear = $this->getGenusYear ( '' ); $familiesYear = $this->getFamiliesYear ( '' ); $samplesYear = $this->getSamplesYear ( '' ); return $this->render ( 'index', array_merge ( [ 'kindofunitdatasamples' => $kindofunitdatasamples, 'kindofunitdatavouchers' => $kindofunitdatavouchers, 'datasets' => $datasets [1], 'registries' => $datasets [0], 'classes' => $classes, 'orders' => $ordo, 'families' => $family, 'genera' => $genus, 'species' => $species, 'statistics_tissue' => $orders ['statistics_tissue'], 'statistics_request' => $orders ['statistics_request'], 'statistics_all' => $orders ['statistics_all'], 'statistics_dna' => $orders ['statistics_dna'], 'continents' => $continents, 'countries' => $countries, 'oceans' => $oceans, 'seas' => $seas, 'speciesYear' => $speciesYear, 'genusYear' => $genusYear, 'familiesYear' => $familiesYear, 'samplesYearAll' => $samplesYear ["all"], 'samplesYearDNA' => $samplesYear ["DNA"], 'samplesYearCulture' => $samplesYear ["culture"], 'samplesYearSpecimen' => $samplesYear ["specimen"], 'samplesYearTissue' => $samplesYear ["tissue"], 'samplesYearEnviro' => $samplesYear ["enviro"], 'repositoriessamples' => $repositoriessamples, 'repositoriesvouchers' => $repositoriesvouchers, ], $filterURL ) ); // 'kindofunits'=>$datasets[0], // 'classes'=>$datasets[2] } public function getSpeciesYear($registry) { // requete directe DB $speYs = DBInterface::getSpeciesYear ( $registry ); $statistics = [ ]; foreach ( $speYs as $i ) { $day = DateTime::createFromFormat ( 'Y-m-d', $i ['date'] ); $year = $day->format ( 'Y' ); $nb = $i ['numberOfSpecies']; if (! array_key_exists ( $year, $statistics )) $atmp = 0; else $atmp = $statistics [$year]; if (empty ( $registry )) // sums up $atmp += $nb; else // keep the uper value { if ($nb > $atmp) $atmp = $nb; } $statistics [$year] = $atmp; } $statistics_ret = [ ]; foreach ( $statistics as $k => $v ) { $statistics_ret [] = "['" . $k . "', " . $v . "]"; } return "[" . implode ( ", ", $statistics_ret ) . "]"; } public function getGenusYear($registry) { // requete directe DB $speYs = DBInterface::getGenusYear ( $registry ); $statistics = [ ]; foreach ( $speYs as $i ) { $day = DateTime::createFromFormat ( 'Y-m-d', $i ['date'] ); $year = $day->format ( 'Y' ); $nb = $i ['numberOfGenus']; if (! array_key_exists ( $year, $statistics )) $atmp = 0; else $atmp = $statistics [$year]; if (empty ( $registry )) // sums up $atmp += $nb; else // keep the uper value { if ($nb > $atmp) $atmp = $nb; } $statistics [$year] = $atmp; } $statistics_ret = [ ]; foreach ( $statistics as $k => $v ) { $statistics_ret [] = "['" . $k . "', " . $v . "]"; } return "[" . implode ( ", ", $statistics_ret ) . "]"; } public function getFamiliesYear($registry) { // requete directe DB $speYs = DBInterface::getFamiliesYear ( $registry ); $statistics = [ ]; foreach ( $speYs as $i ) { $day = DateTime::createFromFormat ( 'Y-m-d', $i ['date'] ); $year = $day->format ( 'Y' ); $nb = $i ['numberOfFamily']; if (! array_key_exists ( $year, $statistics )) $atmp = 0; else $atmp = $statistics [$year]; if (empty ( $registry )) // sums up $atmp += $nb; else // keep the uper value { if ($nb > $atmp) $atmp = $nb; } $statistics [$year] = $atmp; } $statistics_ret = [ ]; foreach ( $statistics as $k => $v ) { $statistics_ret [] = "['" . $k . "', " . $v . "]"; } return "[" . implode ( ", ", $statistics_ret ) . "]"; } public function getSamplesYear($registry) { // requete directe DB $speYs = DBInterface::getSamplesYear ( $registry ); $statisticsDNA = [ ]; $statisticsTissue = [ ]; $statisticsSpecimen = [ ]; $statisticsCulture = [ ]; $statisticsEnviro = [ ]; $statisticsAll = [ ]; $statistics = [ ]; $years = [ ]; foreach ( $speYs as $i ) { $day = DateTime::createFromFormat ( 'Y-m-d', $i ['date'] ); $year = $day->format ( 'Y' ); $years [] = $year; $type = $i ['sampleType']; $nb = $i ['numberSamples']; if ($type === 'DNA') $statistics = $statisticsDNA; if ($type === 'tissue') $statistics = $statisticsTissue; if ($type === 'specimen') $statistics = $statisticsSpecimen; if ($type === 'culture') $statistics = $statisticsCulture; if ($type === 'environmental sample') $statistics = $statisticsEnviro; if (! array_key_exists ( $year, $statistics )) $atmp = 0; else $atmp = $statistics [$year]; if (empty ( $registry )) // sums up $atmp += $nb; else // keep the uper value { if ($nb > $atmp) $atmp += $nb; } $statistics [$year] = $atmp; if ($type === 'DNA') $statisticsDNA = $statistics; if ($type === 'tissue') $statisticsTissue = $statistics; if ($type === 'specimen') $statisticsSpecimen = $statistics; if ($type === 'culture') $statisticsCulture = $statistics; if ($type === 'environmental sample') $statisticsEnviro = $statistics; // if (! array_key_exists ( $year, $statisticsAll )) // $atmpy = 0; // else // $atmpy = $statisticsAll [$year]; // $atmpy += $atmp; // $statisticsAll [$year] = $atmpy; } foreach ( $years as $y ) { $t = 0; if (isset ( $statisticsDNA [$y] )) $t += $statisticsDNA [$y]; if (isset ( $statisticsCulture [$y] )) $t += $statisticsCulture [$y]; if (isset ( $statisticsTissue [$y] )) $t += $statisticsTissue [$y]; if (isset ( $statisticsEnviro [$y] )) $t += $statisticsEnviro [$y]; if (isset ( $statisticsSpecimen [$y] )) $t += $statisticsSpecimen [$y]; $statisticsAll [$y] = $t; } $statistics_retDNA = [ ]; foreach ( $statisticsDNA as $k => $v ) { $statistics_retDNA [] = "['" . $k . "', " . $v . "]"; } $statistics_retCulture = [ ]; foreach ( $statisticsCulture as $k => $v ) { $statistics_retCulture [] = "['" . $k . "', " . $v . "]"; } $statistics_retTissue = [ ]; foreach ( $statisticsTissue as $k => $v ) { $statistics_retTissue [] = "['" . $k . "', " . $v . "]"; } $statistics_retEnviro = [ ]; foreach ( $statisticsEnviro as $k => $v ) { $statistics_retEnviro [] = "['" . $k . "', " . $v . "]"; } $statistics_retSpecimen = [ ]; foreach ( $statisticsSpecimen as $k => $v ) { $statistics_retSpecimen [] = "['" . $k . "', " . $v . "]"; } $statistics_retAll = [ ]; foreach ( $statisticsAll as $k => $v ) { $statistics_retAll [] = "['" . $k . "', " . $v . "]"; } $toRet = [ ]; $toRet ["all"] = "[" . implode ( ", ", $statistics_retAll ) . "]"; $toRet ["DNA"] = "[" . implode ( ", ", $statistics_retDNA ) . "]"; $toRet ["culture"] = "[" . implode ( ", ", $statistics_retCulture ) . "]"; $toRet ["tissue"] = "[" . implode ( ", ", $statistics_retTissue ) . "]"; $toRet ["enviro"] = "[" . implode ( ", ", $statistics_retEnviro ) . "]"; $toRet ["specimen"] = "[" . implode ( ", ", $statistics_retSpecimen ) . "]"; return $toRet; } public function getSpeciesYearMin($registry) { // requete directe DB $speYs = DBInterface::getSpeciesYear ( $registry ); $yearMin = 2024; foreach ( $speYs as $i ) { $day = DateTime::createFromFormat ( 'Y-m-d', $i ['date'] ); $year = $day->format ( 'Y' ); if ($year < $yearMin) $yearMin = $year; } return $yearMin; } public function getOrders() { $stats = DBInterface::getStats (); $statistics_dna = [ ]; $statistics_tissue = [ ]; $statistics_request = [ ]; $statistics_all = [ ]; foreach ( $stats as $i ) { $day = DateTime::createFromFormat ( 'Y-m-d', $i ['order_date'] ); $month = $day->format ( 'Y-m' ); // $month=$i ['order_date']; $typecnt = $i ['samples_dna']; if (! array_key_exists ( $month, $statistics_all )) $atmp = 0; else $atmp = $statistics_all [$month]; if ($typecnt > 0) { if (! array_key_exists ( $month, $statistics_dna )) $tmp = 0; else $tmp = $statistics_dna [$month]; if (empty ( $tmp )) $tmp = 0; $statistics_dna [$month] = ($tmp + $typecnt); $statistics_all [$month] = ($atmp + $typecnt); } $typecnt = $i ['samples_tissue']; if ($typecnt > 0) { if (! array_key_exists ( $month, $statistics_tissue )) $tmp = 0; else $tmp = $statistics_tissue [$month]; if (empty ( $tmp )) $tmp = 0; $statistics_tissue [$month] = ($tmp + $typecnt); $statistics_all [$month] = ($atmp + $typecnt); } $typecnt = $i ['samples_request_dna']; if ($typecnt > 0) { if (! array_key_exists ( $month, $statistics_request )) $tmp = 0; else $tmp = $statistics_request [$month]; if (empty ( $tmp )) $tmp = 0; $statistics_request [$month] = ($tmp + $typecnt); $statistics_all [$month] = ($atmp + $typecnt); } } $statistics_tissue_ret = [ ]; foreach ( $statistics_tissue as $k => $v ) { $statistics_tissue_ret [] = "['" . $k . "', " . $v . "]"; } $statistics_request_ret = [ ]; foreach ( $statistics_request as $k => $v ) { $statistics_request_ret [] = "['" . $k . "', " . $v . "]"; } $statistics_all_ret = [ ]; foreach ( $statistics_all as $k => $v ) { $statistics_all_ret [] = "['" . $k . "', " . $v . "]"; } $statistics_dna_ret = [ ]; foreach ( $statistics_dna as $k => $v ) { $statistics_dna_ret [] = "['" . $k . "', " . $v . "]"; } return [ 'statistics_tissue' => "[" . implode ( ", ", $statistics_tissue_ret ) . "]", 'statistics_request' => "[" . implode ( ", ", $statistics_request_ret ) . "]", 'statistics_all' => "[" . implode ( ", ", $statistics_all_ret ) . "]", 'statistics_dna' => "[" . implode ( ", ", $statistics_dna_ret ) . "]" ]; } public function actionDetails() { $att = Yii::$app->request->get (); $filter = [ ]; $filterURL = [ ]; $genus = ""; $family = ""; $classes = ""; $ordo = ""; $species = ""; $continents = ""; $countries = ""; $oceans = ""; $seas = ""; $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 ); if (! empty ( $value )) { $filter [] = $k . ":" . $value; if ($k == "institution") { $filterURL ["registry"] = $v; $parentInstitutions = DBInterface::getParentInstitution ( $v ); } else { $filterURL [$k] = $v; if ($k == "registry") $parentInstitutions = DBInterface::getParentInstitution ( $v ); if ($k != "registry") $basisofrecordstxt = ""; } } } if (empty ( $filter ) || ! isset ( $parentInstitutions )) { Yii::$app->session->setFlash ( 'error', 'This URL will not work - Did you manually edit the URL? The parameter "institution" is mandatory here. ' ); return $this->render ( 'details', array_merge ( [ 'kindofunitssamples' => "", 'kindofunitsvouchers' => "", 'classes' => "", 'orders' => "", 'families' => "", 'genera' => "", 'species' => "", 'basisofrecordstxt' => "", 'names' => "", 'partners' => [ ], 'counts' => "", 'contacts' => "", 'continents' => "", 'countries' => "", 'oceans' => "", 'seas' => "", 'registry' => "" ], $filterURL ) ); } else { $f = implode ( " AND ", $filter ); if (! array_key_exists ( 'continent', $filterURL )) try { $continents = $this->getContinent ( $f ); } catch ( \Solarium\Exception\HttpException $e ) { Yii::$app->mailer->compose ()->setFrom ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'Error occured' )->setTextBody ( $e )->send (); return $this->render ( '/site/error', [ "name" => "Oooops", "message" => "The SOLR instance seems to be gone.", "error" => $e ] ); } else $continents = [ ]; if (array_key_exists ( 'continent', $filterURL )) { $countries = $this->getCountries ( $f ); } else $countries = [ ]; if (! array_key_exists ( 'ocean', $filterURL )) try { $oceans = $this->getOcean ( $f ); } catch ( \Solarium\Exception\HttpException $e ) { Yii::$app->mailer->compose ()->setFrom ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'Error occured' )->setTextBody ( $e )->send (); return $this->render ( '/site/error', [ "name" => "Oooops", "message" => "The SOLR instance seems to be gone.", "error" => $e ] ); } else $oceans = [ ]; if (array_key_exists ( 'ocean', $filterURL )) $seas = $this->getSeas ( $f ); else $seas = [ ]; $institution = [ ]; $names = [ ]; $counts = [ ]; $contacts = [ ]; $speciesYear = [ ]; $yearMin = 2009; $fullName = ""; foreach ( $parentInstitutions as $i ) { $institution [$i ['institutionFullName']] = [ $i ['Latitude'], $i ['Longitude'] ]; $latitudes [] = $i ['Latitude']; $longitudes [] = $i ['Longitude']; $names [] = $i ['institutionFullName']; $tmp = DBInterface::getNbUnits ( $i ['parentInstitutionID'] ); if (sizeof ( $tmp ) > 0) { foreach ( $tmp as $t ) $counts [$i ['institutionFullName']] = $t ['nb']; } else $counts [$i ['institutionFullName']] = 0; $contact = [ ]; $tmp = DBInterface::getContacts ( $i ['parentInstitutionID'] ); if (sizeof ( $tmp ) > 0) { foreach ( $tmp as $t ) $contact [] = [ $t ['name'], $t ['email'] ]; } else $contact [] = [ ]; $contacts [$i ['institutionFullName']] = $contact; $speciesYear = $this->getSpeciesYear ( $i ['parentInstitutionID'] ); $samplesYear = $this->getSamplesYear ( $i ['parentInstitutionID'] ); $yearMin = $this->getSpeciesYearMin ( $i ['parentInstitutionID'] ); $fullName = $i ['institutionFullName']; } $f = implode ( " AND ", $filter ); $kindofunitdatasamples = $this->getKindofunit ( $f, 'samples' ); $kindofunitdatavouchers = $this->getKindofunit ( $f, 'vouchers' ); $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, "familia" ); if (! empty ( explode ( "familia", $f, - 1 ) )) $genus = $this->getHigher ( $f, "genus" ); if (! empty ( explode ( "genus", $f, - 1 ) )) $species = $this->getHigher ( $f, "fullScientificName" ); return $this->render ( 'details', array_merge ( [ 'kindofunitssamples' => $kindofunitdatasamples, 'kindofunitsvouchers' => $kindofunitdatavouchers, 'classes' => $classes, 'orders' => $ordo, 'families' => $family, 'genera' => $genus, 'species' => $species, 'basisofrecordstxt' => $basisofrecordstxt, 'names' => $names, 'partners' => $parentInstitutions, 'counts' => $counts, 'contacts' => $contacts, 'continents' => $continents, 'countries' => $countries, 'oceans' => $oceans, 'seas' => $seas, 'speciesYear' => $speciesYear, 'yearMin' => $yearMin, 'fullName' => $fullName, 'samplesYearAll' => $samplesYear ["all"], 'samplesYearDNA' => $samplesYear ["DNA"], 'samplesYearCulture' => $samplesYear ["culture"], 'samplesYearSpecimen' => $samplesYear ["specimen"], 'samplesYearTissue' => $samplesYear ["tissue"], 'samplesYearEnviro' => $samplesYear ["enviro"] ], $filterURL ) ); } } public function getKindofunit($filter, $type) { // Yii::info ( "getKindofunit " . $filter ); $config = SOLRQueryManager::getConfigSearch (); // 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 ($type === "vouchers") $q = "sampletype:(culture OR specimen OR unknown OR eVoucher)"; if ($type === "samples") $q = "-sampletype:(culture OR specimen OR unknown OR eVoucher)"; 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 getRepositories($filter, $type) { // Yii::info ( "getKindofunit " . $filter ); $config = SOLRQueryManager::getConfigSearch (); // 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 ($type === "vouchers") $q = "sampletype:(culture OR specimen OR unknown OR eVoucher)"; if ($type === "samples") $q = "-sampletype:(culture OR specimen OR unknown OR eVoucher)"; 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 ( "institution" )->setField ( "institution" ); // this executes the query and returns the result $raw_response = $client->select ( $query ); $result = $raw_response->getFacetSet ()->getFacet ( "institution" ); $data = [ ]; foreach ( $result as $doc => $count ) { $data [] = '["' . $doc . ' (' . $count . ')",' . $count . ']'; // Yii::info("SUBLIST: ".$doc); } return "[" . implode ( ",", $data ) . "]"; } public function getContinent($filter) { Yii::info ( "getContinent " . $filter ); $config = SOLRQueryManager::getConfigSearch (); // 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 = "continent:*"; 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 ( "continent" )->setField ( "continent" ); // this executes the query and returns the result $raw_response = $client->select ( $query ); $result = $raw_response->getFacetSet ()->getFacet ( "continent" ); $data = [ ]; foreach ( $result as $doc => $count ) { $data [] = '["' . str_replace("\n","",$doc) . ' (' . $count . ')",' . $count . ']'; // Yii::info("SUBLIST: ".$doc); } return "[" . implode ( ",", $data ) . "]"; } /** * @param $filter * @return string */ public function getOcean($filter) { // Yii::info ( "getKindofunit " . $filter ); $config = SOLRQueryManager::getConfigSearch (); // 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 = "ocean:*"; 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 ( "ocean" )->setField ( "ocean" ); // this executes the query and returns the result $raw_response = $client->select ( $query ); $result = $raw_response->getFacetSet ()->getFacet ( "ocean" ); $data = [ ]; foreach ( $result as $doc => $count ) { $data [] = '["' . str_replace("\n","",$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::getConfigSearch (); // 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 [] = '["' . str_replace("\n","",$doc) . ' (' . $count . ')",' . $count . ']'; // Yii::info("SUBLIST: ".$doc); } return "[" . implode ( ",", $data ) . "]"; } public function getCountries($filter) { $config = SOLRQueryManager::getConfigSearch (); // 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 = "country:*"; $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 ( "country" )->setField ( "country" ); // this executes the query and returns the result $raw_response = $client->select ( $query ); $result = $raw_response->getFacetSet ()->getFacet ( "country" ); $data = [ ]; foreach ( $result as $doc => $count ) { $data [] = '["' . str_replace("\n","",$doc) . ' (' . $count . ')",' . $count . ']'; // Yii::info("SUBLIST: ".$doc); } return "[" . implode ( ",", $data ) . "]"; } public function getSeas($filter) { $config = SOLRQueryManager::getConfigSearch (); // 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 = "sea:*"; $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 ( "sea" )->setField ( "sea" ); // this executes the query and returns the result $raw_response = $client->select ( $query ); $result = $raw_response->getFacetSet ()->getFacet ( "sea" ); $data = [ ]; foreach ( $result as $doc => $count ) { $data [] = '["' . str_replace("\n","",$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\')' .Yii::$app->params['thematicB-HITfilter']. '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 ["cnt"] . ", \"" . $row ["reg"] . ' (' . number_format($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]; } }