tripal_entities.chado_entity.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. *
  4. * Implements hook_entity_load().
  5. */
  6. function tripal_entities_entity_presave($entity, $type) {
  7. }
  8. /**
  9. *
  10. * @param $entity
  11. * @param $type
  12. */
  13. function tripal_entities_entity_postsave($entity, $type) {
  14. // Set the title for this entity using the chado data.
  15. $title = chado_get_entity_title($entity);
  16. $ec = new TripalEntityController($entity->type);
  17. $ec->setTitle($entity, $title);
  18. }
  19. /**
  20. *
  21. * Implements hook_entity_load().
  22. */
  23. function tripal_entities_entity_load($entities, $type) {
  24. }
  25. /**
  26. *
  27. * Implements hook_entity_insert().
  28. */
  29. function tripal_entities_entity_insert($entity, $type) {
  30. }
  31. /**
  32. *
  33. * Implements hook_entity_update().
  34. */
  35. function tripal_entities_entity_update($entity, $type) {
  36. }
  37. /**
  38. *
  39. * Implements hook_entity_delete().
  40. */
  41. function tripal_entities_entity_delete($entity, $type) {
  42. $record = db_select('chado_entity', 'ce')
  43. ->fields('ce', array('chado_entity_id', 'data_table', 'record_id'))
  44. ->condition('entity_id', $entity->id)
  45. ->execute()
  46. ->fetchObject();
  47. if ($record && property_exists($record, 'chado_entity_id')) {
  48. // Delete the corresponding record in Chado
  49. $table = $record->data_table;
  50. $record_id = $record->record_id;
  51. chado_delete_record($table, array($table . '_id' => $record_id));
  52. //Delete the record in the public.chado_entity table
  53. $sql = "DELETE FROM {chado_entity} WHERE chado_entity_id = :id";
  54. db_query($sql, array(':id' => $record->chado_entity_id));
  55. }
  56. }
  57. /**
  58. *
  59. * @param unknown $display
  60. * @param unknown $context
  61. */
  62. function tripal_entities_field_widget_form_alter(&$element, &$form_state, $context) {
  63. // The timelastmodified field exists in many Chado tables. We want
  64. // the form element to update to the most recent time rather than the time
  65. // in the database.
  66. if (array_key_exists('#field_name', $element)) {
  67. $field_name = $element['#field_name'];
  68. $matches = array();
  69. if (preg_match('/(.+?)__(.+?)$/', $field_name, $matches)) {
  70. $tablename = $matches[1];
  71. $colname = $matches[2];
  72. $schema = chado_get_schema($tablename);
  73. if ($colname == 'timelastmodified' and
  74. $schema['fields'][$colname]['type'] == 'datetime') {
  75. $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s");
  76. $element['#date_items']['value'] = $element['#default_value']['value'];
  77. }
  78. }
  79. }
  80. }
  81. /**
  82. * Implements hook_chado_field_alter().
  83. *
  84. */
  85. function tripal_entities_chado_field_alter(&$field) {
  86. // Here we provide new field types and widgets for FK fields
  87. // and fields that need special attention.
  88. if ($field['chado_column'] =='organism_id') {
  89. $field['field_type'] = 'organism_id';
  90. $field['widget_type'] = 'tripal_fields_organism_select_widget';
  91. $field['label'] = 'Organism';
  92. $field['description'] = 'Select an organism.';
  93. }
  94. else if ($field['chado_column'] =='dbxref_id') {
  95. $field['field_type'] = 'dbxref_id';
  96. $field['widget_type'] = 'tripal_fields_primary_dbxref_widget';
  97. $field['label'] = 'Primary Cross Reference';;
  98. $field['description'] = 'This record can be cross-referenced with a record in another online database. This field is intended for the most prominent reference. At a minimum, the database and accession must be provided.';
  99. }
  100. else if ($field['chado_table'] == 'feature' and
  101. $field['chado_column'] == 'md5checksum') {
  102. $field['field_type'] = 'md5checksum';
  103. $field['widget_type'] = 'tripal_fields_md5checksum_checkbox_widget';
  104. $field['label'] = 'MD5 Checksum';
  105. $field['description'] = 'Generating MD5 checksum for the sequence.';
  106. }
  107. else if ($field['chado_table'] == 'feature' and $field['chado_column'] == 'seqlen') {
  108. $field['field_type'] = 'seqlen';
  109. $field['widget_type'] = 'tripal_fields_seqlen_hidden_widget';
  110. $field['label'] = 'Seqlen';
  111. $field['description'] = 'The length of the residues.';
  112. }
  113. else if ($field['chado_table'] == 'feature' and $field['chado_column'] == 'residues') {
  114. $field['field_type'] = 'residues';
  115. $field['widget_type'] = 'tripal_fields_residues_textarea_widget';
  116. $field['label'] = 'Residues';
  117. $field['description'] = 'Please provide an IUPAC compatible residues for this feature. Spaces and new lines are allowed.';
  118. }
  119. }