Skip to content

Commit

Permalink
Filter by collection for review
Browse files Browse the repository at this point in the history
  • Loading branch information
reynoldtan committed Aug 12, 2022
1 parent ffa66fe commit e676bcb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
16 changes: 13 additions & 3 deletions includes/GermplasmSearch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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)";
Expand Down
18 changes: 12 additions & 6 deletions includes/KPSEARCH.inc
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ 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;
}
}

$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'];
Expand All @@ -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();
Expand All @@ -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
);
Expand Down

0 comments on commit e676bcb

Please sign in to comment.