tripal_stock.admin.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. $details = array(
  49. 'module' => 'tripal_stock',
  50. 'content_type' => 'chado_stock',
  51. 'options' => array(
  52. '[stock.name]' => 'Stock Name Only',
  53. '[stock.uniquename]' => 'Stock Unique Name Only',
  54. '[stock.name], [stock.uniquename] ([stock.type_id>cvterm.name]) [stock.organism_id>organism.genus] [stock.organism_id>organism.species]' => 'Unique Contraint: Includes the name, uniquename, type and scientific name'
  55. ),
  56. 'unique_option' => '[stock.name], [stock.uniquename] ([stock.type_id>cvterm.name]) [stock.organism_id>organism.genus] [stock.organism_id>organism.species]'
  57. );
  58. chado_add_admin_form_set_title($form, $form_state, $details);
  59. // STOCK URL CONFIGURATION
  60. $form['url'] = array(
  61. '#type' => 'fieldset',
  62. '#title' => t('Stock URL Path'),
  63. '#collapsible' => TRUE,
  64. '#collapsed' => FALSE,
  65. );
  66. $options = array(
  67. 'SID[id]' => '[id]:' . t('The Chado stock_id'),
  68. 'stock' => 'stock:' . t('Chado table name'),
  69. '[genus]' => '[genus]:' . t('Genus to which the stock belongs'),
  70. '[species]' => '[species]:' . t('Species to which the stock belongs'),
  71. '[type]' => '[type]:' . t('The type of stock'),
  72. '[uniquename]' => '[uniquename]:' . t('The stock unique name'),
  73. '[name]' => '[name]:' . t('The stock name'),
  74. 'reset' => t('Reset'),
  75. );
  76. $form['url']['chado_stock_url_string'] = array(
  77. '#title' => 'URL Syntax',
  78. '#type' => 'textfield',
  79. '#description' => t('You may rearrange elements in this text box to
  80. customize the URLs. The available tags include: [id],
  81. [uniquename]. [name], [species], [genus], [type]. You can separate or
  82. include any text between the tags. Click the "Set Stock URLs" button to
  83. reset the URLs for all stock pages. Click the "Save Configuration" button to
  84. simply save this setup. <b>Important</b>: be sure that whatever you choose will always be unique even considering
  85. future data that may be added. If you include the Chado table name, genus, species, type
  86. and uniquename you are guaranteed to have a unique URL. For example stock/[genus]/[species]/[type]/[uniquename]'),
  87. '#size' => 150,
  88. '#default_value' => variable_get('chado_stock_url_string', '/stock/[genus]/[species]/[type]/[uniquename]'),
  89. );
  90. $form['url']['chado_stock_url'] = array(
  91. '#title' => t('URL components'),
  92. '#type' => 'checkboxes',
  93. '#required' => FALSE,
  94. '#options' => $options,
  95. '#description' => t('Click the item above to make it appear in the URL Syntax box'),
  96. '#attributes' => array(
  97. 'onclick' => '
  98. box = $(\'#edit-chado-stock-url-string\');
  99. if (this.value == \'reset\') {
  100. box.val(\'\');
  101. }
  102. else {
  103. box.val(box.val() + "/" + this.value);
  104. }
  105. this.checked = false;
  106. ',
  107. ),
  108. );
  109. $form['url']['button'] = array(
  110. '#type' => 'submit',
  111. '#value' => t('Set Stock URLs'),
  112. );
  113. return system_settings_form($form);
  114. }
  115. /**
  116. * Implements hook_form_validate(): Validates user input
  117. *
  118. * @param $form
  119. * An array describing the form that was rendered
  120. * @param $form_state
  121. * An array describing the current state of the form including user input
  122. *
  123. * @ingroup tripal_stock
  124. */
  125. function tripal_stock_admin_validate($form, &$form_state) {
  126. global $user; // we need access to the user info
  127. $job_args = array();
  128. switch ($form_state['values']['op']) {
  129. case t('Set Controlled Vacabularies') :
  130. break;
  131. case t('Clean up orphaned stocks') :
  132. tripal_add_job('Cleanup orphaned stocks', 'tripal_stock',
  133. 'tripal_stock_cleanup', $job_args, $user->uid);
  134. break;
  135. case t('Set Stock URLs') :
  136. tripal_add_job('Set Stock URLs', 'tripal_stock',
  137. 'tripal_stock_set_urls', $job_args, $user->uid);
  138. break;
  139. }
  140. }