tripal_views.api.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <?php
  2. /**
  3. * @file
  4. * API functions for Tripal Views Integration
  5. */
  6. /**
  7. * Retrieve the priority of the lightest priority for a given table
  8. *
  9. * NOTE: Uses lightest priority (drupal-style) where the range is from -10 to 10
  10. * and -10 is of highest priority.
  11. *
  12. * @param $table_name
  13. * The name of the table to retrieve the setup ID for. This can be either a materialized
  14. * view or a chado table
  15. *
  16. * @return
  17. * returns the lowest priority. If the table has not been integrated, a priority of 10
  18. * is returned.
  19. */
  20. function tripal_views_get_table_lightest_priority($table_name) {
  21. $sql = "SELECT priority FROM {tripal_views} WHERE table_name='%s' ORDER BY priority ASC";
  22. $setup = db_fetch_object(db_query($sql, $table_name));
  23. if ($setup) {
  24. return $setup->priority;
  25. }
  26. else {
  27. // default priority is 10
  28. return 10;
  29. }
  30. }
  31. /**
  32. * Retrieve the views integration setup with the lightest priority for a given table
  33. *
  34. * NOTE: Uses lightest priority (drupal-style) where the range is from -10 to 10
  35. * and -10 is of highest priority.
  36. *
  37. * @param $table_name
  38. * The name of the table to retrieve the setup ID for. This can be either a materialized
  39. * view or a chado table
  40. *
  41. * @return
  42. * On success, the setup_id to use for integration of this table; otherwise FALSE
  43. */
  44. function tripal_views_get_lightest_priority_setup($table_name) {
  45. $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' ORDER BY priority ASC";
  46. $setup = db_fetch_object(db_query($sql, $table_name));
  47. if ($setup) {
  48. return $setup->setup_id;
  49. }
  50. else {
  51. return FALSE;
  52. }
  53. }
  54. /**
  55. * Check to see if this table already has an integration record with the given priority
  56. *
  57. * @param $table_name
  58. * The name of the table to check for integration
  59. * @param $priority (optional)
  60. * The priority of record to check for
  61. *
  62. * @return
  63. * If the table is already integrated, the setup_id of the existing integration
  64. * record is returned (If priority is not specified this will be the lightest record);
  65. * Otherwise the table is not already integrated and FALSE is returned.
  66. */
  67. function tripal_views_is_integrated($table_name, $priority = NULL) {
  68. if ($priority) {
  69. $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' AND priority=%d";
  70. $setup = db_fetch_object(db_query($sql, $table_name, $priority));
  71. }
  72. else {
  73. $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' ORDER BY priority ASC";
  74. $setup = db_fetch_object(db_query($sql, $table_name));
  75. }
  76. if ($setup) {
  77. return $setup->setup_id;
  78. }
  79. else {
  80. return FALSE;
  81. }
  82. }
  83. /**
  84. * Checks if you are dealing with the lightest priority setup for a given table
  85. *
  86. * @param $setup_id
  87. * The ID of the setup to check (is this setup the lightest one?)
  88. * @param $table_name
  89. * The name of the table associated with this setup
  90. *
  91. * @return TRUE is this is the lightest priority; FALSE otherwise
  92. */
  93. function tripal_views_is_lightest_priority_setup($setup_id, $table_name) {
  94. $lightest_priority_setup_id = tripal_views_get_lightest_priority_setup($table_name);
  95. if ($lightest_priority_setup_id == $setup_id) {
  96. return TRUE;
  97. }
  98. else {
  99. return FALSE;
  100. }
  101. }
  102. /**
  103. * Add views integration records into the tripal_views* tables
  104. *
  105. * @param $defn_array
  106. * An array describing the structure and fields of the table
  107. *
  108. * @return
  109. * True/False if completed successfully/not
  110. *
  111. * Example usage (in hook_install()):
  112. * @code
  113. $defn_array = array(
  114. 'table' => 'feature', //tablename or materialized view name
  115. 'name' => 'Sequence Features', // Human readable name
  116. 'type' => 'chado', //either chado or mview depending on tablename
  117. 'description' => 'Create a listing of features.', //description seen when creating a view of this type
  118. 'priority' => 10, //For Base tripal modules: 10; custom modules: 9 to 0;
  119. 'base_table' => TRUE //either TRUE or FALSE depending on whether the current table should show up in the add view list
  120. 'fields' => array(
  121. 'feature_id' => array(
  122. 'name' => 'feature_id', //field name in database
  123. 'title' => 'Feature ID', //human-readable name -seen in Views UI
  124. 'description' => 'This is the unique identifier for features', //help/description seen in Views UI
  125. 'type' => 'int', // the type of field
  126. 'handlers' => array( //possible keys are field, filter, sort, argument, relationship
  127. 'field' => array(
  128. 'name' => 'chado_views_handler_numeric' //name of handler
  129. ),
  130. 'filter' => array( ... ),
  131. ...
  132. ),
  133. 'join' => array( //describe a table that joins to this one via this field
  134. 'table' => 'featureprop', //table to join to
  135. 'field' => 'feature_id', //field in above table (featureprop)
  136. 'handler' => 'views_handler_join_chado_aggregator', //handler to use
  137. ),
  138. )
  139. ),
  140. );
  141. tripal_views_integration_add_entry($defn_array);
  142. * @endcode
  143. */
  144. function tripal_views_integration_add_entry($defn_array) {
  145. $no_errors = TRUE;
  146. // First insert into tripal_views
  147. $view_record = array(
  148. 'table_name' => $defn_array['table'],
  149. 'name' => $defn_array['name'],
  150. 'comment' => $defn_array['description'],
  151. 'priority' => $defn_array['priority'],
  152. 'base_table' => $defn_array['base_table'],
  153. );
  154. if ($defn_array['type'] == 'mview') {
  155. $mview = db_fetch_object(db_query("SELECT mview_id FROM {tripal_mviews} WHERE mv_table='%s'", $defn_array['table']));
  156. $view_record['mview_id'] = $mview->mview_id;
  157. if (!$mview->mview_id) {
  158. return FALSE;
  159. }
  160. }
  161. if ($view_record['name']) { // && $view_record['comment']) { # SPF: commented out 9/24/2012 .. It's not required on the form
  162. if ($defn_array['additional_content']) {
  163. $setup = db_fetch_object(db_query("SELECT * FROM {tripal_views} WHERE table_name='%s' AND priority=%d", $view_record['table_name'], $view_record['priority']));
  164. if (empty($setup->setup_id)) {
  165. $status = drupal_write_record('tripal_views', $view_record);
  166. }
  167. else {
  168. $view_record['setup_id'] = $setup->setup_id;
  169. $status = drupal_write_record('tripal_views', $view_record, 'setup_id');
  170. }
  171. }
  172. else {
  173. $status = drupal_write_record('tripal_views', $view_record);
  174. }
  175. }
  176. else {
  177. $status = FALSE;
  178. drupal_set_message(t('Unable to integrate "%table" table due to a missing name field.', array('%table' => $defn_array['table'])), 'error');
  179. }
  180. if ($status) {
  181. // Need to update the tripal_views record so base_table can be false
  182. // this is a fix because drupal_write_record() puts in defaults if !isset()
  183. // and a variable is considered not set if it's null!
  184. db_query(
  185. "UPDATE {tripal_views} SET base_table=%d WHERE table_name='%s' AND priority=%d",
  186. $defn_array['base_table'],
  187. $defn_array['table'],
  188. $defn_array['priority']
  189. );
  190. // Insert Field Definitions
  191. foreach ($defn_array['fields'] as $field) {
  192. $field_record = array(
  193. 'setup_id' => $view_record['setup_id'],
  194. 'column_name' => $field['name'],
  195. 'name' => $field['title'],
  196. 'description' => $field['description'],
  197. 'type' => $field['type'],
  198. );
  199. if ($view_record['setup_id'] && $field['name'] && $field['title'] && $field['description'] && $field['type']) {
  200. if ($defn_array['additional_content']) {
  201. $is = db_fetch_object(db_query("SELECT true as present FROM {tripal_views_field} WHERE column_name='%s' AND setup_id=%d", $field_record['column_name'], $field_record['setup_id']));
  202. if (!$is->present) {
  203. $status = drupal_write_record('tripal_views_field', $field_record);
  204. }
  205. else {
  206. $status = drupal_write_record('tripal_views_field', $field_record, array('setup_id', 'column_name'));
  207. }
  208. }
  209. else {
  210. $status = drupal_write_record('tripal_views_field', $field_record);
  211. }
  212. }
  213. else {
  214. drupal_set_message(t('Unable to integrate %name field due to missing required fields.', array('%name' => $field['name'])), 'error');
  215. $status = FALSE;
  216. }
  217. if ($status) {
  218. // Insert Handler Definitions
  219. foreach ($field['handlers'] as $handler_type => $handler) {
  220. $handler_record = array(
  221. 'setup_id' => $view_record['setup_id'],
  222. 'column_name' => $field['name'],
  223. 'handler_type' => $handler_type,
  224. 'handler_name' => $handler['name'],
  225. 'arguments' => serialize($handler)
  226. );
  227. if ($view_record['setup_id'] && $field['name'] && $handler_type && $handler['name'] && $handler) {
  228. $status = drupal_write_record('tripal_views_handlers', $handler_record);
  229. }
  230. else {
  231. $status = FALSE;
  232. }
  233. if (!$status) {
  234. drupal_set_message(t('Unable to integrate %handler_type handler: %handler_name', array('%handler_type' => $handler_type, '%handler_name' => $handler['name'])), 'error');
  235. $no_errors = FALSE;
  236. }
  237. }
  238. // Insert Joins
  239. if (!is_array($field['joins'])) {
  240. $field['joins'] = array();
  241. }
  242. foreach ($field['joins'] as $join) {
  243. $join_record = array(
  244. 'setup_id' => $view_record['setup_id'],
  245. 'base_table' => $defn_array['table'],
  246. 'base_field' => $field['name'],
  247. 'left_table' => $join['table'],
  248. 'left_field' => $join['field'],
  249. );
  250. if (!empty($join['handler'])) {
  251. $join_record['handler'] = $join['handler'];
  252. }
  253. else {
  254. $join_record['handler'] = 'views_join';
  255. }
  256. if ($view_record['setup_id'] && $defn_array['table'] && $field['name'] && $join['table'] && $join['field']) {
  257. $status = drupal_write_record('tripal_views_join', $join_record);
  258. }
  259. else {
  260. $status = FALSE;
  261. }
  262. if (!$status) {
  263. drupal_set_message(
  264. t(
  265. 'Unable to join %left_table.%left_field with %table.%field',
  266. array(
  267. '%left_table' => $join['table'],
  268. '%left_field' => $join['field'],
  269. '%table' => $defn_array['table'],
  270. '%field' => $field['name']
  271. )
  272. ),
  273. 'error'
  274. );
  275. $no_errors = FALSE;
  276. }
  277. }
  278. }
  279. else {
  280. drupal_set_message(t('Unable to integrate %field_name field', array('%field_name' => $field['name'])), 'error');
  281. $no_errors = FALSE;
  282. }
  283. }
  284. }
  285. else {
  286. drupal_set_message(t('Unable to set default tripal views integration'), 'error');
  287. $no_errors = FALSE;
  288. }
  289. return $no_errors;
  290. }
  291. /**
  292. * Export Views integration records
  293. *
  294. * @param $setup_id
  295. * The unique setup id of the tripal views integration
  296. *
  297. * @return
  298. * A views integration definition array as used by tripal_views_integration_add_entry()
  299. */
  300. function tripal_views_integration_export_entry($setup_id) {
  301. // Main setup details
  302. $r = db_fetch_object(db_query("SELECT * FROM {tripal_views} WHERE setup_id=%d", $setup_id));
  303. $defn_array = array(
  304. 'table' => $r->table_name,
  305. 'name' => $r->name,
  306. 'type' => ($r->mview_id) ? 'mview' : 'chado',
  307. 'description' => $r->comment,
  308. 'priority' => $r->priority,
  309. 'base_table' => $r->base_table,
  310. 'fields' => array(),
  311. );
  312. // Add fields
  313. $resource = db_query("SELECT * FROM {tripal_views_field} WHERE setup_id=%d", $setup_id);
  314. while ($r = db_fetch_object($resource)) {
  315. $defn_array['fields'][ $r->column_name ] = array(
  316. 'name' => $r->column_name,
  317. 'title' => $r->name,
  318. 'description' => $r->description,
  319. 'type' => $r->type,
  320. 'handlers' => array(),
  321. 'joins' => array()
  322. );
  323. }
  324. // Add handlers
  325. $resource = db_query("SELECT * FROM {tripal_views_handlers} WHERE setup_id=%d", $setup_id);
  326. while ($r = db_fetch_object($resource)) {
  327. $defn_array['fields'][ $r->column_name ]['handlers'][ $r->handler_type ] = array(
  328. 'name' => $r->handler_name
  329. );
  330. }
  331. // Add joins
  332. $resource = db_query("SELECT * FROM {tripal_views_join} WHERE setup_id=%d", $setup_id);
  333. while ($r = db_fetch_object($resource)) {
  334. $defn_array['fields'][ $r->base_field ]['joins'][ $r->left_table ] = array(
  335. 'table' => $r->left_table,
  336. 'field' => $r->left_field,
  337. 'handler' => $r->handler,
  338. );
  339. }
  340. return $defn_array;
  341. }
  342. /**
  343. * Removes a View Integration Entry
  344. *
  345. * @param $table_name
  346. * The name of the table to remove a views integration entry for
  347. * @param $priority
  348. * The priority of the of views integration entry
  349. *
  350. * @return
  351. * TRUE on Success; FALSE otherwise
  352. */
  353. function tripal_views_integration_remove_entry_by_table_name($table_name, $priority) {
  354. $views = db_fetch_object(db_query(
  355. "SELECT * FROM {tripal_views} WHERE table_name='%s' AND priority=%d",
  356. $table_name,
  357. $priority
  358. ));
  359. if ($views->setup_id) {
  360. tripal_views_integration_remove_entry_by_setup_id($views->setup_id);
  361. return TRUE;
  362. }
  363. else {
  364. return FALSE;
  365. }
  366. }
  367. /**
  368. * Removes a View Integration Entry
  369. *
  370. * @param $setup_id
  371. * The setup ID of the views integration entry to remove
  372. */
  373. function tripal_views_integration_remove_entry_by_setup_id($setup_id) {
  374. db_query('DELETE FROM {tripal_views} WHERE setup_id=%d', $setup_id);
  375. db_query('DELETE FROM {tripal_views_field} WHERE setup_id=%d', $setup_id);
  376. db_query('DELETE FROM {tripal_views_handlers} WHERE setup_id=%d', $setup_id);
  377. db_query('DELETE FROM {tripal_views_join} WHERE setup_id=%d', $setup_id);
  378. }
  379. /**
  380. * Integrate all chado tables in the schema api. This integration only occurs
  381. * once and sets all Chado tables to a priority of 10
  382. */
  383. function tripal_views_integrate_all_chado_tables() {
  384. $tables = tripal_core_get_chado_tables(TRUE);
  385. foreach ($tables as $tablename) {
  386. $priority = 10;
  387. if (!tripal_views_is_integrated($tablename, $priority)) {
  388. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority);
  389. if ($table_integration_array) {
  390. tripal_views_integration_add_entry($table_integration_array);
  391. }
  392. }
  393. }
  394. }
  395. /**
  396. * Returns the array needed to integrate a given chado table with views
  397. *
  398. * @param $tablename
  399. * The table to generate the tripal views integration array for
  400. * @return
  401. * The tripal views integration array which is the parameter for
  402. * tripal_views_integration_add_entry($defn_array)
  403. */
  404. function tripal_views_get_integration_array_for_chado_table($table_name, $base_table = TRUE, $priority = 9) {
  405. // Get the schema for this table (via the chado schema api)
  406. $schema = tripal_core_get_chado_table_schema($table_name);
  407. // Base definition array
  408. $defn_array = array(
  409. 'table' => $table_name,
  410. 'type' => 'chado',
  411. 'name' => 'Chado ' . ucwords(str_replace('_', ' ', $table_name)),
  412. 'description' => (!empty($schema['description'])) ? $schema['description'] : ' ',
  413. 'priority' => $priority,
  414. 'base_table' => $base_table,
  415. 'fields' => array(),
  416. );
  417. // Add fields
  418. if (!isset($schema['fields'])) {
  419. watchdog('tripal_views', 'There are no fields defined for %table in the Chado Schema API.', array('%table' => $table_name), WATCHDOG_NOTICE);
  420. return FALSE;
  421. }
  422. foreach ($schema['fields'] as $field_name => $field_schema) {
  423. // Base field definition
  424. if (!empty($field_name) && !empty($field_schema['type'])) {
  425. $defn_array['fields'][$field_name] = array(
  426. 'name' => $field_name,
  427. 'title' => ucwords(str_replace('_', ' ', $field_name)),
  428. 'type' => $field_schema['type'],
  429. 'description' => ($field_schema['description']) ? $field_schema['description'] : ucwords(str_replace('_', ' ', $field_name)),
  430. 'handlers' => array(),
  431. 'joins' => array()
  432. );
  433. // Add handlers based on type
  434. if (preg_match('/^int/', $field_schema['type'])) {
  435. $defn_array['fields'][$field_name]['handlers'] = array(
  436. 'field' => array('name' => 'chado_views_handler_field_numeric'),
  437. 'filter' => array('name' => 'chado_views_handler_filter_numeric'),
  438. 'sort' => array('name' => 'chado_views_handler_sort'),
  439. );
  440. }
  441. elseif (preg_match('/^serial/', $field_schema['type'])) {
  442. $defn_array['fields'][$field_name]['handlers'] = array(
  443. 'field' => array('name' => 'chado_views_handler_field_numeric'),
  444. 'filter' => array('name' => 'chado_views_handler_filter_numeric'),
  445. 'sort' => array('name' => 'chado_views_handler_sort'),
  446. );
  447. $defn_array['fields'][$field_name]['type'] = 'int';
  448. }
  449. elseif (preg_match('/^varchar/', $field_schema['type'])) {
  450. $defn_array['fields'][$field_name]['handlers'] = array(
  451. 'field' => array('name' => 'chado_views_handler_field'),
  452. 'filter' => array('name' => 'chado_views_handler_filter_string'),
  453. 'sort' => array('name' => 'chado_views_handler_sort'),
  454. );
  455. }
  456. elseif (preg_match('/^text/', $field_schema['type'])) {
  457. $defn_array['fields'][$field_name]['handlers'] = array(
  458. 'field' => array('name' => 'chado_views_handler_field'),
  459. 'filter' => array('name' => 'chado_views_handler_filter_string'),
  460. 'sort' => array('name' => 'chado_views_handler_sort'),
  461. );
  462. }
  463. elseif (preg_match('/^boolean/', $field_schema['type'])) {
  464. $defn_array['fields'][$field_name]['handlers'] = array(
  465. 'field' => array('name' => 'chado_views_handler_field_boolean'),
  466. 'filter' => array('name' => 'chado_views_handler_filter_boolean_operator'),
  467. 'sort' => array('name' => 'chado_views_handler_sort'),
  468. );
  469. }
  470. elseif (preg_match('/^datetime/', $field_schema['type'])) {
  471. $defn_array['fields'][$field_name]['handlers'] = array(
  472. 'field' => array('name' => 'chado_views_handler_field_date'),
  473. 'filter' => array('name' => 'chado_views_handler_filter_date'),
  474. 'sort' => array('name' => 'views_handler_sort_date'),
  475. );
  476. }
  477. else {
  478. $defn_array['fields'][$field_name]['handlers'] = array(
  479. 'field' => array('name' => 'chado_views_handler_field'),
  480. 'filter' => array('name' => 'chado_views_handler_filter_string'),
  481. 'sort' => array('name' => 'chado_views_handler_sort'),
  482. );
  483. }
  484. // Specify specialty handlers
  485. if ($field_name == 'type_id' OR $field_name == 'cvterm_id') {
  486. $defn_array['fields'][$field_name]['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_cvterm';
  487. }
  488. }
  489. }
  490. // Add Joins & Relationship Handlers to fields
  491. if (!isset($schema['foreign keys'])) {
  492. $schema['foreign keys'] = array();
  493. watchdog('tripal_views', 'There are no foreign keys defined for %table in the Chado Schema API.', array('%table' => $table_name), WATCHDOG_WARNING);
  494. }
  495. foreach ($schema['foreign keys'] as $foreign_key_schema) {
  496. foreach ($foreign_key_schema['columns'] as $left_field => $right_field) {
  497. // Join
  498. $defn_array['fields'][$left_field]['joins'][ $foreign_key_schema['table'] ] = array(
  499. 'table' => $foreign_key_schema['table'],
  500. 'field' => $right_field,
  501. 'handler' => 'views_handler_join_chado_aggregator'
  502. );
  503. // Relationship Handler
  504. $defn_array['fields'][$left_field]['handlers']['relationship'] = array(
  505. 'name' => 'chado_views_handler_relationship',
  506. 'base' => $foreign_key_schema['table'],
  507. 'base field' => $right_field,
  508. 'label' => $table_name . ' ' . $left_field . ' to ' . $foreign_key_schema['table'] . ' ' . $right_field
  509. );
  510. }
  511. }
  512. return $defn_array;
  513. }
  514. /**
  515. * Adds the joins necessary to link a chado table to it's node counterpart
  516. *
  517. * @param &$defn_array
  518. * The current definition array for a given table
  519. */
  520. function tripal_views_add_node_relationship_to_chado_table_integration($defn_array) {
  521. $integrations[$defn_array['table']] = $defn_array;
  522. $primary_key = $defn_array['table'] . '_id';
  523. $chado_linking = 'chado_' . $defn_array['table'];
  524. // Add table.primary_key => chado_table.primary key join to $defn_array
  525. $integrations[$defn_array['table']]['fields'][$primary_key]['joins'][$chado_linking] = array(
  526. 'table' => $chado_linking,
  527. 'field' => $primary_key,
  528. );
  529. // Create chado_table defn_array
  530. $integrations[$chado_linking] = array(
  531. 'table' => $chado_linking,
  532. 'type' => 'drupal',
  533. 'name' => 'Chado ' . $defn_array['table'] . ' Node',
  534. 'description' => 'Links chado content to its drupal node counterpart',
  535. 'priority' => $defn_array['priority'],
  536. 'base_table' => FALSE,
  537. 'fields' => array(
  538. $primary_key => array(
  539. 'name' => $primary_key,
  540. 'title' => ucwords(str_replace('_', ' ', $primary_key)),
  541. 'type' => 'int',
  542. 'description' => 'The primary key of the chado ' . $defn_array['table'] . ' table',
  543. 'handlers' => array(),
  544. 'joins' => array(
  545. $defn_array['table'] => array(
  546. 'table' => $defn_array['table'],
  547. 'field' => $primary_key,
  548. )
  549. ),
  550. ),
  551. 'nid' => array(
  552. 'name' => 'nid',
  553. 'title' => 'Node ID',
  554. 'type' => 'int',
  555. 'description' => 'Link ' . ucfirst($defn_array['table']) . ' to it\'s node',
  556. 'handlers' => array(
  557. 'relationship' => array(
  558. 'name' => 'chado_views_handler_relationship_to_node',
  559. 'title' => ucfirst($defn_array['table']) . ' to Node',
  560. 'label' => ucfirst($defn_array['table']) . ' to Node',
  561. 'base table' => $defn_array['table'],
  562. 'base field' => $primary_key
  563. )
  564. ),
  565. 'joins' => array(
  566. 'node' => array(
  567. 'table' => 'node',
  568. 'field' => 'nid',
  569. ),
  570. ),
  571. )
  572. ),
  573. );
  574. // Create node defn_array
  575. $integrations['node'] = array(
  576. 'table' => 'node',
  577. 'name' => 'Node',
  578. 'description' => 'Primary Drupal Content',
  579. 'priority' => $defn_array['priority'],
  580. 'additional_content' => TRUE, // Allows multiple modules to add to the node setup
  581. 'fields' => array(
  582. 'nid' => array(
  583. 'name' => 'nid',
  584. 'title' => 'Node ID',
  585. 'type' => 'int',
  586. 'description' => 'the primary key of the drupal node table',
  587. 'handlers' => array(),
  588. 'joins' => array(
  589. $defn_array['table'] => array(
  590. 'table' => $defn_array['table'],
  591. 'field' => 'nid',
  592. ),
  593. $chado_linking => array(
  594. 'table' => $chado_linking,
  595. 'field' => 'nid',
  596. ),
  597. ),
  598. ),
  599. ),
  600. );
  601. return $integrations;
  602. }