tripal_library.views.inc 14 KB

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