public function getCropBreedingUses($cropID)
 {
     global $db;
     $query = "select distinct b.ID, b.Pot_Conf, b.Description, ref.Ref, sp.*\n                    from Breeding_data b\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                    where b.`Crop_ID` = " . $cropID . " ORDER BY sp.Taxon_ID";
     $result = $db->getAll($query);
     $cropBreedingUses = array();
     foreach ($result as $r) {
         $cropBreedingUse = new CropBreedingUse($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"]));
         $cropBreedingUse->setTaxon($taxon);
         // insert reference to the array.
         array_push($cropBreedingUses, $cropBreedingUse);
     }
     return $cropBreedingUses;
 }
 public function getResultsAdvancedSearch($term, $search_type, $countries, $regions, $concept_type, $concept_levels, $priority_genera)
 {
     global $db;
     $priority_taxa = "'Aegilops bicornis'\n        ,'Aegilops bicornis var. anathera'\n        ,'Aegilops bicornis var. bicornis'\n        ,'Aegilops biuncialis'\n        ,'Aegilops columnaris'\n        ,'Aegilops comosa'\n        ,'Aegilops comosa var. comosa'\n        ,'Aegilops comosa var. subventricosa'\n        ,'Aegilops crassa'\n        ,'Aegilops cylindrica'\n        ,'Aegilops geniculata'\n        ,'Aegilops juvenalis'\n        ,'Aegilops kotschyi'\n        ,'Aegilops longissima'\n        ,'Aegilops markgrafii'\n        ,'Aegilops neglecta'\n        ,'Aegilops peregrina'\n        ,'Aegilops peregrina var. brachyathera'\n        ,'Aegilops peregrina var. peregrina'\n        ,'Aegilops searsii'\n        ,'Aegilops sharonensis'\n        ,'Aegilops speltoides'\n        ,'Aegilops speltoides var. ligustica'\n        ,'Aegilops speltoides var. speltoides'\n        ,'Aegilops tauschii'\n        ,'Aegilops triuncialis'\n        ,'Aegilops triuncialis var. persica'\n        ,'Aegilops triuncialis var. triuncialis'\n        ,'Aegilops umbellulata'\n        ,'Aegilops uniaristata'\n        ,'Aegilops vavilovii'\n        ,'Aegilops ventricosa'\n        ,'Amblyopyrum muticum'\n        ,'Amblyopyrum muticum var. loliaceum'\n        ,'Amblyopyrum muticum var. muticum'\n        ,'Avena abyssinica'\n        ,'Avena atherantha'\n        ,'Avena byzantina'\n        ,'Avena fatua'\n        ,'Avena hybrida'\n        ,'Avena insularis'\n        ,'Avena macrostachya'\n        ,'Avena maroccana'\n        ,'Avena murphyi'\n        ,'Avena occidentalis'\n        ,'Avena pilosa'\n        ,'Avena prostrata'\n        ,'Avena sterilis'\n        ,'Avena strigosa'\n        ,'Avena trichophylla'\n        ,'Cajanus acutifolius'\n        ,'Cajanus albicans'\n        ,'Cajanus cajanifolius'\n        ,'Cajanus cinereus'\n        ,'Cajanus confertiflorus'\n        ,'Cajanus crassus'\n        ,'Cajanus lanceolatus'\n        ,'Cajanus latisepalus'\n        ,'Cajanus lineatus'\n        ,'Cajanus mollis'\n        ,'Cajanus platycarpus'\n        ,'Cajanus reticulatus'\n        ,'Cajanus scarabaeoides'\n        ,'Cajanus sericeus'\n        ,'Cajanus trinervius'\n        ,'Cajanus volubis'\n        ,'Cicer bijugum'\n        ,'Cicer echinospermum'\n        ,'Cicer judaicum'\n        ,'Cicer pinnatifidum'\n        ,'Cicer reticulatum'\n        ,'Daucus capillifolius'\n        ,'Daucus carota subsp. azoricus'\n        ,'Daucus carota subsp. cantabricus'\n        ,'Daucus carota subsp. carota'\n        ,'Daucus carota subsp. commutatus'\n        ,'Daucus carota subsp. drepanensis'\n        ,'Daucus carota subsp. fontanesii'\n        ,'Daucus carota subsp. gadecaei'\n        ,'Daucus carota subsp. gummifer'\n        ,'Daucus carota subsp. halophilus'\n        ,'Daucus carota subsp. hispanicus'\n        ,'Daucus carota subsp. major'\n        ,'Daucus carota subsp. majoricus'\n        ,'Daucus carota subsp. maritimus'\n        ,'Daucus carota subsp. maximus'\n        ,'Daucus carota subsp. parviflorus'\n        ,'Daucus carota subsp. rupestris'\n        ,'Daucus syrticus'\n        ,'Eleusine africana'\n        ,'Eleusine floccifolia'\n        ,'Eleusine indica'\n        ,'Eleusine intermedia'\n        ,'Eleusine kigeziensis'\n        ,'Eleusine tristachya'\n        ,'Helianthus annuus'\n        ,'Helianthus anomalus'\n        ,'Helianthus argophyllus'\n        ,'Helianthus arizonensis'\n        ,'Helianthus atrorubens'\n        ,'Helianthus bolanderi'\n        ,'Helianthus debilis'\n        ,'Helianthus debilis subsp. cucumerifolius'\n        ,'Helianthus debilis subsp. debilis'\n        ,'Helianthus debilis subsp. silvestris'\n        ,'Helianthus debilis subsp. tardiflorus'\n        ,'Helianthus debilis subsp. vestitus'\n        ,'Helianthus deserticola'\n        ,'Helianthus divaricatus'\n        ,'Helianthus exilis'\n        ,'Helianthus giganteus'\n        ,'Helianthus grosseserratus'\n        ,'Helianthus hirsutus'\n        ,'Helianthus maximilianii'\n        ,'Helianthus neglectus'\n        ,'Helianthus niveus'\n        ,'Helianthus niveus subsp. canescens'\n        ,'Helianthus niveus subsp. niveus'\n        ,'Helianthus niveus subsp. tephrodes'\n        ,'Helianthus paradoxus'\n        ,'Helianthus pauciflorus'\n        ,'Helianthus petiolaris'\n        ,'Helianthus petiolaris subsp. fallax'\n        ,'Helianthus petiolaris subsp. petiolaris'\n        ,'Helianthus praecox'\n        ,'Helianthus praecox subsp. hirtus'\n        ,'Helianthus praecox subsp. praecox'\n        ,'Helianthus praecox subsp. runyonii'\n        ,'Helianthus resinosus'\n        ,'Helianthus salicifolius'\n        ,'Helianthus silphioides'\n        ,'Helianthus strumosus'\n        ,'Helianthus tuberosus'\n        ,'Hordeum brevisubulatum'\n        ,'Hordeum bulbosum'\n        ,'Hordeum chilense'\n        ,'Hordeum vulgare subsp. spontaneum'\n        ,'Ipomoea batatas var. apiculata'\n        ,'Ipomoea cordatotriloba'\n        ,'Ipomoea cynanchifolia'\n        ,'Ipomoea grandifolia'\n        ,'Ipomoea lacunosa'\n        ,'Ipomoea leucantha'\n        ,'Ipomoea littoralis'\n        ,'Ipomoea ramosissima'\n        ,'Ipomoea tabascana'\n        ,'Ipomoea tenuissima'\n        ,'Ipomoea tiliacea'\n        ,'Ipomoea trifida'\n        ,'Ipomoea triloba'\n        ,'Ipomoea umbraticola'\n        ,'Lathyrus chrysanthus'\n        ,'Lathyrus gorgoni'\n        ,'Lathyrus marmoratus'\n        ,'Lathyrus pseudocicera'\n        ,'Lathyrus sativus'\n        ,'Lens culinaris subsp. odemensis'\n        ,'Lens culinaris subsp. orientalis'\n        ,'Lens culinaris subsp. tomentosus'\n        ,'Lens ervoides'\n        ,'Lens nigricans'\n        ,'Malus baccata'\n        ,'Malus baccata var. baccata'\n        ,'Malus baccata var. daochengensis'\n        ,'Malus baccata var. jinxianensis'\n        ,'Malus baccata var. xiaojinensis'\n        ,'Malus chitralensis'\n        ,'Malus crescimannoi'\n        ,'Malus doumeri'\n        ,'Malus floribunda'\n        ,'Malus fusca'\n        ,'Malus halliana'\n        ,'Malus honanensis'\n        ,'Malus hupehensis'\n        ,'Malus kansuensis'\n        ,'Malus komarovii'\n        ,'Malus mandshurica'\n        ,'Malus muliensis'\n        ,'Malus ombrophila'\n        ,'Malus orientalis'\n        ,'Malus prattii'\n        ,'Malus prunifolia'\n        ,'Malus pumila'\n        ,'Malus sargentii'\n        ,'Malus sieversii'\n        ,'Malus sikkimensis'\n        ,'Malus spectabilis'\n        ,'Malus sylvestris'\n        ,'Malus toringo'\n        ,'Malus toringoides'\n        ,'Malus transitoria'\n        ,'Malus tschonoskii'\n        ,'Malus yunnanensis'\n        ,'Malus zumi'\n        ,'Medicago papillosa'\n        ,'Medicago papillosa subsp. macrocarpa'\n        ,'Medicago papillosa subsp. papillosa'\n        ,'Medicago prostrata'\n        ,'Medicago sativa subsp. caerulea'\n        ,'Medicago sativa subsp. falcata var. falcata'\n        ,'Medicago sativa subsp. falcata var. viscosa'\n        ,'Medicago sativa subsp. glomerata'\n        ,'Medicago sativa subsp. hemicycla'\n        ,'Medicago sativa subsp. sativa'\n        ,'Medicago sativa subsp. tunetana'\n        ,'Medicago sativa subsp. varia'\n        ,'Medicago saxatilis'\n        ,'Musa acuminata subsp. acuminata var. acuminata'\n        ,'Musa acuminata subsp. banksii'\n        ,'Musa acuminata subsp. burmannica'\n        ,'Musa acuminata subsp. burmannicoides'\n        ,'Musa acuminata subsp. errans'\n        ,'Musa acuminata subsp. halabanensis'\n        ,'Musa acuminata subsp. malaccensis'\n        ,'Musa acuminata subsp. malaccensis var. minor'\n        ,'Musa acuminata subsp. siamea'\n        ,'Musa acuminata subsp. truncata'\n        ,'Musa acuminata var. alasensis'\n        ,'Musa acuminata var. bantamensis'\n        ,'Musa acuminata var. breviformis'\n        ,'Musa acuminata var. cerifera'\n        ,'Musa acuminata var. chinensis'\n        ,'Musa acuminata var. flava'\n        ,'Musa acuminata var. longipetiolata'\n        ,'Musa acuminata var. microcarpa'\n        ,'Musa acuminata var. nakaii'\n        ,'Musa acuminata var. rutilipes'\n        ,'Musa acuminata var. sumatrana'\n        ,'Musa acuminata var. tomentosa'\n        ,'Musa acuminata var. zebrina'\n        ,'Musa balbisiana var. andamica'\n        ,'Musa balbisiana var. bakeri'\n        ,'Musa balbisiana var. balbisiana'\n        ,'Musa balbisiana var. brachycarpa'\n        ,'Musa balbisiana var. dechangensis'\n        ,'Musa balbisiana var. liukiuensis'\n        ,'Musa flaviflora'\n        ,'Musa schizocarpa'\n        ,'Musa textilis'\n        ,'Musa yunnanensis'\n        ,'Musa yunnanensis var. caii'\n        ,'Musa yunnanensis var. jingdongensis'\n        ,'Musa yunnanensis var. yongpingensis'\n        ,'Oryza alta'\n        ,'Oryza australiensis'\n        ,'Oryza barthii'\n        ,'Oryza brachyantha'\n        ,'Oryza eichingeri'\n        ,'Oryza glaberrima'\n        ,'Oryza glumipatula'\n        ,'Oryza grandiglumis'\n        ,'Oryza latifolia'\n        ,'Oryza longistaminata'\n        ,'Oryza malampuzhaensis'\n        ,'Oryza meridionalis'\n        ,'Oryza minuta'\n        ,'Oryza nivara'\n        ,'Oryza officinalis'\n        ,'Oryza perennis var. cubensis'\n        ,'Oryza punctata'\n        ,'Oryza rhizomatis'\n        ,'Oryza ridleyi'\n        ,'Oryza rufipogon'\n        ,'Oryza schweinfurthiana'\n        ,'Pennisetum glaucum subsp. monodii'\n        ,'Pennisetum orientale'\n        ,'Pennisetum purpureum'\n        ,'Pennisetum squamulatum'\n        ,'Pennisetum stenostachyum'\n        ,'Phaseolus albescens'\n        ,'Phaseolus augusti'\n        ,'Phaseolus coccineus'\n        ,'Phaseolus costaricensis'\n        ,'Phaseolus dumosus'\n        ,'Phaseolus longiplacentifer'\n        ,'Phaseolus lunatus'\n        ,'Phaseolus mollis'\n        ,'Phaseolus pachyrrhizoides'\n        ,'Phaseolus persistentus'\n        ,'Phaseolus vulgaris var. aborigineus'\n        ,'Pisum abyssinicum'\n        ,'Pisum fulvum'\n        ,'Pisum sativum subsp. elatius var. brevipedunculatum'\n        ,'Pisum sativum subsp. elatius var. elatius'\n        ,'Pisum sativum subsp. elatius var. pumilo'\n        ,'Secale cereale subsp. afghanicum'\n        ,'Secale cereale subsp. ancestrale'\n        ,'Secale cereale subsp. dighoricum'\n        ,'Secale cereale subsp. segetale'\n        ,'Solanum acaule'\n        ,'Solanum acroglossum'\n        ,'Solanum acroscopicum'\n        ,'Solanum aculeatissimum'\n        ,'Solanum adoense'\n        ,'Solanum aethiopicum'\n        ,'Solanum agnewiorum'\n        ,'Solanum agrimonifolium'\n        ,'Solanum albicans'\n        ,'Solanum albornozii'\n        ,'Solanum aldabrense'\n        ,'Solanum andreanum'\n        ,'Solanum anguivi'\n        ,'Solanum anomalum'\n        ,'Solanum asperolanatum'\n        ,'Solanum aureitomentosum'\n        ,'Solanum ayacuchense'\n        ,'Solanum berthaultii'\n        ,'Solanum boliviense'\n        ,'Solanum bombycinum'\n        ,'Solanum brevicaule'\n        ,'Solanum buesii'\n        ,'Solanum bulbocastanum'\n        ,'Solanum burchellii'\n        ,'Solanum burkartii'\n        ,'Solanum cajamarquense'\n        ,'Solanum campylacanthum'\n        ,'Solanum candolleanum'\n        ,'Solanum cantense'\n        ,'Solanum capense'\n        ,'Solanum catombelense'\n        ,'Solanum cerasiferum'\n        ,'Solanum chacoense'\n        ,'Solanum chilliasense'\n        ,'Solanum chiquidenum'\n        ,'Solanum chomatophilum'\n        ,'Solanum clarum'\n        ,'Solanum coelestipetalum'\n        ,'Solanum colombianum'\n        ,'Solanum commersonii'\n        ,'Solanum contumazaense'\n        ,'Solanum cumingii'\n        ,'Solanum cyaneopurpureum'\n        ,'Solanum dasyphyllum'\n        ,'Solanum deflexicarpum'\n        ,'Solanum demissum'\n        ,'Solanum flahaultii'\n        ,'Solanum flavoviridens'\n        ,'Solanum gandarillasii'\n        ,'Solanum garcia-barrigae'\n        ,'Solanum glabratum'\n        ,'Solanum gracilifrons'\n        ,'Solanum grandiflorum'\n        ,'Solanum guerreroense'\n        ,'Solanum hastifolium'\n        ,'Solanum hastiforme'\n        ,'Solanum hintonii'\n        ,'Solanum hjertingii'\n        ,'Solanum hougasii'\n        ,'Solanum hovei'\n        ,'Solanum huancabambense'\n        ,'Solanum humile'\n        ,'Solanum inaequiradians'\n        ,'Solanum incanum'\n        ,'Solanum incasicum'\n        ,'Solanum infundibuliforme'\n        ,'Solanum insanum'\n        ,'Solanum iopetalum'\n        ,'Solanum kurtzianum'\n        ,'Solanum lamprocarpum'\n        ,'Solanum laxissimum'\n        ,'Solanum lesteri'\n        ,'Solanum lichtensteinii'\n        ,'Solanum lidii'\n        ,'Solanum limbaniense'\n        ,'Solanum linnaeanum'\n        ,'Solanum litoraneum'\n        ,'Solanum lobbianum'\n        ,'Solanum longiconicum'\n        ,'Solanum macracanthum'\n        ,'Solanum macrocarpon'\n        ,'Solanum maglia'\n        ,'Solanum malindiense'\n        ,'Solanum marginatum'\n        ,'Solanum marinasense'\n        ,'Solanum mauense'\n        ,'Solanum medians'\n        ,'Solanum microdontum'\n        ,'Solanum morelliforme'\n        ,'Solanum multiflorum'\n        ,'Solanum multiinterruptum'\n        ,'Solanum neocardenasii'\n        ,'Solanum neorossii'\n        ,'Solanum neovavilovii'\n        ,'Solanum nigriviolaceum'\n        ,'Solanum nubicola'\n        ,'Solanum okadae'\n        ,'Solanum olmosense'\n        ,'Solanum ortegae'\n        ,'Solanum oxycarpum'\n        ,'Solanum palustre'\n        ,'Solanum paucissectum'\n        ,'Solanum pillahuatense'\n        ,'Solanum piurae'\n        ,'Solanum platacanthum'\n        ,'Solanum polhillii'\n        ,'Solanum polyadenium'\n        ,'Solanum raphanifolium'\n        ,'Solanum rhomboideilanceolatum'\n        ,'Solanum richardii'\n        ,'Solanum rubetorum'\n        ,'Solanum ruvu'\n        ,'Solanum salasianum'\n        ,'Solanum schenckii'\n        ,'Solanum setaceum'\n        ,'Solanum sisymbriifolium'\n        ,'Solanum sodomeodes'\n        ,'Solanum sogarandinum'\n        ,'Solanum stipitatostellatum'\n        ,'Solanum stoloniferum'\n        ,'Solanum supinum'\n        ,'Solanum taitense'\n        ,'Solanum tarnii'\n        ,'Solanum taulisense'\n        ,'Solanum tomentosum'\n        ,'Solanum torreanum'\n        ,'Solanum torvum'\n        ,'Solanum umtuma'\n        ,'Solanum usambarense'\n        ,'Solanum usaramense'\n        ,'Solanum venturii'\n        ,'Solanum vernei'\n        ,'Solanum verrucosum'\n        ,'Solanum vespertilio'\n        ,'Solanum viarum'\n        ,'Solanum vicinum'\n        ,'Solanum violaceimarmoratum'\n        ,'Solanum violaceum'\n        ,'Solanum zanzibarense'\n        ,'Sorghum angustum'\n        ,'Sorghum bicolor subsp. drummondii'\n        ,'Sorghum bicolor subsp. verticilliflorum'\n        ,'Sorghum ecarinatum'\n        ,'Sorghum exstans'\n        ,'Sorghum halepense'\n        ,'Sorghum interjectum'\n        ,'Sorghum intrans'\n        ,'Sorghum laxiflorum'\n        ,'Sorghum macrospermum'\n        ,'Sorghum matarankense'\n        ,'Sorghum nitidum'\n        ,'Sorghum propinquum'\n        ,'Sorghum purpureosericeum'\n        ,'Sorghum stipoideum'\n        ,'Sorghum timorense'\n        ,'Sorghum versicolor'\n        ,'Tornabenea annua'\n        ,'Tornabenea insularis'\n        ,'Tornabenea tenuissima'\n        ,'Triticum aestivum subsp. tibeticum'\n        ,'Triticum aestivum subsp. yunnanense'\n        ,'Triticum boeoticum'\n        ,'Triticum monococcum'\n        ,'Triticum monococcum subsp. aegilopoides'\n        ,'Triticum timopheevii'\n        ,'Triticum timopheevii subsp. armeniacum'\n        ,'Triticum turgidum subsp. dicoccoides'\n        ,'Triticum turgidum subsp. paleocolchicum'\n        ,'Triticum urartu'\n        ,'Vicia barbazitae'\n        ,'Vicia faba subsp. faba'\n        ,'Vicia faba subsp. paucijuga'\n        ,'Vicia grandiflora'\n        ,'Vicia pyrenaica'\n        ,'Vicia qatmensis'\n        ,'Vicia sativa subsp. amphicarpa'\n        ,'Vicia sativa subsp. devia'\n        ,'Vicia sativa subsp. incisa'\n        ,'Vicia sativa subsp. macrocarpa'\n        ,'Vicia sativa subsp. nigra'\n        ,'Vigna hosei'\n        ,'Vigna keraudrenii'\n        ,'Vigna monantha'\n        ,'Vigna schlecteri'\n        ,'Vigna subterranea var. spontanea'\n        ,'Vigna unguiculata subsp. aduensis'\n        ,'Vigna unguiculata subsp. alba'\n        ,'Vigna unguiculata subsp. baoulensis'\n        ,'Vigna unguiculata subsp. burundiensis'\n        ,'Vigna unguiculata subsp. dekindtiana'\n        ,'Vigna unguiculata subsp. letouzeyi'\n        ,'Vigna unguiculata subsp. pawekiae'\n        ,'Vigna unguiculata subsp. pubescens'\n        ,'Vigna unguiculata subsp. stenophylla'\n        ,'Vigna unguiculata subsp. tenuis'\n        ,'Vigna unguiculata subsp. unguiculata var. spontanea'";
     switch ($search_type) {
         case 0:
             //Busqueda teniendo en cuenta $term, no se van a evaluar entonces lo que haya en los genus prioritarios ni taxa prioritarios
             $query = "SELECT  s . *\n                            FROM species AS s\n                            JOIN distribution AS d ON s.Taxon_ID = d.Taxon_ID\n                            JOIN countries AS c ON d.Country = c.Code\n                            WHERE d.Taxon_ID\n                            IN \n                            (SELECT s.Taxon_ID FROM species AS s";
             if ($concept_type != "" && $concept_type != "empty") {
                 $query .= " INNER JOIN concepts AS co ON s.Taxon_ID = co.Taxon_ID";
             }
             $query .= " WHERE ";
             if ($term != "") {
                 $query .= "s.Scientific_Name like '" . $term . "%'";
             }
             if ($concept_type != "" && $concept_type != "empty") {
                 if ($term != "") {
                     $query .= " and";
                 }
                 $query .= " co.Concept_Type = '{$concept_type}'";
                 if ($concept_levels) {
                     $query .= " and co.Concept_Level in (";
                     foreach ($concept_levels as $level) {
                         $query .= "'{$level}',";
                     }
                     $query .= ")";
                     $query = str_replace(",)", ")", $query);
                 }
             }
             if ($term != "") {
                 /* La misma busqueda en el campo Common_Name */
                 $query .= " or s.Common_Name like '" . $term . "%'";
                 if ($concept_type != "" && $concept_type != "empty") {
                     $query .= " and co.Concept_Type = '{$concept_type}'";
                     if ($concept_levels) {
                         $query .= " and co.Concept_Level in (";
                         foreach ($concept_levels as $level) {
                             $query .= "'{$level}',";
                         }
                         $query .= ")";
                         $query = str_replace(",)", ")", $query);
                     }
                 }
             }
             if ($term != "") {
                 $query .= " or s.Family like '" . $term . "%'";
                 if ($concept_type != "" && $concept_type != "empty") {
                     $query .= " and co.Concept_Type = '{$concept_type}'";
                     if ($concept_levels) {
                         $query .= " and co.Concept_Level in (";
                         foreach ($concept_levels as $level) {
                             $query .= "'{$level}',";
                         }
                         $query .= ")";
                         $query = str_replace(",)", ")", $query);
                     }
                 }
             }
             $query .= ")";
             $query = str_replace("WHERE )", " )", $query);
             if ($countries) {
                 // Si hay paises por los cuales restringir la busqueda
                 $query .= " and c.Name in (";
                 foreach ($countries as $country) {
                     $query .= "'{$country}',";
                 }
                 $query .= ")";
                 $query = str_replace(",)", ")", $query);
             }
             if ($regions) {
                 $query .= " and c.Region in (";
                 foreach ($regions as $region) {
                     $query .= "'{$region}',";
                 }
                 $query .= ")";
                 $query = str_replace(",)", ")", $query);
             }
             $query .= " GROUP BY s.Genus, s.Species, s.Species_Author, s.Subsp, s.Subsp_Author, s.Var, s.Var_Author";
             break;
         case 1:
             $query = "SELECT  s . *\n                            FROM species AS s\n                            JOIN distribution AS d ON s.Taxon_ID = d.Taxon_ID ";
             //if ($countries) {
             $query .= "JOIN countries AS c ON d.Country = c.Code";
             //}
             $query .= " WHERE d.Taxon_ID\n                            IN \n                            (SELECT s.Taxon_ID FROM species AS s";
             if ($concept_type != "" && $concept_type != "empty") {
                 $query .= " INNER JOIN concepts AS co ON s.Taxon_ID = co.Taxon_ID";
             }
             $query .= " WHERE Genus in (";
             foreach ($priority_genera as $genus) {
                 $query .= "'{$genus}',";
             }
             $query .= ")";
             $query = str_replace(",)", ")", $query);
             if ($concept_type != "" && $concept_type != "empty") {
                 /*if ($term != "") {
                       $query .= " and";
                   }**/
                 $query .= " and co.Concept_Type = '{$concept_type}'";
                 if ($concept_levels) {
                     $query .= " and co.Concept_Level in (";
                     foreach ($concept_levels as $level) {
                         $query .= "'{$level}',";
                     }
                     $query .= ")";
                     $query = str_replace(",)", ")", $query);
                 }
             }
             $query .= ")";
             if ($countries) {
                 // Si hay paises por los cuales restringir la busqueda
                 $query .= " and c.Name in (";
                 foreach ($countries as $country) {
                     $query .= "'{$country}',";
                 }
                 $query .= ")";
                 $query = str_replace(",)", ")", $query);
             }
             if ($regions) {
                 $query .= " and c.Region in (";
                 foreach ($regions as $region) {
                     $query .= "'{$region}',";
                 }
                 $query .= ")";
                 $query = str_replace(",)", ")", $query);
             }
             $query .= " GROUP BY s.Genus, s.Species, s.Species_Author, s.Subsp, s.Subsp_Author, s.Var, s.Var_Author";
             break;
         case 2:
             $query = "SELECT s . *\n                            FROM species AS s\n                            JOIN distribution AS d ON s.Taxon_ID = d.Taxon_ID ";
             //if ($countries) {
             $query .= "JOIN countries AS c ON d.Country = c.Code";
             //}
             $query .= " WHERE d.Taxon_ID\n                            IN \n                            (SELECT s.Taxon_ID FROM species AS s";
             if ($concept_type != "" && $concept_type != "empty") {
                 $query .= " INNER JOIN concepts AS co ON s.Taxon_ID = co.Taxon_ID";
             }
             $query .= " WHERE Scientific_Name in ({$priority_taxa})";
             $query = str_replace(",)", ")", $query);
             if ($concept_type != "" && $concept_type != "empty") {
                 /*if ($term != "") {
                       $query .= " and";
                   }*/
                 $query .= " and co.Concept_Type = '{$concept_type}'";
                 if ($concept_levels) {
                     $query .= " and co.Concept_Level in (";
                     foreach ($concept_levels as $level) {
                         $query .= "'{$level}',";
                     }
                     $query .= ")";
                     $query = str_replace(",)", ")", $query);
                 }
             }
             $query .= ")";
             if ($countries) {
                 // Si hay paises por los cuales restringir la busqueda
                 $query .= " and c.Name in (";
                 foreach ($countries as $country) {
                     $query .= "'{$country}',";
                 }
                 $query .= ")";
                 $query = str_replace(",)", ")", $query);
             }
             if ($regions) {
                 $query .= " and c.Region in (";
                 foreach ($regions as $region) {
                     $query .= "'{$region}',";
                 }
                 $query .= ")";
                 $query = str_replace(",)", ")", $query);
             }
             $query .= " GROUP BY s.Genus, s.Species, s.Species_Author, s.Subsp, s.Subsp_Author, s.Var, s.Var_Author";
             break;
         case 3:
             $query = "SELECT s.* FROM species AS s";
             if ($concept_type != "" && $concept_type != "empty") {
                 $query .= " INNER JOIN concepts AS co ON s.Taxon_ID = co.Taxon_ID";
             }
             $query .= " WHERE s.Scientific_Name like '" . $term . "%'";
             if ($concept_type != "" && $concept_type != "empty") {
                 if ($term != "") {
                     $query .= " and";
                 }
                 $query .= " and co.Concept_Type = '{$concept_type}'";
                 if ($concept_levels) {
                     $query .= " and co.Concept_Level in (";
                     foreach ($concept_levels as $level) {
                         $query .= "'{$level}', ";
                     }
                     $query .= ")";
                     $query = str_replace(", )", ")", $query);
                 }
             }
             if ($term != "") {
                 /* La misma busqueda en el campo Common_Name */
                 $query .= " or s.Common_Name like '" . $term . "%'";
                 if ($concept_type != "" && $concept_type != "empty") {
                     $query .= " and co.Concept_Type = '{$concept_type}'";
                     if ($concept_levels) {
                         $query .= " and co.Concept_Level in (";
                         foreach ($concept_levels as $level) {
                             $query .= "'{$level}', ";
                         }
                         $query .= ")";
                         $query = str_replace(", )", ")", $query);
                     }
                 }
             }
             if ($term != "") {
                 $query .= " or s.Family like '" . $term . "%'";
                 if ($concept_type != "" && $concept_type != "empty") {
                     $query .= " and co.Concept_Type = '{$concept_type}'";
                     if ($concept_levels) {
                         $query .= " and co.Concept_Level in (";
                         foreach ($concept_levels as $level) {
                             $query .= "'{$level}',";
                         }
                         $query .= ")";
                         $query = str_replace(",)", ")", $query);
                     }
                 }
             }
             $query .= " GROUP BY s.Genus, s.Species, s.Species_Author, s.Subsp, s.Subsp_Author, s.Var, s.Var_Author";
             break;
     }
     $query .= " order by s.Genus, s.Species, s.Species_Author, s.Subsp, s.Subsp_Author, s.Var, s.Var_Author";
     //print($query);
     $result = $db->getAll($query);
     $taxa = array();
     foreach ($result as $r) {
         $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->setMainCrop($r["Main_Crop"]);
         // insert reference to the array.
         array_push($taxa, $taxon);
     }
     return $taxa;
 }
 /**
  *
  * @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;
 }
Ejemplo n.º 4
0
 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;
 }