sbo__phenotype.inc

File

tripal_chado/includes/TripalFields/sbo__phenotype/sbo__phenotype.inc
View source
  1. <?php
  2. class sbo__phenotype extends ChadoField {
  3. // --------------------------------------------------------------------------
  4. // EDITABLE STATIC CONSTANTS
  5. //
  6. // The following constants SHOULD be set for each descendent class. They are
  7. // used by the static functions to provide information to Drupal about
  8. // the field and it's default widget and formatter.
  9. // --------------------------------------------------------------------------
  10. // The default lable for this field.
  11. public static $default_label = 'Phenotype';
  12. // The default description for this field.
  13. public static $description = 'A biochemical network can generate phenotypes or affects
  14. biological processes. Such processes can take place at different levels and are
  15. independent of the biochemical network itself.';
  16. // Provide a list of instance specific settings. These can be access within
  17. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  18. // then Drupal with automatically change these settings for the instnace.
  19. // It is recommended to put settings at the instance level whenever possible.
  20. // If you override this variable in a child class be sure to replicate the
  21. // term_name, term_vocab, term_accession and term_fixed keys as these are
  22. // required for all TripalFields.
  23. public static $default_instance_settings = array(
  24. // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
  25. 'term_vocabulary' => 'SBO',
  26. // The name of the term.
  27. 'term_name' => 'Phenotype',
  28. // The unique ID (i.e. accession) of the term.
  29. 'term_accession' => '0000358',
  30. // Set to TRUE if the site admin is allowed to change the term
  31. // type. This will create form elements when editing the field instance
  32. // to allow the site admin to change the term settings above.
  33. 'term_fixed' => FALSE,
  34. );
  35. // The default widget for this field.
  36. public static $default_widget = 'sbo__phenotype_widget';
  37. // The default formatter for this field.
  38. public static $default_formatter = 'sbo__phenotype_formatter';
  39. // --------------------------------------------------------------------------
  40. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  41. // --------------------------------------------------------------------------
  42. // An array containing details about the field. The format of this array
  43. // is the same as that returned by field_info_fields()
  44. protected $field;
  45. // An array containing details about an instance of the field. A field does
  46. // not have to have an instance. But if dealing with an instance (such as
  47. // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
  48. protected $instance;
  49. /**
  50. * @see TripalField::elementInfo()
  51. */
  52. public function elementInfo() {
  53. $field_term = $this->getFieldTermID();
  54. return array(
  55. $field_term => array(
  56. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  57. 'sortable' => FALSE,
  58. 'searchable' => FALSE,
  59. 'type' => 'xs:string',
  60. 'readonly' => TRUE,
  61. ),
  62. );
  63. }
  64. /**
  65. *
  66. * @see TripalField::load()
  67. */
  68. public function load($entity) {
  69. $record = $entity->chado_record;
  70. $field_name = $this->field['field_name'];
  71. $field_type = $this->field['type'];
  72. $field_table = $this->instance['settings']['chado_table'];
  73. $field_column = $this->instance['settings']['chado_column'];
  74. // Get the FK that links to the base record.
  75. $schema = chado_get_schema($field_table);
  76. $base_table = $entity->chado_table;
  77. $pkey = $schema['primary key'][0];
  78. $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
  79. $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
  80. // Set some defaults for the empty record.
  81. $entity->{$field_name}['und'][0] = array(
  82. 'value' => array(),
  83. $field_table . '__' . $pkey => '',
  84. $field_table . '__' . $fkey_lcolumn => '',
  85. $field_table . '__' . 'phenotype_id' => '',
  86. // Ignore the synonym_sgml column for now.
  87. );
  88. $linker_table = $base_table . '_phenotype';
  89. $options = array(
  90. 'return_array' => 1,
  91. 'include_fk' => array(
  92. 'phenotype_id' => array(
  93. 'attr_id' => array(
  94. 'dbxref_id' => array(
  95. 'db_id' => TRUE,
  96. ),
  97. ),
  98. ),
  99. $fkey_lcolumn => TRUE,
  100. ),
  101. );
  102. $record = chado_expand_var($record, 'table', $linker_table, $options);
  103. $phenotype_linkers = $record->$linker_table;
  104. if ($phenotype_linkers) {
  105. foreach ($phenotype_linkers as $i => $phenotype_linker) {
  106. $phenotype = $phenotype_linker->phenotype_id;
  107. $entity->{$field_name}['und'][$i]['value']['type'] = $phenotype->attr_id->name;
  108. $entity->{$field_name}['und'][$i]['value']['name'] = $phenotype->name;
  109. if ($phenotype->cvalue_id) {
  110. $entity->{$field_name}['und'][$i]['value']['value'] = $phenotype->cvalue_id->name;
  111. }
  112. else {
  113. $entity->{$field_name}['und'][$i]['value']['value'] = $phenotype->value;
  114. }
  115. $entity->{$field_name}['und'][$i][$field_table . '__' . $pkey] = $phenotype_linker->$pkey;
  116. $entity->{$field_name}['und'][$i][$field_table . '__' . $fkey_lcolumn] = $phenotype_linker->$fkey_lcolumn->$fkey_lcolumn;
  117. $entity->{$field_name}['und'][$i][$field_table . '__' . 'phenotype_id'] = $phenotype->phenotype_id;
  118. if ($phenotype && property_exists($phenotype, 'entity_id')) {
  119. $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $phenotype->entity_id;
  120. }
  121. }
  122. }
  123. }
  124. }