public function getCropBreedingUses($cropID)
 {
     global $db;
     /*
               $query = "select DISTINCT b.ID, b.Pot_Conf, b.Description, ref.Ref, sp2.*
               from Breeding_data b
               inner join concepts c on c.Crop_ID = b.Crop_ID
               inner join species sp on b.Taxon_ID = sp.Taxon_ID
               inner join Breeding_ref ref on b.Ref_ID = ref.ID
               INNER JOIN species sp2 ON sp.Valid_Taxon_ID = sp2.Taxon_ID
               where c.Taxon_ID = " . $cropID . "
               ORDER BY b.Pot_Conf, sp2.Genus, sp2.Species, sp2.Species_Author, sp2.Subsp, sp2.Subsp_Author, sp2.Var, sp2.Var_Author,
               sp2.Form, sp2.Form_Author"; */
     $query = "SELECT DISTINCT b.ID, b.Pot_Conf, b.Description, ref.Ref, sp2 . * \n                    FROM Breeding_data b\n                    INNER JOIN concepts c ON c.Crop_ID = b.Crop_ID\n                    INNER JOIN species sp ON b.Taxon_ID = sp.Taxon_ID\n                    INNER JOIN Breeding_ref ref ON b.Ref_ID = ref.ID\n                    INNER JOIN species sp2 ON sp.Valid_Taxon_ID = sp2.Taxon_ID\n                    WHERE c.Crop_ID IN ( \n                    SELECT Crop_ID\n                    FROM concepts\n                    WHERE Taxon_ID = {$cropID}\n                    AND CWR_Flag = 0 ) \n                    ORDER BY b.Pot_Conf, sp2.Genus, sp2.Species, sp2.Species_Author, sp2.Subsp, sp2.Subsp_Author, sp2.Var, sp2.Var_Author, sp2.Form, sp2.Form_Author";
     $result = $db->getAll($query);
     $cropBreedingUses = array();
     $test_array = array();
     if ($result != null) {
         foreach ($result as $r) {
             $cropBreedingUse = new BreedingUse($r["ID"]);
             $cropBreedingUse->setUseType(trim($r['Pot_Conf']));
             $cropBreedingUse->setDescription(trim($r['Description']));
             $cropBreedingUse->setReference(trim($r['Ref']));
             $taxon = new Taxon(trim($r['Taxon_ID']));
             $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->setScientificName(trim($r["Scientific_Name"]));
             $cropBreedingUse->setTaxon($taxon);
             // insert reference to the array.
             array_push($cropBreedingUses, $cropBreedingUse);
             // Join every except ID value as String
             $value = trim($r['Pot_Conf']) . trim($r['Description']) . trim($r['Ref']) . trim($r['Taxon_ID']) . trim($r["Common_Name"]) . trim($r["Genus"]) . trim($r["Species"]) . trim($r["Species_Author"]) . trim($r["Subsp"]) . $r["Subsp_Author"] . trim($r["Var"]) . trim($r["Var_Author"]) . trim($r["Form"]) . trim($r["Form_Author"]) . trim($r["Scientific_Name"]);
             array_push($test_array, $value);
             // add value to array_test
         }
         $index_array = $this->getIndexDup($test_array);
         for ($i = 0; $i < count($index_array); $i++) {
             // Extract the duplicate elements
             unset($cropBreedingUses[$index_array[$i] - $i]);
         }
         return $cropBreedingUses;
     } else {
         return null;
     }
 }
 /**
  *
  * @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;
 }
 public function getTaxaBreedingUse($breedingUse)
 {
     global $db;
     $query = "SELECT * FROM Breeding_data bd\n                INNER JOIN species s ON bd.Taxon_ID = s.Taxon_ID\n                WHERE bd.Description LIKE '%" . $breedingUse . "%' GROUP BY s.Taxon_ID ORDER BY Scientific_Name";
     $results = $db->getAll($query);
     $taxa = array();
     foreach ($results as $r) {
         $taxon = new Taxon($r["Taxon_ID"]);
         $taxon->setCommonName(trim($r["Common_Name"]));
         $taxon->setGenus(trim($r["Genus"]));
         $taxon->setSpecie(trim($r["Species"]));
         $taxon->setSubspecie(trim($r["Subsp"]));
         $taxon->setVariety(trim($r["Var"]));
         $taxon->setForm(trim($r["Form"]));
         $taxon->setScientificName(trim($r["Scientific_Name"]));
         array_push($taxa, $taxon);
     }
     return $taxa;
 }