tripal_entities.api.inc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Deletes a tripal_entity.
  4. */
  5. function tripal_entity_delete(TripalEntity $tripal_entity) {
  6. $tripal_entity->delete();
  7. }
  8. /**
  9. * Saves a tripal_entity to the database.
  10. *
  11. * @param $tripal_entity
  12. * The tripal_entity object.
  13. */
  14. function tripal_entity_save(TripalEntity $entity) {
  15. return $entity->save();
  16. }
  17. /**
  18. * Saves a tripal_entity type to the db.
  19. */
  20. function tripal_bundle_save(TripalBundle $entity) {
  21. $entity->save();
  22. }
  23. /**
  24. * Deletes a tripal_entity type from the db.
  25. */
  26. function tripal_bundle_delete(TripalBundle $type) {
  27. $type->delete();
  28. }
  29. /**
  30. * URI callback for tripal_entitys
  31. */
  32. function tripal_entity_uri(TripalEntity $entity){
  33. return array(
  34. 'path' => 'BioData/' . $entity->id,
  35. );
  36. }
  37. /**
  38. * TODO: The code for creating the title needs to be updated to not
  39. * use nodes but rather entities.
  40. *
  41. * @param unknown $node
  42. * @return mixed
  43. */
  44. function chado_get_entity_title($entity) {
  45. // Get the base table for the entity
  46. $details = db_select('chado_entity', 'ce')
  47. ->fields('ce')
  48. ->condition('entity_id', $entity->id)
  49. ->execute()
  50. ->fetchObject();
  51. $tablename = $details->data_table;
  52. $type_field = $details->field;
  53. $schema = chado_get_schema($tablename);
  54. $pkey_field = $schema['primary key'][0];
  55. $record_id = $details->record_id;
  56. $record = chado_generate_var($tablename, array($pkey_field => $record_id));
  57. // TODO: fix this so it's native for entities and doesn't expect nodes.
  58. // Fake a node
  59. $node = new stdClass();
  60. $node->$tablename = $record;
  61. // Get the tokens and format
  62. $tokens = array(); // this will be set by chado_node_get_title_format
  63. $title = chado_node_get_title_format('chado_' . $tablename, $tokens);
  64. // Determine which tokens were used in the format string
  65. if (preg_match_all('/\[[^]]+\]/', $title, $used_tokens)) {
  66. // Get the value for each token used
  67. foreach ($used_tokens[0] as $token) {
  68. $token_info = $tokens[$token];
  69. if (!empty($token_info)) {
  70. $value = chado_get_token_value($token_info, $node);
  71. $title = str_replace($token, $value, $title);
  72. }
  73. }
  74. }
  75. else {
  76. return $title;
  77. }
  78. return $title;
  79. }