tripal.admin.inc

File

tripal/includes/tripal.admin.inc
View source
  1. <?php
  2. /**
  3. *
  4. * @param unknown $form
  5. * @param unknown $form_state
  6. */
  7. function tripal_admin_data_collection_form($form, &$form_state) {
  8. $form = array();
  9. $options = array(0 => t('Disabled'), 1 => t('Enabled'));
  10. $form['enabled'] = array(
  11. '#type' => 'radios',
  12. '#title' => t('Activate Data Collections'),
  13. '#options' => $options,
  14. '#description' => t('Data collections allow users to save results of search queries for later download or use by other tools.'),
  15. '#default_value' => variable_get('tripal_data_collections_enabled', 1),
  16. '#required' => TRUE,
  17. );
  18. $form['lifespan'] = array(
  19. '#type' => 'textfield',
  20. '#title' => t('Collection Lifespan'),
  21. '#description' => t('Enter the number of days that data collections exist.
  22. Collections will be automatically removed after the lifespan
  23. period has passed. Removal of data collections occurs when the
  24. sites Drupal cron executes.'),
  25. '#default_value' => variable_get('tripal_data_collections_lifespan', 30),
  26. '#required' => TRUE,
  27. );
  28. $form['submit'] = array(
  29. '#type' => 'submit',
  30. '#value' => t('Save changes'),
  31. );
  32. return $form;
  33. }
  34. /**
  35. * Validate function for the tripal_admin_data_collection_form form.
  36. */
  37. function tripal_admin_data_collection_form_validate($form, &$form_state) {
  38. $enable = $form_state['values']['enabled'];
  39. $lifespan = $form_state['values']['lifespan'];
  40. if (!preg_match('/^\d+$/', $lifespan)) {
  41. form_set_error('filespan', 'Please provide a valid numeric value for the number of hours collections exist.');
  42. }
  43. else {
  44. if ($lifespan == 0) {
  45. form_set_error('filespan', 'Please provide a positive numeric value for the number of hours collections exist.');
  46. }
  47. }
  48. }
  49. /**
  50. * Sumbit function for the tripal_admin_data_collection_form form.
  51. */
  52. function tripal_admin_data_collection_form_submit($form, &$form_state) {
  53. $enabled = $form_state['values']['enabled'];
  54. $lifespan = $form_state['values']['lifespan'];
  55. variable_set('tripal_data_collections_enabled', $enabled);
  56. variable_set('tripal_data_collections_lifespan', $lifespan);
  57. menu_cache_clear_all();
  58. drupal_set_message('Settings saved.');
  59. }
  60. /**
  61. * Provides a form for importing vocabularies and their terms.
  62. *
  63. * Tripal allows for vocabularies to be stored separately from the biological
  64. * data. By default, the Tripal Chado module uses Chado for both the data
  65. * storage backend and for storing controlled vocabularies. This is a wrapper
  66. * function that calls the hook_vocab_import_form() hook function that allows
  67. * the term storage backend to provide an approprite import form.
  68. *
  69. * @param $form
  70. * @param $form_state
  71. *
  72. */
  73. function tripal_vocabulary_import_form($form, &$form_state) {
  74. // TODO: we need some sort of administrative interface that lets the user
  75. // switch to the desired vocabulary type. For now, we'll just use the
  76. // first one in the list.
  77. $stores = module_invoke_all('vocab_storage_info');
  78. if (is_array($stores) and count($stores) > 0) {
  79. $keys = array_keys($stores);
  80. $module = $stores[$keys[0]]['module'];
  81. $function = $module . '_vocab_import_form';
  82. if (function_exists($function)) {
  83. $form = $function($form, $form_state);
  84. }
  85. else {
  86. drupal_set_message("The function '$function' is not implemented. Cannot import vocabularies.", 'error');
  87. }
  88. }
  89. else {
  90. tripal_set_message('A storage backend is not enabled for managing
  91. the vocabulary terms used to create content. Please enable
  92. a module that supports storage of vocabualary terms (e.g. tripal_chado)
  93. and return to create new Tripal content types.', TRIPAL_NOTICE);
  94. }
  95. return $form;
  96. }
  97. /**
  98. *
  99. * @param $form
  100. * @param $form_state
  101. */
  102. function tripal_vocabulary_import_form_validate($form, &$form_state) {
  103. // TODO: we need some sort of administrative interface that lets the user
  104. // switch to the desired vocabulary type. For now, we'll just use the
  105. // first one in the list.
  106. $stores = module_invoke_all('vocab_storage_info');
  107. if (is_array($stores) and count($stores) > 0) {
  108. $keys = array_keys($stores);
  109. $module = $stores[$keys[0]]['module'];
  110. $function = $module . '_vocab_import_form_validate';
  111. if (function_exists($function)) {
  112. $form = $function($form, $form_state);
  113. }
  114. else {
  115. drupal_set_message("The function '$function' is not implemented. Cannot import vocabularies.", 'error');
  116. }
  117. }
  118. else {
  119. tripal_set_message('A storage backend is not enabled for managing
  120. the vocabulary terms used to create content. Please enable
  121. a module that supports storage of vocabualary terms (e.g. tripal_chado)
  122. and return to create new Tripal content types.', TRIPAL_NOTICE);
  123. }
  124. return $form;
  125. }
  126. /**
  127. *
  128. * @param $form
  129. * @param $form_state
  130. */
  131. function tripal_vocabulary_import_form_submit($form, &$form_state) {
  132. // TODO: we need some sort of administrative interface that lets the user
  133. // switch to the desired vocabulary type. For now, we'll just use the
  134. // first one in the list.
  135. $stores = module_invoke_all('vocab_storage_info');
  136. if (is_array($stores) and count($stores) > 0) {
  137. $keys = array_keys($stores);
  138. $module = $stores[$keys[0]]['module'];
  139. $function = $module . '_vocab_import_form_submit';
  140. if (function_exists($function)) {
  141. $form = $function($form, $form_state);
  142. }
  143. else {
  144. drupal_set_message("The function '$function' is not implemented. Cannot import vocabularies.", 'error');
  145. }
  146. }
  147. else {
  148. tripal_set_message('A storage backend is not enabled for managing
  149. the vocabulary terms used to create content. Please enable
  150. a module that supports storage of vocabualary terms (e.g. tripal_chado)
  151. and return to create new Tripal content types.', TRIPAL_NOTICE);
  152. }
  153. return $form;
  154. }