tripal_feature.admin.inc 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /**
  3. * @file
  4. * Administration of features
  5. */
  6. /**
  7. * Launchpad for feature administration.
  8. *
  9. * @ingroup tripal_feature
  10. */
  11. function tripal_feature_admin_feature_view() {
  12. $output = '';
  13. // set the breadcrumb
  14. $breadcrumb = array();
  15. $breadcrumb[] = l('Home', '<front>');
  16. $breadcrumb[] = l('Administration', 'admin');
  17. $breadcrumb[] = l('Tripal', 'admin/tripal');
  18. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  19. $breadcrumb[] = l('Features', 'admin/tripal/chado/tripal_feature');
  20. drupal_set_breadcrumb($breadcrumb);
  21. // Add the view
  22. $view = views_embed_view('tripal_feature_admin_features','default');
  23. if (isset($view)) {
  24. $output .= $view;
  25. }
  26. else {
  27. $output .= '<p>The Feature module uses primarily views to provide an '
  28. . 'administrative interface. Currently one or more views needed for this '
  29. . 'administrative interface are disabled. <strong>Click each of the following links to '
  30. . 'enable the pertinent views</strong>:</p>';
  31. $output .= '<ul>';
  32. $output .= '<li>'.l('Features View', 'admin/tripal/chado/tripal_feature/views/features/enable').'</li>';
  33. $output .= '</ul>';
  34. }
  35. return $output;
  36. }
  37. /**
  38. * Feature Settings page
  39. *
  40. * @ingroup tripal_feature
  41. */
  42. function tripal_feature_admin() {
  43. // FEATURE PAGE TITLES
  44. // Using the Chado Node: Title & Path API
  45. $details = array(
  46. 'module' => 'tripal_feature',
  47. 'content_type' => 'chado_feature',
  48. // An array of options to use under "Page Titles"
  49. // the key should be the token and the value should be the human-readable option
  50. 'options' => array(
  51. '[feature.name]' => 'Feature Name Only',
  52. '[feature.uniquename]' => 'Feature Unique Name Only',
  53. // there should always be one options matching the unique constraint.
  54. '[feature.name], [feature.uniquename] ([feature.type_id>cvterm.name]) [feature.organism_id>organism.genus] [feature.organism_id>organism.species]' => 'Unique Contraint: Includes the name, uniquename, type and scientific name'
  55. ),
  56. // the token indicating the unique constraint in the options array
  57. 'unique_option' => '[feature.name], [feature.uniquename] ([feature.type_id>cvterm.name]) [feature.organism_id>organism.genus] [feature.organism_id>organism.species]'
  58. );
  59. // This call adds the configuration form to your current form
  60. // This sub-form handles it's own validation & submit
  61. chado_add_admin_form_set_title($form, $form_state, $details);
  62. // FEATURE URL PATHS
  63. $form['url'] = array(
  64. '#type' => 'fieldset',
  65. '#title' => t('Feature URL Path'),
  66. '#collapsible' => FALSE,
  67. '#collapsed' => FALSE,
  68. );
  69. $options = array(
  70. 'SID[id]' => '[id]:' . t('The Chado feature_id'),
  71. 'feature' => 'feature:' . t('Chado table name'),
  72. '[genus]' => '[genus]:' . t('Genus to which the feature belongs'),
  73. '[species]' => '[species]:' . t('Species to which the feature belongs'),
  74. '[type]' => '[type]:' . t('The type of feature'),
  75. '[uniquename]' => '[uniquename]:' . t('The feature unique name'),
  76. '[name]' => '[name]:' . t('The feature name'),
  77. 'reset' => t('Reset'),
  78. );
  79. $form['url']['chado_feature_url_string'] = array(
  80. '#title' => 'URL Syntax',
  81. '#type' => 'textfield',
  82. '#description' => t('You may rearrange elements in this text box to '.
  83. 'customize the URLs. The available tags include: [id], '.
  84. '[uniquename]. [name], [species], [genus], [type]. You can separate or '.
  85. 'include any text between the tags. Click the "Set Feature URLs" button to '.
  86. 'reset the URLs for all feature pages. Click the "Save Configuration" button to '.
  87. 'simply save this setup. <b>Important</b>: be sure that whatever you choose will always be unique even considering '.
  88. 'future data that may be added. If you include the Chado table name, genus, species, type '.
  89. 'and uniquename you are guaranteed to have a unique URL. For example feature/[genus]/[species]/[type]/[uniquename]'),
  90. '#size' => 150,
  91. '#default_value' => variable_get('chado_feature_url_string', '/feature/[genus]/[species]/[type]/[uniquename]'),
  92. );
  93. $form['url']['chado_feature_url'] = array(
  94. '#title' => t('URL components'),
  95. '#type' => 'checkboxes',
  96. '#required' => FALSE,
  97. '#options' => $options,
  98. '#description' => t('Click the item above to make it appear in the URL Syntax box'),
  99. '#attributes' => array(
  100. 'onclick' => '
  101. box = $(\'#edit-chado-feature-url-string\');
  102. if (this.value == \'reset\') {
  103. box.val(\'\');
  104. }
  105. else {
  106. box.val(box.val() + "/" + this.value);
  107. }
  108. this.checked = false;
  109. ',
  110. ),
  111. );
  112. $form['url']['button'] = array(
  113. '#type' => 'submit',
  114. '#value' => t('Set Feature URLs'),
  115. );
  116. // FEATURE BROWSER
  117. $form['browser'] = array(
  118. '#type' => 'fieldset',
  119. '#title' => t('Feature Browser'),
  120. '#collapsible' => FALSE,
  121. '#collapsed' => FALSE,
  122. );
  123. $form['browser']['browser_desc'] = array(
  124. '#markup' => t('A feature browser can be added to an organism page to allow users to quickly ' .
  125. 'access a feature. This will most likely not be the ideal mechanism for accessing feature ' .
  126. 'information, especially for large sites, but it will alow users exploring the site (such ' .
  127. 'as students) to better understand the data types available on the site.'),
  128. );
  129. $form['browser']['feature_types'] = array(
  130. '#title' => t('Feature Types'),
  131. '#type' => 'textarea',
  132. '#description' => t("Enter the Sequence Ontology (SO) terms for the feature types that " .
  133. "will be shown in the feature browser."),
  134. '#default_value' => variable_get('chado_browser_feature_types', 'gene mRNA'),
  135. );
  136. $form['browser']['set_browse_button'] = array(
  137. '#type' => 'submit',
  138. '#value' => t('Set Browser'),
  139. '#weight' => 2,
  140. );
  141. // FEATURE SUMMARY REPORT
  142. $form['summary'] = array(
  143. '#type' => 'fieldset',
  144. '#title' => t('Feature Summary Report'),
  145. '#collapsible' => FALSE,
  146. '#collapsed' => FALSE,
  147. );
  148. $form['summary']['feature_mapping'] = array(
  149. '#title' => 'Map feature types',
  150. '#description' => t('You may specify which Sequence Ontology (SO) terms to show in the ' .
  151. 'feature summary report by listing them in the following text area. Enter one per line. ' .
  152. 'If left blank, all SO terms for all features will be shown in the report. Only those terms ' .
  153. 'listed below will be shown in the report. Terms will appear in the report in the same order listed. To rename a ' .
  154. 'SO term to be more human readable form, use an \'=\' sign after the SO term (e.g. \'polypeptide = Protein\')'),
  155. '#type' => 'textarea',
  156. '#rows' => 15,
  157. '#default_value' => variable_get('tripal_feature_summary_report_mapping', ''),
  158. );
  159. $form['summary']['set_summary_button'] = array(
  160. '#type' => 'submit',
  161. '#value' => t('Set Summary'),
  162. '#weight' => 2,
  163. );
  164. return system_settings_form($form);
  165. }
  166. /**
  167. * Validate the feature settings forms
  168. *
  169. * @ingroup tripal_feature
  170. */
  171. function tripal_feature_admin_validate($form, &$form_state) {
  172. global $user; // we need access to the user info
  173. $job_args = array();
  174. variable_set('chado_browser_feature_types', $form_state['values']['feature_types']);
  175. switch ($form_state['values']['op']) {
  176. case t('Set Summary') :
  177. variable_set('tripal_feature_summary_report_mapping', $form_state['values']['feature_mapping']);
  178. break;
  179. case t('Set Feature URLs') :
  180. variable_set('chado_feature_url_string', $form_state['values']['chado_feature_url_string']);
  181. tripal_add_job('Set Feature URLs', 'tripal_feature',
  182. 'tripal_feature_set_urls', $job_args, $user->uid);
  183. break;
  184. }
  185. }