|
@@ -73,6 +73,187 @@ class sio__annotation extends ChadoField {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @see TripalField::elementInfo()
|
|
|
+ */
|
|
|
+ public function elementInfo() {
|
|
|
+ $field_table = $this->instance['settings']['chado_table'];
|
|
|
+ $schema = chado_get_schema($field_table);
|
|
|
+
|
|
|
+ $vocabulary_term = tripal_get_chado_semweb_term('cvterm', 'cv_id');
|
|
|
+ $accession_term = tripal_get_chado_semweb_term('dbxref', 'accession');
|
|
|
+ $definition_term = tripal_get_chado_semweb_term('cvterm', 'definition');
|
|
|
+
|
|
|
+ $field_term = $this->getFieldTermID();
|
|
|
+ $info = array(
|
|
|
+ $field_term => array(
|
|
|
+ 'operations' => array(),
|
|
|
+ 'sortable' => FALSE,
|
|
|
+ 'searchable' => FALSE,
|
|
|
+ 'type' => 'array',
|
|
|
+ 'elements' => array(
|
|
|
+ $vocabulary_term => array(
|
|
|
+ 'sortable' => TRUE,
|
|
|
+ 'searchable' => TRUE,
|
|
|
+ 'name' => 'vocabulary',
|
|
|
+ 'label' => 'Annotation Term Vocabulary',
|
|
|
+ 'operations' => array('eq', 'ne', 'contains', 'starts'),
|
|
|
+ ),
|
|
|
+ $accession_term => array(
|
|
|
+ 'sortable' => TRUE,
|
|
|
+ 'searchable' => TRUE,
|
|
|
+ 'name' => 'accession',
|
|
|
+ 'label' => 'Annotation Term Accession',
|
|
|
+ 'operations' => array('eq', 'ne', 'contains', 'starts'),
|
|
|
+ ),
|
|
|
+ $definition_term = array(
|
|
|
+ 'sortable' => TRUE,
|
|
|
+ 'searchable' => TRUE,
|
|
|
+ 'name' => 'description',
|
|
|
+ 'label' => 'Annotation Term Description',
|
|
|
+ 'operations' => array('eq', 'ne', 'contains', 'starts'),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ if (array_key_exists('is_not', $schema['fields'])) {
|
|
|
+ $negation_term = tripal_get_chado_semweb_term($field_table, 'is_not');
|
|
|
+ $info[$field_term]['elements'][$negation_term] = array(
|
|
|
+ 'sortable' => TRUE,
|
|
|
+ 'searchable' => TRUE,
|
|
|
+ 'name' => 'negates',
|
|
|
+ 'label' => 'Annotation Term Negates',
|
|
|
+ 'operations' => array('eq', 'ne'),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (array_key_exists('rank', $schema['fields'])) {
|
|
|
+ $rank_term = tripal_get_chado_semweb_term($field_table, 'rank');
|
|
|
+ $info[$field_term]['elements'][$rank_term] = array(
|
|
|
+ 'sortable' => TRUE,
|
|
|
+ 'searchable' => TRUE,
|
|
|
+ 'name' => 'rank',
|
|
|
+ 'label' => 'Annotation Term Rank',
|
|
|
+ 'operations' => array('eq', 'ne', 'lte', 'gte'),
|
|
|
+ 'type' => numeric
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (array_key_exists('pub_id', $schema['fields'])) {
|
|
|
+ }
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see ChadoField::query()
|
|
|
+ */
|
|
|
+ public function query($query, $condition) {
|
|
|
+ $alias = $this->field['field_name'];
|
|
|
+ $operator = $condition['operator'];
|
|
|
+
|
|
|
+ $field_table = $this->instance['settings']['chado_table'];
|
|
|
+ $base_table = $this->instance['settings']['base_table'];
|
|
|
+
|
|
|
+ $schema = chado_get_schema($field_table);
|
|
|
+ $pkey = $schema['primary key'][0];
|
|
|
+ $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
|
|
|
+ $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
|
|
|
+
|
|
|
+ $field_term_id = $this->getFieldTermID();
|
|
|
+
|
|
|
+ $vocabulary_term = $field_term_id . ',' . tripal_get_chado_semweb_term('cvterm', 'cv_id');
|
|
|
+ $accession_term = $field_term_id . ',' . tripal_get_chado_semweb_term('dbxref', 'accession');
|
|
|
+ $definition_term = $field_term_id . ',' . tripal_get_chado_semweb_term('cvterm', 'definition');
|
|
|
+
|
|
|
+
|
|
|
+ // Join to the xxx_cvterm table for this field.
|
|
|
+ $this->queryJoinOnce($query, $field_table, $alias, "base.$fkey_rcolumn = $alias.$fkey_lcolumn");
|
|
|
+
|
|
|
+ if ($condition['column'] == $vocabulary_term) {
|
|
|
+ $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
|
|
|
+ $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id");
|
|
|
+ $this->queryJoinOnce($query, 'db', $alias . '_db', $alias . "_db.db_id = " . $alias . "_dbxref.db_id");
|
|
|
+ $query->condition($alias . '_db.name', $condition['value'], $operator);
|
|
|
+ }
|
|
|
+ if ($condition['column'] == $accession_term) {
|
|
|
+ $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
|
|
|
+ $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id");
|
|
|
+ $query->condition($alias . '_dbxref.accession', $condition['value'], $operator);
|
|
|
+ }
|
|
|
+ if ($condition['column'] == $definition_term) {
|
|
|
+ $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
|
|
|
+ $query->condition($alias . '_cvterm.definition', $condition['value'], $operator);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (array_key_exists('is_not', $schema['fields'])) {
|
|
|
+ $negation_term = $field_term_id . ',' . tripal_get_chado_semweb_term($field_table, 'is_not');
|
|
|
+ if ($condition['column'] == $negation_term) {
|
|
|
+ $query->condition($alias . '.is_not', $condition['value'], $operator);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (array_key_exists('rank', $schema['fields'])) {
|
|
|
+ $rank_term = $field_term_id . ',' . tripal_get_chado_semweb_term($field_table, 'rank');
|
|
|
+ if ($condition['column'] == $rank_term) {
|
|
|
+ $query->condition($alias . '.rank', $condition['value'], $operator);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (array_key_exists('pub_id', $schema['fields'])) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see ChadoField::queryOrder()
|
|
|
+ */
|
|
|
+ public function queryOrder($query, $order) {
|
|
|
+ $alias = $this->field['field_name'];
|
|
|
+
|
|
|
+ $field_table = $this->instance['settings']['chado_table'];
|
|
|
+ $base_table = $this->instance['settings']['base_table'];
|
|
|
+
|
|
|
+ $schema = chado_get_schema($field_table);
|
|
|
+ $pkey = $schema['primary key'][0];
|
|
|
+ $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
|
|
|
+ $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
|
|
|
+
|
|
|
+ $field_term_id = $this->getFieldTermID();
|
|
|
+
|
|
|
+ $vocabulary_term = $field_term_id . ',' . tripal_get_chado_semweb_term('cvterm', 'cv_id');
|
|
|
+ $accession_term = $field_term_id . ',' . tripal_get_chado_semweb_term('dbxref', 'accession');
|
|
|
+ $definition_term = $field_term_id . ',' . tripal_get_chado_semweb_term('cvterm', 'definition');
|
|
|
+
|
|
|
+ // Join to the xxx_cvterm table for this field.
|
|
|
+ $this->queryJoinOnce($query, $field_table, $alias, "base.$fkey_rcolumn = $alias.$fkey_lcolumn");
|
|
|
+
|
|
|
+ if ($order['column'] == $vocabulary_term) {
|
|
|
+ $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
|
|
|
+ $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id");
|
|
|
+ $this->queryJoinOnce($query, 'db', $alias . '_db', $alias . "_db.db_id = " . $alias . "_dbxref.db_id");
|
|
|
+ $query->orderBy($alias . "_dbxref.name", $order['direction']);
|
|
|
+ }
|
|
|
+ if ($order['column'] == $accession_term) {
|
|
|
+ $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
|
|
|
+ $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id");
|
|
|
+ $query->orderBy($alias . "_dbxref.accession", $order['direction']);
|
|
|
+ }
|
|
|
+ if ($order['column'] == $definition_term) {
|
|
|
+ $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
|
|
|
+ $query->orderBy($alias . "_cvterm.definition", $order['direction']);
|
|
|
+ }
|
|
|
+ if (array_key_exists('is_not', $schema['fields'])) {
|
|
|
+ $negation_term = $field_term_id . ',' . tripal_get_chado_semweb_term($field_table, 'is_not');
|
|
|
+ if ($order['column'] == $negation_term) {
|
|
|
+ $query->orderBy("$alias.is_not", $order['direction']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (array_key_exists('rank', $schema['fields'])) {
|
|
|
+ $rank_term = $field_term_id . ',' . tripal_get_chado_semweb_term($field_table, 'rank');
|
|
|
+ if ($order['column'] == $rank_term) {
|
|
|
+ $query->orderBy("$alias.rank", $order['direction']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (array_key_exists('pub_id', $schema['fields'])) {
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
/**
|
|
|
*
|
|
|
* @see TripalField::load()
|
|
@@ -96,6 +277,9 @@ class sio__annotation extends ChadoField {
|
|
|
if (array_key_exists('is_not', $schema['fields'])) {
|
|
|
$negation = tripal_get_chado_semweb_term($field_table, 'is_not');
|
|
|
}
|
|
|
+ if (array_key_exists('rank', $schema['fields'])) {
|
|
|
+ $rank_term = tripal_get_chado_semweb_term($field_table, 'rank');
|
|
|
+ }
|
|
|
|
|
|
// Set some defaults for the empty record.
|
|
|
$chado_record = $entity->chado_record;
|
|
@@ -147,6 +331,7 @@ class sio__annotation extends ChadoField {
|
|
|
$entity->{$field_name}['und'][$i]['chado-' . $field_table . '__is_not'] = $linker->is_not;
|
|
|
}
|
|
|
if (array_key_exists('rank', $schema['fields'])) {
|
|
|
+ $entity->{$field_name}['und'][$i]['value'][$rank_term] = $linker->rank;
|
|
|
$entity->{$field_name}['und'][$i]['chado-' . $field_table . '__rank'] = $linker->rank;
|
|
|
}
|
|
|
if (array_key_exists('pub_id', $schema['fields'])) {
|