tripal_views.api.inc 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. <?php
  2. /**
  3. * @file
  4. * API functions for Tripal Views Integration
  5. */
  6. /**
  7. * @defgroup tripal_views_api Tripal Views Module API
  8. * @ingroup tripal_api
  9. * @{
  10. * Provides functions to help extension modules add their own tripal views integrations
  11. * as well as functions for managing default views.
  12. *
  13. * Managing Default Views:
  14. *
  15. * When you create administrative default views (or really any default view) you really
  16. * have no way to ensure that the site administrator keeps these views enabled. In some
  17. * cases this is a good thing and provides the site administrator the ability to disable
  18. * views that don't apply to their particular installation or to replace your default view
  19. * with a custom view of their own. But in other cases, particularily for administration
  20. * views, you want to gaurd against accidental disabling of your views.
  21. *
  22. * One way to do this is to add a landing page using a heook_menu() definition to a custom
  23. * callback returning HTML. You can use this page to render the view if it is enabled but
  24. * provide logic to display a message if the view is disabled. Furthermore, it's often
  25. * helpful to provide a link allowing site administrators to enable the view from your
  26. * page rather than expecting them to go to the views administration UI. This is done for
  27. * all the administration views provided by Tripal. The following is an example of how to
  28. * achomplish this functionality for your own module:
  29. * @code
  30. function mymodule_menu() {
  31. $items = array();
  32. // Create the landing page
  33. $items['admin/tripal/<PATH-TO-YOUR-LANDING-PAGE>'] = array(
  34. 'title' => 'MyModule Administration',
  35. 'description' => 'Administration of my module.',
  36. 'page callback' => 'mymodule_admin_landing_page',
  37. 'access arguments' => array('<YOUR-PERMISSION-KEY>'),
  38. 'type' => MENU_NORMAL_ITEM,
  39. );
  40. // Create one of these for each of your default views
  41. $items['admin/tripal/<PATH-TO-YOUR-ADMIN-SECTION>/views/<VIEW-MACHINE-NAME>/enable'] = array(
  42. 'title' => 'Enable <VIEW-HUMAN-READABLE-NAME>',
  43. 'page callback' => 'tripal_enable_view',
  44. 'page arguments' => array('<VIEW-MACHINE-NAME>', '<PATH-TO-REDIRECT-TO-AFTERWARDS>'),
  45. 'access arguments' => array('<YOUR-PERMISSION-KEY>'),
  46. 'type' => MENU_CALLBACK,
  47. );
  48. return $items;
  49. }
  50. function mymodule_admin_landing_page() {
  51. // Get the View Embed Code
  52. // This function will return FALSE if your view is not enabled
  53. $view_code = views_embed_view('<VIEW-MACHINE-NAME>', '<DISPLAY-MACHINE-NAME');
  54. // If your view is enabled then embed it in this page by returning the embed code
  55. if (isset($view_code)) {
  56. $output .= $view_code;
  57. }
  58. else {
  59. // Provide the landing page with links to the menu item created in hook_menu to
  60. // to enable your view
  61. $output .= '<p>The My Module module uses primarily views to provide an '
  62. . 'administrative interface. Currently one or more views needed for this '
  63. . 'administrative interface are disabled. <strong>Click each of the following links to '
  64. . 'enable the pertinent views</strong>:</p>';
  65. $output .= '<ul>';
  66. // NOTE: <URL-FROM-MENU-TO-ENABLE-VIEW> is
  67. // admin/tripal/<PATH-TO-YOUR-ADMIN-SECTION>/views/<VIEW-MACHINE-NAME>/enable
  68. // from above hook_menu().
  69. $output .= '<li>' . l('<VIEW-HUMAN-RADABLE-NAME>', '<URL-FROM-MENU-TO-ENABLE-VIEW>') . '</li>';
  70. $output .= '</ul>';
  71. }
  72. return $output;
  73. }
  74. * @endcode
  75. *
  76. * Adding your own Tripal Views Integrations:
  77. *
  78. * One of the main ways the Tripal View API is likely to be used is if your module needs
  79. * to create it's own tripal views integration. You might need to do this for any number of
  80. * reasons but the following examples are thought to be the most common:
  81. *
  82. * 1) Your module wants to add handlers with better functionality to fields it has more
  83. * knowledge of than the general integration for all tables
  84. * @code
  85. mymodule_views_data() {
  86. // First check that your integration has not already been added
  87. // When selecting a priority, do not choose -10 or -9 and make sure it is below 0
  88. // so that individual sites still have the ability to override it, if needed
  89. $table_name = 'my_chado_table';
  90. $priority = -5;
  91. if (!tripal_is_table_integrated($table_name, $priority)) {
  92. // If you really only need to tweak an existing integration you can clone it
  93. // If you want to clone the integration that is currently taking priority
  94. // then use tripal_get_lightest_views_integration_priority() as below
  95. $lightest_priority = tripal_get_lightest_views_integration_priority($table_name);
  96. $setup_id = tripal_clone_views_integration($table_name, $priority, $lightest_priority);
  97. // And then make a few changes
  98. // First get the definition array created via the clone above
  99. $defn_array = tripal_export_views_integration($setup_id);
  100. // Then make some changes to the array here
  101. // And finally save the changes to the integration
  102. tripal_update_views_integration($setup_id, $defn_array);
  103. }
  104. }
  105. * @endcode
  106. * 2) Your module creates a chado table that is not already integrated.
  107. * @code
  108. mymodule_views_data() {
  109. // First check that your integration has not already been added
  110. // When selecting a priority, do not choose 10 or 9 and make sure it is below 0
  111. // so that individual sites still have the ability to override it, if needed
  112. $table_name = 'my_chado_table';
  113. $priority = 5;
  114. if (!tripal_is_table_integrated($table_name, $priority)) {
  115. // Describe your table using a large array as specified by tripal_add_views_integration().
  116. $defn_array = array(
  117. 'table' => $table_name, //tablename or materialized view name
  118. 'name' => 'My Chado Table', // Human readable name
  119. 'type' => 'chado', //either chado or mview depending on tablename
  120. 'description' => 'Create a listing from my chado table.', //description seen when creating a view of this type
  121. 'priority' => $priority, //For Base tripal modules: 10; custom modules: 9 to 0;
  122. 'base_table' => TRUE //either TRUE or FALSE depending on whether the current table should show up in the add view list
  123. 'fields' => array(
  124. 'feature_id' => array(
  125. 'name' => 'feature_id', //field name in database
  126. 'title' => 'Feature ID', //human-readable name -seen in Views UI
  127. 'description' => 'This is the unique identifier for features', //help/description seen in Views UI
  128. 'type' => 'int', // the type of field
  129. 'handlers' => array( //possible keys are field, filter, sort, argument, relationship
  130. 'field' => array(
  131. 'name' => 'chado_views_handler_numeric' //name of handler
  132. ),
  133. 'filter' => array( ... ),
  134. ...
  135. ),
  136. 'join' => array( //describe a table that joins to this one via this field
  137. 'table' => 'featureprop', //table to join to
  138. 'field' => 'feature_id', //field in above table (featureprop)
  139. 'handler' => 'views_handler_join_chado_aggregator', //handler to use
  140. ),
  141. )
  142. ),
  143. );
  144. // Actually create the entry
  145. tripal_add_views_integration($defn_array);
  146. }
  147. }
  148. * @endcode
  149. * @}
  150. */
  151. /**
  152. * Programatically enable view
  153. *
  154. * This should be used in a hook_menu definition as the callback to provide a link
  155. * to enable the view (first example). It can also be called directly if needed (second example).
  156. * @code
  157. // Create a URL that when the user navigates there, a given view will be enabled.
  158. // You will still need to provide a link to this menu item somewhere appropriate (ie: an admin landing page).
  159. function mymodule_menu() {
  160. $items = array();
  161. // Create one of these for each of your default views
  162. $items['admin/tripal/<PATH-TO-YOUR-ADMIN-SECTION>/views/<VIEW-MACHINE-NAME>/enable'] = array(
  163. 'title' => 'Enable <VIEW-HUMAN-READABLE-NAME>',
  164. 'page callback' => 'tripal_enable_view',
  165. 'page arguments' => array('<VIEW-MACHINE-NAME>', '<PATH-TO-REDIRECT-TO-AFTERWARDS>'),
  166. 'access arguments' => array('<YOUR-PERMISSION-KEY>'),
  167. 'type' => MENU_CALLBACK,
  168. );
  169. return $items;
  170. }
  171. // Call this function directly to disable a view
  172. // The example shows enabling your own default view when your module is enabled.
  173. // This might be useful if you disable your view when your module is disabled.
  174. function mymodule_enable() {
  175. $view_name = '<VIEW-MACHINE-NAME>';
  176. tripal_enable_view($view_name);
  177. }
  178. * @endcode
  179. *
  180. * @param $view_name
  181. * The machine-name of the view to be enabled
  182. * @param $redirect_link
  183. * The path to redirect to. FALSE if no redirect needed
  184. *
  185. * @ingroup tripal_views_api
  186. */
  187. function tripal_enable_view($view_name, $redirect_link = FALSE) {
  188. $status = variable_get('views_defaults', array());
  189. if (isset($status[$view_name])) {
  190. $status[$view_name] = FALSE;
  191. variable_set('views_defaults', $status);
  192. drupal_set_message("Successfully Enabled $view_name");
  193. }
  194. else {
  195. drupal_set_message("Unable to find a view by the name of '$view_name'. Unable to enable this view.",'error');
  196. }
  197. if ($redirect_link) {
  198. drupal_goto($redirect_link);
  199. }
  200. }
  201. /**
  202. * Programatically disable view.
  203. *
  204. * This should be used in a hook_menu definition as the callback to provide a link
  205. * to disable the view (first example). It can also be called directly if needed (second example).
  206. * @code
  207. // Create a URL that when the user navigates there, a given view will be disabled.
  208. // You will still need to provide a link to this menu item somewhere appropriate.
  209. function mymodule_menu() {
  210. $items = array();
  211. // Create one of these for each of your default views
  212. $items['admin/tripal/<PATH-TO-YOUR-ADMIN-SECTION>/views/<VIEW-MACHINE-NAME>/disable'] = array(
  213. 'title' => 'Disable <VIEW-HUMAN-READABLE-NAME>',
  214. 'page callback' => 'tripal_disable_view',
  215. 'page arguments' => array('<VIEW-MACHINE-NAME>', '<PATH-TO-REDIRECT-TO-AFTERWARDS>'),
  216. 'access arguments' => array('<YOUR-PERMISSION-KEY>'),
  217. 'type' => MENU_CALLBACK,
  218. );
  219. return $items;
  220. }
  221. // Call this function directly to disable a view
  222. // The example shows disabling your own default view when your module is uninstalled
  223. function mymodule_uninstall() {
  224. $view_name = '<VIEW-MACHINE-NAME>';
  225. tripal_disable_view($view_name);
  226. }
  227. * @endcode
  228. *
  229. * @param $view_name
  230. * The machine-name of the view to be enabled
  231. * @param $redirect_link
  232. * The path to redirect to. FALSE if no redirect needed
  233. *
  234. * @ingroup tripal_views_api
  235. */
  236. function tripal_disable_view($view_name, $redirect_link = FALSE) {
  237. $status = variable_get('views_defaults', array());
  238. if (isset($status[$view_name])) {
  239. $status[$view_name] = TRUE;
  240. variable_set('views_defaults', $status);
  241. drupal_set_message("Disabled $view_name");
  242. }
  243. else {
  244. drupal_set_message("Unable to find a view by the name of '$view_name'. Unable to disable this view.",'error');
  245. }
  246. if ($redirect_link) {
  247. drupal_goto($redirect_link);
  248. }
  249. }
  250. /**
  251. * Remove any drupal fields from a chado-based default view definition if chado is external.
  252. * This ensures compatibility with an external chado database.
  253. *
  254. * You should be calling this function in your hook_views_default_views(). This function
  255. * will only remove drupal tables if chado is external; thus you do not need to worry about
  256. * checking yourself. For example, the following is a good hook_views_default_views():
  257. * @code
  258. function mymodule_views_default_views() {
  259. $views = array();
  260. // NOTE: <VIEW-TYPE> describes the type of view:
  261. // - 'admin' for views used for administration of your module
  262. // - 'search' for views used to search data
  263. // - 'list' for views used primarily as data listings
  264. // <VIEW-HUMAN-READABLE-NAME>
  265. $view = mymodule_defaultview_<VIEW-TYPE>_<VIEW-MACHINE-NAME>();
  266. $view = tripal_make_view_compatible_with_external($view);
  267. $views[$view->name] = $view;
  268. // <VIEW-HUMAN-READABLE-NAME>
  269. $view = mymodule_defaultview_<VIEW-TYPE>_<VIEW-MACHINE-NAME>();
  270. $view = tripal_make_view_compatible_with_external($view);
  271. $views[$view->name] = $view;
  272. return $views;
  273. }
  274. function mymodule_defaultview_<VIEW-TYPE>_<VIEW-MACHINE-NAME>() {
  275. // PASTE VIEWS EXPORT CODE HERE
  276. return $view;
  277. }
  278. function mymodule_defaultview_<VIEW-TYPE>_<VIEW-MACHINE-NAME>() {
  279. // PASTE VIEWS EXPORT CODE HERE
  280. return $view;
  281. }
  282. * @endcode
  283. * Notice that the actual views export code is in a separate function. This makes your
  284. * hook_views_default_views() more readable.
  285. *
  286. * NOTE: Currently assumes all tables not in the tripal views integration tables are Drupal tables.
  287. *
  288. * @param $view
  289. * The default view definition object
  290. * @return
  291. * The default view with all relationships, fields, filters, sorts, arguements for
  292. * Drupal tables removed.
  293. */
  294. function tripal_make_view_compatible_with_external($view) {
  295. $remove_table = array();
  296. // First check that the base table for the view is a chado table
  297. // If it's not then don't do any filtering
  298. $setup_id = tripal_is_table_integrated($view->base_table);
  299. if (!$setup_id) {
  300. return $view;
  301. }
  302. // IF chado is external then remove all config relating to drupal tables
  303. if (!chado_is_local()) {
  304. // Iterate through all displays
  305. foreach ($view->display as $display_name => $display) {
  306. $display_options = $display->handler->display->display_options;
  307. $sections = array('fields', 'filters', 'sorts', 'relationships');
  308. foreach ($sections as $section) {
  309. $display_options[$section] = (isset($display_options[$section])) ? $display_options[$section] : array();
  310. foreach ($display_options[$section] as $key => $defn) {
  311. // If the table has not already been encountered; check if it's in tripal_views
  312. if (!isset($remove_table[ $defn['table'] ])) {
  313. // If the table is view then this is a general handler; thus keep
  314. if ($defn['table'] == 'views') {
  315. $remove_table[ $defn['table'] ] = FALSE;
  316. }
  317. // If this table is integrated then it is chado; thus keep
  318. $setup_id = tripal_is_table_integrated($defn['table']);
  319. if ($setup_id) {
  320. $remove_table[ $defn['table'] ] = FALSE;
  321. }
  322. else {
  323. $remove_table[ $defn['table'] ] = TRUE;
  324. }
  325. }
  326. // Based on the $remove_table array, unset this field if its from a drupal table
  327. if ($remove_table[ $defn['table'] ]) {
  328. unset($view->display[$display_name]->handler->display->display_options[$section][$key]);
  329. }
  330. }
  331. }
  332. }
  333. }
  334. return $view;
  335. }
  336. /**
  337. * Retrieve the priority of the lightest priority for a given table.
  338. *
  339. * NOTE: Uses lightest priority (drupal-style) where the range is from -10 to 10
  340. * and -10 is of highest priority.
  341. *
  342. * @param $table_name
  343. * The name of the table to retrieve the setup ID for. This can be either a materialized
  344. * view or a chado table
  345. *
  346. * @return
  347. * returns the lowest priority. If the table has not been integrated, a priority of 10
  348. * is returned.
  349. *
  350. * @ingroup tripal_views_api
  351. */
  352. function tripal_get_lightest_views_integration_priority($table_name) {
  353. // D7 TODO: Check DBTNG changes work
  354. $sql = "SELECT priority FROM {tripal_views} WHERE table_name=:table ORDER BY priority ASC";
  355. $setup = db_query($sql, array(':table' => $table_name));
  356. $setup = $setup->fetchObject();
  357. if ($setup) {
  358. return $setup->priority;
  359. }
  360. else {
  361. // default priority is 10
  362. return 10;
  363. }
  364. }
  365. /**
  366. * Retrieve the views integration setup_id with the lightest priority for a given table
  367. *
  368. * NOTE: Uses lightest priority (drupal-style) where the range is from -10 to 10
  369. * and -10 is of highest priority.
  370. *
  371. * @param $table_name
  372. * The name of the table to retrieve the setup ID for. This can be either a materialized
  373. * view or a chado table
  374. *
  375. * @return
  376. * On success, the setup_id to use for integration of this table; otherwise FALSE
  377. *
  378. * @ingroup tripal_views_api
  379. */
  380. function tripal_get_lightest_views_integration_setup($table_name) {
  381. // D7 TODO: Check DBTNG changes work
  382. $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name=:table ORDER BY priority ASC";
  383. $setup = db_query($sql, array(':table' => $table_name));
  384. $setup = $setup->fetchObject();
  385. if ($setup) {
  386. return $setup->setup_id;
  387. }
  388. else {
  389. return FALSE;
  390. }
  391. }
  392. /**
  393. * Retrieve the views integration setup_id with the given priority/table combination.
  394. *
  395. * @param $table_name
  396. * The name of the table to retrieve the setup ID for. This can be either a materialized
  397. * view or a chado table
  398. * @param $priority
  399. * The priority of the integration to retrieve the setup_id for
  400. *
  401. * @return
  402. * On success, the setup_id to use for integration of this table; otherwise FALSE
  403. *
  404. * @ingroup tripal_views_api
  405. */
  406. function tripal_get_views_integration_setup_id($table_name, $priority) {
  407. // D7 TODO: Check DBTNG changes work
  408. $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name=:table AND priority=:priority ORDER BY priority ASC";
  409. $setup = db_query($sql, array(':table' => $table_name, ':priority' => $priority));
  410. $setup = $setup->fetchObject();
  411. if ($setup) {
  412. return $setup->setup_id;
  413. }
  414. else {
  415. return FALSE;
  416. }
  417. }
  418. /**
  419. * Check to see if this table already has an integration record with the given priority.
  420. *
  421. * @param $table_name
  422. * The name of the table to check for integration
  423. * @param $priority (optional)
  424. * The priority of record to check for
  425. *
  426. * @return
  427. * If the table is already integrated, the setup_id of the existing integration
  428. * record is returned (If priority is not specified this will be the lightest record);
  429. * Otherwise the table is not already integrated and FALSE is returned.
  430. *
  431. * @ingroup tripal_views_api
  432. */
  433. function tripal_is_table_integrated($table_name, $priority = NULL) {
  434. if ($priority) {
  435. // D7 TODO: Check DBTNG changes work
  436. $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name=:table AND priority=:priority";
  437. $setup = db_query($sql, array(':table' => $table_name, ':priority' => $priority));
  438. $setup = $setup->fetchObject();
  439. }
  440. else {
  441. // D7 TODO: Check DBTNG changes work
  442. $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name=:table ORDER BY priority ASC";
  443. $setup = db_query($sql, array(':table' => $table_name));
  444. $setup = $setup->fetchObject();
  445. }
  446. if ($setup) {
  447. return $setup->setup_id;
  448. }
  449. else {
  450. return FALSE;
  451. }
  452. }
  453. /**
  454. * Checks if you are dealing with the lightest priority setup for a given table. This is a
  455. * good way to determine whether your modules integration is being used by views.
  456. *
  457. * @param $setup_id
  458. * The ID of the setup to check (is this setup the lightest one?)
  459. * @param $table_name
  460. * The name of the table associated with this setup
  461. *
  462. * @return TRUE is this is the lightest priority; FALSE otherwise
  463. *
  464. * @ingroup tripal_views_api
  465. */
  466. function tripal_is_lightest_priority_setup($setup_id, $table_name) {
  467. $lightest_priority_setup_id = tripal_get_lightest_views_integration_setup($table_name);
  468. if ($lightest_priority_setup_id == $setup_id) {
  469. return TRUE;
  470. }
  471. else {
  472. return FALSE;
  473. }
  474. }
  475. /**
  476. * Rebuilds all the default integrations.
  477. *
  478. * This essentially clears the cache in case you mess up the integrations in your site.
  479. * This should not be used during module development since it really only rebuilds the
  480. * integrations described by all enabled modules in the site and if $delete_first is
  481. * TRUE it can delete custom integrations created by site administrators which will not
  482. * make your module popular.
  483. *
  484. * @param $delete_first
  485. * If TRUE then all integrations are first deleted.
  486. *
  487. * @ingroup tripal_views_api
  488. */
  489. function tripal_rebuild_views_integrations($delete_first = FALSE) {
  490. if ($delete_first) {
  491. tripal_views_delete_all_integrations();
  492. }
  493. tripal_views_integrate_all_chado_tables();
  494. drupal_set_message('Successfully rebuilt default Tripal Views Integrations');
  495. }
  496. /**
  497. * Add views integration records into the tripal_views* tables.
  498. *
  499. * This is the programatic way to add your own integrations to the tripal views integrations
  500. * list. Keep in mind that the priority set in your $defn_array needs to be lighter than
  501. * any existing integrations to be used by views and that it should still be below 0
  502. * in order to allow site administrators to override it should they need to.
  503. *
  504. * @param $defn_array
  505. * An array describing the structure and fields of the table
  506. *
  507. * @return
  508. * True/False if completed successfully/not
  509. *
  510. * Example usage (in hook_install()):
  511. * @code
  512. $defn_array = array(
  513. 'table' => 'feature', //tablename or materialized view name
  514. 'name' => 'Sequence Features', // Human readable name
  515. 'type' => 'chado', //either chado or mview depending on tablename
  516. 'description' => 'Create a listing of features.', //description seen when creating a view of this type
  517. 'priority' => 10, //For Base tripal modules: 10; custom modules: 9 to 0;
  518. 'base_table' => TRUE //either TRUE or FALSE depending on whether the current table should show up in the add view list
  519. 'fields' => array(
  520. 'feature_id' => array(
  521. 'name' => 'feature_id', //field name in database
  522. 'title' => 'Feature ID', //human-readable name -seen in Views UI
  523. 'description' => 'This is the unique identifier for features', //help/description seen in Views UI
  524. 'type' => 'int', // the type of field
  525. 'handlers' => array( //possible keys are field, filter, sort, argument, relationship
  526. 'field' => array(
  527. 'name' => 'chado_views_handler_numeric' //name of handler
  528. ),
  529. 'filter' => array( ... ),
  530. ...
  531. ),
  532. 'join' => array( //describe a table that joins to this one via this field
  533. 'table' => 'featureprop', //table to join to
  534. 'field' => 'feature_id', //field in above table (featureprop)
  535. 'handler' => 'views_handler_join_chado_aggregator', //handler to use
  536. ),
  537. )
  538. ),
  539. );
  540. tripal_add_views_integration($defn_array);
  541. * @endcode
  542. *
  543. * @ingroup tripal_views_api
  544. */
  545. function tripal_add_views_integration($defn_array, $setup_id = FALSE) {
  546. $no_errors = TRUE;
  547. if (empty($defn_array['table'])) {
  548. tripal_report_error('tripal_views', TRIPAL_WARNING, 'Recieved integration with no tablename: %defn', array('%defn' => print_r($defn_array,TRUE)));
  549. $no_errors = FALSE;
  550. return $no_errors;
  551. }
  552. // First insert into tripal_views
  553. $view_record = array(
  554. 'table_name' => $defn_array['table'],
  555. 'name' => $defn_array['name'],
  556. 'comment' => $defn_array['description'],
  557. 'priority' => $defn_array['priority'],
  558. 'base_table' => $defn_array['base_table'],
  559. );
  560. if ($setup_id) {
  561. $view_record['setup_id'] = $setup_id;
  562. }
  563. if ($defn_array['type'] == 'mview') {
  564. // D7 TODO: Check DBTNG changes work
  565. $mview = db_query("SELECT mview_id FROM {tripal_mviews} WHERE mv_table=:table", array(':table' => $defn_array['table']));
  566. $mview = $mview->fetchObject();
  567. $view_record['mview_id'] = $mview->mview_id;
  568. if (!$mview->mview_id) {
  569. return FALSE;
  570. }
  571. }
  572. if ($view_record['name']) { // && $view_record['comment']) { # SPF: commented out 9/24/2012 .. It's not required on the form
  573. if (isset($defn_array['additional_content'])) {
  574. // D7 TODO: Check DBTNG changes work
  575. $setup = db_query(
  576. "SELECT * FROM {tripal_views} WHERE table_name=:table AND priority=:priority",
  577. array(':table' => $view_record['table_name'], ':priority' => $view_record['priority'])
  578. );
  579. $setup = $setup->fetchObject();
  580. if (empty($setup->setup_id)) {
  581. $status = drupal_write_record('tripal_views', $view_record);
  582. }
  583. else {
  584. $view_record['setup_id'] = $setup->setup_id;
  585. $status = drupal_write_record('tripal_views', $view_record, 'setup_id');
  586. }
  587. }
  588. else {
  589. $status = drupal_write_record('tripal_views', $view_record);
  590. }
  591. }
  592. else {
  593. $status = FALSE;
  594. drupal_set_message(t('Unable to integrate "%table" table due to a missing name field.', array('%table' => $defn_array['table'])), 'error');
  595. }
  596. if ($status) {
  597. // Need to update the tripal_views record so base_table can be false
  598. // this is a fix because drupal_write_record() puts in defaults if !isset()
  599. // and a variable is considered not set if it's null!
  600. // D7 TODO: Check DBTNG changes work
  601. db_query(
  602. "UPDATE {tripal_views} SET base_table=:base WHERE table_name=:table AND priority=:priority",
  603. array(
  604. ':base' => $defn_array['base_table'],
  605. ':table' => $defn_array['table'],
  606. ':priority' => $defn_array['priority']
  607. )
  608. );
  609. // Insert Field Definitions
  610. foreach ($defn_array['fields'] as $field) {
  611. $field_record = array(
  612. 'setup_id' => $view_record['setup_id'],
  613. 'column_name' => $field['name'],
  614. 'name' => $field['title'],
  615. 'description' => $field['description'],
  616. 'type' => $field['type'],
  617. );
  618. if ($view_record['setup_id'] && $field['name'] && $field['title'] && $field['description'] && $field['type']) {
  619. if (isset($defn_array['additional_content'])) {
  620. // D7 TODO: Check DBTNG changes work
  621. $is = db_query(
  622. "SELECT true as present FROM {tripal_views_field} WHERE column_name=:column AND setup_id=:setup",
  623. array(
  624. ':column' => $field_record['column_name'],
  625. ':setup' => $field_record['setup_id']
  626. )
  627. );
  628. $is = $is->fetchObject();
  629. if (!$is->present) {
  630. $status = drupal_write_record('tripal_views_field', $field_record);
  631. }
  632. else {
  633. $status = drupal_write_record('tripal_views_field', $field_record, array('setup_id', 'column_name'));
  634. }
  635. }
  636. else {
  637. $status = drupal_write_record('tripal_views_field', $field_record);
  638. }
  639. }
  640. else {
  641. drupal_set_message(t('Unable to integrate %name field due to missing required fields.', array('%name' => $field['name'])), 'error');
  642. $status = FALSE;
  643. }
  644. if ($status) {
  645. // Insert Handler Definitions
  646. foreach ($field['handlers'] as $handler_type => $handler) {
  647. $handler_record = array(
  648. 'setup_id' => $view_record['setup_id'],
  649. 'column_name' => $field['name'],
  650. 'handler_type' => $handler_type,
  651. 'handler_name' => $handler['name'],
  652. 'arguments' => serialize($handler)
  653. );
  654. if ($view_record['setup_id'] && $field['name'] && $handler_type && $handler['name'] && $handler) {
  655. $status = drupal_write_record('tripal_views_handlers', $handler_record);
  656. }
  657. else {
  658. $status = FALSE;
  659. }
  660. if (!$status) {
  661. drupal_set_message(t('Unable to integrate %handler_type handler: %handler_name', array('%handler_type' => $handler_type, '%handler_name' => $handler['name'])), 'error');
  662. $no_errors = FALSE;
  663. }
  664. }
  665. // Insert Joins
  666. if (!is_array($field['joins'])) {
  667. $field['joins'] = array();
  668. }
  669. foreach ($field['joins'] as $join) {
  670. $join_record = array(
  671. 'setup_id' => $view_record['setup_id'],
  672. 'base_table' => $defn_array['table'],
  673. 'base_field' => $field['name'],
  674. 'left_table' => $join['table'],
  675. 'left_field' => $join['field'],
  676. );
  677. $join_record['handler'] = (!empty($join['handler'])) ? $join['handler'] : 'views_join';
  678. $join_record['relationship_handler'] = (!empty($join['relationship_handler'])) ? $join['relationship_handler'] : 'views_handler_relationship';
  679. $join_record['relationship_only'] = (!empty($join['relationship_only'])) ? $join['relationship_only'] : 0;
  680. if ($view_record['setup_id'] && $defn_array['table'] && $field['name'] && $join['table'] && $join['field']) {
  681. $status = drupal_write_record('tripal_views_join', $join_record);
  682. }
  683. else {
  684. $status = FALSE;
  685. }
  686. if (!$status) {
  687. drupal_set_message(
  688. t(
  689. 'Unable to join %left_table.%left_field with %table.%field',
  690. array(
  691. '%left_table' => $join['table'],
  692. '%left_field' => $join['field'],
  693. '%table' => $defn_array['table'],
  694. '%field' => $field['name']
  695. )
  696. ),
  697. 'error'
  698. );
  699. $no_errors = FALSE;
  700. }
  701. }
  702. }
  703. else {
  704. drupal_set_message(t('Unable to integrate %field_name field', array('%field_name' => $field['name'])), 'error');
  705. $no_errors = FALSE;
  706. }
  707. }
  708. }
  709. else {
  710. drupal_set_message(t('Unable to set default tripal views integration'), 'error');
  711. $no_errors = FALSE;
  712. }
  713. return $no_errors;
  714. }
  715. /**
  716. * Export Views integration records.
  717. *
  718. * This is a great way to create your own integration since it returns an already defined
  719. * integration in array form that you can modify. After modifications simply set the
  720. * priority to something lighter (but still below 0) than any existing integrations
  721. * and use tripal_add_views_integration() to add it to the list of integrations.
  722. *
  723. * @param $setup_id
  724. * The unique setup id of the tripal views integration
  725. *
  726. * @return
  727. * A views integration definition array as used by tripal_add_views_integration()
  728. *
  729. * @ingroup tripal_views_api
  730. */
  731. function tripal_export_views_integration($setup_id) {
  732. // Main setup details
  733. // D7 TODO: Check DBTNG changes work
  734. $r = db_query("SELECT * FROM {tripal_views} WHERE setup_id=:setup", array(':setup' => $setup_id));
  735. $r = $r->fetchObject();
  736. $defn_array = array(
  737. 'table' => $r->table_name,
  738. 'name' => $r->name,
  739. 'type' => ($r->mview_id) ? 'mview' : 'chado',
  740. 'description' => $r->comment,
  741. 'priority' => $r->priority,
  742. 'base_table' => $r->base_table,
  743. 'fields' => array(),
  744. );
  745. // Add fields
  746. // D7 TODO: Check DBTNG changes work
  747. $resource = db_query("SELECT * FROM {tripal_views_field} WHERE setup_id=:setup", array(':setup' => $setup_id));
  748. foreach ($resource as $r) {
  749. $defn_array['fields'][ $r->column_name ] = array(
  750. 'name' => $r->column_name,
  751. 'title' => $r->name,
  752. 'description' => $r->description,
  753. 'type' => $r->type,
  754. 'handlers' => array(),
  755. 'joins' => array()
  756. );
  757. }
  758. // Add handlers
  759. // D7 TODO: Check DBTNG changes work
  760. $resource = db_query("SELECT * FROM {tripal_views_handlers} WHERE setup_id=:setup", array(':setup' => $setup_id));
  761. foreach ($resource as $r) {
  762. $defn_array['fields'][ $r->column_name ]['handlers'][ $r->handler_type ] = array(
  763. 'name' => $r->handler_name
  764. );
  765. }
  766. // Add joins
  767. // D7 TODO: Check DBTNG changes work
  768. $resource = db_query("SELECT * FROM {tripal_views_join} WHERE setup_id=:setup", array(':setup' => $setup_id));
  769. foreach ($resource as $r) {
  770. $defn_array['fields'][ $r->base_field ]['joins'][ $r->left_table ] = array(
  771. 'table' => $r->left_table,
  772. 'field' => $r->left_field,
  773. 'handler' => $r->handler,
  774. );
  775. }
  776. return $defn_array;
  777. }
  778. /**
  779. * Removes a View Integration Entry when you only know the table the integration was
  780. * created for and the priority.
  781. *
  782. * This should only be used to remove integrations created by your own module (possibly
  783. * on uninstall of your module). To override existing integrations simply create your own
  784. * integration with a lighter priority using tripal_clone_views_integration() or
  785. * tripal_export_views_integration() to create a template.
  786. *
  787. * @param $identifies
  788. * An array of identifiers where the keys indicate what the identifier is. One of the
  789. * following compinations must be present:
  790. * 1) table_name & priority: the name of the table & the priority to remove a views
  791. * integration entry for
  792. * 2) setup_id: the setup_id of the entry to remove
  793. * @param $options
  794. * An array of options, currently none are supported
  795. *
  796. * @return
  797. * TRUE on Success; FALSE otherwise
  798. *
  799. * @ingroup tripal_views_api
  800. */
  801. function tripal_remove_views_integration($identifiers, $options = array()) {
  802. // Remove the views integration using the table_name/priority combo
  803. if (isset($identifiers['table_name'])) {
  804. $table_name = $identifiers['table_name'];
  805. $priority = $identifiers['priority'];
  806. $views = db_query(
  807. "SELECT * FROM {tripal_views} WHERE table_name=:table AND priority=:priority",
  808. array(
  809. ':table' => $table_name,
  810. ':priority' => $priority
  811. )
  812. );
  813. $views = $views->fetchObject();
  814. if ($views->setup_id) {
  815. $identifiers['setup_id'] = $views->setup_id;
  816. }
  817. }
  818. // Remove the views integration using the setup_id
  819. if (isset($identifiers['setup_id'])) {
  820. db_query('DELETE FROM {tripal_views} WHERE setup_id=:setup', array(':setup' => $identifiers['setup_id']));
  821. db_query('DELETE FROM {tripal_views_field} WHERE setup_id=:setup', array(':setup' => $identifiers['setup_id']));
  822. db_query('DELETE FROM {tripal_views_handlers} WHERE setup_id=:setup', array(':setup' => $identifiers['setup_id']));
  823. db_query('DELETE FROM {tripal_views_join} WHERE setup_id=:setup', array(':setup' => $identifiers['setup_id']));
  824. return TRUE;
  825. }
  826. return FALSE;
  827. }
  828. /**
  829. * Update an existing Views Intregration Entry.
  830. * This essentially removes and then re-adds the integration.
  831. *
  832. * @param $setup_id
  833. * The setup ID of the views integration entry to update
  834. * @param $defn_array
  835. * An array describing the structure and fields of the table as is used in
  836. * tripal_add_views_integration().
  837. *
  838. * @ingroup tripal_views_api
  839. */
  840. function tripal_update_views_integration($setup_id, $defn_array) {
  841. tripal_remove_views_integration(array('setup_id' => $setup_id));
  842. $defn_array['additional_content'] = TRUE;
  843. tripal_add_views_integration($def_array, $setup_id);
  844. }
  845. /**
  846. * Clone an integration. This is often a great way to create your own module-specific
  847. * integration while still benifiting from an existing (or even the lightest priority)
  848. * integration.
  849. *
  850. * @param $table_name
  851. * The table for which you'd like to clone an integration
  852. * @param $new_priority
  853. * The priority of the clone; this is the integration which will be created.
  854. * If no priority is supplied then one lighter then the $template_priority will be used.
  855. * @param $template_priority
  856. * The priority of the template to be used for the clone; this is an existing integration.
  857. * If no priority is supplied then the lightest priority will be used.
  858. *
  859. * @ingroup tripal_views_api
  860. */
  861. function tripal_clone_views_integration($table_name, $new_priority = NULL, $template_priority = NULL) {
  862. if (empty($template_priority)) {
  863. $template_setup_id = tripal_get_lightest_views_integration_setup($table_name);
  864. }
  865. else {
  866. $template_setup_id = tripal_get_views_integration_setup_id($table_name, $template_priority);
  867. }
  868. $defn_array = tripal_export_views_integration($template_setup_id);
  869. if (empty($new_priority)) {
  870. $defn_array['priority'] = $new_priority;
  871. }
  872. else {
  873. $new_priority = $defn_array['priority'] - 1;
  874. $defn_array['priority'] = $defn_array['priority'] - 1;
  875. }
  876. // D7 TODO: Check DBTNG changes work
  877. tripal_add_views_integration($defn_array);
  878. $setup_id = db_query(
  879. "SELECT setup_id FROM {tripal_views} WHERE table_name=:table AND priority=:priority",
  880. array(
  881. ':table' => $table_name,
  882. ':priority' => $new_priority
  883. )
  884. );
  885. $setup_id = $setup_id->fetchObject();
  886. if (empty($setup_id)) {
  887. tripal_report_error('tripal_views', TRIPAL_ERROR, 'Unable to clone the setup for %table in order to add the following field to the integration: %field.',
  888. array('%table' => $table_name, '%field' => print_r($field_array,TRUE)));
  889. return FALSE;
  890. }
  891. else {
  892. return $setup_id;
  893. }
  894. }
  895. /**
  896. * Adds the given field to an existing or cloned integration. In the case of a cloned
  897. * integration, the lightest integration is used as the template for the clone.
  898. *
  899. * NOTE: If that field already exists in the specified integration then it will first be
  900. * deleted and the new one added.
  901. *
  902. * @param $table_name
  903. * The name of the table the integration is for
  904. * @param $priority
  905. * The priority of the integration to use; pass NULL to use the lightest integration
  906. * @param $field
  907. * An array describing the field ot add; uses the same format as the $defn_array
  908. *
  909. * @return
  910. * TRUE if the field was added successfully; FALSE otherwise
  911. *
  912. * @ingroup tripal_views_api
  913. */
  914. function tripal_add_field_to_views_integration($table_name, $priority, $field) {
  915. $no_errors = TRUE;
  916. // If no priority is supplied then add the field to the lightest integration
  917. if (empty($priority)) {
  918. $priority = tripal_get_lightest_views_integration_priority($table_name);
  919. }
  920. // First get the setup_id
  921. // D7 TODO: Check DBTNG changes work
  922. $setup_id = db_query(
  923. "SELECT setup_id FROM {tripal_views} WHERE table_name=:table AND priority=:priority",
  924. array(
  925. ':table' => $table_name,
  926. ':priority' => $priority
  927. )
  928. );
  929. $setup_id = $setup_id->fetchObject();
  930. // If there isn't an integration matching that table/priority combination
  931. // then clone the lightest priority integration
  932. if (empty($setup_id)) {
  933. $setup_id = tripal_clone_views_integration($table_name, $priority);
  934. }
  935. // Now delete any existing field
  936. db_query("DELETE FROM {tripal_views_field} WHERE setup_id=:setup AND column_name=:column",
  937. array(':setup' => $setup_id, 'column' => $field['name'])
  938. );
  939. db_query("DELETE FROM {tripal_views_handlers} WHERE setup_id=:setup AND column_name=:column",
  940. array(':setup' => $setup_id, 'column' => $field['name'])
  941. );
  942. db_query("DELETE FROM {tripal_views_join} WHERE setup_id=:setup AND base_table=:table AND base_field=:field",
  943. array(':setup' => $setup_id, ':table' => $table_name, ':field' => $field['name'])
  944. );
  945. // Now we need to add/update the field
  946. $field_record = array(
  947. 'setup_id' => $setup_id,
  948. 'column_name' => $field['name'],
  949. 'name' => $field['title'],
  950. 'description' => $field['description'],
  951. 'type' => $field['type'],
  952. );
  953. if ($setup_id && $field['name'] && $field['title'] && $field['description'] && $field['type']) {
  954. if ($defn_array['additional_content']) {
  955. // D7 TODO: Check DBTNG changes work
  956. $is = db_query(
  957. "SELECT true as present FROM {tripal_views_field} WHERE column_name=:column AND setup_id=:setup",
  958. array(':column' => $field_record['column_name'], ':setup' => $field_record['setup_id'])
  959. );
  960. $is = $is->fetchObject();
  961. if (!$is->present) {
  962. $status = drupal_write_record('tripal_views_field', $field_record);
  963. }
  964. else {
  965. $status = drupal_write_record('tripal_views_field', $field_record, array('setup_id', 'column_name'));
  966. }
  967. }
  968. else {
  969. $status = drupal_write_record('tripal_views_field', $field_record);
  970. }
  971. }
  972. else {
  973. drupal_set_message(t('Unable to integrate %name field due to missing required fields.', array('%name' => $field['name'])), 'error');
  974. $status = FALSE;
  975. }
  976. if ($status) {
  977. // Insert Handler Definitions
  978. foreach ($field['handlers'] as $handler_type => $handler) {
  979. $handler_record = array(
  980. 'setup_id' => $setup_id,
  981. 'column_name' => $field['name'],
  982. 'handler_type' => $handler_type,
  983. 'handler_name' => $handler['name'],
  984. 'arguments' => serialize($handler)
  985. );
  986. if ($setup_id && $field['name'] && $handler_type && $handler['name'] && $handler) {
  987. $status = drupal_write_record('tripal_views_handlers', $handler_record);
  988. }
  989. else {
  990. $status = FALSE;
  991. }
  992. if (!$status) {
  993. drupal_set_message(t('Unable to integrate %handler_type handler: %handler_name', array('%handler_type' => $handler_type, '%handler_name' => $handler['name'])), 'error');
  994. $no_errors = FALSE;
  995. }
  996. }
  997. // Insert Joins
  998. if (!is_array($field['joins'])) {
  999. $field['joins'] = array();
  1000. }
  1001. foreach ($field['joins'] as $join) {
  1002. $join_record = array(
  1003. 'setup_id' => $setup_id,
  1004. 'base_table' => $defn_array['table'],
  1005. 'base_field' => $field['name'],
  1006. 'left_table' => $join['table'],
  1007. 'left_field' => $join['field'],
  1008. );
  1009. if (!empty($join['handler'])) {
  1010. $join_record['handler'] = $join['handler'];
  1011. }
  1012. else {
  1013. $join_record['handler'] = 'views_join';
  1014. }
  1015. if ($setup_id && $defn_array['table'] && $field['name'] && $join['table'] && $join['field']) {
  1016. $status = drupal_write_record('tripal_views_join', $join_record);
  1017. }
  1018. else {
  1019. $status = FALSE;
  1020. }
  1021. if (!$status) {
  1022. drupal_set_message(
  1023. t(
  1024. 'Unable to join %left_table.%left_field with %table.%field',
  1025. array(
  1026. '%left_table' => $join['table'],
  1027. '%left_field' => $join['field'],
  1028. '%table' => $defn_array['table'],
  1029. '%field' => $field['name']
  1030. )
  1031. ),
  1032. 'error'
  1033. );
  1034. $no_errors = FALSE;
  1035. }
  1036. }
  1037. }
  1038. else {
  1039. drupal_set_message(t('Unable to integrate %field_name field', array('%field_name' => $field['name'])), 'error');
  1040. $no_errors = FALSE;
  1041. }
  1042. return $no_errors;
  1043. }
  1044. /**
  1045. * Adds the given field to an existing or cloned integration. In the case of a cloned
  1046. * integration, the lightest integration is used as the template for the clone.
  1047. *
  1048. * NOTE: If that field already exists in the specified integration then it will first be
  1049. * deleted and the new one added.
  1050. *
  1051. * @param $table_name
  1052. * The name of the table the integration is for
  1053. * @param $priority
  1054. * The priority of the integration to use; pass NULL to use the lightest integration
  1055. * @param $field
  1056. * An array describing the field ot add; uses the same format as the $defn_array
  1057. *
  1058. * @return
  1059. * TRUE if the field was added successfully; FALSE otherwise
  1060. *
  1061. * @ingroup tripal_views_api
  1062. */
  1063. function tripal_add_join_to_views_integration($table_name, $priority, $join) {
  1064. $no_errors = TRUE;
  1065. // If no priority is supplied then add the field to the lightest integration
  1066. if (empty($priority)) {
  1067. $priority = tripal_get_lightest_views_integration_priority($table_name);
  1068. }
  1069. // First get the setup_id
  1070. $setup_id = db_query(
  1071. "SELECT setup_id FROM {tripal_views} WHERE table_name=:table AND priority=:priority",
  1072. array(
  1073. ':table' => $table_name,
  1074. ':priority' => $priority
  1075. )
  1076. );
  1077. $setup_id = $setup_id->fetchField();
  1078. // If there isn't an integration matching that table/priority combination
  1079. // then clone the lightest priority integration
  1080. if (empty($setup_id)) {
  1081. $setup_id = tripal_clone_views_integration($table_name, $priority);
  1082. $setup_id = $setup_id->setup_id;
  1083. }
  1084. // Add the setup_id to the join record passed in
  1085. $join['setup_id'] = $setup_id;
  1086. drupal_write_record('tripal_views_join', $join);
  1087. }
  1088. /**
  1089. * Remove a join from an integration. This is usually done after cloning an existing
  1090. * integration using tripal_clone_views_integration().
  1091. *
  1092. * @param $setup_id
  1093. * The setup_id of the integration to delete the join from
  1094. * @param $base_table
  1095. * The name of the base table involved the join
  1096. * @param $base_field
  1097. * The field from the base table involved in the join
  1098. * @param $left_table
  1099. * The name of the other table involved in the join
  1100. * @param $left_field
  1101. * The name of the field from the other table involved in the join
  1102. *
  1103. * @ingroup tripal_views_api
  1104. */
  1105. function tripal_remove_join_from_views_integration($setup_id, $base_table, $base_field, $left_table, $left_field) {
  1106. db_query(
  1107. "DELETE FROM {tripal_views_join} WHERE setup_id=:setup AND base_table=:base-table AND base_field=:base-field AND left_table=:left-table AND left_field=:left-field",
  1108. array(
  1109. ':setup' => $setup_id,
  1110. ':base-table' => $base_table,
  1111. ':base-field' => $base_field,
  1112. ':left-table' => $left_table,
  1113. ':left-field' => $left_field
  1114. )
  1115. );
  1116. }