tripal_views.api.inc 22 KB

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