tripal_stock.admin.inc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. *
  8. */
  9. function tripal_stock_admin_stock_view() {
  10. $output = '';
  11. // set the breadcrumb
  12. $breadcrumb = array();
  13. $breadcrumb[] = l('Home', '<front>');
  14. $breadcrumb[] = l('Administration', 'admin');
  15. $breadcrumb[] = l('Tripal', 'admin/tripal');
  16. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  17. $breadcrumb[] = l('Stocks', 'admin/tripal/chado/tripal_stock');
  18. drupal_set_breadcrumb($breadcrumb);
  19. // Add the view
  20. $view = views_embed_view('tripal_stock_admin_stocks','default');
  21. if (isset($view)) {
  22. $output .= $view;
  23. }
  24. else {
  25. $output .= '<p>The Stock module uses primarily views to provide an '
  26. . 'administrative interface. Currently one or more views needed for this '
  27. . 'administrative interface are disabled. <strong>Click each of the following links to '
  28. . 'enable the pertinent views</strong>:</p>';
  29. $output .= '<ul>';
  30. $output .= '<li>'.l('Stocks View', 'admin/tripal/chado/tripal_stock/views/stocks/enable').'</li>';
  31. $output .= '</ul>';
  32. }
  33. return $output;
  34. }
  35. /**
  36. * Purpose: Provide administration options for chado_stocks
  37. *
  38. * @return
  39. * Form array (as described by the drupal form api)
  40. *
  41. * @ingroup tripal_stock
  42. */
  43. function tripal_stock_admin() {
  44. $form = array();
  45. get_tripal_stock_admin_form_title_set($form);
  46. get_tripal_stock_admin_form_url_set($form);
  47. get_tripal_stock_admin_form_vocabulary_set($form);
  48. get_tripal_stock_admin_form_cleanup_set($form);
  49. return system_settings_form($form);
  50. }
  51. /**
  52. * Implements hook_form_validate(): Validates user input
  53. *
  54. * @param $form
  55. * An array describing the form that was rendered
  56. * @param $form_state
  57. * An array describing the current state of the form including user input
  58. *
  59. * @ingroup tripal_stock
  60. */
  61. function tripal_stock_admin_validate($form, &$form_state) {
  62. global $user; // we need access to the user info
  63. $job_args = array();
  64. variable_set('chado_stock_types_cv', $form_state['values']['stock_types_cv']);
  65. variable_set('chado_stock_prop_types_cv', $form_state['values']['stock_prop_types_cv']);
  66. variable_set('chado_stock_relationship_cv', $form_state['values']['stock_relationship_cv']);
  67. variable_set('chado_stock_url_string', $form_state['values']['chado_stock_url_string']);
  68. switch ($form_state['values']['op']) {
  69. case t('Set Controlled Vacabularies') :
  70. break;
  71. case t('Clean up orphaned stocks') :
  72. tripal_add_job('Cleanup orphaned stocks', 'tripal_stock',
  73. 'tripal_stock_cleanup', $job_args, $user->uid);
  74. break;
  75. case t('Set Stock URLs') :
  76. tripal_add_job('Set Stock URLs', 'tripal_stock',
  77. 'tripal_stock_set_urls', $job_args, $user->uid);
  78. break;
  79. }
  80. }
  81. /**
  82. *
  83. * @param $form
  84. */
  85. function get_tripal_stock_admin_form_title_set(&$form) {
  86. $form['title'] = array(
  87. '#type' => 'fieldset',
  88. '#title' => t('Stock Page Titles'),
  89. '#collapsible' => TRUE,
  90. '#collapsed' => TRUE,
  91. );
  92. $form['title']['desc'] = array(
  93. '#type' => 'markup',
  94. '#value' => t('Each synced stock must have a unique page title, however, stocks
  95. may have the same name if they are of different types or from different
  96. organisms. Therefore, we must be sure that the page titles can uniquely
  97. identify the stock being viewed. Select an option below that will
  98. uniquely identify all stocks on your site.'),
  99. );
  100. $options = array(
  101. 'stock_unique_name' => 'Only stock unique name',
  102. 'stock_name' => 'Only stock name',
  103. 'unique_constraint' => 'Includes stock name, uniquename, type and species',
  104. );
  105. $form['title']['chado_stock_title'] = array(
  106. '#title' => t('Stock Page Titles'),
  107. '#type' => 'radios',
  108. '#description' => t('Choose a title type from the list above that is
  109. guaranteed to be unique for all stocks If in doubt it is safest to choose
  110. the last option as that guarantees uniqueness. Click the
  111. \'Save Configuration\' button at the bottom to save your selection.'),
  112. '#required' => FALSE,
  113. '#options' => $options,
  114. '#default_value' => variable_get('chado_stock_title', 'unique_constraint'),
  115. );
  116. }
  117. /**
  118. *
  119. * @param $form
  120. */
  121. function get_tripal_stock_admin_form_url_set(&$form) {
  122. $form['url'] = array(
  123. '#type' => 'fieldset',
  124. '#title' => t('Stock URL Path'),
  125. '#collapsible' => TRUE,
  126. '#collapsed' => TRUE,
  127. );
  128. $options = array(
  129. 'SID[id]' => '[id]:' . t('The Chado stock_id'),
  130. 'stock' => 'stock:' . t('Chado table name'),
  131. '[genus]' => '[genus]:' . t('Genus to which the stock belongs'),
  132. '[species]' => '[species]:' . t('Species to which the stock belongs'),
  133. '[type]' => '[type]:' . t('The type of stock'),
  134. '[uniquename]' => '[uniquename]:' . t('The stock unique name'),
  135. '[name]' => '[name]:' . t('The stock name'),
  136. 'reset' => t('Reset'),
  137. );
  138. $form['url']['chado_stock_url_string'] = array(
  139. '#title' => 'URL Syntax',
  140. '#type' => 'textfield',
  141. '#description' => t('You may rearrange elements in this text box to
  142. customize the URLs. The available tags include: [id],
  143. [uniquename]. [name], [species], [genus], [type]. You can separate or
  144. include any text between the tags. Click the "Set Stock URLs" button to
  145. reset the URLs for all stock pages. Click the "Save Configuration" button to
  146. simply save this setup. <b>Important</b>: be sure that whatever you choose will always be unique even considering
  147. future data that may be added. If you include the Chado table name, genus, species, type
  148. and uniquename you are guaranteed to have a unique URL. For example stock/[genus]/[species]/[type]/[uniquename]'),
  149. '#size' => 150,
  150. '#default_value' => variable_get('chado_stock_url_string', '/stock/[genus]/[species]/[type]/[uniquename]'),
  151. );
  152. $form['url']['chado_stock_url'] = array(
  153. '#title' => t('URL components'),
  154. '#type' => 'checkboxes',
  155. '#required' => FALSE,
  156. '#options' => $options,
  157. '#description' => t('Click the item above to make it appear in the URL Syntax box'),
  158. '#attributes' => array(
  159. 'onclick' => '
  160. box = $(\'#edit-chado-stock-url-string\');
  161. if (this.value == \'reset\') {
  162. box.val(\'\');
  163. }
  164. else {
  165. box.val(box.val() + "/" + this.value);
  166. }
  167. this.checked = false;
  168. ',
  169. ),
  170. );
  171. $form['url']['button'] = array(
  172. '#type' => 'submit',
  173. '#value' => t('Set Stock URLs'),
  174. );
  175. }
  176. /**
  177. *
  178. * @param $form
  179. */
  180. function get_tripal_stock_admin_form_vocabulary_set(&$form) {
  181. $form['set_cv'] = array(
  182. '#type' => 'fieldset',
  183. '#title' => t('Set Stock Controlled Vocabularies'),
  184. '#collapsible' => TRUE,
  185. '#collapsed' => TRUE,
  186. );
  187. $form['set_cv']['message'] = array(
  188. '#value' => t("This setting allows you to set which chado controlled vocabularies (cv)"
  189. ." are used. Cvs are used to control user input for the type of stock,"
  190. ." any properties they enter for a stock & the types of relationships"
  191. ." between stocks. Only cvs already loaded into chado can be selected here.")
  192. );
  193. // get the list of CVs for the next form element
  194. $sql = "SELECT * FROM {cv} ORDER BY name";
  195. $results = chado_query($sql);
  196. $cv_options = array();
  197. while ($r = $results->fetchObject()) {
  198. $cv_options[$r->cv_id] = $r->name;
  199. }
  200. $form['set_cv']['stock_types_cv'] = array(
  201. '#type' => 'select',
  202. '#title' => t('Controlled Vocabulary governing Stock Types'),
  203. '#options' => $cv_options,
  204. '#default_value' => variable_get('chado_stock_types_cv', 0)
  205. );
  206. $form['set_cv']['stock_prop_types_cv'] = array(
  207. '#type' => 'select',
  208. '#title' => t('Controlled Vocabulary governing Types of Stock Properties'),
  209. '#description' => t("This cv must contain a cvterm entry where name='synonym'."),
  210. '#options' => $cv_options,
  211. '#default_value' => variable_get('chado_stock_prop_types_cv', 0)
  212. );
  213. $form['set_cv']['stock_relationship_cv'] = array(
  214. '#type' => 'select',
  215. '#title' => t('Controlled Vocabulary governing Types of Relationsips between Stocks'),
  216. '#options' => $cv_options,
  217. '#default_value' => variable_get('chado_stock_relationship_cv', 0)
  218. );
  219. $form['set_cv']['button'] = array(
  220. '#type' => 'submit',
  221. '#value' => t('Set Controlled Vacabularies')
  222. );
  223. }