TripalBundleController.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * The Controller for Tripal data type entities
  4. */
  5. class TripalBundleController extends EntityAPIControllerExportable {
  6. public function __construct($entityType) {
  7. parent::__construct($entityType);
  8. }
  9. /**
  10. * Create a type - we first set up the values that are specific
  11. * to our type schema but then also go through the EntityAPIController
  12. * function.
  13. *
  14. * @param $type
  15. * The machine-readable type of the tripal data entity.
  16. *
  17. * @return
  18. * A type object with all default fields initialized.
  19. */
  20. public function create(array $values = array()) {
  21. // Add values that are specific to our entity
  22. $values += array(
  23. 'id' => '',
  24. 'is_new' => TRUE,
  25. 'data' => '',
  26. );
  27. return parent::create($values);
  28. }
  29. /**
  30. * Overrides the parent delete function.
  31. *
  32. * @param $ids
  33. * @param DatabaseTransaction $transaction
  34. */
  35. public function delete($ids, DatabaseTransaction $transaction = NULL) {
  36. $entities = $ids ? $this->load($ids) : FALSE;
  37. if ($entities) {
  38. foreach ($entities as $id => $entity) {
  39. $bundle = tripal_load_bundle_entity(array('id' => $id));
  40. // Remove the terms for the bundles that are to be deleted.
  41. db_delete('tripal_term')
  42. ->condition('id', $bundle->term_id)
  43. ->execute();
  44. // Remove the chado_entity records for this type.
  45. }
  46. // Use the parent function to delete the bundles.
  47. parent::delete($ids, $transaction);
  48. // Not sure what this does, but copied from the
  49. // EntityAPIControllerExportable->delete() function which this one
  50. // overrides.
  51. foreach ($entities as $id => $entity) {
  52. if (entity_has_status($this->entityType, $entity, ENTITY_IN_CODE)) {
  53. entity_defaults_rebuild(array($this->entityType));
  54. break;
  55. }
  56. }
  57. }
  58. }
  59. }