123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- class sio__references extends ChadoField {
-
-
-
-
-
-
-
-
- public static $default_label = 'References';
-
- public static $description = 'Records references by this publication.';
-
-
-
-
-
-
-
- public static $default_instance_settings = array(
-
- 'term_vocabulary' => 'SIO',
-
- 'term_name' => 'references',
-
- 'term_accession' => '000631',
-
-
-
- 'term_fixed' => FALSE,
-
- 'chado_table' => 'pub',
-
- 'chado_column' => 'pub_id',
-
- 'base_table' => 'pub',
- );
-
- public static $default_widget = 'sio__references_widget';
-
- public static $default_formatter = 'sio__references_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'];
-
- $chado_record = $entity->chado_record;
- $entity->{$field_name}['und'][0] = array(
- 'value' => '',
- );
-
-
- $chado_tables = chado_get_table_names(TRUE);
- $delta = 0;
- foreach ($chado_tables as $chado_table) {
- $matches = array();
- if (preg_match('/^(.+?)_pub$/', $chado_table, $matches)) {
- $reference_table = $matches[1];
-
- $schema = chado_get_schema($chado_table);
- $fkeys = $schema['foreign keys'];
- foreach ($fkeys as $linked_table => $fk_details) {
- if ($linked_table == $reference_table) {
- $fkleft = array_keys($fk_details['columns'])[0];
- $fkright = $fk_details['columns'][$fkleft];
- }
- }
-
-
- $records = chado_generate_var($chado_table, array('pub_id' => $chado_record->pub_id), array('return_array' => TRUE));
- foreach ($records as $record) {
-
-
-
-
- $entity->{$field_name}['und'][$delta]['value'] = array();
-
- if (property_exists($record->$fkleft, 'type_id') and $record->$fkleft->type_id) {
- $entity->{$field_name}['und'][$delta]['value']['rdfs:type'] = $record->$fkleft->type_id->name;
- }
- else {
-
-
- $mapping = db_select('chado_cvterm_mapping', 'CVM')
- ->fields('CVM')
- ->condition('chado_table', $reference_table)
- ->execute()
- ->fetchObject();
- if ($mapping) {
- $cvterm = tripal_get_cvterm(array('cvterm_id' => $mapping->cvterm_id));
- $entity->{$field_name}['und'][$delta]['value']['rdfs:type'] = $cvterm->name;
- }
- }
-
- if (property_exists($record->$fkleft, 'name')) {
- $entity->{$field_name}['und'][$delta]['value']['schema:name'] = $record->$fkleft->name;
- }
- if (property_exists($record->$fkleft, 'uniquename')) {
- $entity->{$field_name}['und'][$delta]['value']['data:0842'] = $record->$fkleft->name;
- }
-
- if (property_exists($record->$fkleft, 'entity_id')) {
- $entity->{$field_name}['und'][$delta]['value']['entity'] = 'TripalEntity:' . $record->$fkleft->entity_id;
- }
-
-
- if (property_exists($record->$fkleft, 'genus')) {
- $name = '<i>' . $record->$fkleft->genus . ' ' . $record->$fkleft->species . '</i>';
- if (property_exists($record->$fkleft, 'infraspecific_name')) {
- if ($record->$fkleft->type_id) {
- $name .= ' ' . $record->$fkleft->type_id->name;
- }
- $name .= ' ' . $record->$fkleft->infraspecific_name;
- }
- $entity->{$field_name}['und'][$delta]['value']['schema:name'] = $name;
- }
- $delta++;
- }
- }
- }
- }
- }
|