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. dpm($defn_array);
  147. // First insert into tripal_views
  148. $view_record = array(
  149. 'table_name' => $defn_array['table'],
  150. 'name' => $defn_array['name'],
  151. 'comment' => $defn_array['description'],
  152. 'priority' => $defn_array['priority'],
  153. 'base_table' => $defn_array['base_table'],
  154. );
  155. if ($defn_array['type'] == 'mview') {
  156. $mview = db_fetch_object(db_query("SELECT mview_id FROM {tripal_mviews} WHERE mv_table='%s'", $defn_array['table']));
  157. $view_record['mview_id'] = $mview->mview_id;
  158. if (!$mview->mview_id) {
  159. return FALSE;
  160. }
  161. }
  162. if ($view_record['name']) { // && $view_record['comment']) { # SPF: commented out 9/24/2012 .. It's not required on the form
  163. if ($defn_array['additional_content']) {
  164. $setup = db_fetch_object(db_query("SELECT * FROM {tripal_views} WHERE table_name='%s' AND priority=%d",$view_record['table_name'], $view_record['priority']));
  165. if (empty($setup->setup_id)) {
  166. $status = drupal_write_record('tripal_views', $view_record);
  167. }
  168. else {
  169. $view_record['setup_id'] = $setup->setup_id;
  170. $status = drupal_write_record('tripal_views', $view_record, 'setup_id');
  171. }
  172. }
  173. else {
  174. $status = drupal_write_record('tripal_views', $view_record);
  175. }
  176. }
  177. else {
  178. $status = FALSE;
  179. drupal_set_message(t('Unable to integrate "%table" table due to a missing name field.', array('%table' => $defn_array['table'])), 'error');
  180. }
  181. if ($status) {
  182. // Need to update the tripal_views record so base_table can be false
  183. // this is a fix because drupal_write_record() puts in defaults if !isset()
  184. // and a variable is considered not set if it's null!
  185. db_query(
  186. "UPDATE {tripal_views} SET base_table=%d WHERE table_name='%s' AND priority=%d",
  187. $defn_array['base_table'],
  188. $defn_array['table'],
  189. $defn_array['priority']
  190. );
  191. // Insert Field Definitions
  192. foreach ($defn_array['fields'] as $field) {
  193. $field_record = array(
  194. 'setup_id' => $view_record['setup_id'],
  195. 'column_name' => $field['name'],
  196. 'name' => $field['title'],
  197. 'description' => $field['description'],
  198. 'type' => $field['type'],
  199. );
  200. if ($view_record['setup_id'] && $field['name'] && $field['title'] && $field['description'] && $field['type']) {
  201. if ($defn_array['additional_content']) {
  202. $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']));
  203. if (!$is->present) {
  204. $status = drupal_write_record('tripal_views_field', $field_record);
  205. }
  206. else {
  207. $status = drupal_write_record('tripal_views_field', $field_record, array('setup_id', 'column_name'));
  208. }
  209. }
  210. else {
  211. $status = drupal_write_record('tripal_views_field', $field_record);
  212. }
  213. }
  214. else {
  215. drupal_set_message(t('Unable to integrate %name field due to missing required fields.', array('%name' => $field['name'])), 'error');
  216. $status = FALSE;
  217. }
  218. if ($status) {
  219. // Insert Handler Definitions
  220. foreach ($field['handlers'] as $handler_type => $handler) {
  221. $handler_record = array(
  222. 'setup_id' => $view_record['setup_id'],
  223. 'column_name' => $field['name'],
  224. 'handler_type' => $handler_type,
  225. 'handler_name' => $handler['name'],
  226. 'arguments' => serialize($handler)
  227. );
  228. if ($view_record['setup_id'] && $field['name'] && $handler_type && $handler['name'] && $handler) {
  229. $status = drupal_write_record('tripal_views_handlers', $handler_record);
  230. }
  231. else {
  232. $status = FALSE;
  233. }
  234. if (!$status) {
  235. drupal_set_message(t('Unable to integrate %handler_type handler: %handler_name', array('%handler_type' => $handler_type, '%handler_name' => $handler['name'])), 'error');
  236. $no_errors = FALSE;
  237. }
  238. }
  239. // Insert Joins
  240. if (!is_array($field['joins'])) {
  241. $field['joins'] = array();
  242. }
  243. foreach ($field['joins'] as $join) {
  244. $join_record = array(
  245. 'setup_id' => $view_record['setup_id'],
  246. 'base_table' => $defn_array['table'],
  247. 'base_field' => $field['name'],
  248. 'left_table' => $join['table'],
  249. 'left_field' => $join['field'],
  250. );
  251. if (!empty($join['handler'])) {
  252. $join_record['handler'] = $join['handler'];
  253. }
  254. else {
  255. $join_record['handler'] = 'views_join';
  256. }
  257. if ($view_record['setup_id'] && $defn_array['table'] && $field['name'] && $join['table'] && $join['field']) {
  258. $status = drupal_write_record('tripal_views_join', $join_record);
  259. }
  260. else {
  261. $status = FALSE;
  262. }
  263. if (!$status) {
  264. drupal_set_message(
  265. t(
  266. 'Unable to join %left_table.%left_field with %table.%field',
  267. array(
  268. '%left_table' => $join['table'],
  269. '%left_field' => $join['field'],
  270. '%table' => $defn_array['table'],
  271. '%field' => $field['name']
  272. )
  273. ),
  274. 'error'
  275. );
  276. $no_errors = FALSE;
  277. }
  278. }
  279. }
  280. else {
  281. drupal_set_message(t('Unable to integrate %field_name field', array('%field_name' => $field['name'])), 'error');
  282. $no_errors = FALSE;
  283. }
  284. }
  285. }
  286. else {
  287. drupal_set_message(t('Unable to set default tripal views integration'), 'error');
  288. $no_errors = FALSE;
  289. }
  290. return $no_errors;
  291. }
  292. /**
  293. * Export Views integration records
  294. *
  295. * @param $setup_id
  296. * The unique setup id of the tripal views integration
  297. *
  298. * @return
  299. * A views integration definition array as used by tripal_views_integration_add_entry()
  300. */
  301. function tripal_views_integration_export_entry($setup_id) {
  302. // Main setup details
  303. $r = db_fetch_object(db_query("SELECT * FROM {tripal_views} WHERE setup_id=%d", $setup_id));
  304. $defn_array = array(
  305. 'table' => $r->table_name,
  306. 'name' => $r->name,
  307. 'type' => ($r->mview_id) ? 'mview' : 'chado',
  308. 'description' => $r->comment,
  309. 'priority' => $r->priority,
  310. 'base_table' => $r->base_table,
  311. 'fields' => array(),
  312. );
  313. // Add fields
  314. $resource = db_query("SELECT * FROM {tripal_views_field} WHERE setup_id=%d", $setup_id);
  315. while ($r = db_fetch_object($resource)) {
  316. $defn_array['fields'][ $r->column_name ] = array(
  317. 'name' => $r->column_name,
  318. 'title' => $r->name,
  319. 'description' => $r->description,
  320. 'type' => $r->type,
  321. 'handlers' => array(),
  322. 'joins' => array()
  323. );
  324. }
  325. // Add handlers
  326. $resource = db_query("SELECT * FROM {tripal_views_handlers} WHERE setup_id=%d", $setup_id);
  327. while ($r = db_fetch_object($resource)) {
  328. $defn_array['fields'][ $r->column_name ]['handlers'][ $r->handler_type ] = array(
  329. 'name' => $r->handler_name
  330. );
  331. }
  332. // Add joins
  333. $resource = db_query("SELECT * FROM {tripal_views_join} WHERE setup_id=%d", $setup_id);
  334. while ($r = db_fetch_object($resource)) {
  335. $defn_array['fields'][ $r->base_field ]['joins'][ $r->left_table ] = array(
  336. 'table' => $r->left_table,
  337. 'field' => $r->left_field,
  338. 'handler' => $r->handler,
  339. );
  340. }
  341. return $defn_array;
  342. }
  343. /**
  344. * Removes a View Integration Entry
  345. *
  346. * @param $table_name
  347. * The name of the table to remove a views integration entry for
  348. * @param $priority
  349. * The priority of the of views integration entry
  350. *
  351. * @return
  352. * TRUE on Success; FALSE otherwise
  353. */
  354. function tripal_views_integration_remove_entry_by_table_name($table_name, $priority) {
  355. $views = db_fetch_object(db_query(
  356. "SELECT * FROM {tripal_views} WHERE table_name='%s' AND priority=%d",
  357. $table_name,
  358. $priority
  359. ));
  360. if ($views->setup_id) {
  361. tripal_views_integration_remove_entry_by_setup_id($views->setup_id);
  362. return TRUE;
  363. }
  364. else {
  365. return FALSE;
  366. }
  367. }
  368. /**
  369. * Removes a View Integration Entry
  370. *
  371. * @param $setup_id
  372. * The setup ID of the views integration entry to remove
  373. */
  374. function tripal_views_integration_remove_entry_by_setup_id($setup_id) {
  375. db_query('DELETE FROM {tripal_views} WHERE setup_id=%d', $setup_id);
  376. db_query('DELETE FROM {tripal_views_field} WHERE setup_id=%d', $setup_id);
  377. db_query('DELETE FROM {tripal_views_handlers} WHERE setup_id=%d', $setup_id);
  378. db_query('DELETE FROM {tripal_views_join} WHERE setup_id=%d', $setup_id);
  379. }
  380. /**
  381. * Integrate all chado tables in the schema api. This integration only occurs
  382. * once and sets all Chado tables to a priority of 10
  383. */
  384. function tripal_views_integrate_all_chado_tables() {
  385. $tables = tripal_core_get_chado_tables(TRUE);
  386. foreach ($tables as $tablename) {
  387. $priority = 10;
  388. if (!tripal_views_is_integrated($tablename, $priority)) {
  389. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority);
  390. if ($table_integration_array) {
  391. tripal_views_integration_add_entry($table_integration_array);
  392. }
  393. }
  394. }
  395. }
  396. /**
  397. * Returns the array needed to integrate a given chado table with views
  398. *
  399. * @param $tablename
  400. * The table to generate the tripal views integration array for
  401. * @return
  402. * The tripal views integration array which is the parameter for
  403. * tripal_views_integration_add_entry($defn_array)
  404. */
  405. function tripal_views_get_integration_array_for_chado_table($table_name, $base_table = TRUE, $priority = 9) {
  406. // Get the schema for this table (via the chado schema api)
  407. $schema = tripal_core_get_chado_table_schema($table_name);
  408. // Base definition array
  409. $defn_array = array(
  410. 'table' => $table_name,
  411. 'type' => 'chado',
  412. 'name' => 'Chado ' . ucwords(str_replace('_', ' ', $table_name)),
  413. 'description' => (!empty($schema['description'])) ? $schema['description'] : ' ',
  414. 'priority' => $priority,
  415. 'base_table' => $base_table,
  416. 'fields' => array(),
  417. );
  418. // Add fields
  419. if (!isset($schema['fields'])) {
  420. watchdog('tripal_views', 'There are no fields defined for %table in the Chado Schema API.', array('%table' => $table_name), WATCHDOG_NOTICE);
  421. return FALSE;
  422. }
  423. foreach ($schema['fields'] as $field_name => $field_schema) {
  424. // Base field definition
  425. if (!empty($field_name) && !empty($field_schema['type'])) {
  426. $defn_array['fields'][$field_name] = array(
  427. 'name' => $field_name,
  428. 'title' => ucwords(str_replace('_', ' ', $field_name)),
  429. 'type' => $field_schema['type'],
  430. 'description' => ($field_schema['description']) ? $field_schema['description'] : ucwords(str_replace('_', ' ', $field_name)),
  431. 'handlers' => array(),
  432. 'joins' => array()
  433. );
  434. // Add handlers based on type
  435. if (preg_match('/^int/', $field_schema['type'])) {
  436. $defn_array['fields'][$field_name]['handlers'] = array(
  437. 'field' => array('name' => 'chado_views_handler_field_numeric'),
  438. 'filter' => array('name' => 'chado_views_handler_filter_numeric'),
  439. 'sort' => array('name' => 'chado_views_handler_sort'),
  440. );
  441. }
  442. elseif (preg_match('/^serial/', $field_schema['type'])) {
  443. $defn_array['fields'][$field_name]['handlers'] = array(
  444. 'field' => array('name' => 'chado_views_handler_field_numeric'),
  445. 'filter' => array('name' => 'chado_views_handler_filter_numeric'),
  446. 'sort' => array('name' => 'chado_views_handler_sort'),
  447. );
  448. $defn_array['fields'][$field_name]['type'] = 'int';
  449. }
  450. elseif (preg_match('/^varchar/', $field_schema['type'])) {
  451. $defn_array['fields'][$field_name]['handlers'] = array(
  452. 'field' => array('name' => 'chado_views_handler_field'),
  453. 'filter' => array('name' => 'chado_views_handler_filter_string'),
  454. 'sort' => array('name' => 'chado_views_handler_sort'),
  455. );
  456. }
  457. elseif (preg_match('/^text/', $field_schema['type'])) {
  458. $defn_array['fields'][$field_name]['handlers'] = array(
  459. 'field' => array('name' => 'chado_views_handler_field'),
  460. 'filter' => array('name' => 'chado_views_handler_filter_string'),
  461. 'sort' => array('name' => 'chado_views_handler_sort'),
  462. );
  463. }
  464. elseif (preg_match('/^boolean/', $field_schema['type'])) {
  465. $defn_array['fields'][$field_name]['handlers'] = array(
  466. 'field' => array('name' => 'chado_views_handler_field_boolean'),
  467. 'filter' => array('name' => 'chado_views_handler_filter_boolean_operator'),
  468. 'sort' => array('name' => 'chado_views_handler_sort'),
  469. );
  470. }
  471. elseif (preg_match('/^datetime/', $field_schema['type'])) {
  472. $defn_array['fields'][$field_name]['handlers'] = array(
  473. 'field' => array('name' => 'chado_views_handler_field_date'),
  474. 'filter' => array('name' => 'chado_views_handler_filter_date'),
  475. 'sort' => array('name' => 'views_handler_sort_date'),
  476. );
  477. }
  478. else {
  479. $defn_array['fields'][$field_name]['handlers'] = array(
  480. 'field' => array('name' => 'chado_views_handler_field'),
  481. 'filter' => array('name' => 'chado_views_handler_filter_string'),
  482. 'sort' => array('name' => 'chado_views_handler_sort'),
  483. );
  484. }
  485. // Specify specialty handlers
  486. if ($field_name == 'type_id' OR $field_name == 'cvterm_id') {
  487. $defn_array['fields'][$field_name]['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_cvterm';
  488. }
  489. }
  490. }
  491. // Add Joins & Relationship Handlers to fields
  492. if (!isset($schema['foreign keys'])) {
  493. $schema['foreign keys'] = array();
  494. watchdog('tripal_views', 'There are no foreign keys defined for %table in the Chado Schema API.', array('%table' => $table_name), WATCHDOG_WARNING);
  495. }
  496. foreach ($schema['foreign keys'] as $foreign_key_schema) {
  497. foreach ($foreign_key_schema['columns'] as $left_field => $right_field) {
  498. // Join
  499. $defn_array['fields'][$left_field]['joins'][ $foreign_key_schema['table'] ] = array(
  500. 'table' => $foreign_key_schema['table'],
  501. 'field' => $right_field,
  502. 'handler' => 'views_handler_join_chado_aggregator'
  503. );
  504. // Relationship Handler
  505. $defn_array['fields'][$left_field]['handlers']['relationship'] = array(
  506. 'name' => 'chado_views_handler_relationship',
  507. 'base' => $foreign_key_schema['table'],
  508. 'base field' => $right_field,
  509. 'label' => $table_name . ' ' . $left_field . ' to ' . $foreign_key_schema['table'] . ' ' . $right_field
  510. );
  511. }
  512. }
  513. return $defn_array;
  514. }
  515. /**
  516. * Adds the joins necessary to link a chado table to it's node counterpart
  517. *
  518. * @param &$defn_array
  519. * The current definition array for a given table
  520. */
  521. function tripal_views_add_node_relationship_to_chado_table_integration($defn_array) {
  522. $integrations[$defn_array['table']] = $defn_array;
  523. $primary_key = $defn_array['table'] . '_id';
  524. $chado_linking = 'chado_' . $defn_array['table'];
  525. // Add table.primary_key => chado_table.primary key join to $defn_array
  526. $integrations[$defn_array['table']]['fields'][$primary_key]['joins'][$chado_linking] = array(
  527. 'table' => $chado_linking,
  528. 'field' => $primary_key,
  529. );
  530. // Create chado_table defn_array
  531. $integrations[$chado_linking] = array(
  532. 'table' => $chado_linking,
  533. 'type' => 'drupal',
  534. 'name' => 'Chado ' . $defn_array['table'] . ' Node',
  535. 'description' => 'Links chado content to its drupal node counterpart',
  536. 'priority' => $defn_array['priority'],
  537. 'base_table' => FALSE,
  538. 'fields' => array(
  539. $primary_key => array(
  540. 'name' => $primary_key,
  541. 'title' => ucwords(str_replace('_', ' ', $primary_key)),
  542. 'type' => 'int',
  543. 'description' => 'The primary key of the chado ' . $defn_array['table'] . ' table',
  544. 'handlers' => array(),
  545. 'joins' => array(
  546. $defn_array['table'] => array(
  547. 'table' => $defn_array['table'],
  548. 'field' => $primary_key,
  549. )
  550. ),
  551. ),
  552. 'nid' => array(
  553. 'name' => 'nid',
  554. 'title' => 'Node ID',
  555. 'type' => 'int',
  556. 'description' => 'Link ' . ucfirst($defn_array['table']) . ' to it\'s node',
  557. 'handlers' => array(
  558. 'relationship' => array(
  559. 'name' => 'chado_views_handler_relationship_to_node',
  560. 'title' => ucfirst($defn_array['table']) . ' to Node',
  561. 'label' => ucfirst($defn_array['table']) . ' to Node',
  562. 'base table' => $defn_array['table'],
  563. 'base field' => $primary_key
  564. )
  565. ),
  566. 'joins' => array(
  567. 'node' => array(
  568. 'table' => 'node',
  569. 'field' => 'nid',
  570. ),
  571. ),
  572. )
  573. ),
  574. );
  575. // Create node defn_array
  576. $integrations['node'] = array(
  577. 'table' => 'node',
  578. 'name' => 'Node',
  579. 'description' => 'Primary Drupal Content',
  580. 'priority' => $defn_array['priority'],
  581. 'additional_content' => TRUE, // Allows multiple modules to add to the node setup
  582. 'fields' => array(
  583. 'nid' => array(
  584. 'name' => 'nid',
  585. 'title' => 'Node ID',
  586. 'type' => 'int',
  587. 'description' => 'the primary key of the drupal node table',
  588. 'handlers' => array(),
  589. 'joins' => array(
  590. $defn_array['table'] => array(
  591. 'table' => $defn_array['table'],
  592. 'field' => 'nid',
  593. ),
  594. $chado_linking => array(
  595. 'table' => $chado_linking,
  596. 'field' => 'nid',
  597. ),
  598. ),
  599. ),
  600. ),
  601. );
  602. return $integrations;
  603. }