/**
  *
  * @param type $db - ADONewConnection.
  * @param type $cropID - Crop ID to search from concepts table.
  * @return \GenePoolConcept - GenePoolConcept Object and its Concepts.
  */
 public function getGenePoolConcept($taxonID)
 {
     global $db;
     $query = "SELECT DISTINCT c.Crop_ID, c.Concept_ID, c.Concept_Type, c.Concept_Level, s2.*\n          FROM concepts c\n          INNER JOIN species s ON c.Taxon_ID = s.Taxon_ID\n          JOIN species s2 ON s.Valid_Taxon_ID = s2.Taxon_ID\n          WHERE c.Concept_ID = (\n            SELECT c.Concept_ID\n            FROM concepts c\n            WHERE c.Concept_Level in ('1A','Crop taxa') and c.Taxon_ID = {$taxonID}\n          )  AND s2.Taxon_ID = s2.Valid_Taxon_ID\n          ORDER BY c.Concept_Level, s2.Scientific_Name";
     $result = $db->getAll($query);
     $genePoolConcept = null;
     $cropID = null;
     // Validate if $result has not data.
     if (!empty($result)) {
         $genePoolConcept = new GenePoolConcept();
         $theConceptID = null;
         $theConceptType = null;
         $array_id = array();
         foreach ($result as $db_concept) {
             $concept = new Concept();
             $concept->setConceptType(trim($db_concept["Concept_Type"]));
             $concept->setConceptLevel(trim($db_concept["Concept_Level"]));
             $concept->setConceptID(trim($db_concept["Concept_ID"]));
             $concept->setCropID(trim($db_concept["Crop_ID"]));
             if ($cropID == null) {
                 $cropID = trim($db_concept["Crop_ID"]);
             }
             if ($theConceptID == null) {
                 $theConceptID = $concept->getConceptID();
             }
             if ($theConceptType == null) {
                 $theConceptType = $concept->getConceptType();
             }
             /*                 * ** TAXON - BASIC INFORMATION *** */
             $taxon = new Taxon(trim($db_concept["Valid_Taxon_ID"]));
             // Taxon_ID will be the identifier of the suggestion list.
             $taxon->setCommonName(trim($db_concept["Common_Name"]));
             $taxon->setFamily(trim($db_concept["Family"]));
             $taxon->setFamilyAuthor(trim($db_concept["Family_Author"]));
             $taxon->setGenus(trim($db_concept["Genus"]));
             $taxon->setSpecie(trim($db_concept["Species"]));
             $taxon->setSpecieAuthor(trim($db_concept["Species_Author"]));
             $taxon->setSubspecie(trim($db_concept["Subsp"]));
             $taxon->setSubspecieAuthor($db_concept["Subsp_Author"]);
             $taxon->setVariety(trim($db_concept["Var"]));
             $taxon->setVarietyAuthor(trim($db_concept["Var_Author"]));
             $taxon->setForm(trim($db_concept["Form"]));
             $taxon->setFormAuthor(trim($db_concept["Form_Author"]));
             $taxon->setMainCrop(trim($db_concept["Main_Crop"]));
             $taxon->setScientificName(trim($db_concept["Scientific_Name"]));
             $concept->setTaxon($taxon);
             if ($concept->getConceptLevel() == "Crop taxa") {
                 $genePoolConcept->addCropTaxa($taxon);
             } else {
                 // if concept level = 1A it should be also in the genepool concept list.
                 if ($concept->getConceptLevel() == "1A") {
                     $genePoolConcept->addCropTaxa($taxon);
                 }
                 $genePoolConcept->addConcept($concept);
             }
         }
         $taxonDAO = DAOFactory::getDAOFactory()->getTaxonDAO();
         $mainTaxon = $taxonDAO->getTaxon($cropID);
         $mainCrop = new Concept($mainTaxon->getId());
         $mainCrop->setConceptID($theConceptID);
         $mainCrop->setConceptType($theConceptType);
         $mainCrop->setCropID($cropID);
         $mainCrop->setTaxon($mainTaxon);
         $genePoolConcept->setMainCrop($mainCrop);
     }
     return $genePoolConcept;
 }
Exemplo n.º 2
0
 public function getTaxaInRegion($term)
 {
     global $db;
     $query = "SELECT s.*\n            FROM distribution d\n            INNER JOIN species s ON d.Taxon_ID = s.Taxon_ID\n            INNER JOIN countries c ON d.Country = c.Code\n            WHERE c.Region like '" . $term . "%'\n            AND s.Main_Crop = 0\n            GROUP BY s.Taxon_ID\n            ORDER BY s.Genus, s.Species, s.Subsp, s.Var ASC";
     $results = $db->getAll($query);
     $taxa = array();
     foreach ($results as $r) {
         $taxon = new Taxon($r["Taxon_ID"]);
         $taxon->setFamily(trim($r["Family"]));
         $taxon->setFamilyAuthor(trim($r["FamilyAuthor"]));
         $taxon->setCommonName(trim($r["Common_Name"]));
         $taxon->setGenus(trim($r["Genus"]));
         $taxon->setSpecie(trim($r["Species"]));
         $taxon->setSpecieAuthor(trim($r["Species_Author"]));
         $taxon->setSubspecie(trim($r["Subsp"]));
         $taxon->setSubspecieAuthor($r["Subsp_Author"]);
         $taxon->setVariety(trim($r["Var"]));
         $taxon->setVarietyAuthor(trim($r["Var_Author"]));
         $taxon->setForm(trim($r["Form"]));
         $taxon->setFormAuthor(trim($r["Form_Author"]));
         $taxon->setMainCrop(trim($r["Main_Crop"]));
         $taxon->setScientificName(trim($r["Scientific_Name"]));
         array_push($taxa, $taxon);
     }
     return $taxa;
 }