tripal_contact.admin.inc

  1. 2.x tripal_contact/includes/tripal_contact.admin.inc
  2. 3.x legacy/tripal_contact/includes/tripal_contact.admin.inc
  3. 1.x tripal_contact/includes/tripal_contact.admin.inc

File

tripal_contact/includes/tripal_contact.admin.inc
View source
  1. <?php
  2. /**
  3. * Administrative settings form
  4. *
  5. * @ingroup tripal_contact
  6. */
  7. function tripal_contact_admin() {
  8. $form = array();
  9. // before proceeding check to see if we have any
  10. // currently processing jobs. If so, we don't want
  11. // to give the opportunity to sync maps
  12. $active_jobs = FALSE;
  13. if (tripal_get_module_active_jobs('tripal_contact')) {
  14. $active_jobs = TRUE;
  15. }
  16. // add the field set for syncing maps
  17. if (!$active_jobs) {
  18. get_tripal_contact_admin_form_cleanup_set($form);
  19. // TODO: complete coding of indexing and taxonomy assignment to features.
  20. // get_tripal_contact_admin_form_reindex_set($form);
  21. // get_tripal_contact_admin_form_taxonomy_set($form);
  22. }
  23. else {
  24. $form['notice'] = array(
  25. '#type' => 'fieldset',
  26. '#title' => t('Feature Map Management Temporarily Unavailable')
  27. );
  28. $form['notice']['message'] = array(
  29. '#value' => t('Currently, feature map management jobs are waiting or are running. Managemment features have been hidden until these jobs complete. Please check back later once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.'),
  30. );
  31. }
  32. return system_settings_form($form);
  33. }
  34. /**
  35. *
  36. *
  37. * @ingroup tripal_contact
  38. */
  39. function get_tripal_contact_admin_form_cleanup_set(&$form) {
  40. $form['cleanup'] = array(
  41. '#type' => 'fieldset',
  42. '#title' => t('Clean Up')
  43. );
  44. $form['cleanup']['description'] = array(
  45. '#type' => 'item',
  46. '#value' => t("With Drupal and chado residing in different databases ".
  47. "it is possible that nodes in Drupal and maps in Chado become ".
  48. "\"orphaned\". This can occur if an map node in Drupal is ".
  49. "deleted but the corresponding chado map is not and/or vice ".
  50. "versa. Click the button below to resolve these discrepancies."),
  51. '#weight' => 1,
  52. );
  53. $form['cleanup']['button'] = array(
  54. '#type' => 'submit',
  55. '#value' => t('Clean up orphaned maps'),
  56. '#weight' => 2,
  57. );
  58. }
  59. /**
  60. *
  61. * @ingroup tripal_contact
  62. */
  63. function get_tripal_contact_admin_form_reindex_set(&$form) {
  64. // define the fieldsets
  65. $form['reindex'] = array(
  66. '#type' => 'fieldset',
  67. '#title' => t('Reindex Map Features')
  68. );
  69. // get the list of maps
  70. $sql = "SELECT * FROM {contact} ORDER BY name";
  71. $lib_rset = chado_query($sql);
  72. // iterate through all of the maps
  73. $lib_boxes = array();
  74. while ($contact = db_fetch_object($lib_rset)) {
  75. $lib_boxes[$contact->contact_id] = "$contact->name";
  76. }
  77. $form['reindex']['description'] = array(
  78. '#type' => 'item',
  79. '#value' => t("This option allows for reindexing of only those features that belong to the selected maps below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."),
  80. '#weight' => 1,
  81. );
  82. $form['reindex']['re-maps'] = array(
  83. '#title' => t('Contacts'),
  84. '#type' => t('checkboxes'),
  85. '#description' => t("Check the maps whoee features you want to reindex. Note: this list contains all maps, even those that may not be synced."),
  86. '#required' => FALSE,
  87. '#prefix' => '<div id="lib_boxes">',
  88. '#suffix' => '</div>',
  89. '#options' => $lib_boxes,
  90. '#weight' => 2,
  91. );
  92. $form['reindex']['re-button'] = array(
  93. '#type' => 'submit',
  94. '#value' => t('Reindex Features'),
  95. '#weight' => 3,
  96. );
  97. }
  98. /**
  99. *
  100. * @ingroup tripal_contact
  101. */
  102. function tripal_contact_admin_validate($form, &$form_state) {
  103. global $user; // we need access to the user info
  104. $job_args = array();
  105. // -------------------------------------
  106. // Submit the Reindex Job if selected
  107. if ($form_state['values']['op'] == t('Reindex Features')) {
  108. $contacts = $form_state['values']['re-maps'];
  109. foreach ($contacts as $contact_id) {
  110. if ($contact_id and preg_match("/^\d+$/i", $contact_id)) {
  111. // get the map info
  112. $sql = "SELECT * FROM {contact} WHERE contact_id = %d";
  113. $contact = db_fetch_object(chado_query($sql, $contact_id));
  114. $job_args[0] = $contact_id;
  115. tripal_add_job("Reindex features for map: $contact->name", 'tripal_contact',
  116. 'tripal_contact_reindex_features', $job_args, $user->uid);
  117. }
  118. }
  119. }
  120. // -------------------------------------
  121. // Submit the Cleanup Job if selected
  122. if ($form_state['values']['op'] == t('Clean up orphaned maps')) {
  123. tripal_add_job('Cleanup orphaned maps', 'tripal_contact',
  124. 'tripal_contact_cleanup', $job_args, $user->uid);
  125. }
  126. }
  127. /**
  128. * Remove orphaned drupal nodes
  129. *
  130. * @param $dummy
  131. * Not Used -kept for backwards compatibility
  132. * @param $job_id
  133. * The id of the tripal job executing this function
  134. *
  135. * @ingroup tripal_contact
  136. */
  137. function tripal_contact_cleanup($dummy = NULL, $job_id = NULL) {
  138. return tripal_core_clean_orphaned_nodes('contact', $job_id);
  139. }
  140. /**
  141. * Add the map as a taxonomy term for associating with map_features
  142. *
  143. * @ingroup tripal_contact
  144. */
  145. function tripal_contact_add_taxonomy($node, $contact_id) {
  146. }