tripal_stock.admin.inc 6.1 KB

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