tripal_library.views.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions for views integration of
  5. * chado/tripal organism tables. Supplementary functions can be found in
  6. * ./views/
  7. *
  8. * Documentation on views integration can be found at
  9. * http://views2.logrus.com/doc/html/index.html.
  10. */
  11. /**
  12. * @defgroup tripal_library_views Library Views Integration
  13. * @ingroup views
  14. * @ingroup tripal_library
  15. */
  16. /*************************************************************************
  17. * Implements hook_views_data()
  18. * Purpose: Describe chado/tripal tables & fields to views
  19. * @return: a data array which follows the structure outlined in the
  20. * views2 documentation for this hook. Essentially, it's an array of table
  21. * definitions keyed by chado/tripal table name. Each table definition
  22. * includes basic details about the table, fields in that table and
  23. * relationships between that table and others (joins)
  24. *
  25. * @ingroup tripal_library_views
  26. */
  27. function tripal_library_views_data() {
  28. $data = array();
  29. if (module_exists('tripal_views')) {
  30. $tables = array(
  31. 'library'
  32. );
  33. foreach ($tables as $tablename) {
  34. // get the setup with the lightest priority. That's the table
  35. // that currently integrated with views.
  36. $priority = tripal_views_get_lightest_priority_setup($tablename);
  37. // check to see if the table is integrated. If it is then integrate it's
  38. // corresponding 'chado_[table]' table.
  39. if (!tripal_views_is_integrated($tablename, $priority)) {
  40. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
  41. // Add in node relationships if chado is in the same db as drupal
  42. if (tripal_core_chado_schema_exists()) {
  43. $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array);
  44. foreach ($integrations as $integration) {
  45. tripal_views_integration_add_entry($integration);
  46. }
  47. }
  48. else {
  49. tripal_views_integration_add_entry($table_integration_array);
  50. }
  51. }
  52. }
  53. $tables = array(
  54. 'library_cvterm',
  55. 'library_feature',
  56. 'library_pub',
  57. 'library_synonym',
  58. 'libraryprop'
  59. );
  60. foreach ($tables as $tablename) {
  61. if (!tripal_views_is_integrated($tablename, 9)) {
  62. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
  63. tripal_views_integration_add_entry($table_integration_array);
  64. }
  65. }
  66. }
  67. return $data;
  68. }
  69. /*************************************************************************
  70. * Implements hook_views_handlers()
  71. * Purpose: Register all custom handlers with views
  72. * where a handler describes either "the type of field",
  73. * "how a field should be filtered", "how a field should be sorted"
  74. * @return: An array of handler definitions
  75. *
  76. * @ingroup tripal_library_views
  77. */
  78. function tripal_library_views_handlers() {
  79. return array(
  80. 'info' => array(
  81. 'path' => drupal_get_path('module', 'tripal_library') . '/views/handlers',
  82. ),
  83. 'handlers' => array(
  84. 'views_handler_field_computed_library_nid' => array(
  85. 'parent' => 'views_handler_field_numeric',
  86. ),
  87. ),
  88. );
  89. }
  90. /**
  91. * Implementation of hook_views_data_alter().
  92. */
  93. function tripal_library_views_data_alter(&$data) {
  94. if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  95. // Add featuer relationship to node
  96. $data['node']['library_chado_nid'] = array(
  97. 'group' => 'Library',
  98. 'title' => 'Library Node',
  99. 'help' => 'Links Chado Library Fields/Data to the Nodes in the current View.',
  100. 'real field' => 'nid',
  101. 'relationship' => array(
  102. 'handler' => 'views_handler_relationship',
  103. 'title' => t('Node => Chado'),
  104. 'label' => t('Node => Chado'),
  105. 'real field' => 'nid',
  106. 'base' => 'chado_library',
  107. 'base field' => 'nid'
  108. ),
  109. );
  110. }
  111. }
  112. /**
  113. *
  114. *
  115. * @ingroup tripal_library_views
  116. */
  117. function tripal_library_views_default_views() {
  118. $views = array();
  119. if (!module_exists('tripal_views')) {
  120. return $views;
  121. }
  122. // Main default view
  123. $view = new view;
  124. $view->name = 'library_listing';
  125. $view->description = 'A listing of all libraries';
  126. $view->tag = 'chado default';
  127. $view->base_table = 'library';
  128. $view->core = 0;
  129. $view->api_version = '2';
  130. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  131. $handler = $view->new_display('default', 'Defaults', 'default');
  132. $handler->override_option('fields', array(
  133. 'uniquename' => array(
  134. 'label' => 'Unique Name',
  135. 'alter' => array(
  136. 'alter_text' => 0,
  137. 'text' => '',
  138. 'make_link' => 0,
  139. 'path' => '',
  140. 'link_class' => '',
  141. 'alt' => '',
  142. 'prefix' => '',
  143. 'suffix' => '',
  144. 'target' => '',
  145. 'help' => '',
  146. 'trim' => 0,
  147. 'max_length' => '',
  148. 'word_boundary' => 1,
  149. 'ellipsis' => 1,
  150. 'html' => 0,
  151. 'strip_tags' => 0,
  152. ),
  153. 'empty' => '',
  154. 'hide_empty' => 0,
  155. 'empty_zero' => 0,
  156. 'link_to_node' => 1,
  157. 'exclude' => 0,
  158. 'id' => 'uniquename',
  159. 'table' => 'library',
  160. 'field' => 'uniquename',
  161. 'relationship' => 'none',
  162. ),
  163. 'name_1' => array(
  164. 'label' => 'Name',
  165. 'alter' => array(
  166. 'alter_text' => 0,
  167. 'text' => '',
  168. 'make_link' => 0,
  169. 'path' => '',
  170. 'link_class' => '',
  171. 'alt' => '',
  172. 'prefix' => '',
  173. 'suffix' => '',
  174. 'target' => '',
  175. 'help' => '',
  176. 'trim' => 0,
  177. 'max_length' => '',
  178. 'word_boundary' => 1,
  179. 'ellipsis' => 1,
  180. 'html' => 0,
  181. 'strip_tags' => 0,
  182. ),
  183. 'empty' => '',
  184. 'hide_empty' => 0,
  185. 'empty_zero' => 0,
  186. 'link_to_node' => 1,
  187. 'exclude' => 0,
  188. 'id' => 'name_1',
  189. 'table' => 'library',
  190. 'field' => 'name',
  191. 'relationship' => 'none',
  192. ),
  193. 'common_name' => array(
  194. 'label' => 'Organism',
  195. 'alter' => array(
  196. 'alter_text' => 0,
  197. 'text' => '',
  198. 'make_link' => 0,
  199. 'path' => '',
  200. 'link_class' => '',
  201. 'alt' => '',
  202. 'prefix' => '',
  203. 'suffix' => '',
  204. 'target' => '',
  205. 'help' => '',
  206. 'trim' => 0,
  207. 'max_length' => '',
  208. 'word_boundary' => 1,
  209. 'ellipsis' => 1,
  210. 'html' => 0,
  211. 'strip_tags' => 0,
  212. ),
  213. 'empty' => '',
  214. 'hide_empty' => 0,
  215. 'empty_zero' => 0,
  216. 'link_to_node' => 1,
  217. 'exclude' => 0,
  218. 'id' => 'common_name',
  219. 'table' => 'organism',
  220. 'field' => 'common_name',
  221. 'relationship' => 'none',
  222. ),
  223. 'name' => array(
  224. 'label' => 'Type',
  225. 'alter' => array(
  226. 'alter_text' => 0,
  227. 'text' => '',
  228. 'make_link' => 0,
  229. 'path' => '',
  230. 'link_class' => '',
  231. 'alt' => '',
  232. 'prefix' => '',
  233. 'suffix' => '',
  234. 'target' => '',
  235. 'help' => '',
  236. 'trim' => 0,
  237. 'max_length' => '',
  238. 'word_boundary' => 1,
  239. 'ellipsis' => 1,
  240. 'html' => 0,
  241. 'strip_tags' => 0,
  242. ),
  243. 'empty' => '',
  244. 'hide_empty' => 0,
  245. 'empty_zero' => 0,
  246. 'exclude' => 0,
  247. 'id' => 'name',
  248. 'table' => 'cvterm',
  249. 'field' => 'name',
  250. 'relationship' => 'none',
  251. ),
  252. 'is_obsolete' => array(
  253. 'label' => 'Is Obsolete?',
  254. 'alter' => array(
  255. 'alter_text' => 0,
  256. 'text' => '',
  257. 'make_link' => 0,
  258. 'path' => '',
  259. 'link_class' => '',
  260. 'alt' => '',
  261. 'prefix' => '',
  262. 'suffix' => '',
  263. 'target' => '',
  264. 'help' => '',
  265. 'trim' => 0,
  266. 'max_length' => '',
  267. 'word_boundary' => 1,
  268. 'ellipsis' => 1,
  269. 'html' => 0,
  270. 'strip_tags' => 0,
  271. ),
  272. 'empty' => '',
  273. 'hide_empty' => 0,
  274. 'empty_zero' => 0,
  275. 'type' => 'yes-no',
  276. 'not' => 0,
  277. 'exclude' => 0,
  278. 'id' => 'is_obsolete',
  279. 'table' => 'library',
  280. 'field' => 'is_obsolete',
  281. 'relationship' => 'none',
  282. ),
  283. ));
  284. $handler->override_option('sorts', array(
  285. 'name' => array(
  286. 'id' => 'name',
  287. 'table' => 'library',
  288. 'field' => 'name',
  289. ),
  290. ));
  291. $handler->override_option('filters', array(
  292. 'common_name' => array(
  293. 'operator' => '=',
  294. 'value' => array(),
  295. 'group' => '0',
  296. 'exposed' => TRUE,
  297. 'expose' => array(
  298. 'use_operator' => 0,
  299. 'operator' => 'common_name_op',
  300. 'identifier' => 'organism_common_name',
  301. 'label' => 'Organism',
  302. 'remember' => 0,
  303. ),
  304. 'case' => 1,
  305. 'id' => 'common_name',
  306. 'table' => 'organism',
  307. 'field' => 'common_name',
  308. 'relationship' => 'none',
  309. 'values_form_type' => 'select',
  310. 'multiple' => 1,
  311. 'optional' => 0,
  312. 'agg' => array(
  313. 'records_with' => 1,
  314. 'aggregates_with' => 1,
  315. ),
  316. ),
  317. 'type_id' => array(
  318. 'operator' => '=',
  319. 'value' => array(),
  320. 'group' => '0',
  321. 'exposed' => TRUE,
  322. 'expose' => array(
  323. 'use_operator' => 0,
  324. 'operator' => 'type_id_op',
  325. 'identifier' => 'type_id',
  326. 'label' => 'Type',
  327. 'remember' => 0,
  328. ),
  329. 'case' => 1,
  330. 'id' => 'type_id',
  331. 'table' => 'library',
  332. 'field' => 'type_id',
  333. 'relationship' => 'none',
  334. 'values_form_type' => 'select',
  335. 'multiple' => 1,
  336. 'optional' => 0,
  337. 'show_all' => 0,
  338. 'agg' => array(
  339. 'records_with' => 1,
  340. 'aggregates_with' => 0,
  341. ),
  342. ),
  343. ));
  344. $handler->override_option('access', array(
  345. 'type' => 'perm',
  346. 'perm' => 'access chado_library content',
  347. ));
  348. $handler->override_option('cache', array(
  349. 'type' => 'none',
  350. ));
  351. $handler->override_option('title', 'Libraries');
  352. $handler->override_option('header', 'Click "Show" to see a list of all libraries matching the entered criteria. If you leave a any of the criteria blank then the libraries will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all libraries will be listed.');
  353. $handler->override_option('header_format', '2');
  354. $handler->override_option('header_empty', 0);
  355. $handler->override_option('empty', 'No libraries match the supplied criteria.');
  356. $handler->override_option('empty_format', '1');
  357. $handler->override_option('items_per_page', 50);
  358. $handler->override_option('use_pager', '1');
  359. $handler->override_option('style_plugin', 'table');
  360. $handler->override_option('style_options', array(
  361. 'grouping' => '',
  362. 'override' => 1,
  363. 'sticky' => 0,
  364. 'order' => 'asc',
  365. 'summary' => '',
  366. 'columns' => array(
  367. 'uniquename' => 'uniquename',
  368. 'name_1' => 'name_1',
  369. 'common_name' => 'common_name',
  370. 'name' => 'name',
  371. 'is_obsolete' => 'is_obsolete',
  372. ),
  373. 'info' => array(
  374. 'uniquename' => array(
  375. 'sortable' => 1,
  376. 'separator' => '',
  377. ),
  378. 'name_1' => array(
  379. 'sortable' => 1,
  380. 'separator' => '',
  381. ),
  382. 'common_name' => array(
  383. 'sortable' => 1,
  384. 'separator' => '',
  385. ),
  386. 'name' => array(
  387. 'sortable' => 1,
  388. 'separator' => '',
  389. ),
  390. 'is_obsolete' => array(
  391. 'sortable' => 1,
  392. 'separator' => '',
  393. ),
  394. ),
  395. 'default' => 'uniquename',
  396. ));
  397. $default_handler = $handler;
  398. $handler = $view->new_display('page', 'Page', 'page_1');
  399. $handler->override_option('path', 'chado/libraries');
  400. $handler->override_option('menu', array(
  401. 'type' => 'normal',
  402. 'title' => 'Libraries',
  403. 'description' => 'A library is a collection of features of a given type. For example, a cDNA or BAC clone library.',
  404. 'weight' => '10',
  405. 'name' => 'navigation',
  406. ));
  407. $handler->override_option('tab_options', array(
  408. 'type' => 'none',
  409. 'title' => '',
  410. 'description' => '',
  411. 'weight' => 0,
  412. 'name' => 'navigation',
  413. ));
  414. // Add code specific to a local chado installation
  415. // NOTE: Edit $handler above to $default_handler for the default display
  416. if (tripal_core_chado_schema_exists()) {
  417. // Add nid field
  418. $fields = $view->get_items('field', 'default');
  419. $new_fields = array(
  420. 'nid' => array(
  421. 'label' => 'Nid',
  422. 'alter' => array(
  423. 'alter_text' => 0,
  424. 'text' => '',
  425. 'make_link' => 0,
  426. 'path' => '',
  427. 'absolute' => 0,
  428. 'link_class' => '',
  429. 'alt' => '',
  430. 'rel' => '',
  431. 'prefix' => '',
  432. 'suffix' => '',
  433. 'target' => '',
  434. 'help' => '',
  435. 'trim' => 0,
  436. 'max_length' => '',
  437. 'word_boundary' => 1,
  438. 'ellipsis' => 1,
  439. 'html' => 0,
  440. 'strip_tags' => 0,
  441. ),
  442. 'empty' => '',
  443. 'hide_empty' => 0,
  444. 'empty_zero' => 0,
  445. 'hide_alter_empty' => 1,
  446. 'link_to_node' => 0,
  447. 'exclude' => 1,
  448. 'id' => 'nid',
  449. 'table' => 'node',
  450. 'field' => 'nid',
  451. 'relationship' => 'none',
  452. )
  453. );
  454. $fields = $new_fields + $fields;
  455. // Adds library => Node relationship
  456. $default_handler->override_option('relationships', array(
  457. 'nid' => array(
  458. 'label' => 'Library to Node',
  459. 'required' => 0,
  460. 'id' => 'nid',
  461. 'table' => 'chado_library',
  462. 'field' => 'nid',
  463. 'relationship' => 'none',
  464. ),
  465. ));
  466. // Change analysis.name to have a link to the node
  467. $fields['name_1']['alter']['make_link'] = 1;
  468. $fields['name_1']['alter']['path'] = 'node/[nid]';
  469. $default_handler->override_option('fields', $fields);
  470. // Only show records with published nodes
  471. $filters = $view->get_items('filter', 'default');
  472. $filters['status'] = array(
  473. 'operator' => '=',
  474. 'value' => '1',
  475. 'group' => '0',
  476. 'exposed' => FALSE,
  477. 'expose' => array(
  478. 'operator' => FALSE,
  479. 'label' => '',
  480. ),
  481. 'id' => 'status',
  482. 'table' => 'node',
  483. 'field' => 'status',
  484. 'relationship' => 'none',
  485. );
  486. $default_handler->override_option('filters', $filters);
  487. }
  488. $views[$view->name] = $view;
  489. return $views;
  490. }