tripal_feature-secondary_tables.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. *
  8. *
  9. * @ingroup tripal_feature
  10. */
  11. function tripal_feature_implement_back_to_feature_button($form_state, $nid) {
  12. $form = array();
  13. $form['nid'] = array(
  14. '#type' => 'hidden',
  15. '#value' => $nid
  16. );
  17. $form["submit-back"] = array(
  18. '#type' => 'submit',
  19. '#value' => t('Back to Stock')
  20. );
  21. return $form;
  22. }
  23. /**
  24. *
  25. *
  26. * @ingroup tripal_feature
  27. */
  28. function tripal_feature_implement_back_to_feature_button_submit($form, $form_state) {
  29. drupal_goto('node/' . $form_state['values']['nid']);
  30. }
  31. /**
  32. *
  33. *
  34. * @ingroup tripal_feature
  35. */
  36. function tripal_feature_implement_add_chado_properties_progress($current) {
  37. $value = '<div class="form_progress"><div class="form_progress-text">';
  38. if ($current == 'main') {
  39. $value .= '<span id="form-step-current">Create Basic Feature</span>'; }
  40. else { $value .= '<span id="form-step">Create Basic Stock</span>'; }
  41. $value .= '<span id="form-segway"> >> </span>';
  42. if ($current == 'properties') {
  43. $value .= '<span id="form-step-current">Add Synonyms & Properties</span>'; }
  44. else { $value .= '<span id="form-step">Add Synonyms & Properties</span>'; }
  45. $value .= '<span id="form-segway"> >> </span>';
  46. if ($current == 'db_references') {
  47. $value .= '<span id="form-step-current">Add Database References</span>'; }
  48. else { $value .= '<span id="form-step">Add Database References</span>'; }
  49. $value .= '<span id="form-segway"> >> </span>';
  50. if ($current == 'relationships') {
  51. $value .= '<span id="form-step-current">Add Relationships</span>'; }
  52. else { $value .= '<span id="form-step">Add Relationships</span>'; }
  53. $value .= '</div></div>';
  54. return $value;
  55. }
  56. /**
  57. *
  58. *
  59. * @ingroup tripal_feature
  60. */
  61. function tripal_feature_implement_add_chado_properties_navigate($form_state, $step, $nid) {
  62. $form = array();
  63. $form['current_step'] = array(
  64. '#type' => 'hidden',
  65. '#value' => $step
  66. );
  67. // Use this field to set all the steps and the path to each form
  68. // where each step is of the form name;path and each step is separated by ::
  69. $steps =array(
  70. 'properties' => 'node/%node/properties',
  71. 'db_references' => 'node/%node/db_references',
  72. 'relationships' => 'node/%node/relationships'
  73. );
  74. $steps_value = array();
  75. foreach ($steps as $k => $v) {
  76. $steps_value[] = $k . ';' . $v; }
  77. $form['steps'] = array(
  78. '#type' => 'hidden',
  79. '#value' => implode('::', $steps_value)
  80. );
  81. $form['first_step'] = array(
  82. '#type' => 'hidden',
  83. '#value' => 'properties'
  84. );
  85. $form['last_step'] = array(
  86. '#type' => 'hidden',
  87. '#value' => 'relationships'
  88. );
  89. $form['nid'] = array(
  90. '#type' => 'hidden',
  91. '#value' => $nid
  92. );
  93. if ($step != $form['first_step']['#value']) {
  94. $form['submit-prev'] = array(
  95. '#type' => 'submit',
  96. '#value' => t('Previous Step')
  97. );
  98. }
  99. if ($step != $form['last_step']['#value']) {
  100. $form['submit-next'] = array(
  101. '#type' => 'submit',
  102. '#value' => t('Next Step')
  103. );
  104. }
  105. if ($step == $form['last_step']['#value']) {
  106. $form['submit-finish'] = array(
  107. '#type' => 'submit',
  108. '#value' => t('Finish')
  109. );
  110. }
  111. return $form;
  112. }
  113. /**
  114. *
  115. *
  116. * @ingroup tripal_feature
  117. */
  118. function tripal_feature_implement_add_chado_properties_navigate_submit($form, $form_state) {
  119. $raw_steps = preg_split('/::/', $form_state['values']['steps']);
  120. $steps = array();
  121. $current_index = 'EMPTY';
  122. $i=0;
  123. foreach ($raw_steps as $raw_step) {
  124. $step = preg_split('/;/', $raw_step);
  125. $steps[$i] = $step;
  126. if ($step[0] == $form_state['values']['current_step']) {
  127. $current_index = $i;
  128. }
  129. $i++;
  130. }
  131. $num_steps = $i;
  132. if (strcmp($current_index, 'EMPTY') == 0) {
  133. // No Matching Step
  134. drupal_set_message(t('Could not determine next step - %currentstep, please contact the administrator', array('%currentstep' => $form_state['values']['current_step'])), 'error');
  135. }
  136. elseif ($current_index == 0) {
  137. $next_goto = $steps[$current_index+1][1];
  138. }
  139. elseif ($current_index == ($num_steps-1)) {
  140. $prev_goto = $steps[$current_index-1][1];
  141. $next_goto = 'node/%node';
  142. }
  143. else {
  144. $prev_goto = $steps[$current_index-1][1];
  145. $next_goto = $steps[$current_index+1][1];
  146. }
  147. if ($form_state['clicked_button']['#value'] == t('Previous Step') ) {
  148. //replace %node
  149. $prev_goto = preg_replace('/%node/', $form_state['values']['nid'], $prev_goto);
  150. $_REQUEST['destination'] = $prev_goto;
  151. }
  152. elseif ($form_state['clicked_button']['#value'] == t('Next Step') ) {
  153. $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
  154. $_REQUEST['destination'] = $next_goto;
  155. }
  156. elseif ($form_state['clicked_button']['#value'] == t('Finish') ) {
  157. $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
  158. $_REQUEST['destination'] = $next_goto;
  159. }
  160. }
  161. /**
  162. * Implements Hook_form()
  163. * Handles setting the is_obsolete property of stocks
  164. *
  165. * @ingroup tripal_feature
  166. */
  167. function tripal_feature_is_obsolete_form($node, $stock_id) {
  168. $form['make_obsolete'] = array(
  169. '#type' => 'submit',
  170. '#value' => t('Mark Stock as Obsolete')
  171. );
  172. $form['make_obsolete_stock_id'] = array(
  173. '#type' => 'value',
  174. '#value' => $stock_id,
  175. '#required' => TRUE
  176. );
  177. return $form;
  178. }
  179. /**
  180. *
  181. *
  182. * @ingroup tripal_feature
  183. */
  184. function tripal_feature_is_obsolete_form_submit($form, &$form_state) {
  185. $previous_db = db_set_active('chado');
  186. db_query(
  187. "UPDATE {stock} SET is_obsolete='t' WHERE stock_id=%d",
  188. $form_state['values']['make_obsolete_stock_id']
  189. );
  190. db_set_active($previous_db);
  191. }