tripal_stock.admin.inc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /**
  3. * @file
  4. * Administration of stocks
  5. */
  6. /**
  7. * Admin launchpad
  8. *
  9. * @ingroup tripal_stock
  10. */
  11. function tripal_stock_admin_stock_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('Stocks', 'admin/tripal/chado/tripal_stock');
  20. drupal_set_breadcrumb($breadcrumb);
  21. // Add the view
  22. $view = views_embed_view('tripal_stock_admin_stocks','default');
  23. if (isset($view)) {
  24. $output .= $view;
  25. }
  26. else {
  27. $output .= '<p>The Stock 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('Stocks View', 'admin/tripal/chado/tripal_stock/views/stocks/enable').'</li>';
  33. $output .= '</ul>';
  34. }
  35. return $output;
  36. }
  37. /**
  38. * Provide administration options for chado_stocks
  39. *
  40. * @return
  41. * Form array (as described by the drupal form api)
  42. *
  43. * @ingroup tripal_stock
  44. */
  45. function tripal_stock_admin() {
  46. $form = array();
  47. // STOCK PAGE TITLES CONFIGURATION
  48. $form['title'] = array(
  49. '#type' => 'fieldset',
  50. '#title' => t('Stock Page Titles'),
  51. '#collapsible' => TRUE,
  52. '#collapsed' => FALSE,
  53. );
  54. $form['title']['desc'] = array(
  55. '#type' => 'markup',
  56. '#value' => t('Each synced stock must have a unique page title, however, stocks
  57. may have the same name if they are of different types or from different
  58. organisms. Therefore, we must be sure that the page titles can uniquely
  59. identify the stock being viewed. Select an option below that will
  60. uniquely identify all stocks on your site.'),
  61. );
  62. $options = array(
  63. 'stock_unique_name' => 'Only stock unique name',
  64. 'stock_name' => 'Only stock name',
  65. 'unique_constraint' => 'Includes stock name, uniquename, type and species',
  66. );
  67. $form['title']['chado_stock_title'] = array(
  68. '#title' => t('Stock Page Titles'),
  69. '#type' => 'radios',
  70. '#description' => t('Choose a title type from the list above that is
  71. guaranteed to be unique for all stocks If in doubt it is safest to choose
  72. the last option as that guarantees uniqueness. Click the
  73. \'Save Configuration\' button at the bottom to save your selection.'),
  74. '#required' => FALSE,
  75. '#options' => $options,
  76. '#default_value' => variable_get('chado_stock_title', 'unique_constraint'),
  77. );
  78. // STOCK URL CONFIGURATION
  79. $form['url'] = array(
  80. '#type' => 'fieldset',
  81. '#title' => t('Stock URL Path'),
  82. '#collapsible' => TRUE,
  83. '#collapsed' => FALSE,
  84. );
  85. $options = array(
  86. 'SID[id]' => '[id]:' . t('The Chado stock_id'),
  87. 'stock' => 'stock:' . t('Chado table name'),
  88. '[genus]' => '[genus]:' . t('Genus to which the stock belongs'),
  89. '[species]' => '[species]:' . t('Species to which the stock belongs'),
  90. '[type]' => '[type]:' . t('The type of stock'),
  91. '[uniquename]' => '[uniquename]:' . t('The stock unique name'),
  92. '[name]' => '[name]:' . t('The stock name'),
  93. 'reset' => t('Reset'),
  94. );
  95. $form['url']['chado_stock_url_string'] = array(
  96. '#title' => 'URL Syntax',
  97. '#type' => 'textfield',
  98. '#description' => t('You may rearrange elements in this text box to
  99. customize the URLs. The available tags include: [id],
  100. [uniquename]. [name], [species], [genus], [type]. You can separate or
  101. include any text between the tags. Click the "Set Stock URLs" button to
  102. reset the URLs for all stock pages. Click the "Save Configuration" button to
  103. simply save this setup. <b>Important</b>: be sure that whatever you choose will always be unique even considering
  104. future data that may be added. If you include the Chado table name, genus, species, type
  105. and uniquename you are guaranteed to have a unique URL. For example stock/[genus]/[species]/[type]/[uniquename]'),
  106. '#size' => 150,
  107. '#default_value' => variable_get('chado_stock_url_string', '/stock/[genus]/[species]/[type]/[uniquename]'),
  108. );
  109. $form['url']['chado_stock_url'] = array(
  110. '#title' => t('URL components'),
  111. '#type' => 'checkboxes',
  112. '#required' => FALSE,
  113. '#options' => $options,
  114. '#description' => t('Click the item above to make it appear in the URL Syntax box'),
  115. '#attributes' => array(
  116. 'onclick' => '
  117. box = $(\'#edit-chado-stock-url-string\');
  118. if (this.value == \'reset\') {
  119. box.val(\'\');
  120. }
  121. else {
  122. box.val(box.val() + "/" + this.value);
  123. }
  124. this.checked = false;
  125. ',
  126. ),
  127. );
  128. $form['url']['button'] = array(
  129. '#type' => 'submit',
  130. '#value' => t('Set Stock URLs'),
  131. );
  132. return system_settings_form($form);
  133. }
  134. /**
  135. * Implements hook_form_validate(): Validates user input
  136. *
  137. * @param $form
  138. * An array describing the form that was rendered
  139. * @param $form_state
  140. * An array describing the current state of the form including user input
  141. *
  142. * @ingroup tripal_stock
  143. */
  144. function tripal_stock_admin_validate($form, &$form_state) {
  145. global $user; // we need access to the user info
  146. $job_args = array();
  147. variable_set('chado_stock_types_cv', $form_state['values']['stock_types_cv']);
  148. variable_set('chado_stock_prop_types_cv', $form_state['values']['stock_prop_types_cv']);
  149. variable_set('chado_stock_relationship_cv', $form_state['values']['stock_relationship_cv']);
  150. variable_set('chado_stock_url_string', $form_state['values']['chado_stock_url_string']);
  151. switch ($form_state['values']['op']) {
  152. case t('Set Controlled Vacabularies') :
  153. break;
  154. case t('Clean up orphaned stocks') :
  155. tripal_add_job('Cleanup orphaned stocks', 'tripal_stock',
  156. 'tripal_stock_cleanup', $job_args, $user->uid);
  157. break;
  158. case t('Set Stock URLs') :
  159. tripal_add_job('Set Stock URLs', 'tripal_stock',
  160. 'tripal_stock_set_urls', $job_args, $user->uid);
  161. break;
  162. }
  163. }