tripal_views.api.inc 23 KB

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