function tripal_feature_load_organism_feature_counts
2.x tripal_feature.theme.inc | tripal_feature_load_organism_feature_counts($organism) |
3.x tripal_feature.theme.inc | tripal_feature_load_organism_feature_counts($organism) |
1.x tripal_feature.module | tripal_feature_load_organism_feature_counts($organism) |
Related topics
1 call to tripal_feature_load_organism_feature_counts()
File
- tripal_feature/
tripal_feature.module, line 1420 - @todo Add file header description
Code
function tripal_feature_load_organism_feature_counts($organism) {
// don't show the browser if the settings in the admin page is turned off
// instead return the array indicating the status of the browser
$show_counts = variable_get('tripal_feature_summary_setting', 'show_feature_summary');
if (strcmp($show_counts, 'show_feature_summary') != 0) {
return array('enabled' => FALSE);
}
$args = array();
$names = array();
$order = array();
// build the where clause for the SQL statement if we have a custom term list
// we'll also keep track of the names the admin provided (if any) and the
// order that the terms should appear.
$is_custom = 0;
$temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
$where = '';
if ($temp) {
$is_custom = 1;
$temp = explode("\n", $temp);
foreach ($temp as $key => $value) {
// separate the key value pairs
$temp2 = explode("=", $value);
$feature_type = rtrim($temp2[0]);
$args[] = $feature_type;
$order[] = $feature_type;
// if a new name is provided then use that otherwise just
// use the feature type
if (count($temp2) == 2) {
$names[] = rtrim($temp2[1]);
}
else {
$names[] = $feature_type;
}
$where .= "OFC.feature_type = '%s' OR \n";
}
if ($where) {
$where = drupal_substr($where, 0, -5); # remove OR from the end
$where = "($where) AND";
}
}
// get the feature counts. This is dependent on a materialized view
// installed with the organism module
$sql = "
SELECT OFC.num_features,OFC.feature_type,CVT.definition
FROM {organism_feature_count} OFC
INNER JOIN {cvterm} CVT on OFC.cvterm_id = CVT.cvterm_id
WHERE $where organism_id = %d
ORDER BY num_features desc
";
$args[] = $organism->organism_id;
$org_features = chado_query($sql, $args);
// iterate through the types
$types = array();
while ($type = db_fetch_object($org_features)) {
$types[$type->feature_type] = $type;
// if we don't have an order this means we didn't go through the loop
// above to set the names, so do that now
if (!$is_custom) {
$names[] = $type->feature_type;
$order[] = $type->feature_type;
}
}
# now reorder the types
$ordered_types = array();
foreach ($order as $type) {
$ordered_types[] = $types[$type];
}
return array('types' => $ordered_types, 'names' => $names, 'enabled' => TRUE);
}