function tripal_views_handler_filter_select_cvterm::init
1.x tripal_views_handler_filter_select_cvterm.inc | tripal_views_handler_filter_select_cvterm::init(&$view, $options) |
Executed when the field is added Determine which cv to limit the cvterms to
Overrides views_handler_filter::init
File
- tripal_views/
views/ handlers/ tripal_views_handler_filter_select_cvterm.inc, line 19 - Purpose: This Handler provides a select list for the type field
Class
- tripal_views_handler_filter_select_cvterm
- @file Purpose: This Handler provides a select list for the type field
Code
function init(&$view, $options) {
include_once ('chado_wrapper_functions.inc');
parent::init($view, $options);
if ($this->options['show_all']) {
$cv_id = variable_get('chado_' . $this->view->base_table . '_cv', NULL);
if ($cv_id) {
$results = tripal_core_chado_select('cvterm', array('cvterm_id', 'name'), array('cv_id' => $cv_id));
if (empty($results)) {
$results = array();
}
foreach ($results as $c) {
$cvterms[$c->cvterm_id] = $c->name;
}
}
else {
//get a list of cvs currently used
if ($this->view->base_table == 'cvterm') {
$sql = 'SELECT distinct(cv.cv_id) FROM {' . $this->view->base_table . '}'
. ' LEFT JOIN cv cv ON cv.cv_id=cvterm.cv_id';
}
else {
$sql = 'SELECT distinct(cv.cv_id) FROM {' . $this->view->base_table . '}'
. ' LEFT JOIN cvterm cvterm ON cvterm.cvterm_id=' . $this->view->base_table . '.type_id '
. 'LEFT JOIN cv cv ON cv.cv_id=cvterm.cv_id';
}
$resource = chado_query($sql);
$cvterms = array();
while ($r = db_fetch_object($resource)) {
$results = tripal_core_chado_select('cvterm', array('cvterm_id', 'name'), array('cv_id' => $r->cv_id));
if (empty($results)) {
$results = array();
}
foreach ($results as $c) {
$cvterms[$c->cvterm_id] = $c->name;
}
}
}
// end of if variable not defined
}
else {
// @coder-ignore: non-drupal schema therefore table prefixing does not apply
$sql = "SELECT cvterm_id, name FROM {cvterm} WHERE cvterm_id IN (SELECT distinct(%s) FROM {%s})";
$resource = chado_query($sql, $this->field, $this->table);
$cvterms = array();
while ($r = db_fetch_object($resource)) {
$cvterms[$r->cvterm_id] = $r->name;
}
}
//sort cvterms by name (case insensitive)
natcasesort($cvterms);
//add to this handler
$this->cvterm_options = $cvterms;
}