tripal_entities.chado_entity.inc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. }