tripal_views_integration.inc 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. <?php
  2. /**
  3. * @file
  4. * Functions related to the UI for integrating tables with views
  5. */
  6. /**
  7. * Purpose: Provide Guidance to new Tripal Admin
  8. *
  9. * @return
  10. * HTML Formatted text
  11. *
  12. * @ingroup tripal_views_integration
  13. */
  14. function tripal_views_description_page() {
  15. $text .= '<h3>Tripal Views Quick Links:</h3>';
  16. $text .= "<ul>
  17. <li><a href=\"" . url("admin/tripal/views/integration/list") . "\">List of integrated tables</a></li>
  18. <li><a href=\"" . url("admin/tripal/views/integration/new") . "\">Integrate a new table</a></li>
  19. <li><a href=\"" . url("admin/tripal/views/integration/import") . "\">Import a previously exported table integration.</a></li>
  20. </ul>";
  21. $text .= '<h3>Views Integration Description:</h3>';
  22. $text .= '<p>Tripal Views provides an interface for integrating <a href="http://drupal.org/project/views">Drupal Views</a>
  23. with Tripal materialized views. This will allow site administrators to create custom queries for the materialized views
  24. and in turn provide custom content pages, custom blocks and custom search forms. The forms allow a site administrator
  25. to select a materialized view and associate other Chado tables on which the view can join. Usage of this module requires
  26. a good understanding of foreign-key relationships in Chado.
  27. </p>';
  28. $text .= '<h3>Setup Instructions:</h3>';
  29. $text .= '<p>After installation of the Tripal core module. The following tasks should be performed
  30. <ol>
  31. <li><b>Set Permissions</b>: To allow access to site administrators for this module, simply
  32. <a href="' . url('admin/user/permissions') . '">assign permissions</a> to the appropriate user roles for the
  33. permission type "manage tripal_views_integration". </li>
  34. </ol>
  35. </p>';
  36. $text .= '<h3>Usage Instructions:</h3>';
  37. $text .= "<p>To use Tripal Views integration follow these steps:
  38. <ol>
  39. <li><b>Identify or create a materialized view:</b> Using the <a href=\"" . url("admin/tripal/views/mviews") . "\">
  40. Tripal materialized View</a> interface, identify the view you would like to integrate or create a new one.</li>
  41. <li><b>Setup the Views Integration</b>: Navigate to the <a href=\"" . url("admin/tripal/views/integration/mviews/new") . "\">
  42. Tripal views integration setup page</a> to integrate the selected materialized view. Provide a user friendly name
  43. and description to help you remember the purpose for integrating the view. Next, select the view you want to integrate
  44. from the provided select box. If your materialized view has fields that can join with other Chado tables, you may
  45. provide those relationships in the provided form. Finally, if your fields require a special handler for display, you
  46. may select it from the drop down provided</li>
  47. <li><b>Create custom pages/block/search form</b>: After saving setup information from step 2 above, you will be redirected to the
  48. Drupal Views interface</a> where you can create a custom page, block or search form.</li>
  49. <li><b>Review your integrated views</b>: A page providing a
  50. <a href=\"" . url("admin/tripal/views/integration/mviews/list") . "\">list of all integrated views</a> is provided. You may
  51. view this page to see all integrated views, but also to remove any unwanted integrations.</li>
  52. </ol>
  53. </p>";
  54. return $text;
  55. }
  56. /**
  57. * Purpose: Generates a themable table containing the list of integrated tables
  58. * The look-and-feel of the table can be altered by overriding the theme for
  59. * tables.
  60. *
  61. * @return
  62. * a themed HTML table
  63. *
  64. * @ingroup tripal_views_integration
  65. */
  66. function tripal_views_integration_setup_list() {
  67. $output = '';
  68. $output .= l(t('Add a New Entry'), "admin/tripal/views/integration/new") ;
  69. $output .= '<p>' . t('The following tables are available for integration with Drupal Views. If '
  70. . 'a table is integrated more than once, then the setup with the lightest '
  71. . 'priority will be used. For example, if you have created a custom setup with a priority of -5 then '
  72. . 'that will be used instead of the default setup with priority 10. '
  73. . 'Priorities range from -10 to +10 where a setup with -10 has '
  74. . 'greater precedent than any other and +10 has the least.') . '</p>';
  75. // Start with materialized views
  76. $output .= '<br /><h3>Legacy Materialized Views</h3>';
  77. $header = array('', 'Drupal Views Type Name', 'Table Name', 'Is Legacy?', 'Priority', 'Comment');
  78. $rows = array();
  79. // get the list of materialized views
  80. $tviews = db_query('SELECT tv.setup_id, tv.name, tv.table_name, tc.table_id, tv.priority, tv.comment '
  81. .'FROM {tripal_views} tv '
  82. .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
  83. .'WHERE tv.mview_id IS NOT NULL '
  84. .'ORDER BY tv.table_name ASC, tv.priority ASC');
  85. while ($tview = db_fetch_object($tviews)) {
  86. $rows[] = array(
  87. l(t('Edit'), "admin/tripal/views/integration/edit/" . $tview->setup_id) . "<br />"
  88. . l(t('Export'), "admin/tripal/views/integration/export/" . $tview->setup_id) . "<br />"
  89. . l(t('Delete'), "admin/tripal/views/integration/delete/" . $tview->setup_id),
  90. $tview->name,
  91. $tview->table_name,
  92. ($tview->table_id) ? 'No' : 'Yes',
  93. $tview->priority,
  94. $tview->comment,
  95. );
  96. }
  97. if ($rows) {
  98. $output .= theme('table', $header, $rows);
  99. }
  100. else {
  101. $output .= '<p>There are currently no Materialized Views defined. ';
  102. $output .= l(t('Add a New Entry'), "admin/tripal/views/integration/new") . '</p>';
  103. }
  104. // Now list non-mview custom tables
  105. $output .= '<br /><h3>Custom Tables & Non-Legacy Materialized Views</h3>';
  106. $header = array('', 'Drupal Views Type Name', 'Table Name', 'Priority', 'Comment');
  107. $rows = array();
  108. // get the list of chado tables
  109. $tviews = db_query('SELECT tv.setup_id, tv.name, tv.table_name, tv.priority, tv.comment '
  110. .'FROM {tripal_views} tv '
  111. .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
  112. .'WHERE mview_id IS NULL AND tc.table_id IS NOT NULL '
  113. .'ORDER BY table_name ASC, priority ASC');
  114. while ($tview = db_fetch_object($tviews)) {
  115. $rows[] = array(
  116. l(t('Edit'), "admin/tripal/views/integration/edit/" . $tview->setup_id) . "<br />"
  117. . l(t('Export'), "admin/tripal/views/integration/export/" . $tview->setup_id) . "<br />"
  118. . l(t('Delete'), "admin/tripal/views/integration/delete/" . $tview->setup_id),
  119. $tview->name,
  120. $tview->table_name,
  121. $tview->priority,
  122. $tview->comment,
  123. );
  124. }
  125. if ($rows) {
  126. $output .= theme('table', $header, $rows);
  127. }
  128. else {
  129. $output .= '<p>There are currently no non-Materialized View Custom Tables defined.</p>';
  130. }
  131. // Now list chado tables
  132. $output .= '<br /><h3>Chado Tables</h3>';
  133. $header = array('', 'Drupal Views Type Name', 'Table Name', 'Priority', 'Comment');
  134. $rows = array();
  135. // get the list of chado tables
  136. $tviews = db_query('SELECT tv.setup_id, tv.name, tv.table_name, tv.priority, tv.comment '
  137. .'FROM {tripal_views} tv '
  138. .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
  139. .'WHERE mview_id IS NULL AND tc.table_id IS NULL '
  140. .'ORDER BY table_name ASC, priority ASC');
  141. while ($tview = db_fetch_object($tviews)) {
  142. $rows[] = array(
  143. l(t('Edit'), "admin/tripal/views/integration/edit/" . $tview->setup_id) . "<br />"
  144. . l(t('Export'), "admin/tripal/views/integration/export/" . $tview->setup_id) . "<br />"
  145. . l(t('Delete'), "admin/tripal/views/integration/delete/" . $tview->setup_id),
  146. $tview->name,
  147. $tview->table_name,
  148. $tview->priority,
  149. $tview->comment,
  150. );
  151. }
  152. $output .= theme('table', $header, $rows);
  153. return $output;
  154. }
  155. /**
  156. * Purpose: Deletes integration of a table with the Views module. This
  157. * function is meant to be called from a menu item. After completion it
  158. * redirects the user to the views intergation page.
  159. *
  160. * @param $setup_id
  161. * the unique setup id for the integrated table
  162. *
  163. * @ingroup tripal_views_integration
  164. */
  165. function tripal_views_integration_delete($setup_id) {
  166. tripal_views_integration_remove_entry_by_setup_id($setup_id);
  167. drupal_set_message(t("Record Deleted"));
  168. drupal_goto('admin/tripal/views/integration');
  169. }
  170. /**
  171. * Purpose: defines the web form used for specifing the base table, joins and
  172. * handlers when integrating a table with views. This form is used for both
  173. * creating a new record and editing an existing record.
  174. *
  175. * @param &$form_state
  176. * The form state which is passed automatically by drupal
  177. *
  178. * @param $setup_id
  179. * The unique setup for an integrated table. This value is only set when
  180. * the form is used for updating an existing record.
  181. *
  182. * @return
  183. * A proper Drupal form associative array.
  184. *
  185. * @ingroup tripal_views_integration
  186. */
  187. function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
  188. $form = array();
  189. $data = array();
  190. $form['#cache'] = TRUE;
  191. // initialize Tripal AHAH
  192. tripal_core_ahah_init_form();
  193. // if a setup_id is provided then we want to get the form defaults
  194. $setup_obj = array();
  195. if (isset($setup_id)) {
  196. // get the deafult setup values
  197. $sql = "SELECT * FROM {tripal_views} WHERE setup_id = %d";
  198. $setup_obj = db_fetch_object(db_query($sql, $setup_id));
  199. $mview_id = $setup_obj->mview_id;
  200. $table_name = $setup_obj->table_name;
  201. $form_state['values']['mview_id'] = $mview_id;
  202. $form_state['values']['table_name'] = $table_name;
  203. // get the default field name/description
  204. $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
  205. $query = db_query($sql, $setup_id);
  206. $default_fields = array();
  207. while ($field = db_fetch_object($query)) {
  208. $default_fields[$field->column_name]['name'] = $field->name;
  209. $default_fields[$field->column_name]['description'] = $field->description;
  210. }
  211. // get the default join settings and handlers
  212. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
  213. $query = db_query($sql, $setup_id);
  214. $default_joins = array();
  215. while ($join = db_fetch_object($query)) {
  216. $default_joins[$join->base_field]['left_table'] = $join->left_table;
  217. $default_joins[$join->base_field]['left_field'] = $join->left_field;
  218. }
  219. // get the default handlers
  220. $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d";
  221. $query = db_query($sql, $setup_id);
  222. $default_handlers = array();
  223. while ($handler = db_fetch_object($query)) {
  224. $default_handlers[$handler->column_name][$handler->handler_type]['handler_name'] = $handler->handler_name;
  225. $default_handlers[$handler->column_name][$handler->handler_type]['arguments'] = $handler->arguments;
  226. }
  227. // get the default join handlers
  228. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
  229. $query = db_query($sql, $setup_id);
  230. while ($handler = db_fetch_object($query)) {
  231. $default_handlers[$handler->base_field]['join']['handler_name'] = $handler->handler;
  232. //$default_handlers[$handler->base_field]['join']['arguments'] = $handler->arguments;
  233. }
  234. // add in the setup_id for the form so we know this is an update not an insert
  235. $form['setup_id'] = array(
  236. '#type' => 'hidden',
  237. '#value' => $setup_id,
  238. );
  239. }
  240. // add a fieldset for the MView & Chado table selectors
  241. $form['base_table_type'] = array(
  242. '#type' => 'fieldset',
  243. '#title' => 'Base Table',
  244. '#description' => 'Please select either a materialized view or a Chado table for integration with '.
  245. 'Drupal Views. In Drupal Views terminology, the selected table becomes the "base table". '.
  246. 'After you select a table from either list, the fields from that table will appear below '.
  247. 'and you can specify other tables to join with and handlers.',
  248. );
  249. // build the form element for the Chado tables
  250. $chado_tables = tripal_core_get_chado_tables(TRUE);
  251. $chado_tables = array_merge(array('Select'), $chado_tables);
  252. $form['base_table_type']['table_name'] = array(
  253. '#title' => t('Chado/Custom Table'),
  254. '#type' => 'select',
  255. '#options' => $chado_tables,
  256. '#description' => t('Tables from Chado, custom tables and materialized view tables (non-legacy MViews) can be selected for integration.'),
  257. '#default_value' => (!$setup_obj->mview_id) ? $setup_obj->table_name : '',
  258. '#ahah' => array(
  259. 'path' => 'tripal/views/integration/ajax/view_setup_table',
  260. 'wrapper' => 'table-rows-div',
  261. 'effect' => 'fade',
  262. 'event' => 'change',
  263. 'method' => 'replace',
  264. ),
  265. );
  266. // build the form element that lists the materialized views
  267. $query = db_query("SELECT mview_id, name FROM {tripal_mviews} WHERE mv_schema is NULL or mv_schema = '' ORDER BY name");
  268. $mview_tables = array();
  269. $mview_tables['0'] = 'Select';
  270. while ($mview = db_fetch_object($query)) {
  271. $mview_tables[$mview->mview_id] = $mview->name;
  272. }
  273. $form['base_table_type']['mview_id'] = array(
  274. '#title' => t('Legacy Materialized View'),
  275. '#type' => 'select',
  276. '#options' => $mview_tables,
  277. '#description' => 'Which materialized view to use.',
  278. '#default_value' => $setup_obj->mview_id,
  279. '#ahah' => array(
  280. 'path' => 'tripal/views/integration/ajax/view_setup_table',
  281. 'wrapper' => 'table-rows-div',
  282. 'effect' => 'fade',
  283. 'event' => 'change',
  284. 'method' => 'replace',
  285. ),
  286. );
  287. $form['views_type'] = array(
  288. '#type' => 'fieldset',
  289. '#title' => 'View Type',
  290. '#description' => 'Here you can provide the "type" of View you want to create.',
  291. );
  292. // field for the name of the
  293. $form['views_type']['row_name'] = array(
  294. '#title' => t('View Type Name'),
  295. '#type' => 'textfield',
  296. '#default_value' => $setup_obj->name,
  297. '#size' => 60,
  298. '#maxlength' => 128,
  299. '#description' => 'Provide the view type name. This is the name that will appear in '.
  300. 'the Drupal Views interface when adding a new view. The view type name '.
  301. 'must be unique.',
  302. '#required' => TRUE,
  303. );
  304. if (isset($setup_id)) {
  305. $form['row_name']['#attributes'] = array('readonly' => 'readonly');
  306. }
  307. $priorities = array();
  308. foreach (range(-10, 10) as $v) {
  309. $priorities[$v] = (string) $v;
  310. }
  311. $form['views_type']['row_priority'] = array(
  312. '#type' => 'select',
  313. '#title' => t('Priority'),
  314. '#description' => t('The level of priority your Views integration has in relation to the '
  315. .'default core and module definitions. The views integration definition with the '
  316. .'lightest priority will be used. For example, if there is a definition created by '
  317. .'core with a priority of 10 and another by a custom module of 5 and yours is -1 then '
  318. .'you definition will be used for that table because -1 is lighter then both 5 and 10.'),
  319. '#options' => $priorities,
  320. '#default_value' => (isset($setup_obj->priority)) ? $setup_obj->priority : -1,
  321. );
  322. if ($setup_obj->priority >= 9) {
  323. drupal_set_message('You are editing a default views integration. To ensure your changes
  324. are used, change the priority to -10.', 'warning');
  325. }
  326. $form['views_type']['new_integration'] = array(
  327. '#type' => 'checkbox',
  328. '#title' => t('Create a New Tripal Views Integration Record'),
  329. '#description' => t('If this checkbox is checked then a new tripal views integration '
  330. .'will be created rather then overriding the current one with your changes. This '
  331. .'especially important if you are editing one of the default views integrations '
  332. .'(ie: if the original priority was either 10 or 9).'),
  333. '#default_value' => ($setup_obj->priority >= 9) ? true : false,
  334. );
  335. $form['views_type']['base_table'] = array(
  336. '#type' => 'checkbox',
  337. '#title' => t('Base Table?'),
  338. '#description' => t('If you want this table to show up as one of the options in the '
  339. . 'add view page, then check this checkbox. It allows you to create listings '
  340. . 'primarily from this table'),
  341. '#default_value' => (isset($setup_obj->base_table)) ? $setup_obj->base_table : 1,
  342. );
  343. $form['views_type']['row_description'] = array(
  344. '#title' => t('Comment'),
  345. '#type' => 'textarea',
  346. '#description' => '(Optional). Provide any details regarding this setup you would like. This '.
  347. 'description will appear when selecting a type for a new Drupal View',
  348. '#required' => FALSE,
  349. '#default_value' => (isset($setup_obj->comment)) ? $setup_obj->comment : '',
  350. );
  351. // we need a div block where the table fields will get put when the
  352. // AHAH callback is made
  353. $form['view_setup_table'] = array(
  354. '#type' => 'item',
  355. '#prefix' => '<div id="table-rows-div">',
  356. '#suffix' => '</div>',
  357. );
  358. // add the fieldset for the table fields, but only if the $mview_id or $table_name
  359. // is set. The only times these values are set is if we're editing an existing
  360. // record or if the AHAH callback is being made.
  361. if ($form_state['values']['mview_id'] or $form_state['values']['table_name']) {
  362. $mview_id = $form_state['values']['mview_id'];
  363. $table_name = $form_state['values']['table_name'];
  364. $form['view_setup_table'] = array(
  365. '#type' => 'fieldset',
  366. '#title' => 'Join Selection',
  367. '#prefix' => '<div id="fieldset-table-rows-wrapper">',
  368. '#suffix' => '</div>',
  369. );
  370. // get the columns in this materialized view. They are separated by commas
  371. // where the first word is the column name and the rest is the type
  372. $columns = array();
  373. if ($mview_id) {
  374. $sql = "SELECT mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
  375. $mview = db_fetch_object(db_query($sql, $mview_id));
  376. $columns = explode(",", $mview->mv_specs);
  377. }
  378. else {
  379. $table_desc = tripal_core_get_chado_table_schema($table_name);
  380. if ($table_desc) {
  381. $fields = $table_desc['fields'];
  382. // iterate through the columns and build the format
  383. // compatible with the code below. The column name is first followed
  384. // by the type with a separating space
  385. foreach ($fields as $column => $attrs) {
  386. $columns[] = "$column " . $attrs['type'];
  387. }
  388. }
  389. }
  390. $i=1;
  391. $form['view_setup_table']["instructions"] = array(
  392. '#type' => 'markup',
  393. '#value' => filter_xss("Select an optional table to which the fields of the ".
  394. "materialized view can join. If a field does not need to ".
  395. "join you may leave the selection blank."),
  396. );
  397. $data['field_types'] = array();
  398. // get the list of chado tables to join on
  399. $chado_join_tables = tripal_core_get_chado_tables(TRUE);
  400. $chado_join_tables = array_merge(array('Select a Join Table'), $chado_join_tables);
  401. // get list of all handlers
  402. $all_handlers = tripal_views_integration_discover_handlers();
  403. $handlers_fields = array(0 => "Select a field handler");
  404. $handlers_filters = array(0 => "Select a filter handler");
  405. $handlers_sort = array(0 => "Select a sort handler");
  406. $handlers_argument = array(0 => "Select an argument handler");
  407. $handlers_join = array(0 => "Select a join handler");
  408. $handlers_rel = array(0 => "Select a relationship handler");
  409. foreach ($all_handlers as $handler) {
  410. if (preg_match("/views_handler_field/", $handler)) {
  411. $handlers_fields[$handler] = $handler;
  412. }
  413. if (preg_match("/views_handler_filter/", $handler)) {
  414. $handlers_filters[$handler] = $handler;
  415. }
  416. if (preg_match("/views_handler_sort/", $handler)) {
  417. $handlers_sort[$handler] = $handler;
  418. }
  419. if (preg_match("/views_handler_argument/", $handler)) {
  420. $handlers_argument[$handler] = $handler;
  421. }
  422. if (preg_match("/_join/", $handler)) {
  423. $handlers_join[$handler] = $handler;
  424. }
  425. if (preg_match("/views_handler_relationship/", $handler)) {
  426. $handlers_rel[$handler] = $handler;
  427. }
  428. }
  429. // generate a unique $table_id for keeping track of the table
  430. if ($mview_id) {
  431. $table_id = $mview_id;
  432. }
  433. else {
  434. $table_id = $table_name;
  435. }
  436. // Per Row (Fields) --------------
  437. // now iterate through the columns of the materialized view or
  438. // chado table and generate the join and handler fields
  439. foreach ($columns as $column) {
  440. $column = trim($column); // trim trailing and leading spaces
  441. preg_match("/^(.*?)\ (.*?)$/", $column, $matches);
  442. $column_name = $matches[1];
  443. $column_type = $matches[2];
  444. $form['view_setup_table']["$table_id-$i"] = array(
  445. '#type' => 'markup',
  446. '#prefix' => "<div class=\"fields-new-row\">",
  447. '#suffix' => "</div>",
  448. '#value' => filter_xss('')
  449. );
  450. // COLUMN I
  451. $form['view_setup_table']["$table_id-$i"]["fields_name_$table_id-$i"] = array(
  452. '#type' => 'markup',
  453. '#prefix' => "<div class=\"column-one\">",
  454. '#value' => "<span class=\"column-name\">" . filter_xss($column_name) . "</span>".
  455. "<br /><span class=\"column-type\">" . filter_xss($column_type) . "</span>",
  456. '#suffix' => "</div>",
  457. );
  458. $data['field_types'][$column_name] = $column_type;
  459. // COLUMN II
  460. $form['view_setup_table']["$table_id-$i"]['column-2'] = array(
  461. '#type' => 'markup',
  462. '#prefix' => "<div class=\"column-two\">",
  463. '#suffix' => "</div>",
  464. '#value' => filter_xss('')
  465. );
  466. // set the default values for the human-readable name and description
  467. $default_name = '';
  468. $default_descrip = '';
  469. if (isset($setup_id) && !isset($form_state['values']["fields_readable_name_$table_id-$i"])) {
  470. $default_name = $default_fields[$column_name]['name'];
  471. $default_descrip = $default_fields[$column_name]['description'];
  472. }
  473. else {
  474. $default_name = $form_state['values']["fields_readable_name_$table_id-$i"];
  475. $default_descrip = $form_state['values']["fields_description_$table_id-$i"];
  476. }
  477. $form['view_setup_table']["$table_id-$i"]['column-2']["fields_readable_name_$table_id-$i"] = array(
  478. '#type' => 'textfield',
  479. '#title' => 'Human-Readable Name',
  480. '#description' => 'This is the name of the field in the Views UI',
  481. '#required' => TRUE,
  482. '#default_value' => $default_name,
  483. '#size' => 42,
  484. );
  485. $form['view_setup_table']["$table_id-$i"]['column-2']["fields_description_$table_id-$i"] = array(
  486. '#type' => 'textarea',
  487. '#title' => 'Short Description',
  488. '#description' => 'This is the field help in the Views UI',
  489. '#required' => TRUE,
  490. '#cols' => 42,
  491. '#rows' => 3,
  492. '#default_value' => $default_descrip,
  493. );
  494. // COLUMN III
  495. $form['view_setup_table']["$table_id-$i"]['column-3'] = array(
  496. '#type' => 'markup',
  497. '#prefix' => "<div class=\"column-three\">",
  498. '#suffix' => "</div>",
  499. '#value' => filter_xss('')
  500. );
  501. // set the default values for the join table and columns
  502. $default_join_table = 0;
  503. $default_join_field = 0;
  504. if (isset($setup_id) && !isset($form_state['values']["fields_join_$table_id-$i"])) {
  505. $default_join_table = $default_joins[$column_name]['left_table'];
  506. $default_join_field = $default_joins[$column_name]['left_field'];
  507. $form_state['values']["fields_join_$table_id-$i"] = $default_join_table;
  508. $form_state['values']["fields_join_column_$table_id-$i"] = $default_join_field;
  509. }
  510. else{
  511. $default_join_table = $form_state['values']["fields_join_$table_id-$i"];
  512. $default_join_field = $form_state['values']["fields_join_column_$table_id-$i"];
  513. }
  514. $form['view_setup_table']["$table_id-$i"]['column-3']["fields_join_$table_id-$i"] = array(
  515. '#type' => 'select',
  516. '#prefix' => "<div class=\"fields-column-join\">",
  517. '#suffix' => "</div>",
  518. '#options' => $chado_join_tables,
  519. '#required' => FALSE,
  520. '#default_value' => $default_join_table,
  521. '#ahah' => array(
  522. 'path' => "tripal/views/integration/ajax/join_field/$table_id-$i/fields_join_column_$table_id-$i",
  523. 'wrapper' => "fields-column-join-column-$table_id-$i",
  524. 'effect' => 'fade',
  525. 'event' => 'change',
  526. 'method' => 'replace',
  527. ),
  528. );
  529. $columns = array();
  530. if ($default_join_table) {
  531. // get the table description
  532. $table_desc = tripal_core_get_chado_table_schema($default_join_table);
  533. foreach ($table_desc['fields'] as $column => $def) {
  534. $columns[$column] = $column;
  535. }
  536. }
  537. else {
  538. $columns = array('Select Join Column');
  539. }
  540. $form['view_setup_table']["$table_id-$i"]['column-3']["fields_join_column_$table_id-$i"] = array(
  541. '#type' => 'select',
  542. '#prefix' => " <div id=\"fields-column-join-column-$table_id-$i\" class=\"fields-column-join-column\">",
  543. '#suffix' => "</div>",
  544. '#options' => $columns,
  545. '#required' => FALSE,
  546. '#default_value' => $default_join_field
  547. );
  548. $default_join_handler = 0;
  549. if (isset($setup_id) && !isset($form_state['values']["fields_join_handler_$table_id-$i"])) {
  550. $default_join_handler = $default_handlers[$column_name]['join']['handler_name'];
  551. $form_state['values']["fields_join_handler_$table_id-$i"] = $default_join_handler;
  552. }
  553. else {
  554. $default_join_handler = $form_state['values']["fields_join_handler_$table_id-$i"];
  555. }
  556. $form['view_setup_table']["$table_id-$i"]['column-3']["fields_join_handler_$table_id-$i"] = array(
  557. '#type' => 'select',
  558. '#prefix' => "<div class=\"fields-join-handler\">",
  559. '#suffix' => "</div>",
  560. '#options' => $handlers_join,
  561. '#required' => FALSE,
  562. '#default_value' => $default_join_handler,
  563. );
  564. // COLUMN 4
  565. $form['view_setup_table']["$table_id-$i"]['column-4'] = array(
  566. '#type' => 'markup',
  567. '#prefix' => "<div class=\"column-four\">",
  568. '#suffix' => "</div>",
  569. '#value' => filter_xss('')
  570. );
  571. // create the handler fields
  572. $default_field_handler = 0;
  573. if (isset($setup_id) && !isset($form_state['values']["fields_field_handler_$table_id-$i"])) {
  574. $default_field_handler = $default_handlers[$column_name]['field']['handler_name'];
  575. $form_state['values']["fields_field_handler_$table_id-$i"] = $default_field_handler;
  576. }
  577. else {
  578. $default_field_handler = $form_state['values']["fields_field_handler_$table_id-$i"];
  579. if (!$default_field_handler) {
  580. if ($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial') {
  581. $default_field_handler = 'chado_views_handler_field_numeric';
  582. }
  583. elseif (preg_match("/character varying/", $column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar') {
  584. $default_field_handler = 'chado_views_handler_field';
  585. }
  586. elseif ($column_type == 'boolean') {
  587. $default_field_handler = 'chado_views_handler_field_boolean';
  588. }
  589. elseif ($column_type == 'float') {
  590. $default_field_handler = 'chado_views_handler_field_numeric';
  591. }
  592. elseif ($column_type == 'datetime') {
  593. $default_field_handler = 'chado_views_handler_field_date';
  594. }
  595. }
  596. }
  597. $form['view_setup_table']["$table_id-$i"]['column-4']["fields_field_handler_$table_id-$i"] = array(
  598. '#type' => 'select',
  599. '#prefix' => "<div class=\"fields-field-handler\">",
  600. '#suffix' => "</div>",
  601. '#options' => $handlers_fields,
  602. '#required' => FALSE,
  603. '#default_value' => $default_field_handler,
  604. );
  605. $default_filter_handler = 0;
  606. if (isset($setup_id) && !isset($form_state['values']["fields_filter_handler_$table_id-$i"])) {
  607. $default_filter_handler = $default_handlers[$column_name]['filter']['handler_name'];
  608. $form_state['values']["fields_filter_handler_$table_id-$i"]= $default_filter_handler;
  609. }
  610. else {
  611. $default_filter_handler = $form_state['values']["fields_filter_handler_$table_id-$i"];
  612. if (!$default_filter_handler) {
  613. if ($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial') {
  614. $default_filter_handler = 'chado_views_handler_filter_numeric';
  615. }
  616. elseif (preg_match("/^character varying/", $column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar') {
  617. $default_filter_handler = 'chado_views_handler_filter_string';
  618. }
  619. elseif ($column_type == 'boolean') {
  620. $default_filter_handler = 'chado_views_handler_filter_boolean';
  621. }
  622. elseif ($column_type == 'float') {
  623. $default_filter_handler = 'chado_views_handler_filter_float';
  624. }
  625. elseif ($column_type == 'datetime') {
  626. $default_filter_handler = 'chado_views_handler_filter_date';
  627. }
  628. }
  629. }
  630. $form['view_setup_table']["$table_id-$i"]['column-4']["fields_filter_handler_$table_id-$i"] = array(
  631. '#type' => 'select',
  632. '#prefix' => "<div class=\"fields-filter-handler\">",
  633. '#suffix' => "</div>",
  634. '#options' => $handlers_filters,
  635. '#required' => FALSE,
  636. '#default_value' => $default_filter_handler,
  637. );
  638. $default_sort_handler = 0;
  639. if (isset($setup_id) && !isset($form_state['values']["fields_sort_handler_$table_id-$i"])) {
  640. $default_sort_handler = $default_handlers[$column_name]['sort']['handler_name'];
  641. $form_state['values']["fields_sort_handler_$table_id-$i"] = $default_sort_handler;
  642. }
  643. else {
  644. $default_sort_handler = $form_state['values']["fields_sort_handler_$table_id-$i"];
  645. if (!$default_sort_handler) {
  646. if ($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial') {
  647. $default_sort_handler = 'chado_views_handler_sort';
  648. }
  649. elseif (preg_match("/character varying/", $column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar') {
  650. $default_sort_handler = 'chado_views_handler_sort';
  651. }
  652. elseif ($column_type == 'boolean') {
  653. $default_sort_handler = 'chado_views_handler_sort';
  654. }
  655. elseif ($column_type == 'float') {
  656. $default_sort_handler = 'chado_views_handler_sort';
  657. }
  658. elseif ($column_type == 'datetime') {
  659. $default_sort_handler = 'chado_views_handler_sort_date';
  660. }
  661. }
  662. }
  663. $form['view_setup_table']["$table_id-$i"]['column-4']["fields_sort_handler_$table_id-$i"] = array(
  664. '#type' => 'select',
  665. '#prefix' => "<div class=\"fields-sort-handler\">",
  666. '#suffix' => "</div>",
  667. '#options' => $handlers_sort,
  668. '#required' => FALSE,
  669. '#default_value' => $default_sort_handler,
  670. );
  671. $default_argument_handler = 0;
  672. if (isset($setup_id) && !isset($form_state['values']["fields_argument_handler_$table_id-$i"])) {
  673. $default_argument_handler = $default_handlers[$column_name]['argument']['handler_name'];
  674. $form_state['values']["fields_argument_handler_$table_id-$i"]=$default_argument_handler ;
  675. }
  676. else {
  677. $default_argument_handler = $form_state['values']["fields_argument_handler_$table_id-$i"];
  678. if (!$default_argument_handler) {
  679. if ($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial') {
  680. $default_argument_handler = 'views_handler_argument_numeric';
  681. }
  682. elseif (preg_match("/character varying/", $column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar') {
  683. $default_argument_handler = 'views_handler_argument_string';
  684. }
  685. elseif ($column_type == 'boolean') {
  686. $default_argument_handler = 'views_handler_argument_numeric';
  687. }
  688. elseif ($column_type == 'float') {
  689. $default_argument_handler = 'views_handler_argument_numeric';
  690. }
  691. elseif ($column_type == 'datetime') {
  692. $default_argument_handler = 'views_handler_argument_date';
  693. }
  694. }
  695. }
  696. $form['view_setup_table']["$table_id-$i"]['column-4']["fields_argument_handler_$table_id-$i"] = array(
  697. '#type' => 'select',
  698. '#prefix' => "<div class=\"fields-argument-handler\">",
  699. '#suffix' => "</div>",
  700. '#options' => $handlers_argument,
  701. '#required' => FALSE,
  702. '#default_value' => $default_argument_handler,
  703. );
  704. $default_relationship_handler = 0;
  705. if (isset($setup_id) && !isset($form_state['values']["fields_relationship_handler_$table_id-$i"])) {
  706. $default_relationship_handler = $default_handlers[$column_name]['relationship']['handler_name'];
  707. $form_state['values']["fields_relationship_handler_$table_id-$i"]=$default_relationship_handler;
  708. }
  709. else {
  710. $default_relationship_handler = $form_state['values']["fields_relationship_handler_$table_id-$i"];
  711. if (!$default_relationship_handler) {
  712. if ($column_type == 'integer' or $column_type == 'int' or $column_type == 'serial') {
  713. $default_relationship_handler = 'views_handler_relationship';
  714. }
  715. elseif (preg_match("/character varying/", $column_type) or $column_type == 'char' or $column_type == 'text' or $column_type == 'varchar') {
  716. $default_relationship_handler = 'views_handler_relationship';
  717. }
  718. elseif ($column_type == 'boolean') {
  719. $default_relationship_handler = 'views_handler_relationship';
  720. }
  721. elseif ($column_type == 'float') {
  722. $default_relationship_handler = 'views_handler_relationship';
  723. }
  724. elseif ($column_type == 'datetime') {
  725. $default_relationship_handler = 'views_handler_relationship';
  726. }
  727. }
  728. }
  729. $form['view_setup_table']["$table_id-$i"]['column-4']["fields_relationship_handler_$table_id-$i"] = array(
  730. '#type' => 'select',
  731. '#prefix' => "<div class=\"fields-relationship-handler\">",
  732. '#suffix' => "</div>",
  733. '#options' => $handlers_rel,
  734. '#required' => FALSE,
  735. '#default_value' => $default_relationship_handler,
  736. );
  737. $i++;
  738. }
  739. $form['view_setup_table']['save'] = array(
  740. '#type' => 'submit',
  741. '#value' => t('Save'),
  742. );
  743. $data['row_count'] = $i - 1;
  744. }
  745. //use this to put values into $form_state['values']
  746. $form['data'] = array();
  747. // Ensure that we don't store an array
  748. // since we will get a check_plain:htmlspecial_characters error if we do
  749. foreach ($data as $key => $value) {
  750. if (is_array($value)) {
  751. $form['data'][$key] = array(
  752. '#type' => 'hidden',
  753. '#value' => serialize($value),
  754. );
  755. }
  756. else {
  757. $form['data'][$key] = array(
  758. '#type' => 'hidden',
  759. '#value' => $value,
  760. );
  761. }
  762. }
  763. $form['#redirect'] = 'admin/tripal/views/integration/list';
  764. return $form;
  765. }
  766. /**
  767. * Purpose: validates the tripal_views_integration_form after submission
  768. *
  769. * @param $form
  770. * The form object which is passed automatically by drupal
  771. *
  772. * @param &$form_state
  773. * The form state pbject which is passed automatically by drupal
  774. *
  775. * @ingroup tripal_views_integration
  776. */
  777. function tripal_views_integration_form_validate($form, &$form_state) {
  778. $name_array = explode(" ", $form_state['values']['row_name']);
  779. $mview_id = $form_state['values']['mview_id'];
  780. $table_name = $form_state['values']['table_name'];
  781. // if (count($name_array) > 1) {
  782. // form_set_error($form_state['values']['row_name'], 'The View type name must be a single word only.');
  783. // }
  784. if ($mview_id and $table_name) {
  785. form_set_error('mview_id', 'Please select either a materialized view or a Chado table but not both');
  786. }
  787. if (!$mview_id and !$table_name) {
  788. form_set_error('mview_id', 'Please select either a materialized view or a Chado table');
  789. }
  790. // Ensure that users don't override the default integrations
  791. if ($form_state['values']['row_priority'] >= 9) {
  792. form_set_error('row_priority', 'A priority of 10 or 9 is reserved for default tripal '
  793. .'views integrations created by core modules. Please set the priority between '
  794. .'0 and -10 to ensure your changes are used rather over the defaults.');
  795. }
  796. // TODO: do we need to require that a handler be set for each field and each type of handler?
  797. }
  798. /**
  799. * Purpose: inserts or updates the record in the tripal views integration
  800. * tables. This function is only called if validation is passed.
  801. *
  802. * @param $form
  803. * The form object which is passed automatically by drupal
  804. *
  805. * @param &$form_state
  806. * The form state pbject which is passed automatically by drupal
  807. *
  808. * @ingroup tripal_views_integration
  809. */
  810. function tripal_views_integration_form_submit($form, &$form_state) {
  811. $name = $form_state['values']['row_name'];
  812. $mview_id = $form_state['values']['mview_id'];
  813. $table_name = $form_state['values']['table_name'];
  814. $setup_id = $form_state['values']['setup_id'];
  815. $priority = $form_state['values']['row_priority'];
  816. $comment = $form_state['values']['row_description'];
  817. // get details about this mview
  818. if ($mview_id) {
  819. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d";
  820. $mview = db_fetch_object(db_query($sql, $mview_id));
  821. $table_name = $mview->mv_table;
  822. $table_id = $mview_id;
  823. $type = 'mview';
  824. }
  825. else {
  826. $type = 'chado';
  827. $table_id = $table_name;
  828. }
  829. // If this is for a materialized view then we want to add/update that record
  830. $tripal_views_record = array();
  831. if ($mview_id) {
  832. // get details about this mview
  833. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d";
  834. $mview = db_fetch_object(db_query($sql, $mview_id));
  835. // build the record for insert/update
  836. $tripal_views_record = array(
  837. 'mview_id' => $mview_id,
  838. 'table_name' => $mview->mv_table,
  839. 'name' => $name,
  840. 'priority' => $priority,
  841. 'comment' => $comment,
  842. 'base_table' => $form_state['values']['base_table']
  843. );
  844. }
  845. // if a chado table then...
  846. else {
  847. // build the record for insert/update
  848. $tripal_views_record = array(
  849. 'table_name' => $table_name,
  850. 'name' => $name,
  851. 'priority' => $priority,
  852. 'comment' => $comment,
  853. 'base_table' => $form_state['values']['base_table']
  854. );
  855. }
  856. // perform the insert or update
  857. if (!$setup_id) { // this is an insert
  858. if (!drupal_write_record('tripal_views', $tripal_views_record)) {
  859. drupal_set_message(t("Failed to add record."), 'error');
  860. return;
  861. }
  862. }
  863. else { // this is an update
  864. // check to see if it was specified to create a new integration
  865. if ($form_state['values']['new_integration']) {
  866. if (!drupal_write_record('tripal_views', $tripal_views_record)) {
  867. drupal_set_message(t("Failed to add record."), 'error');
  868. return;
  869. }
  870. }
  871. else {
  872. $tripal_views_record['setup_id'] = $setup_id;
  873. if (!drupal_write_record('tripal_views', $tripal_views_record, array('setup_id'))) {
  874. drupal_set_message(t("Failed to update record."), 'error');
  875. return;
  876. }
  877. }
  878. }
  879. // if this is an update then clean out the existing joins and handlers so we can add new ones
  880. if ($setup_id) {
  881. db_query("DELETE FROM {tripal_views_field} WHERE setup_id = %d", $setup_id);
  882. db_query("DELETE FROM {tripal_views_join} WHERE setup_id = %d", $setup_id);
  883. db_query("DELETE FROM {tripal_views_handlers} WHERE setup_id = %d", $setup_id);
  884. }
  885. // iterate through the columns of the form and add
  886. // the joins if provided, and the handlers
  887. $i = 1;
  888. foreach (unserialize($form_state['values']['field_types']) as $key => $value) {
  889. // add the field definition
  890. $view_field_record = array(
  891. 'setup_id' => $tripal_views_record['setup_id'],
  892. 'column_name' => $key,
  893. 'name' => $form_state['values']["fields_readable_name_$table_id-$i"],
  894. 'description' => $form_state['values']["fields_description_$table_id-$i"],
  895. 'type' => $value,
  896. );
  897. drupal_write_record('tripal_views_field', $view_field_record);
  898. // first add the join if it exists
  899. $left_table = $form_state['values']["fields_join_$table_id-$i"];
  900. $left_column = $form_state['values']["fields_join_column_$table_id-$i"];
  901. if ($left_column) {
  902. if ($mview_id) {
  903. $base_table = $mview->mv_table;
  904. }
  905. else {
  906. $base_table = $table_name;
  907. }
  908. $view_join_record = array(
  909. 'setup_id' => $tripal_views_record['setup_id'],
  910. 'base_table' => $base_table,
  911. 'base_field' => $key,
  912. 'left_table' => $left_table,
  913. 'left_field' => $left_column,
  914. 'handler' => $form_state['values']["fields_join_handler_$table_id-$i"],
  915. );
  916. // write the new joins to the database
  917. drupal_write_record('tripal_views_join', $view_join_record);
  918. }
  919. // add the hanlders
  920. $handlers = array('filter', 'field', 'sort', 'argument', 'join', 'relationship');
  921. foreach ($handlers as $handler) {
  922. $handler_name = $form_state['values']["fields_" . $handler . "_handler_$table_id-$i"];
  923. if ($handler_name) {
  924. $handler_record = array(
  925. 'setup_id' => $tripal_views_record['setup_id'],
  926. 'column_name' => $key,
  927. 'handler_type' => $handler,
  928. 'handler_name' => $handler_name,
  929. );
  930. drupal_write_record('tripal_views_handlers', $handler_record);
  931. }
  932. }
  933. $i++;
  934. }
  935. if ($setup_id) {
  936. drupal_set_message(t('Record Updated'));
  937. }
  938. else {
  939. drupal_set_message(t('Record Added'));
  940. }
  941. // now clear all the caches so that Drupal views picks up our chages
  942. views_invalidate_cache();
  943. }
  944. /**
  945. * Purpose: this function queries all modules currently enabled on the site
  946. * looking for custom handlers and returns a list of all available handerls.
  947. * The base View handlers are also included.
  948. *
  949. * @return
  950. * Returns an array of handler names
  951. *
  952. * @ingroup tripal_views_integration
  953. */
  954. function tripal_views_integration_discover_handlers() {
  955. $handlers = array();
  956. // Get handlers from all modules.
  957. foreach (module_implements('views_handlers') as $module) {
  958. $function = $module . '_views_handlers';
  959. $result = $function();
  960. if (!is_array($result)) {
  961. continue;
  962. }
  963. foreach ($result['handlers'] as $handler => $parent) {
  964. $handlers[] = $handler;
  965. }
  966. }
  967. // these handlers are hard coded because I could not
  968. // get the views_handlers() function to be called
  969. // in the code above. However, we will be creating
  970. // Chado wrappers for many of these and once that work
  971. // is done these will no longer be needed.
  972. // argument handlers
  973. $handlers[] = 'views_handler_argument';
  974. $handlers[] = 'views_handler_argument_numeric';
  975. $handlers[] = 'views_handler_argument_formula';
  976. $handlers[] = 'views_handler_argument_date';
  977. $handlers[] = 'views_handler_argument_string';
  978. $handlers[] = 'views_handler_argument_many_to_one';
  979. $handlers[] = 'views_handler_argument_null';
  980. // field handlers
  981. $handlers[] = 'views_handler_field';
  982. $handlers[] = 'views_handler_field_date';
  983. $handlers[] = 'views_handler_field_boolean';
  984. $handlers[] = 'views_handler_field_markup';
  985. $handlers[] = 'views_handler_field_xss';
  986. $handlers[] = 'views_handler_field_url';
  987. $handlers[] = 'views_handler_field_file_size';
  988. $handlers[] = 'views_handler_field_prerender_list';
  989. $handlers[] = 'views_handler_field_numeric';
  990. $handlers[] = 'views_handler_field_custom';
  991. $handlers[] = 'views_handler_field_counter';
  992. // filter handlers
  993. $handlers[] = 'views_handler_filter';
  994. $handlers[] = 'views_handler_filter_equality';
  995. $handlers[] = 'views_handler_filter_string';
  996. $handlers[] = 'views_handler_filter_boolean_operator';
  997. $handlers[] = 'views_handler_filter_boolean_operator_string';
  998. $handlers[] = 'views_handler_filter_in_operator';
  999. $handlers[] = 'views_handler_filter_numeric';
  1000. $handlers[] = 'views_handler_filter_float';
  1001. $handlers[] = 'views_handler_filter_date';
  1002. $handlers[] = 'views_handler_filter_many_to_one';
  1003. // relationship handlers
  1004. $handlers[] = 'views_handler_relationship';
  1005. // sort handlers
  1006. $handlers[] = 'views_handler_sort';
  1007. $handlers[] = 'views_handler_sort_formula';
  1008. $handlers[] = 'views_handler_sort_date';
  1009. $handlers[] = 'views_handler_sort_menu_hierarchy';
  1010. $handlers[] = 'views_handler_sort_random';
  1011. // join handler
  1012. $handlers[] = 'views_join';
  1013. return $handlers;
  1014. }
  1015. /*
  1016. *
  1017. * */
  1018. function tripal_views_integration_ajax_view_setup_table() {
  1019. // we only want the table row setup fields
  1020. $form = tripal_core_ahah_prepare_form();
  1021. $form = $form['view_setup_table'];
  1022. $data = drupal_render($form);
  1023. // bind javascript events to the new objects that will be returned
  1024. // so that AHAH enabled elements will work.
  1025. $settings = tripal_core_ahah_bind_events();
  1026. // return the updated JSON
  1027. drupal_json(
  1028. array(
  1029. 'status' => TRUE,
  1030. 'data' => $data,
  1031. 'settings' => $settings,
  1032. )
  1033. );
  1034. }
  1035. /*
  1036. *
  1037. */
  1038. function tripal_views_integration_ajax_join_field($field, $join_field) {
  1039. // prepare and render the form
  1040. $form = tripal_core_ahah_prepare_form();
  1041. $form = $form['view_setup_table'][$field]['column-3'][$join_field];
  1042. $data = drupal_render($form);
  1043. // bind javascript events to the new objects that will be returned
  1044. // so that AHAH enabled elements will work.
  1045. $settings = tripal_core_ahah_bind_events();
  1046. // return the updated JSON
  1047. drupal_json(
  1048. array(
  1049. 'status' => TRUE,
  1050. 'data' => $data,
  1051. 'settings' => $settings,
  1052. )
  1053. );
  1054. }