schema__alternate_name.inc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. class schema__alternate_name extends TripalField {
  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 term that this field maps to. The format for the term should be:
  11. // [vocab]:[accession] where [vocab] is the short name of the vocabulary
  12. // and [acession] is the unique accession number for the term. This term
  13. // must already exist in the vocabulary storage backend. This
  14. // value should never be changed once fields exist for this type.
  15. public static $term = 'schema:alternateName';
  16. // The default lable for this field.
  17. public static $label = 'Synonyms';
  18. // The default description for this field.
  19. public static $description = 'Adds an alternative name (synonym or alias) to this record.';
  20. // Provide a list of global settings. These can be accessed witihn the
  21. // globalSettingsForm. When the globalSettingsForm is submitted then
  22. // Drupal will automatically change these settings for all fields.
  23. public static $settings = array(
  24. 'chado_table' => '',
  25. 'chado_column' => '',
  26. 'base_table' => '',
  27. );
  28. // Provide a list of instance specific settings. These can be access within
  29. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  30. // then Drupal with automatically change these settings for the instnace.
  31. // It is recommended to put settings at the instance level whenever possible.
  32. public static $instance_settings = array();
  33. // Set this to the name of the storage backend that by default will support
  34. // this field.
  35. public static $storage = 'tripal_no_storage';
  36. // The default widget for this field.
  37. public static $default_widget = 'schema__alternate_name_widget';
  38. // The default formatter for this field.
  39. public static $default_formatter = 'schema__alternate_name_formatter';
  40. // --------------------------------------------------------------------------
  41. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  42. // --------------------------------------------------------------------------
  43. // An array containing details about the field. The format of this array
  44. // is the same as that returned by field_info_fields()
  45. protected $field;
  46. // An array containing details about an instance of the field. A field does
  47. // not have to have an instance. But if dealing with an instance (such as
  48. // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
  49. protected $instance;
  50. /**
  51. *
  52. * @see TripalField::validate()
  53. */
  54. public function validate($entity_type, $entity, $field, $items, &$errors) {
  55. }
  56. /**
  57. *
  58. * @see TripalField::load()
  59. */
  60. public function load($entity, $details = array()) {
  61. $record = $details['record'];
  62. $base_table = $this->field['settings']['base_table'];
  63. $field_name = $this->field['field_name'];
  64. $field_type = $this->field['type'];
  65. $field_table = $this->field['settings']['chado_table'];
  66. $field_column = $this->field['settings']['chado_column'];
  67. // Get the PKey for this table
  68. $schema = chado_get_schema($field_table);
  69. $pkey = $schema['primary key'][0];
  70. // Get the FK that links to the base record.
  71. $schema = chado_get_schema($field_table);
  72. $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
  73. $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
  74. // Set some defaults for the empty record.
  75. $entity->{$field_name}['und'][0] = array(
  76. 'value' => array(),
  77. 'chado-' . $field_table . '__' . $pkey => '',
  78. 'chado-' . $field_table . '__' . $fkey_lcolumn => '',
  79. 'chado-' . $field_table . '__' . 'synonym_id' => '',
  80. 'chado-' . $field_table . '__' . 'pub_id' => '',
  81. 'chado-' . $field_table . '__' . 'is_current' => TRUE,
  82. 'chado-' . $field_table . '__' . 'is_internal' => '',
  83. 'name' => '',
  84. 'type_id' => '',
  85. // Ignore the synonym_sgml column for now.
  86. );
  87. $linker_table = $base_table . '_synonym';
  88. $options = array('return_array' => 1);
  89. $record = chado_expand_var($record, 'table', $linker_table, $options);
  90. if (count($record->$linker_table) > 0) {
  91. $i = 0;
  92. foreach ($record->$linker_table as $index => $linker) {
  93. $synonym = $linker->synonym_id;
  94. $entity->{$field_name}['und'][$i] = array(
  95. 'value' => array(
  96. '@type' => $synonym->type_id->dbxref_id->db_id->name . ':' . $synonym->type_id->dbxref_id->accession,
  97. 'type' => $synonym->type_id->name,
  98. 'name' => $synonym->name,
  99. ),
  100. 'chado-' . $field_table . '__' . $pkey => $linker->$pkey,
  101. 'chado-' . $field_table . '__' . $fkey_lcolumn => $linker->$fkey_lcolumn->$fkey_lcolumn,
  102. 'chado-' . $field_table . '__' . 'synonym_id' => $synonym->synonym_id,
  103. 'chado-' . $field_table . '__' . 'pub_id' => $linker->pub_id->pub_id,
  104. 'chado-' . $field_table . '__' . 'is_current' => $linker->is_current,
  105. 'chado-' . $field_table . '__' . 'is_internal' => $linker->is_internal,
  106. 'name' => $synonym->name,
  107. 'type_id' => $synonym->type_id->cvterm_id,
  108. );
  109. $i++;
  110. }
  111. }
  112. }
  113. /**
  114. *
  115. * @see TripalField::settingsForm()
  116. */
  117. public function settingsForm($has_data) {
  118. }
  119. /**
  120. *
  121. * @param unknown $form
  122. * @param unknown $form_state
  123. */
  124. public function settingsFormValidate($form, &$form_state) {
  125. }
  126. /**
  127. *
  128. * @see TripalField::instanceSettingsForm()
  129. */
  130. public function instanceSettingsForm() {
  131. }
  132. /**
  133. *
  134. * @see TripalField::instanceSettingsFormValidate()
  135. */
  136. public function instanceSettingsFormValidate($form, &$form_state) {
  137. }
  138. }