123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- class chado_linker__prop extends ChadoField {
-
-
-
-
-
-
-
-
- public static $default_label = 'Chado Property';
-
- public static $description = 'Add details about this property.';
-
-
-
-
-
-
-
- public static $default_instance_settings = array(
-
- 'term_vocabulary' => 'local',
-
- 'term_name' => 'property',
-
- 'term_accession' => 'property',
-
-
-
- 'term_fixed' => FALSE,
-
- 'chado_table' => '',
-
- 'chado_column' => '',
-
- 'base_table' => '',
- );
-
- public static $default_widget = 'chado_linker__prop_widget';
-
- public static $default_formatter = 'chado_linker__prop_formatter';
-
-
-
-
- public static $no_ui = FALSE;
-
- public function load($entity) {
- $field_name = $this->field['field_name'];
- $field_type = $this->field['type'];
- $field_table = $this->instance['settings']['chado_table'];
- $field_column = $this->instance['settings']['chado_column'];
- $base_table = $this->instance['settings']['base_table'];
- $vocabulary = $this->instance['settings']['term_vocabulary'];
- $accession = $this->instance['settings']['term_accession'];
- $cvterm = tripal_get_cvterm(array(
- 'dbxref_id' => array(
- 'db_id' => array(
- 'name' => $vocabulary,
- ),
- 'accession' => $accession,
- ),
- ));
- $cvterm_id = $cvterm->cvterm_id;
-
- $schema = chado_get_schema($field_table);
- $pkey = $schema['primary key'][0];
- if (!isset($schema['foreign keys'][$base_table]['columns'])) {
- return;
- }
- $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
- $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
-
- $chado_record = $entity->chado_record;
- $entity->{$field_name}['und'][0] = array(
- 'value' => '',
- 'chado-' . $field_table . '__' . $pkey => '',
- 'chado-' . $field_table . '__' . $fkey_lcolumn => $chado_record->$fkey_lcolumn,
- 'chado-' . $field_table . '__value' => '',
- 'chado-' . $field_table . '__type_id' => $cvterm_id,
- 'chado-' . $field_table . '__rank' => '',
- );
-
- $columns = array('*');
- $match = array(
- $fkey_lcolumn => $chado_record->{$fkey_lcolumn},
- 'type_id' => $cvterm_id,
- );
- $options = array(
- 'return_array' => TRUE,
- 'order_by' => array('rank' => 'ASC')
- );
- $properties = chado_select_record($field_table, $columns, $match, $options);
- for ($i = 0; $i < count($properties); $i++) {
- $property = $properties[$i];
- foreach ($schema['fields'] as $fname => $details) {
- $entity->{$field_name}['und'][$i] = array(
- 'value' => $property->value,
- 'chado-' . $field_table . '__' . $pkey => $property->$pkey,
- 'chado-' . $field_table . '__' . $fkey_lcolumn => $property->$fkey_lcolumn,
- 'chado-' . $field_table . '__value' => $property->value,
- 'chado-' . $field_table . '__type_id' => $property->type_id,
- 'chado-' . $field_table . '__rank' => $property->rank,
- );
- }
- }
- }
-
- public function query($query, $condition) {
- $prop_linker = $this->instance['settings']['chado_table'];
- $base_table = $this->instance['settings']['base_table'];
- $bschema = chado_get_schema($base_table);
- $bpkey = $bschema['primary key'][0];
- $alias = $this->field['field_name'];
- $operator = $condition['operator'];
- $vocab = $this->instance['settings']['term_vocabulary'];
- $accession = $this->instance['settings']['term_accession'];
- $cvterm = tripal_get_cvterm(array('id' => $vocab . ':' . $accession));
- $query->join($prop_linker, $alias, "base.$bpkey = $alias.$bpkey");
- $query->condition("$alias.type_id", $cvterm->cvterm_id);
- $query->condition("$alias.value", $condition['value'], $operator);
- }
- }
|