tripal_library.views.inc 14 KB

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