tripal_views_setup.admin.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. /**
  3. *
  4. * @ingroup tripal_view_search
  5. */
  6. function tripal_views_setup_admin_form(){
  7. $form = array();
  8. $form['#theme'] = 'tripal';
  9. $query_results = db_query('SELECT * FROM public.tripal_views_setup;');
  10. $header = array('Setup ID', 'Name', 'Materialized View ID', 'Base Table Name', 'Description');
  11. $rows = array();
  12. $results = array();
  13. while($result = db_fetch_object($query_results)){
  14. $rows[] = array($result->setup_id, $result->name, $result->mview_id, $result->base_table_name, $result->description,);
  15. $results[] = $result;
  16. }
  17. $options = array();
  18. foreach ($results as $key => $value) {
  19. if(!empty($value))
  20. $options[] = $value->setup_id;// . ' | ' . $value->name . ' | ' . $value->mview_id . ' | ' . $value->base_table_name;
  21. }
  22. $form['existing_rows'] = array(
  23. '#type' => 'select',
  24. '#options' => $options,
  25. '#description' => '<strong>Select a View Setup to delete from the database.</strong>',
  26. '#prefix' => theme('table', $header, $rows),
  27. );
  28. $form['submit'] = array(
  29. '#type' => 'submit',
  30. '#value' => t('Remove'),
  31. );
  32. $form['cancel'] = array(
  33. '#type' => 'markup',
  34. '#value' => l(t('Cancel '), 'admin/tripal/'),
  35. );
  36. $form['new'] = array(
  37. '#type' => 'markup',
  38. '#value' => l(t(' New'), 'admin/tripal/tripal_views_setup_new'),
  39. );
  40. return $form;
  41. }
  42. /**
  43. *
  44. * @ingroup tripal_view_search
  45. */
  46. function tripal_views_setup_admin_form_submit($form, &$form_state){
  47. $value = $form['existing_rows']['#options'][$form_state['values']['existing_rows']];
  48. db_query("DELETE FROM public.tripal_views_setup WHERE setup_id = $value;");
  49. db_query("DELETE FROM public.tripal_views_handlers WHERE setup_id = $value;");
  50. db_query("DELETE FROM public.tripal_mviews_join WHERE setup_id = $value;");
  51. }
  52. /**
  53. *
  54. * @ingroup tripal_view_search
  55. */
  56. function tripal_views_setup_new_search_form($form_state){
  57. $form = array();
  58. $form['#cache'] = TRUE;
  59. $form['row_name'] = array(
  60. '#title' => t('Name'),
  61. '#type' => 'textfield',
  62. '#size' => 60,
  63. '#maxlength' => 128,
  64. '#description' => 'Name of the Views Setup',
  65. '#required' => TRUE,
  66. );
  67. $form['row_description'] = array(
  68. '#title' => t('Description'),
  69. '#type' => 'textfield',
  70. '#size' => 60,
  71. '#maxlength' => 255,
  72. '#description' => 'Briefly describe in which view this will be used',
  73. '#required' => TRUE,
  74. );
  75. $mview_query = db_query("SELECT mview_id,name FROM {tripal_mviews} ORDER BY name;");
  76. $mview_options = array();
  77. while ($mview_option = db_fetch_array($mview_query)){
  78. $mview_options[$mview_option['mview_id']] = $mview_option['name'];
  79. }
  80. $form['mview_id'] = array(
  81. '#title' => t('Materialized View'),
  82. '#type' => 'select',
  83. '#options' => $mview_options,
  84. '#description' => 'Which materialized view to use.',
  85. '#required' => TRUE,
  86. '#ahah' => array(
  87. 'path' => 'admin/tripal/tripal_views_setup/ajax/mview_cols',
  88. 'wrapper' => 'table-rows-div',
  89. 'effect' => 'fade',
  90. 'event' => 'change',
  91. 'method' => 'replace',
  92. ),
  93. );
  94. // ignore this for now... we'll come back to it later -- spf
  95. // $form['row_base_table_name'] = array(
  96. // '#title' => t('Base Table Name'),
  97. // '#type' => 'select',
  98. // // '#options' => array('stub'),
  99. // '#options' => tripal_core_get_chado_tables(),
  100. // '#description' => 'Select which chado table to use for this view.',
  101. // '#required' => TRUE,
  102. // );
  103. $form['table-rows-div'] = array(
  104. '#type' => 'markup',
  105. '#value' => '<div id="table-rows-div">',
  106. );
  107. return $form;
  108. }
  109. /**
  110. *
  111. * @ingroup tripal_view_search
  112. */
  113. function tripal_view_search_ajax_mview_cols(){
  114. $mview_id = $_POST['mview_id'];
  115. $form = drupal_get_form('tripal_views_setup_fields_form',$mview_id);
  116. drupal_json(array('status' => TRUE, 'data' => $form));
  117. }
  118. /**
  119. *
  120. * @ingroup tripal_view_search
  121. */
  122. function tripal_views_setup_fields_form(&$form_state=NULL, $mview_id = NULL){
  123. if(!$mview_id){
  124. return;
  125. }
  126. // get the columns in this materialized view. They are separated by commas
  127. // where the first word is the column name and the rest is the type
  128. $sql = "SELECT mv_specs FROM {tripal_mviews} WHERE mview_id = $mview_id";
  129. $mview = db_fetch_object(db_query($sql));
  130. $columns = explode(",",$mview->mv_specs);
  131. $i=1;
  132. $chado_tables = tripal_core_get_chado_tables();
  133. $handlers = array();
  134. $form["fields_headers"] = array(
  135. '#type' => 'markup',
  136. '#value' => "<div class=\"field-headers\">".
  137. "<div class=\"column-id\">Field Name and Type</div>".
  138. "<div class=\"fields-column-join\">Join Table</div>".
  139. "<div class=\"fields-column-join-column\">Join Column</div>".
  140. "<div class=\"fields-column-handler\">Handler</div></div>",
  141. );
  142. foreach ($columns as $column){
  143. $column = trim($column); // trim trailing and leading spaces
  144. preg_match("/^(.*?)\ (.*?)$/",$column,$matches);
  145. $column_name = $matches[1];
  146. $column_type = $matches[2];
  147. // first print the field name
  148. $form["fields_start_$i"] = array(
  149. '#type' => 'markup',
  150. '#value' => "<div class=\"fields-new-row\">",
  151. );
  152. $form["fields_column_name_$i"] = array(
  153. '#type' => 'markup',
  154. '#attributes' => array('class' => 'fields-column-name'),
  155. '#value' => "<div class=\"column-id\"><span class=\"column-name\">$column_name</span>".
  156. "<br><span class=\"column-type\">$column_type</span></div>",
  157. );
  158. // second print the table join drop down
  159. $form["fields_column_join_$i"] = array(
  160. '#type' => 'select',
  161. '#prefix' => "<div class=\"fields-column-join\">",
  162. '#suffix' => "</div>",
  163. '#options' => $chado_tables,
  164. '#required' => FALSE,
  165. );
  166. $form["fields_column_join_column_$i"] = array(
  167. '#type' => 'select',
  168. '#prefix' => "<div class=\"fields-column-join-column\">",
  169. '#suffix' => "</div>",
  170. '#options' => array(),
  171. '#required' => FALSE,
  172. );
  173. $form["fields_column_handler_$i"] = array(
  174. '#type' => 'select',
  175. '#prefix' => "<div class=\"fields-column-handler\">",
  176. '#suffix' => "</div>",
  177. '#options' => $handlers,
  178. '#required' => FALSE,
  179. );
  180. $form["fields_end_$i"] = array(
  181. '#type' => 'markup',
  182. '#value' => "</div>",
  183. );
  184. $i++;
  185. }
  186. /* $form['row_view_column'] = array(
  187. '#title' => t('View Column'),
  188. '#type' => 'select',
  189. '#options' => array('stub'),
  190. '#description' => 'Which materialized view column to use.',
  191. '#required' => TRUE,
  192. );
  193. $form['row_chado_column'] = array(
  194. '#title' => t('Chado Column'),
  195. '#type' => 'select',
  196. '#options' => array('stub'),
  197. '#description' => 'Which Chado table column to use.',
  198. '#required' => TRUE,
  199. );
  200. */
  201. $form['submit'] = array(
  202. '#type' => 'submit',
  203. '#value' => 'Create',
  204. );
  205. return $form;
  206. }
  207. // function rowmview_ahah(){
  208. // $query = "SELECT mv_specs FROM tripal_mviews;";
  209. // $row_options = db_fetch_array(db_query($query));
  210. //
  211. //
  212. // }
  213. // function tripal_views_setup_ajax_db_mview_columns(){
  214. // $mview = $_POST['row_mview'];
  215. // $form = drupal_get_form('tripal_views_setup_mview_column_form', $mview);
  216. // drupal_json(array('status' => TRUE, 'data' => $form));
  217. // }
  218. // function tripal_views_setup_mview_column_form(&$form_state = NULL, $mview = NULL){
  219. // if ($mview){
  220. // $mview_query = db_fetch_array(db_query("SELECT mv_specs FROM tripal_mviews WHERE name = $mview;"));
  221. //
  222. // $form['row_mview']
  223. // }
  224. //
  225. // }
  226. // function tripal_views_setup_ajax_db_chado_tables(){
  227. // }
  228. /**
  229. *
  230. * @ingroup tripal_view_search
  231. */
  232. function tripal_views_setup_new_search_form_submit($form, &$form_state){
  233. }