diff --git a/includes/GermplasmSearch.inc b/includes/GermplasmSearch.inc index 3dfd583..3666e4e 100644 --- a/includes/GermplasmSearch.inc +++ b/includes/GermplasmSearch.inc @@ -128,7 +128,7 @@ class GermplasmSearch extends KPSEARCH { 'help' => 'The country the seed originated from.' ], 'collection' => [ - 'title' => 'Collection/Population', + 'title' => 'Collection', 'help' => 'The collection or population the germplasm is part of.' ], 'source_institute' => [ @@ -293,13 +293,17 @@ class GermplasmSearch extends KPSEARCH { s.stock_id, tb.label as type, origin.value as origin, - source.value as source_institute + source.value as source_institute, + col.name as collection FROM {stock} s LEFT JOIN {organism} o ON o.organism_id=s.organism_id LEFT JOIN {stockprop} source ON source.stock_id=s.stock_id AND source.type_id=3711 LEFT JOIN {stockprop} origin ON origin.stock_id=s.stock_id AND origin.type_id=3976 LEFT JOIN chado_bundle cb ON cb.type_id=s.type_id - LEFT JOIN tripal_bundle tb ON tb.id=cb.bundle_id "; + LEFT JOIN tripal_bundle tb ON tb.id=cb.bundle_id + LEFT JOIN {stockcollection_stock} c ON s.stock_id = c.stock_id + LEFT JOIN {stockcollection} col ON c.stockcollection_id = col.stockcollection_id + "; $where = []; $joins = []; @@ -334,6 +338,12 @@ class GermplasmSearch extends KPSEARCH { $args[':origin'] = $filter_results['origin']; } + // -- Collection: 0 - select all. + if ($filter_results['collection'] > 0) { + $where[] = "col.stockcollection_id = :collection"; + $args[':collection'] = $filter_results['collection']; + } + // -- Name. if ($filter_results['name'] != '') { $where[] = "(s.name ~* :name OR s.uniquename = :name)"; diff --git a/includes/KPSEARCH.inc b/includes/KPSEARCH.inc index 23ffd85..1018614 100644 --- a/includes/KPSEARCH.inc +++ b/includes/KPSEARCH.inc @@ -166,6 +166,8 @@ class KPSEARCH extends ChadoCustomSearch { $collections = chado_query($sql_collection); if ($collections->rowCount() > 0) { foreach($collections as $collection) { + // Collection id number - Collection Name: Field will return + // collection id number, NOT THE NAME. $collection_options[ $collection->id ] = $collection->name; } } @@ -173,7 +175,7 @@ class KPSEARCH extends ChadoCustomSearch { $q = drupal_get_query_parameters(); // Refine collection options to only collection names - // where registered germplasm has the genus selected. + // where a registered germplasm has the genus of the selected genus. if (isset($q) && is_array($q) && $collection_options) { if (isset($q['genus']) && !empty($q['genus'])) { $genus = $q['genus']; @@ -192,7 +194,7 @@ class KPSEARCH extends ChadoCustomSearch { $new_collection_options = [0 => $default_text]; foreach($collection_options as $i => $collection) { if ($i > 0) { - // Skip default select option. + // Skip default select option 0. $has_genus = chado_query($sql_new_collection, [':genus' => $genus, ':collection' => $i]) ->fetchObject(); @@ -203,14 +205,18 @@ class KPSEARCH extends ChadoCustomSearch { } } } + + // Use currently selected collection not the default. + $default_collection = $q['collection']; } - - $options = (count($new_collection_options) > 0) ? $new_collection_options : $collection_options; + + $options = (count($new_collection_options) > 1) ? $new_collection_options : $collection_options; + $collection_field = $class::$info['filters']['collection']; $form['collection'] = array( '#type' => 'select', - '#title' => $class::$info['filters']['collection']['title'], - '#description' => $class::$info['filters']['collection']['help'], + '#title' => t($collection_field['title']), + '#description' => t($collection_field['help']), '#options' => $options, '#default_value' => $default_collection );