schema__publication.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. class schema__publication 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:publication';
  16. // The default lable for this field.
  17. public static $label = 'Publication';
  18. // The default description for this field.
  19. public static $description = 'Associates a publication (e.g. journal article,
  20. conference proceedings, book chapter, etc.) with this record.';
  21. // Provide a list of global settings. These can be accessed witihn the
  22. // globalSettingsForm. When the globalSettingsForm is submitted then
  23. // Drupal will automatically change these settings for all fields.
  24. public static $settings = array(
  25. 'chado_table' => '',
  26. 'chado_column' => '',
  27. 'base_table' => '',
  28. );
  29. // Provide a list of instance specific settings. These can be access within
  30. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  31. // then Drupal with automatically change these settings for the instnace.
  32. // It is recommended to put settings at the instance level whenever possible.
  33. public static $instance_settings = array();
  34. // Set this to the name of the storage backend that by default will support
  35. // this field.
  36. public static $storage = 'tripal_no_storage';
  37. // The default widget for this field.
  38. public static $default_widget = 'schema__publication_widget';
  39. // The default formatter for this field.
  40. public static $default_formatter = 'schema__publication_formatter';
  41. // --------------------------------------------------------------------------
  42. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  43. // --------------------------------------------------------------------------
  44. // An array containing details about the field. The format of this array
  45. // is the same as that returned by field_info_fields()
  46. protected $field;
  47. // An array containing details about an instance of the field. A field does
  48. // not have to have an instance. But if dealing with an instance (such as
  49. // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
  50. protected $instance;
  51. /**
  52. *
  53. * @see TripalField::validate()
  54. */
  55. public function validate($entity_type, $entity, $field, $items, &$errors) {
  56. }
  57. /**
  58. *
  59. * @see TripalField::load()
  60. */
  61. public function load($entity, $details = array()) {
  62. $record = $details['record'];
  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. $base_table = $this->field['settings']['base_table'];
  68. // Get the FK that links to the base record.
  69. $schema = chado_get_schema($field_table);
  70. $pkey = $schema['primary key'][0];
  71. $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
  72. $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
  73. // Set some defaults for the empty record.
  74. $entity->{$field_name}['und'][0] = array(
  75. 'value' => array(),
  76. 'chado-' . $field_table . '__' . $pkey => '',
  77. 'chado-' . $field_table . '__' . $fkey_lcolumn => '',
  78. 'chado-' . $field_table . '__' . 'pub_id' => '',
  79. 'uniquename' => '',
  80. );
  81. $linker_table = $base_table . '_pub';
  82. $options = array(
  83. 'return_array' => 1,
  84. );
  85. $record = chado_expand_var($record, 'table', $linker_table, $options);
  86. if (count($record->$linker_table) > 0) {
  87. $i = 0;
  88. foreach ($record->$linker_table as $index => $linker) {
  89. $pub = $linker->pub_id;
  90. $pub_details = tripal_get_minimal_pub_info($pub);
  91. $pub_details['@type'] = $pub->type_id->dbxref_id->db_id->name . ':' . $pub->type_id->dbxref_id->accession;
  92. $pub_details['publication']['type'] = $pub->type_id->name;
  93. $entity->{$field_name}['und'][$i]['value'] = $pub_details;
  94. $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $linker->$pkey;
  95. $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $fkey_lcolumn] = $linker->$fkey_lcolumn->$fkey_lcolumn;
  96. $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . 'pub_id'] = $pub->pub_id;
  97. $entity->{$field_name}['und'][$i]['uniquename'] = $pub->uniquename;
  98. if (property_exists($pub, 'entity_id')) {
  99. $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $pub->entity_id;
  100. }
  101. $i++;
  102. }
  103. }
  104. }
  105. /**
  106. *
  107. * @see TripalField::settingsForm()
  108. */
  109. public function settingsForm($has_data) {
  110. }
  111. /**
  112. *
  113. * @param unknown $form
  114. * @param unknown $form_state
  115. */
  116. public function settingsFormValidate($form, &$form_state) {
  117. }
  118. /**
  119. *
  120. * @see TripalField::instanceSettingsForm()
  121. */
  122. public function instanceSettingsForm() {
  123. }
  124. /**
  125. *
  126. * @see TripalField::instanceSettingsFormValidate()
  127. */
  128. public function instanceSettingsFormValidate($form, &$form_state) {
  129. }
  130. }