local__source_data.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. class local__source_data 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 = 'Source of Data';
  12. // The default description for this field.
  13. public static $description = 'The source data used for this analysis.';
  14. // Provide a list of instance specific settings. These can be access within
  15. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  16. // then Drupal with automatically change these settings for the instnace.
  17. // It is recommended to put settings at the instance level whenever possible.
  18. // If you override this variable in a child class be sure to replicate the
  19. // term_name, term_vocab, term_accession and term_fixed keys as these are
  20. // required for all TripalFields.
  21. public static $default_instance_settings = array(
  22. // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
  23. 'term_vocabulary' => 'local',
  24. // The name of the term.
  25. 'term_name' => 'source_data',
  26. // The unique ID (i.e. accession) of the term.
  27. 'term_accession' => 'source_data',
  28. // Set to TRUE if the site admin is allowed to change the term
  29. // type. This will create form elements when editing the field instance
  30. // to allow the site admin to change the term settings above.
  31. 'term_fixed' => FALSE,
  32. );
  33. // The default widget for this field.
  34. public static $default_widget = 'local__source_data_widget';
  35. // The default formatter for this field.
  36. public static $default_formatter = 'local__source_data_formatter';
  37. // --------------------------------------------------------------------------
  38. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  39. // --------------------------------------------------------------------------
  40. // An array containing details about the field. The format of this array
  41. // is the same as that returned by field_info_fields()
  42. protected $field;
  43. // An array containing details about an instance of the field. A field does
  44. // not have to have an instance. But if dealing with an instance (such as
  45. // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
  46. protected $instance;
  47. /**
  48. * @see TripalField::elementInfo()
  49. */
  50. public function elementInfo() {
  51. $field_term = $this->getFieldTermID();
  52. $sourcename_term = tripal_get_chado_semweb_term('analysis', 'sourcename');
  53. $sourceversion_term = tripal_get_chado_semweb_term('analysis', 'sourceversion');
  54. $sourceuri_term = tripal_get_chado_semweb_term('analysis', 'sourceuri');
  55. return array(
  56. $field_term => array(
  57. 'operations' => array(),
  58. 'sortable' => FALSE,
  59. 'searchable' => FALSE,
  60. 'elements' => array(
  61. $sourcename_term => array(
  62. 'searchable' => TRUE,
  63. 'name' => 'sourcename',
  64. 'label' => 'Data Source Name',
  65. 'help' => 'The name of the data source used for the analysis.',
  66. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  67. 'sortable' => TRUE,
  68. ),
  69. $sourceversion_term => array(
  70. 'searchable' => FALSE,
  71. 'name' => 'sourceversion',
  72. 'label' => 'Data Source Version',
  73. 'help' => 'If applicable, the version number of the source data used for the analysis.',
  74. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  75. 'sortable' => FALSE,
  76. ),
  77. $sourceuri_term => array(
  78. 'searchable' => FALSE,
  79. 'name' => 'sourceuri',
  80. 'label' => 'Data Source URI',
  81. 'help' => 'If applicable, the universal resource indicator (e.g. URL) of the source data used for the analysis.',
  82. 'operations' => array(),
  83. 'sortable' => FALSE,
  84. ),
  85. ),
  86. ),
  87. );
  88. }
  89. /**
  90. *
  91. * @see TripalField::load()
  92. */
  93. public function load($entity) {
  94. $analysis = $entity->chado_record;
  95. $field_name = $this->field['field_name'];
  96. $field_type = $this->field['type'];
  97. $field_table = $this->instance['settings']['chado_table'];
  98. $field_column = $this->instance['settings']['chado_column'];
  99. $sourcename_term = tripal_get_chado_semweb_term('analysis', 'sourcename');
  100. $sourceversion_term = tripal_get_chado_semweb_term('analysis', 'sourceversion');
  101. $sourceuri_term = tripal_get_chado_semweb_term('analysis', 'sourceuri');
  102. $entity->{$field_name}['und'][0] = array(
  103. 'value' => array(
  104. $sourcename_term => $analysis->sourcename,
  105. $sourceversion_term => $analysis->sourceversion,
  106. $sourceuri_term => $analysis->sourceuri,
  107. ),
  108. 'chado-analysis__sourcename' => $analysis->sourcename,
  109. 'chado-analysis__sourceversion' => $analysis->sourceversion,
  110. 'chado-analysis__sourceuri' => $analysis->sourceuri,
  111. );
  112. }
  113. }