tripal_contact.admin.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. *
  4. */
  5. function tripal_contact_admin_contact_view() {
  6. $output = '';
  7. // set the breadcrumb
  8. $breadcrumb = array();
  9. $breadcrumb[] = l('Home', '<front>');
  10. $breadcrumb[] = l('Administration', 'admin');
  11. $breadcrumb[] = l('Tripal', 'admin/tripal');
  12. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  13. $breadcrumb[] = l('Contacts', 'admin/tripal/chado/tripal_contact');
  14. drupal_set_breadcrumb($breadcrumb);
  15. // Add the view
  16. $view = views_embed_view('tripal_contact_admin_contacts','default');
  17. if (isset($view)) {
  18. $output .= $view;
  19. }
  20. else {
  21. $output .= '<p>The Contact module uses primarily views to provide an '
  22. . 'administrative interface. Currently one or more views needed for this '
  23. . 'administrative interface are disabled. <strong>Click each of the following links to '
  24. . 'enable the pertinent views</strong>:</p>';
  25. $output .= '<ul>';
  26. $output .= '<li>'.l('Contacts View', 'admin/tripal/chado/tripal_contact/views/contacts/enable').'</li>';
  27. $output .= '</ul>';
  28. }
  29. return $output;
  30. }
  31. /**
  32. * Administrative settings form
  33. *
  34. * @ingroup tripal_contact
  35. */
  36. function tripal_contact_admin() {
  37. $form = array();
  38. // before proceeding check to see if we have any
  39. // currently processing jobs. If so, we don't want
  40. // to give the opportunity to sync maps
  41. $active_jobs = FALSE;
  42. if (tripal_get_module_active_jobs('tripal_contact')) {
  43. $active_jobs = TRUE;
  44. }
  45. // add the field set for syncing maps
  46. if (!$active_jobs) {
  47. get_tripal_contact_admin_form_cleanup_set($form);
  48. // TODO: complete coding of indexing and taxonomy assignment to features.
  49. // get_tripal_contact_admin_form_reindex_set($form);
  50. // get_tripal_contact_admin_form_taxonomy_set($form);
  51. }
  52. else {
  53. $form['notice'] = array(
  54. '#type' => 'fieldset',
  55. '#title' => t('Feature Map Management Temporarily Unavailable')
  56. );
  57. $form['notice']['message'] = array(
  58. '#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.'),
  59. );
  60. }
  61. return system_settings_form($form);
  62. }
  63. /**
  64. *
  65. *
  66. * @ingroup tripal_contact
  67. */
  68. function get_tripal_contact_admin_form_cleanup_set(&$form) {
  69. $form['cleanup'] = array(
  70. '#type' => 'fieldset',
  71. '#title' => t('Clean Up')
  72. );
  73. $form['cleanup']['description'] = array(
  74. '#type' => 'item',
  75. '#value' => t("With Drupal and chado residing in different databases ".
  76. "it is possible that nodes in Drupal and maps in Chado become ".
  77. "\"orphaned\". This can occur if an map node in Drupal is ".
  78. "deleted but the corresponding chado map is not and/or vice ".
  79. "versa. Click the button below to resolve these discrepancies."),
  80. '#weight' => 1,
  81. );
  82. $form['cleanup']['button'] = array(
  83. '#type' => 'submit',
  84. '#value' => t('Clean up orphaned maps'),
  85. '#weight' => 2,
  86. );
  87. }
  88. /**
  89. *
  90. * @ingroup tripal_contact
  91. */
  92. function get_tripal_contact_admin_form_reindex_set(&$form) {
  93. // define the fieldsets
  94. $form['reindex'] = array(
  95. '#type' => 'fieldset',
  96. '#title' => t('Reindex Map Features')
  97. );
  98. // get the list of maps
  99. $sql = "SELECT * FROM {contact} ORDER BY name";
  100. $lib_rset = chado_query($sql);
  101. // iterate through all of the maps
  102. $lib_boxes = array();
  103. while ($contact = $lib_rset->fetchObject()) {
  104. $lib_boxes[$contact->contact_id] = "$contact->name";
  105. }
  106. $form['reindex']['description'] = array(
  107. '#type' => 'item',
  108. '#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."),
  109. '#weight' => 1,
  110. );
  111. $form['reindex']['re-maps'] = array(
  112. '#title' => t('Contacts'),
  113. '#type' => t('checkboxes'),
  114. '#description' => t("Check the maps whoee features you want to reindex. Note: this list contains all maps, even those that may not be synced."),
  115. '#required' => FALSE,
  116. '#prefix' => '<div id="lib_boxes">',
  117. '#suffix' => '</div>',
  118. '#options' => $lib_boxes,
  119. '#weight' => 2,
  120. );
  121. $form['reindex']['re-button'] = array(
  122. '#type' => 'submit',
  123. '#value' => t('Reindex Features'),
  124. '#weight' => 3,
  125. );
  126. }
  127. /**
  128. *
  129. * @ingroup tripal_contact
  130. */
  131. function tripal_contact_admin_validate($form, &$form_state) {
  132. global $user; // we need access to the user info
  133. $job_args = array();
  134. // -------------------------------------
  135. // Submit the Reindex Job if selected
  136. if ($form_state['values']['op'] == t('Reindex Features')) {
  137. $contacts = $form_state['values']['re-maps'];
  138. foreach ($contacts as $contact_id) {
  139. if ($contact_id and preg_match("/^\d+$/i", $contact_id)) {
  140. // get the map info
  141. $sql = "SELECT * FROM {contact} WHERE contact_id = :contact_id";
  142. $contact = chado_query($sql, array(':contact_id' => $contact_id))->fetchObject();
  143. $job_args[0] = $contact_id;
  144. tripal_add_job("Reindex features for map: $contact->name", 'tripal_contact',
  145. 'tripal_contact_reindex_features', $job_args, $user->uid);
  146. }
  147. }
  148. }
  149. // -------------------------------------
  150. // Submit the Cleanup Job if selected
  151. if ($form_state['values']['op'] == t('Clean up orphaned maps')) {
  152. tripal_add_job('Cleanup orphaned maps', 'tripal_contact',
  153. 'tripal_contact_cleanup', $job_args, $user->uid);
  154. }
  155. }
  156. /**
  157. * Remove orphaned drupal nodes
  158. *
  159. * @param $dummy
  160. * Not Used -kept for backwards compatibility
  161. * @param $job_id
  162. * The id of the tripal job executing this function
  163. *
  164. * @ingroup tripal_contact
  165. */
  166. function tripal_contact_cleanup($dummy = NULL, $job_id = NULL) {
  167. return tripal_core_clean_orphaned_nodes('contact', $job_id);
  168. }
  169. /**
  170. * Add the map as a taxonomy term for associating with map_features
  171. *
  172. * @ingroup tripal_contact
  173. */
  174. function tripal_contact_add_taxonomy($node, $contact_id) {
  175. }