tripal_phylogeny.admin.inc

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

This file contains the functions used for administration of the module

File

tripal_phylogeny/includes/tripal_phylogeny.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the functions used for administration of the module
  5. *
  6. */
  7. function tripal_phylogeny_admin_phylotrees_listing() {
  8. $output = '';
  9. // set the breadcrumb
  10. $breadcrumb = array();
  11. $breadcrumb[] = l('Home', '<front>');
  12. $breadcrumb[] = l('Administration', 'admin');
  13. $breadcrumb[] = l('Tripal', 'admin/tripal');
  14. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  15. $breadcrumb[] = l('Phylotrees', 'admin/tripal/extension/tripal_phylogeny');
  16. drupal_set_breadcrumb($breadcrumb);
  17. // Add the view
  18. $view = views_embed_view('tripal_phylogeny_admin_phylotree','default');
  19. if (isset($view)) {
  20. $output .= $view;
  21. }
  22. else {
  23. $output .= '<p>The Phylotree module uses primarily views to provide an '
  24. . 'administrative interface. Currently one or more views needed for this '
  25. . 'administrative interface are disabled. <strong>Click each of the following links to '
  26. . 'enable the pertinent views</strong>:</p>';
  27. $output .= '<ul>';
  28. $output .= '<li>'.l('Phylotree View', 'admin/tripal/extension/tripal_phylogeny/views/phylotree/enable').'</li>';
  29. $output .= '</ul>';
  30. }
  31. return $output;
  32. }
  33. /**
  34. * Administrative settings form
  35. *
  36. * @ingroup tripal_phylogeny
  37. */
  38. function tripal_phylogeny_admin() {
  39. $form = array();
  40. // PHYLOTREE NODE TITLES
  41. // If your module is using the Chado Node: Title & Path API to allow
  42. // custom titles for your node type then you need to add the
  43. // configuration form for this functionality.
  44. $details = array(
  45. 'module' => 'tripal_phylogeny',
  46. 'content_type' => 'chado_phylotree',
  47. // An array of options to use under "Page Titles"
  48. // the key should be the token and the value should be the human-readable option
  49. 'options' => array(
  50. '[phylotree.name]' => 'Tree Name Only',
  51. // there should always be one options matching the unique constraint.
  52. '[phylotree.phylotree_id]' => 'The Chado ID for Phylotrees'
  53. ),
  54. // the token indicating the unique constraint in the options array
  55. 'unique_option' => '[phylotree.phylotree_id]'
  56. );
  57. // This call adds the configuration form to your current form
  58. // This sub-form handles it's own validation & submit
  59. chado_add_admin_form_set_title($form, $form_state, $details);
  60. // PHYLOTREE NODE URL
  61. // Using the Chado Node: Title & Path API
  62. $details = array(
  63. 'module' => 'tripal_phylogeny',
  64. 'content_type' => 'chado_phylotree',
  65. // An array of options to use under "Page URL"
  66. // the key should be the token and the value should be the human-readable option
  67. 'options' => array(
  68. '/tree/[phylotree.name]' => 'Tree Name Only',
  69. // there should always be one options matching the unique constraint.
  70. '/tree/[phylotree.phylotree_id]' => 'The Chado ID for Phylotrees',
  71. )
  72. );
  73. // This call adds the configuration form to your current form
  74. // This sub-form handles it's own validation & submit
  75. chado_add_admin_form_set_url($form, $form_state, $details);
  76. return system_settings_form($form);
  77. }
  78. /**
  79. *
  80. * @param unknown $form
  81. * @param unknown $form_state
  82. */
  83. function tripal_phylogeny_default_plots_form($form, &$form_state) {
  84. $form = array();
  85. $form['plot_settings'] = array(
  86. '#type' => 'fieldset',
  87. '#title' => t('Plot Settings'),
  88. '#description' => t('You can customize settings for each plot'),
  89. '#collapsible' => TRUE,
  90. '#collapsed' => FALSE
  91. );
  92. $form['plot_settings']['phylogram_width'] = array(
  93. '#type' => 'textfield',
  94. '#title' => 'Tree Width',
  95. '#description' => 'Please specify the width in pixels for the phylogram',
  96. '#default_value' => variable_get('tripal_phylogeny_default_phylogram_width', 350),
  97. '#element_validate' => array(
  98. 'element_validate_integer_positive'
  99. ),
  100. '#size' => 5,
  101. );
  102. $form['node_settings'] = array(
  103. '#type' => 'fieldset',
  104. '#title' => t('Node Settings'),
  105. '#description' => t('You can customize settings for the nodes on the trees.'),
  106. '#collapsible' => TRUE,
  107. '#collapsed' => FALSE
  108. );
  109. $form['node_settings']['root_node_size'] = array(
  110. '#type' => 'textfield',
  111. '#title' => 'Root Node Size',
  112. '#description' => 'Please specify a size for the root node size. If set to zero, the node will not appear.',
  113. '#default_value' => variable_get('tripal_phylogeny_default_root_node_size', 3),
  114. '#element_validate' => array(
  115. 'element_validate_integer'
  116. ),
  117. '#size' => 3,
  118. );
  119. $form['node_settings']['interior_node_size'] = array(
  120. '#type' => 'textfield',
  121. '#title' => 'Interor Node Size',
  122. '#description' => 'Please specify a size for the interior node size. If set to zero, the node will not appear.',
  123. '#default_value' => variable_get('tripal_phylogeny_default_interior_node_size', 0),
  124. '#element_validate' => array(
  125. 'element_validate_integer'
  126. ),
  127. '#size' => 3,
  128. );
  129. $form['node_settings']['leaf_node_size'] = array(
  130. '#type' => 'textfield',
  131. '#title' => 'Leaf Node Size',
  132. '#description' => 'Please specify a size for the leaf node size. If set to zero, the node will not appear.',
  133. '#default_value' => variable_get('tripal_phylogeny_default_leaf_node_size', 6),
  134. '#element_validate' => array(
  135. 'element_validate_integer'
  136. ),
  137. '#size' => 3,
  138. );
  139. // Get the number of organism colors that already exist. If the site admin
  140. // has set colors then those settings will be in a Drupal variable which we
  141. // will retrieve. Otherwise the num_orgs defaults to 1 and a single
  142. // set of fields is provided.
  143. $num_orgs = variable_get("tripal_phylogeny_num_orgs", 1);
  144. if (array_key_exists('values', $form_state) and array_key_exists('num_orgs', $form_state['values'])) {
  145. $num_orgs = $form_state['values']['num_orgs'];
  146. }
  147. // The default values for each organism color are provided in a d
  148. // Drupal variable that gets set when the form is set.
  149. $color_defaults = variable_get("tripal_phylogeny_org_colors", array('1' => array('organism' => '', 'color' => '')));
  150. $form['node_settings']['desc'] = array(
  151. '#type' => 'item',
  152. '#title' => t('Node Colors by Organism'),
  153. '#markup' => t('If the trees are associated with features (e.g. proteins)
  154. then the nodes can be color-coded by their organism. This helps the user
  155. visualize which nodes belong to each organism. Please enter the
  156. name of the organism and it\'s corresponding color in HEX code (e.g. #FF0000 == red).
  157. Organisms that are not given a color will be gray.'),
  158. );
  159. $form['node_settings']['org_table']['num_orgs'] = array(
  160. '#type' => 'value',
  161. '#value' => $num_orgs,
  162. );
  163. // Iterate through the number of organism colors and add a field for each one.
  164. for ($i = 0; $i < $num_orgs; $i++) {
  165. $form['node_settings']['org_table']['organism_' . $i] = array(
  166. '#type' => 'textfield',
  167. '#default_value' => array_key_exists($i, $color_defaults) ? $color_defaults[$i]['organism'] : '',
  168. '#autocomplete_path' => "admin/tripal/chado/tripal_organism/organism/auto_name",
  169. '#description' => t('Please enter the name of the organism.'),
  170. '#size' => 30,
  171. );
  172. $form['node_settings']['org_table']['color_' . $i] = array(
  173. '#type' => 'textfield',
  174. '#description' => t('Please provide a color in Hex format (e.g. #FF0000).'),
  175. '#default_value' => array_key_exists($i, $color_defaults) ? $color_defaults[$i]['color'] : '',
  176. '#suffix' => "<div id=\"color-box-$i\" style=\"width: 30px;\"></div>",
  177. '#size' => 10,
  178. );
  179. }
  180. $form['node_settings']['org_table']['add'] = array(
  181. '#type' => 'submit',
  182. '#name' => 'add',
  183. '#value' => 'Add',
  184. '#ajax' => array(
  185. 'callback' => "tripal_phylogeny_default_plots_form_ajax_callback",
  186. 'wrapper' => 'tripal_phylogeny_default_plots_form',
  187. 'effect' => 'fade',
  188. 'method' => 'replace',
  189. ),
  190. );
  191. $form['node_settings']['org_table']['remove'] = array(
  192. '#type' => 'submit',
  193. '#name' => 'remove',
  194. '#value' => 'Remove',
  195. '#ajax' => array(
  196. 'callback' => "tripal_phylogeny_default_plots_form_ajax_callback",
  197. 'wrapper' => 'tripal_phylogeny_default_plots_form',
  198. 'effect' => 'fade',
  199. 'method' => 'replace',
  200. ),
  201. );
  202. $form['node_settings']['org_table']['#theme'] = 'tripal_phylogeny_admin_org_color_tables';
  203. $form['node_settings']['org_table']['#prefix'] = '<div id="tripal_phylogeny_default_plots_form">';
  204. $form['node_settings']['org_table']['#suffix'] = '</div>';
  205. $form['submit'] = array(
  206. '#type' => 'submit',
  207. '#name' => 'submit',
  208. '#value' => 'Save Configuration',
  209. );
  210. $form['#submit'][] = 'tripal_phylogeny_default_plots_form_submit';
  211. return $form;
  212. }
  213. /**
  214. * Validate the phylotree settings forms
  215. *
  216. * @ingroup tripal_phylogeny
  217. */
  218. function tripal_phylogeny_default_plots_form_validate($form, &$form_state) {
  219. }
  220. /**
  221. *
  222. * @param unknown $form
  223. * @param unknown $form_state
  224. */
  225. function tripal_phylogeny_default_plots_form_submit($form, &$form_state) {
  226. // Rebuild this form after submission so that any changes are reflected in
  227. // the flat tables.
  228. $form_state['rebuild'] = TRUE;
  229. if ($form_state['clicked_button']['#name'] == 'submit') {
  230. variable_set('tripal_phylogeny_default_phylogram_width', $form_state['values']['phylogram_width']);
  231. variable_set('tripal_phylogeny_default_root_node_size', $form_state['values']['root_node_size']);
  232. variable_set('tripal_phylogeny_default_interior_node_size', $form_state['values']['interior_node_size']);
  233. variable_set('tripal_phylogeny_default_leaf_node_size', $form_state['values']['leaf_node_size']);
  234. $num_orgs = $form_state['values']['num_orgs'];
  235. variable_set("tripal_phylogeny_num_orgs", $num_orgs);
  236. $colors = array();
  237. for ($i = 0; $i < $num_orgs ;$i++) {
  238. $colors[$i] = array(
  239. 'organism' => $form_state['values']['organism_' . $i],
  240. 'color' => $form_state['values']['color_' . $i]
  241. );
  242. }
  243. variable_set("tripal_phylogeny_org_colors", $colors);
  244. }
  245. if ($form_state['clicked_button']['#name'] == 'add') {
  246. $form_state['values']['num_orgs']++;
  247. }
  248. if ($form_state['clicked_button']['#name'] == 'remove') {
  249. $form_state['values']['num_orgs']--;
  250. }
  251. }
  252. /**
  253. *
  254. * @param unknown $variables
  255. */
  256. function theme_tripal_phylogeny_admin_org_color_tables($variables){
  257. $fields = $variables['element'];
  258. $num_orgs = $fields['num_orgs']['#value'];
  259. $headers = array('Organism', 'Color', '');
  260. $rows = array();
  261. for ($i = 0; $i < $num_orgs; $i++) {
  262. $add_button = ($i == $num_orgs - 1) ? drupal_render($fields['add']) : '';
  263. $del_button = ($i == $num_orgs - 1 and $i != 0) ? drupal_render($fields['remove']) : '';
  264. $rows[] = array(
  265. drupal_render($fields['organism_' . $i]),
  266. drupal_render($fields['color_' . $i]),
  267. $add_button . $del_button,
  268. );
  269. }
  270. $table_vars = array(
  271. 'header' => $headers,
  272. 'rows' => $rows,
  273. 'attributes' => array(),
  274. 'sticky' => FALSE,
  275. 'colgroups' => array(),
  276. 'empty' => '',
  277. );
  278. $form['orgs']['num_orgs'] = $fields['num_orgs'];
  279. return theme('table', $table_vars);
  280. }
  281. /**
  282. * Ajax callback function for the gensas_job_view_panel_form.
  283. *
  284. * @param $form
  285. * @param $form_state
  286. */
  287. function tripal_phylogeny_default_plots_form_ajax_callback($form, $form_state) {
  288. // drupal_debug($form['tree_settings']['org_table']['num_orgs']);
  289. return $form['node_settings']['org_table'];
  290. }