dropDownAttributes )) { $this->dropDownAttributes = array (); foreach ( $model->getParameters () as $name => $list ) { if (isset ( $list ['type'] ) && $list ['type'] == 'select') { array_push ( $this->dropDownAttributes, $name ); } } } if (! isset ( $this->_selectionlists )) { $this->_selectionlists = FormSelectionQueryManager::getAllLists ( $this->dropDownAttributes, $model->getSelectionListNonChosen () ); } return $this->_selectionlists; } */ // ------------------- controller actions ---------------- /** * this does all the thing for searching the index: */ public function actionIndex() { // Yii::info ( "actionIndexSearch" ); if(Yii::$app->user->isGuest) { $model = new SearchFormGuest (); } else { $model = new SearchForm (); } $model->attributes = Yii::$app->request->post (); //erase previously stored units for the multiple units selection Yii::$app->session->remove ( 'multiunits'); $modelwebsite = new WebsitesearchForm (); // we get all the lists for the drop-down lists in the form -- why?? try { $model->collectDropDownAttributesLists ( $model ); } 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.", "exception" => $e ] ); } // Rukeia 23-02-2013: we store all form parameter values in $filters $filters = array (); if(Yii::$app->user->isGuest) { if (isset ( $_REQUEST ['SearchFormGuest'] )) { $searchform = $_REQUEST ['SearchFormGuest']; } else $searchform = [ ]; } else { if (isset ( $_REQUEST ['SearchForm'] )) { $searchform = $_REQUEST ['SearchForm']; } else $searchform = [ ]; } foreach ( $model->knownLParams as $kp ) { if (isset ( $searchform [$kp] ) && strlen ( $searchform [$kp] ) > 0) { if (strcasecmp ( $searchform [$kp], "---" ) > 0) $filters [$kp] = $searchform [$kp]; } if (isset ( $_REQUEST [$kp] ) && strlen ( $_REQUEST [$kp] ) > 0) { if (strcasecmp ( $_REQUEST [$kp], "---" ) > 0) $filters [$kp] = $_REQUEST [$kp]; } } if (isset ( $searchform ['countrycode'] ) && strlen ( $searchform ['countrycode'] ) > 0) { $filters ['isocountrycode'] = $searchform ['countrycode']; } if (isset ( $_REQUEST ['countrycode'] ) && strlen ( $_REQUEST ['countrycode'] ) > 0) { $filters ['isocountrycode'] = $_REQUEST ['countrycode']; } foreach ( $model->knownParams as $kp ) { if (isset ( $searchform [$kp] ) && strlen ( $searchform [$kp] ) > 0) { $filters [$kp] = $searchform [$kp]; } if (isset ( $_REQUEST [$kp] ) && strlen ( $_REQUEST [$kp] ) > 0) { $filters [$kp] = $_REQUEST [$kp]; } } $submitWebsearch = Yii::$app->getUrlManager ()->createUrl ( [ 'websitesearch/search' ] ); // Yii::info ( "Filters: " . implode ( $filters, "\n" ) ); if ($filters) { if ($model->validate ()) { $this->redirect ( Url::to ( array_merge ( [ 'search/result' ], $filters ) ) ); } else { $errors = $model->errors; $shopM = new CartForm (); $multiUnitsM = new MultiunitsForm (); $multiUnitsCart = Yii::$app->session['listView']; if (Yii::$app->params ['useLogin'] && ! Yii::$app->user->isGuest) { $shoppingCart = sizeof ( DBInterface::getShoppingCart ( Yii::$app->user->identity->id ) ); } else { $shoppingCart = ''; } return $this->render ( 'show/listView', [ 'model' => $model, 'selectionLists' => $model->_selectionlists, "filters" => $filters, "errors" => $errors, 'submitWebsearch' => $submitWebsearch, 'shoppingCart' => $shoppingCart, 'shopM' => $shopM, 'multiUnitsCart'=>$multiUnitsCart, 'multiUnitsM'=>$multiUnitsM, 'primaryObject' => $this ] ); } } try { return $this->render ( 'search', array ( 'model' => $model, 'selectionLists' => $model->_selectionlists, 'modelwebsite' => $modelwebsite, 'submitWebsearch' => $submitWebsearch, 'primaryObject' => $this ) ); } catch ( \yii\base\ErrorException $e ) { // if(strpos($e, "SOLR")!=0) 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" => "Something went wrong.", "exception" => $e ] ); } } public function actionOverview() { $q = $_GET["q"]; return $this->render ( 'show/overview', [ 'q' => $q ] ); } public function actionResult() { // Yii::info ( "actionResult" ); $filters = [ ]; if(Yii::$app->user->isGuest) { $model = new SearchFormGuest (); } else { $model = new SearchForm (); } $model->attributes = Yii::$app->request->post (); // foreach ( $model->attributes as $att ) // Yii::info ( "ATTR" + $att ); //erase previously stored units for the multiple units selection Yii::$app->session->remove( 'multiunits'); if(Yii::$app->user->isGuest) { if (isset ( $_REQUEST ['SearchFormGuest'] )) { $searchform = $_REQUEST ['SearchFormGuest']; } else $searchform = [ ]; } else { if (isset ( $_REQUEST ['SearchForm'] )) { $searchform = $_REQUEST ['SearchForm']; } else $searchform = [ ]; } foreach ( $model->knownLParams as $kp ) { if (isset ( $searchform [$kp] ) && strlen ( $searchform [$kp] ) > 0) { if (strcasecmp ( $searchform [$kp], "---" ) > 0) $filters [$kp] = $searchform [$kp]; } if (isset ( $_REQUEST [$kp] ) && strlen ( $_REQUEST [$kp] ) > 0) { if (strcasecmp ( $_REQUEST [$kp], "---" ) > 0) $filters [$kp] = $_REQUEST [$kp]; } } if (isset ( $searchform ['countrycode'] ) && strlen ( $searchform ['countrycode'] ) > 0) { $filters ['isocountrycode'] = $searchform ['countrycode']; } if (isset ( $_REQUEST ['countrycode'] ) && strlen ( $_REQUEST ['countrycode'] ) > 0) { $filters ['isocountrycode'] = $_REQUEST ['countrycode']; } foreach ( $model->knownParams as $kp ) { if (isset ( $searchform [$kp] ) && strlen ( $searchform [$kp] ) > 0) { $filters [$kp] = $searchform [$kp]; } if (isset ( $_REQUEST [$kp] ) && strlen ( $_REQUEST [$kp] ) > 0) { $filters [$kp] = $_REQUEST[$kp]; } } // HERE THE TRICK FOR THE NICE URL if(Yii::$app->user->isGuest) { if(Yii::$app->params['siteName'] == 'evoboga') { $filters['accessionStatus'] = 'onlyLiving'; } if ($filters && isset ( $_REQUEST ['SearchFormGuest'] )) { $this->redirect ( Url::to ( array_merge ( [ 'search/result' ], $filters ) ) ); } else return $this->render ( 'show/listViewGuest', SOLRQueryManager::performSearch ( $filters, $model, $this )); } else { if ($filters && isset ( $_REQUEST ['SearchForm'] )) { $this->redirect ( Url::to ( array_merge ( [ 'search/result' ], $filters ) ) ); } else return $this->render ( 'show/listView', SOLRQueryManager::performSearch ( $filters, $model, $this ), [ "model" => $model, "filters" => $filters ] ); } } public function actionDownload() { if(Yii::$app->user->isGuest) { return $this->render ( '/site/error', [ "name" => "", "message" => "Please login to download data." ] ); } else { $model = new SearchForm (); $model->attributes = Yii::$app->request->get (); $filters = [ ]; if (isset ( $_REQUEST ['SearchForm'] )) { $searchform = $_REQUEST ['SearchForm']; } else $searchform = [ ]; foreach ( $model->knownLParams as $kp ) { if (isset ( $searchform [$kp] ) && strlen ( $searchform [$kp] ) > 0) { if (strcasecmp ( $searchform [$kp], "---" ) > 0) $filters [$kp] = $searchform [$kp]; } if (isset ( $_REQUEST [$kp] ) && strlen ( $_REQUEST [$kp] ) > 0) { if (strcasecmp ( $_REQUEST [$kp], "---" ) > 0) $filters [$kp] = $_REQUEST [$kp]; } } if (isset ( $searchform ['countrycode'] ) && strlen ( $searchform ['countrycode'] ) > 0) { $filters ['isocountrycode'] = $searchform ['countrycode']; } if (isset ( $_REQUEST ['countrycode'] ) && strlen ( $_REQUEST ['countrycode'] ) > 0) { $filters ['isocountrycode'] = $_REQUEST ['countrycode']; } foreach ( $model->knownParams as $kp ) { if (isset ( $searchform [$kp] ) && strlen ( $searchform [$kp] ) > 0) { $filters [$kp] = $searchform [$kp]; } if (isset ( $_REQUEST [$kp] ) && strlen ( $_REQUEST [$kp] ) > 0) { $filters [$kp] = $_REQUEST [$kp]; } } $documents = array_merge ( SOLRQueryManager::performSearch ( $filters, $model, $this ), [ "model" => $model, "filters" => $filters ] ); DownloadCsv::generateDownloadCSV($documents, $date = date('Y-m-d_').'gardens4science.csv', false); } } /* public function actionMydownload() { $model = new DownloadForm(); $count = $_GET['count']; return $this->renderAjax('show/_download', [ 'model' => $model, 'item_count_total' => $count, 'querydownload' => urldecode($_GET['query']) ]); } public function actionStartdownload() { $model = new DownloadForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { // Push a job into queue and get message ID. $id = Yii::$app->queue->push(new DownloadJob([ 'file' => Yii::$app->basePath.'\web\jobtest\\'.$model->filename.'.txt', 'querydownload' => $model->querydownload, 'email' => $model->email ])); return $this->render('show/_download_entry_confirm', ['model' => $model]); } else { // either the page is initially displayed or there is some validation error return 'hallo'; } } */ function performSearch($filters, $model) { // Yii::info ( "actionperformSearch" ); // we get all the lists for the drop-down lists in the form -- why?? $this->collectDropDownAttributesLists ( $model ); $submitURL = $this->createUrl ( [ 'search/create' ], $filters ); // validate user input if ($model->validate ()) { $config = SOLRQueryManager::getConfigSearch (); $query = SOLRQueryManager::createSearchQuery ( $config ); $fq = ""; $q = [ ]; $filterInstitution = false; $filterVouchercol = false; foreach ( $filters as $key => $value ) { $value = str_replace ( " ", "\ ", $value ); $value = str_replace ( "(", "\(", $value ); $value = str_replace ( ")", "\)", $value ); $value = str_replace ( ":", "\:", $value ); if ($key == "institution") { $q [] = SOLRQueryManager::getPartialQuery ( $key, $value, $filters, False ); $filterInstitution = true; } if ($key == "voucherCol") { $q [] = SOLRQueryManager::getPartialQuery ( $key, $value, $filters, False ); $filterVouchercol = true; } } //if (! $filterInstitution && ! $filterVouchercol) $q = [ "*:*".Yii::$app->params['thematicSOLRfilter'] ]; $raw_response = SOLRQueryManager::fillAndExecuteQuery ( $query, implode ( " AND ", $q ), $fq, $filters, False ); $backboneaccepted = ""; $backbonefullname = ""; // foreach($raw_response as $backbonedisplay) // { $backboneaccepted = $backbonedisplay->backboneaccepted; // $backbonefullname = $backbonedisplay->backbonefullname; } $q[]="isLowest:1"; $query2 = SOLRQueryManager::createSearchQuery ( $config ); $raw_responseCounts = SOLRQueryManager::fillAndExecuteQuery ( $query2, implode ( " AND ", $q ), $fq, $filters, False ); $tripleidstoreids=[]; foreach($raw_response as $document){ $tripleidstoreids = array_merge($tripleidstoreids, $document->lowestTripleIDs); } $tripleidstoreids=array_unique($tripleidstoreids); $config = SOLRQueryManager::getConfigPreview(); $query = SOLRQueryManager::createSearchQuery ( $config ); //$q = "tripleidstoreid:(".implode(" OR ", $tripleidstoreids).")"; if(sizeof($tripleidstoreids)>0){ $q = "tripleidstoreid:(".implode(" OR ", $tripleidstoreids).")"; } else $q=""; //echo $q; $raw_response = SOLRQueryManager::fillAndExecuteQuery ( $query, $q , $fq, [], False ); $doc = $raw_response->getDocuments (); $numFoundTotal = $raw_responseCounts->getNumFound (); $numFound = $raw_response->getNumFound (); $ids = [ ]; foreach ( $raw_response as $id ) { $ids [] = $id->tripleidstoreid; } // Repeat query because Solr won't permit queries with more OR clauses, didn't find a better solution :( // Executed in batches of 200 $SOLR_QUERY_CONSTANT = 200; $shoppingArray = [ ]; if(! Yii::$app->user->isGuest && Yii::$app->params ['shopping']){ for($i = 0; $i < ceil ( count ( $ids ) / $SOLR_QUERY_CONSTANT ); $i ++) { $config = SOLRQueryManager::getConfigDetails (); $query1 = SOLRQueryManager::createSearchQuery ( $config ); $loanStatus = SOLRQueryManager::loanQuery ( $query1, "*:*", array_slice ( $ids, $i * $SOLR_QUERY_CONSTANT, $SOLR_QUERY_CONSTANT ) ); foreach ( $loanStatus as $l ) { $shoppingArray [$l->tripleidstoreid] = $l; } } } $shopM = new CartForm (); if (Yii::$app->params ['useLogin'] && ! Yii::$app->user->isGuest) { $shoppingCart = sizeof ( DBInterface::getShoppingCart ( Yii::$app->user->identity->id ) ); } else { $shoppingCart = ''; } $multiUnitsM = new MultiunitsForm (); $multiUnitsCart = Yii::$app->session['listView']; if (Yii::$app->params['logUsageStats']) { // Logging Usage Statistics $piwikSiteID = Yii::$app->params['piwikSiteID']; $fullUrl = addslashes(str_replace("www.","" , urldecode(Yii::$app->request->HostName.Yii::$app->request->baseUrl."/".Yii::$app->request->pathInfo."?".Yii::$app->request->queryString))); $queryString = addslashes(urldecode(Yii::$app->request->queryString)); $serverTime = date('Y-m-d h:i:s'); $actionresult = "INSERT INTO log_action_visitor (server_time, url, hash, piwiksiteid, query_terms, hits) VALUES ('$serverTime','$fullUrl', CRC32('$fullUrl'), $piwikSiteID, '$queryString', $numFoundTotal)"; Yii::$app->usageStats->createCommand($actionresult)->execute(); $idaction = Yii::$app->usageStats->getLastInsertID(); foreach ($doc as $actiondetails) { $actionrecords = "INSERT IGNORE INTO log_action_records (unitID, collectionCode, institutionCode, guid, institution) VALUES ('$actiondetails->unitID', '$actiondetails->collectioncode', '$actiondetails->institutioncode', '$actiondetails->guid', '$actiondetails->institution')"; Yii::$app->usageStats->createCommand($actionrecords)->execute(); $recordids = "SELECT idrecord FROM log_action_records WHERE unitID='$actiondetails->unitID' AND collectionCode = '$actiondetails->collectioncode'"; $getRecordIDs = Yii::$app->usageStats->createCommand($recordids)->queryAll(); $idrecord = $getRecordIDs[0]['idrecord']; $actiondetail = "INSERT INTO log_actionrecords_visitor (idaction, idrecord) VALUES ($idaction, $idrecord)"; Yii::$app->usageStats->createCommand($actiondetail)->execute(); } } return $this->render ( 'show/listView', array ( "model" => $model, 'response' => $doc, 'backboneaccepted' => $backboneaccepted, 'backbonefullname' => $backbonefullname, 'keyForLink' => $this->key_link, 'recordFilters' => $this->recordFilters, 'item_count' => $numFound, 'item_count_total' => $numFoundTotal, 'selectionLists' => $this->_selectionlists, 'submitURL' => $this->submitURL, 'filters' => $filters, 'shopping' => $shoppingArray, 'shopM' => $shopM, 'shoppingCart' => $shoppingCart, 'multiUnitsCart'=>$multiUnitsCart, 'multiUnitsM'=>$multiUnitsM ) ); // Rukeia 26-03-2015: hinzugefĆ¼gt, damit listView auch auf selectionLists zugreifen kann // 'submitURL'=>$this->$submitURL, } else { $errors = $model->errors; return $this->render ( 'search/result', [ "model" => $model, "filters" => $filters, "errors" => $errors ] ); } } /* in CommonSearchForm ausgelagert * * public function createUrl($destination, $formParameters) { $nonEmptyFormParameters = array_filter ( $formParameters, 'strlen' ); unset ( $nonEmptyFormParameters ['yt0'] ); return Yii::$app->getUrlManager ()->createUrl ( $destination, $nonEmptyFormParameters ); } */ public function actionDownloadabcd($unitID){ Yii::$app->response->format = \yii\web\Response::FORMAT_RAW; $headers = Yii::$app->response->headers; $headers->add('Content-Type', 'text/xml'); $filename=Yii::$app->params['tmpFolder'].$unitID.".xml"; if(@file_exists($filename)) return $this->renderFile($filename); else echo "The file does not exist anymore, refresh your results page."; } public function actionRecord() { $model = new SearchForm (); $model->attributes = Yii::$app->request->post (); // get the values that came from url back to an array $requestedAttributes = $this->requestedAttributes; if ($model->validate ()) { if(Yii::$app->user->isGuest && Yii::$app->params['siteName'] == 'evoboga') { if(!isset($_GET['name'])) { return $this->render ( '/site/error', [ "name" => "", "message" => "Oops, it seems you don't have access to this page. Please login to see details." ] ); } else { $output = SingleRecordManager::createOutputTaxonBased( $_GET['name'] ); } } else { $output = SingleRecordManager::createOutput ( $requestedAttributes, $model ); } if (isset ( $output ) && sizeof ( $output ) > 0) { $output ['display'] = 'tab'; $output['model']=$model; if ((strpos ( Yii::$app->request->referrer, "record" ) === 0)) Yii::$app->session->set ('comeFrom', Yii::$app->request->referrer ); $output['back']=Yii::$app->session->get('comeFrom',Yii::$app->request->referrer); if(Yii::$app->user->isGuest) { return $this->render ( 'show/recordViewTabsGuest', $output ); } else { if (Yii::$app->params ['useLogin'] && ! Yii::$app->user->isGuest) { $output['shoppingCart'] = sizeof ( DBInterface::getShoppingCart ( Yii::$app->user->identity->id ) ); } else { $output['shoppingCart'] = ''; } return $this->render ( 'show/recordViewTabs', $output ); } } else return $this->render ( '/site/error', [ "name" => "", "message" => "Oops, the record seems to have submerged! Please check the numbers." ] ); } else { $errors = $model->errors; return $this->render ( 'search/result', [ "filters" => $filters, "errors" => $errors, "model" => $model ] ); } } public function actionTaxon() { $model = new SearchFormGuest(); $model->attributes = Yii::$app->request->post (); // get the values that came from url back to an array $requestedAttributes = $this->requestedAttributes; if ($model->validate ()) { /* $output = TaxonManager::createOutput ( $requestedAttributes, $model ); if (isset ( $output ) && sizeof ( $output ) > 0) { $output ['display'] = 'tab'; $output['model']=$model; if ((strpos ( Yii::$app->request->referrer, "record" ) === 0)) Yii::$app->session->set ('comeFrom', Yii::$app->request->referrer ); $output['back']=Yii::$app->session->get('comeFrom',Yii::$app->request->referrer); return $this->render ( 'show/taxonView', $output ); } else return $this->render ( '/site/error', [ "name" => "", "message" => "Oops, the record seems to have submerged! Please check the numbers." ] ); */ } else { $errors = $model->errors; return $this->render ( 'search/taxon', [ "filters" => $filters, "errors" => $errors, "model" => $model ] ); } } public function getTripleID($tid) { $config = SOLRQueryManager::getConfigSearch (); $query = SOLRQueryManager::createSearchQuery ( $config ); $raw_response = SOLRQueryManager::fillAndExecuteQuery ( $query, "tripleidstoreid:" . $tid, null, null, False ); $doc = $raw_response->getDocuments (); foreach ( $doc as $d ) return [ $d->unitID, $d->collectioncode, $d->institutioncode ]; } public function actionBrowse() { // Yii::info ( "actionIndexbrowse" ); $elts = Yii::$app->request->get(); if (isset ( $elts ["page"] )) $page = $elts ["page"]; else $page = 0; $fqs = [ ]; $q = [ ]; $rawfqs = [ ]; $escapedfqs=[]; $filters = [ "recordbasis", "fullScientificName", "familyName", "unitID", "institutioncode", "collectioncode", "country", "institution", "voucherCol", "sampletype" ]; foreach ( $filters as $filter ) { if (isset ( $elts [$filter] )) { $rawfq = $elts [$filter]; $rawfqs [] = $filter . "=" . $rawfq; $fq = str_replace ( " ", "\ ", $rawfq ); $fq = str_replace ( "(", "\(", $fq ); $fq = str_replace ( ")", "\)", $fq ); $fq = str_replace ( ":", "\:", $fq ); $fq = str_replace ( "'", "\'", $fq ); $fq = str_replace ( "[", "\[", $fq ); $fq = str_replace ( "]", "\]", $fq ); $fq = str_replace ( "+", "\+", $fq ); //$fqs [] = $filter . ":" . $fq; $tmp = SOLRQueryManager::getPartialQuery ( $filter, $fq, $filters, False ); echo $tmp; $q [] = $tmp; } } if (empty ( $q )) $q [] = "*:*".Yii::$app->params['thematicSOLRfilter']; $filters = [ ]; // $config = SOLRQueryManager::getConfigDetails (); $config = SOLRQueryManager::getConfigSearch (); $query = SOLRQueryManager::createSearchQuery ( $config ); $sortScientificName = "fullScientificName_asc"; $sortUnitID = "unitID_asc"; $sortRecordbasis = "recordbasis_asc"; $sortInstitutioncode = "institutioncode_asc"; $sortCollectioncode = "collectioncode_asc"; if (isset ( $elts ["sort"] )) { $field = explode ( "_", $elts ["sort"] )[0]; $direction = explode ( "_", $elts ["sort"] )[1]; $query->addSort ( $field, $direction ); switch ($field) { case "fullScientificName" : if ($direction === "asc") $sortScientificName = "fullScientificName_desc"; else $sortScientificName = "fullScientificName_asc"; break; case "recordbasis" : if ($direction === "asc") $sortRecordbasis = "recordbasis_desc"; else $sortRecordbasis = "recordbasis_asc"; break; case "UnitID" : if ($direction === "asc") $sortUnitID = "UnitID_desc"; else $sortUnitID = "UnitID_asc"; break; case "institutioncode" : if ($direction === "asc") $sortInstitutioncode = "institutioncode_desc"; else $sortInstitutioncode = "institutioncode_asc"; break; case "collectioncode" : if ($direction === "asc") $sortCollectioncode = "collectioncode_desc"; else $sortCollectioncode = "collectioncode_asc"; break; default : $sortScientificName = "fullScientificName_asc"; $sortUnitID = "unitID_asc"; $sortRecordbasis = "recordbasis_asc"; $sortInstitutioncode = "institutioncode_asc"; $sortCollectioncode = "collectioncode_asc"; } } $facetnames = [ 'country', 'institution', 'recordbasis', 'sampletype' ]; try { $raw_response = SOLRQueryManager::browseQuery ( $query, implode ( " AND ", $q ).Yii::$app->params['thematicSOLRfilter'], $fqs, $page, $facetnames ); //$raw_response = SOLRQueryManager::browseQuery ( $query, '*:*'.Yii::$app->params['thematicSOLRfilter'], $fqs, $page, $facetnames ); } catch ( \Solarium\Exception\HttpException $e ) { //disabled because of external calls to try solr injections dr 2019-03-29 /*Yii::$app->mailer->compose ()->setFrom (Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'Error occured' )->setTextBody ( $e . "\n q:" . implode ( " AND ", $q ) . "\nfqs:" . implode ( " ", $fqs ) . "\n facets" . implode ( " ", $facetnames ) . "\n URL built: " . Yii::$app->request->url . "\n and the user is " . Yii::$app->request->userIP )->send ();*/ return $this->render ( '/site/error', [ "name" => "Oooops", "message" => "The SOLR instance seems to be gone.", "error" => $e ] ); } $rawfacets = $raw_response->getFacetSet (); $facets = [ ]; foreach ( $facetnames as $fname ) { $tmp = [ ""; $facets [$fname] = implode ( "", $tmp ); } try { $doc = $raw_response->getDocuments (); } catch (Solarium\Exception\UnexpectedValueException $e) { $doc = $raw_response->getDocuments (); } $lowestDoc = [ ]; foreach ( $doc as $unitdoc ) { $lowestUnits = $unitdoc->lowestTripleIDs; $currentID = $unitdoc->tripleidstoreid; if(empty($lowestUnits)) $lowestUnits[]=$currentID; if (in_array ( $currentID, $lowestUnits )) { $lowestDoc [$currentID] = [ $unitdoc->unitID, $unitdoc->collectioncode, $unitdoc->institutioncode ]; } else { $lowestDoc [$currentID] = $this->getTripleID ( $lowestUnits [0] ); } } $numFound = $raw_response->getNumFound (); $nbPages = $numFound / Yii::$app->params ['listPerPage']; $pages = new Pagination ( [ 'totalCount' => $numFound, 'pageSize' => Yii::$app->params ['listPerPage'] ] ); $from = Yii::$app->params ['listPerPage'] * $page; $to = $from + Yii::$app->params ['listPerPage']; if (sizeof ( $rawfqs ) > 0) return $this->render ( 'browse', [ "lowestDoc" => $lowestDoc, "doc" => $doc, "fq" => implode ( "&", $rawfqs ), "ufq"=>implode ( "&", $escapedfqs ), "pages" => $pages, "page" => $page, "sortScientificName" => $sortScientificName, "sortRecordbasis" => $sortRecordbasis, "sortInstitutioncode" => $sortInstitutioncode, "sortUnitID" => $sortUnitID, "sortCollectioncode" => $sortCollectioncode, "facets" => $facets, "recordsFrom" => $from, "recordsTo" => $to, "recordsTotal" => $numFound ] ); else return $this->render ( 'browse', [ "lowestDoc" => $lowestDoc, "doc" => $doc, "pages" => $pages, "page" => $page, "sortScientificName" => $sortScientificName, "sortRecordbasis" => $sortRecordbasis, "sortInstitutioncode" => $sortInstitutioncode, "sortUnitID" => $sortUnitID, "sortCollectioncode" => $sortCollectioncode, "facets" => $facets, "recordsFrom" => $from, "recordsTo" => $to, "recordsTotal" => $numFound ] ); } public function getSelectionlists(){ return $this->_selectionlists; } public function actionTree() { $elts = Yii::$app->request->get (); if (isset ( $elts ["institution"] )) $institution = $elts ["institution"]; else $institution = null; $model = new SearchForm (); $elements = $model->getParameters (); $model->collectDropDownAttributesLists ( $model ); $facetnames = [ 'institution' ]; $facets = [ ]; foreach ( $elements as $key => $param ) { if (in_array ( $key, $facetnames )) { $attributeList = isset ( $model->_selectionlists ) ? $model->_selectionlists [$key] : array (); $selectField = [ ]; foreach ( $attributeList as $kk => $vv ) { if (preg_match ( "/ \(\d* \/ \d*\)/", $vv )) $selectField [preg_replace ( "/ \(\d* \/ \d*\)/", "", $vv )] = $vv; else $selectField [preg_replace ( "/ \(\d*\)/", "", $vv )] = $vv; } if (! empty ( $institution )) $facets [] = Html::dropDownList ( $key, $institution, $selectField, $htmlOptions = [ 'class' => "dropDownLabel", 'id2' => $key ] ); else $facets [] = Html::dropDownList ( $key, $key, $selectField, $htmlOptions = [ 'class' => "dropDownLabel", 'id2' => $key ] ); } } $connection = new \yii\db\Connection ( Yii::$app->db ); $connection->open (); $command = $connection->createCommand ( "SELECT distinct taxon_id, name, total_species_extant from _taxon_tree where rank='kingdom' order by name asc" ); // $command = $connection->createCommand ( "SELECT distinct taxon_id, name, number_of_children from _taxon_tree where rank='kingdom' order by name asc" ); $dataReader = $command->queryAll (); $tree = [ ]; $config = SOLRQueryManager::getConfigBackbone (); foreach ( $dataReader as $row ) { $sql = "select count(distinct fullscientificname) as nbChildren, count(distinct occurrenceid) as nbOccurrences, kingdom from treeoflife where kingdom='" . $row ["name"] . "'"; if (isset ( $institution )) $sql .= " AND institution='" . $institution . "'"; $sql .= "group by kingdom"; $command2 = $connection->createCommand ( $sql ); $dataReader2 = $command2->queryAll (); // $value = $row['name']; // $value = str_replace (" ", "\ ", $value ); // $q="rank:KINGDOM AND kingdom:".$value; // // $fq="{!join from=colKey to=Keys fromIndex=ggbn_details_local}*:*"; // $fq=null; // $query = SOLRQueryManager::createSearchQuery ( $config ); // $raw_response = SOLRQueryManager::fillAndExecuteQuery ( $query, $q , $fq, null, False); // $docs=$raw_response->getDocuments (); // $nbOccurrences=0; // $nbTaxChildren=0; // foreach ($docs as $doc){ // $nbOccurrences =$doc->occurrenceCount; // $nbTaxChildren =$doc->childrenCount; // if(empty($nbOccurrences)) // $nbOccurrences = 0; // $nbTaxChildren = $doc->childrenCount; // if(empty($nbTaxChildren)) // $nbTaxChildren = 0; // } $ok = false; foreach ( $dataReader2 as $row2 ) { $ok = true; $nbOccurrences = $row2 ['nbOccurrences']; $nbTaxChildren = $row2 ['nbChildren']; $mykingdom = $row2 ['kingdom']; $tree [$row ["taxon_id"]] = [ $mykingdom, $nbTaxChildren, $nbOccurrences ]; // $tree[$row["taxon_id"]]=[$row["name"],$row["number_of_children"]]; } if (! $ok) $tree [$row ["taxon_id"]] = [ $row ["name"], 0, 0 ]; } Yii::$app->db->close (); return $this->render ( 'treeoflife', [ "tree" => $tree, "facets" => $facets ] ); } public function actionTreesearch($canonicalName, $parentName, $parentRank, $institution) { $filters = [ ]; if ($parentRank == "genus") { $filters ['fullScientificName'] = $canonicalName . "*"; } if ($parentRank == "family") { $filters ['genusName'] = $canonicalName; $filters ['familyName'] = $parentName; } if ($parentRank == "order") { $filters ['familyName'] = $canonicalName; $filters ['orderName'] = $parentName; } if ($parentRank == "class") { $filters ['orderName'] = $canonicalName; $filters ['className'] = $parentName; } if ($parentRank == "phylum") { $filters ['className'] = $canonicalName; $filters ['phylumName'] = $parentName; } if ($parentRank == "kingdom") { $filters ['phylumName'] = $canonicalName; $filters ['kingdom'] = $parentName; } if (isset ( $institution )) if(! empty ( str_ireplace ( "---", "", $institution ) )) $filters ['institution'] = $institution; $this->redirect ( Url::to ( array_merge ( [ 'search/result' ], $filters ) ) ); } }