tripal.admin_blocks.inc

File

tripal/includes/tripal.admin_blocks.inc
View source
  1. <?php
  2. /**
  3. *
  4. * Import the field from the admin notification table on the dashboard.
  5. *
  6. * @param $field_or_instance
  7. * The name of the field to be imported.
  8. * * @param $bundle_id
  9. * The ID of the bundle associated with that field.
  10. * @param $field_name_note
  11. * @param $module
  12. *
  13. *
  14. * @return bool
  15. */
  16. function tripal_admin_notification_import_field($field_name_note, $bundle_id, $module, $field_or_instance) {
  17. // Get the bundle object.
  18. $bundle = tripal_load_bundle_entity(array('name' => $bundle_id));
  19. if (!$bundle) {
  20. tripal_report_error('tripal', TRIPAL_ERROR, "Unrecognized bundle name '%bundle'.",
  21. array('%bundle' => $bundle_id));
  22. drupal_goto("admin/dashboard");
  23. return FALSE;
  24. }
  25. if($field_or_instance == 'field'){
  26. $function = $module . '_bundle_fields_info';
  27. $info = $function('TripalEntity', $bundle);
  28. foreach ($info as $field_name => $details) {
  29. $field = field_info_field($field_name);
  30. if($details['field_name'] == $field_name_note) {
  31. // Create the field.
  32. $instance = field_create_field($details);
  33. drupal_set_message(t("Created field: %field", array('%field' => $field['label'])));
  34. if (!$instance) {
  35. tripal_set_message(t("Could not create new field: %field.",
  36. array('%field' => $field_name_note)), TRIPAL_ERROR);
  37. }
  38. }
  39. }
  40. }
  41. else if($field_or_instance == 'instance'){
  42. $function = $module . '_bundle_instances_info';
  43. $info = $function('TripalEntity', $bundle);
  44. foreach ($info as $field_name => $details) {
  45. if($details['field_name'] == $field_name_note) {
  46. // Create the field instance.
  47. $instance = field_create_instance($details);
  48. drupal_set_message(t("Created field: %field", array('%field' => $info[ $field_name ]['label'])));
  49. if (!$instance) {
  50. tripal_set_message(t("Could not create new field: %field.",
  51. array('%field' => $field_name_note)), TRIPAL_ERROR);
  52. }
  53. }
  54. }
  55. }
  56. $submitter_id = $field_name_note . '-' . $bundle_id . '-' . $module;
  57. if($instance){
  58. // Delete the notification table entry.
  59. db_delete('tripal_admin_notfications')
  60. ->condition('submitter_id', $submitter_id, '=')
  61. ->execute();
  62. }
  63. else {
  64. drupal_set_message(t("There was a problem creating: %field", array('%field' => $info[ $field_name ]['label'])));
  65. }
  66. drupal_goto("admin/dashboard");
  67. }
  68. /**
  69. * Disable the notification of the field on the dashboard.
  70. *
  71. * @param $note_id
  72. * The ID of the note in the tripal_admin_notifications table
  73. * that will be dismissed.
  74. */
  75. function tripal_disable_admin_notification($note_id) {
  76. $success = db_update('tripal_admin_notfications')
  77. ->fields(array(
  78. 'enabled' => 0,
  79. ))
  80. ->condition('note_id', $note_id, '=')
  81. ->execute();
  82. if($success){
  83. drupal_set_message("That notification has been dismissed and will no longer appear.");
  84. }
  85. else {
  86. drupal_set_message("Could not dismiss notification.", 'error');
  87. }
  88. drupal_goto("admin/dashboard");
  89. }