tripal_library.views.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. // Main default view
  115. $view = new view;
  116. $view->name = 'library_listing';
  117. $view->description = 'A listing of all libraries';
  118. $view->tag = 'chado default';
  119. $view->base_table = 'library';
  120. $view->core = 0;
  121. $view->api_version = '2';
  122. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  123. $handler = $view->new_display('default', 'Defaults', 'default');
  124. $handler->override_option('fields', array(
  125. 'uniquename' => array(
  126. 'label' => 'Unique Name',
  127. 'alter' => array(
  128. 'alter_text' => 0,
  129. 'text' => '',
  130. 'make_link' => 0,
  131. 'path' => '',
  132. 'link_class' => '',
  133. 'alt' => '',
  134. 'prefix' => '',
  135. 'suffix' => '',
  136. 'target' => '',
  137. 'help' => '',
  138. 'trim' => 0,
  139. 'max_length' => '',
  140. 'word_boundary' => 1,
  141. 'ellipsis' => 1,
  142. 'html' => 0,
  143. 'strip_tags' => 0,
  144. ),
  145. 'empty' => '',
  146. 'hide_empty' => 0,
  147. 'empty_zero' => 0,
  148. 'link_to_node' => 1,
  149. 'exclude' => 0,
  150. 'id' => 'uniquename',
  151. 'table' => 'library',
  152. 'field' => 'uniquename',
  153. 'relationship' => 'none',
  154. ),
  155. 'name_1' => array(
  156. 'label' => 'Name',
  157. 'alter' => array(
  158. 'alter_text' => 0,
  159. 'text' => '',
  160. 'make_link' => 0,
  161. 'path' => '',
  162. 'link_class' => '',
  163. 'alt' => '',
  164. 'prefix' => '',
  165. 'suffix' => '',
  166. 'target' => '',
  167. 'help' => '',
  168. 'trim' => 0,
  169. 'max_length' => '',
  170. 'word_boundary' => 1,
  171. 'ellipsis' => 1,
  172. 'html' => 0,
  173. 'strip_tags' => 0,
  174. ),
  175. 'empty' => '',
  176. 'hide_empty' => 0,
  177. 'empty_zero' => 0,
  178. 'link_to_node' => 1,
  179. 'exclude' => 0,
  180. 'id' => 'name_1',
  181. 'table' => 'library',
  182. 'field' => 'name',
  183. 'relationship' => 'none',
  184. ),
  185. 'common_name' => array(
  186. 'label' => 'Organism',
  187. 'alter' => array(
  188. 'alter_text' => 0,
  189. 'text' => '',
  190. 'make_link' => 0,
  191. 'path' => '',
  192. 'link_class' => '',
  193. 'alt' => '',
  194. 'prefix' => '',
  195. 'suffix' => '',
  196. 'target' => '',
  197. 'help' => '',
  198. 'trim' => 0,
  199. 'max_length' => '',
  200. 'word_boundary' => 1,
  201. 'ellipsis' => 1,
  202. 'html' => 0,
  203. 'strip_tags' => 0,
  204. ),
  205. 'empty' => '',
  206. 'hide_empty' => 0,
  207. 'empty_zero' => 0,
  208. 'link_to_node' => 1,
  209. 'exclude' => 0,
  210. 'id' => 'common_name',
  211. 'table' => 'organism',
  212. 'field' => 'common_name',
  213. 'relationship' => 'none',
  214. ),
  215. 'name' => array(
  216. 'label' => 'Type',
  217. 'alter' => array(
  218. 'alter_text' => 0,
  219. 'text' => '',
  220. 'make_link' => 0,
  221. 'path' => '',
  222. 'link_class' => '',
  223. 'alt' => '',
  224. 'prefix' => '',
  225. 'suffix' => '',
  226. 'target' => '',
  227. 'help' => '',
  228. 'trim' => 0,
  229. 'max_length' => '',
  230. 'word_boundary' => 1,
  231. 'ellipsis' => 1,
  232. 'html' => 0,
  233. 'strip_tags' => 0,
  234. ),
  235. 'empty' => '',
  236. 'hide_empty' => 0,
  237. 'empty_zero' => 0,
  238. 'exclude' => 0,
  239. 'id' => 'name',
  240. 'table' => 'cvterm',
  241. 'field' => 'name',
  242. 'relationship' => 'none',
  243. ),
  244. 'is_obsolete' => array(
  245. 'label' => 'Is Obsolete?',
  246. 'alter' => array(
  247. 'alter_text' => 0,
  248. 'text' => '',
  249. 'make_link' => 0,
  250. 'path' => '',
  251. 'link_class' => '',
  252. 'alt' => '',
  253. 'prefix' => '',
  254. 'suffix' => '',
  255. 'target' => '',
  256. 'help' => '',
  257. 'trim' => 0,
  258. 'max_length' => '',
  259. 'word_boundary' => 1,
  260. 'ellipsis' => 1,
  261. 'html' => 0,
  262. 'strip_tags' => 0,
  263. ),
  264. 'empty' => '',
  265. 'hide_empty' => 0,
  266. 'empty_zero' => 0,
  267. 'type' => 'yes-no',
  268. 'not' => 0,
  269. 'exclude' => 0,
  270. 'id' => 'is_obsolete',
  271. 'table' => 'library',
  272. 'field' => 'is_obsolete',
  273. 'relationship' => 'none',
  274. ),
  275. ));
  276. $handler->override_option('sorts', array(
  277. 'name' => array(
  278. 'id' => 'name',
  279. 'table' => 'library',
  280. 'field' => 'name',
  281. ),
  282. ));
  283. $handler->override_option('filters', array(
  284. 'common_name' => array(
  285. 'operator' => '=',
  286. 'value' => array(),
  287. 'group' => '0',
  288. 'exposed' => TRUE,
  289. 'expose' => array(
  290. 'use_operator' => 0,
  291. 'operator' => 'common_name_op',
  292. 'identifier' => 'organism_common_name',
  293. 'label' => 'Organism',
  294. 'remember' => 0,
  295. ),
  296. 'case' => 1,
  297. 'id' => 'common_name',
  298. 'table' => 'organism',
  299. 'field' => 'common_name',
  300. 'relationship' => 'none',
  301. 'values_form_type' => 'select',
  302. 'multiple' => 1,
  303. 'optional' => 0,
  304. 'agg' => array(
  305. 'records_with' => 1,
  306. 'aggregates_with' => 1,
  307. ),
  308. ),
  309. 'type_id' => array(
  310. 'operator' => '=',
  311. 'value' => array(),
  312. 'group' => '0',
  313. 'exposed' => TRUE,
  314. 'expose' => array(
  315. 'use_operator' => 0,
  316. 'operator' => 'type_id_op',
  317. 'identifier' => 'type_id',
  318. 'label' => 'Type',
  319. 'remember' => 0,
  320. ),
  321. 'case' => 1,
  322. 'id' => 'type_id',
  323. 'table' => 'library',
  324. 'field' => 'type_id',
  325. 'relationship' => 'none',
  326. 'values_form_type' => 'select',
  327. 'multiple' => 1,
  328. 'optional' => 0,
  329. 'show_all' => 0,
  330. 'agg' => array(
  331. 'records_with' => 1,
  332. 'aggregates_with' => 0,
  333. ),
  334. ),
  335. ));
  336. $handler->override_option('access', array(
  337. 'type' => 'perm',
  338. 'perm' => 'access chado_library content',
  339. ));
  340. $handler->override_option('cache', array(
  341. 'type' => 'none',
  342. ));
  343. $handler->override_option('title', 'Libraries');
  344. $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.');
  345. $handler->override_option('header_format', '2');
  346. $handler->override_option('header_empty', 0);
  347. $handler->override_option('empty', 'There are no libraries matching the current criteria. If you think there should be, check that all chado libraries are sync\'d with your website.');
  348. $handler->override_option('empty_format', '1');
  349. $handler->override_option('items_per_page', 50);
  350. $handler->override_option('use_pager', '1');
  351. $handler->override_option('style_plugin', 'table');
  352. $handler->override_option('style_options', array(
  353. 'grouping' => '',
  354. 'override' => 1,
  355. 'sticky' => 0,
  356. 'order' => 'asc',
  357. 'summary' => '',
  358. 'columns' => array(
  359. 'uniquename' => 'uniquename',
  360. 'name_1' => 'name_1',
  361. 'common_name' => 'common_name',
  362. 'name' => 'name',
  363. 'is_obsolete' => 'is_obsolete',
  364. ),
  365. 'info' => array(
  366. 'uniquename' => array(
  367. 'sortable' => 1,
  368. 'separator' => '',
  369. ),
  370. 'name_1' => array(
  371. 'sortable' => 1,
  372. 'separator' => '',
  373. ),
  374. 'common_name' => array(
  375. 'sortable' => 1,
  376. 'separator' => '',
  377. ),
  378. 'name' => array(
  379. 'sortable' => 1,
  380. 'separator' => '',
  381. ),
  382. 'is_obsolete' => array(
  383. 'sortable' => 1,
  384. 'separator' => '',
  385. ),
  386. ),
  387. 'default' => 'uniquename',
  388. ));
  389. $default_handler = $handler;
  390. $handler = $view->new_display('page', 'Page', 'page_1');
  391. $handler->override_option('path', 'chado/libraries');
  392. $handler->override_option('menu', array(
  393. 'type' => 'normal',
  394. 'title' => 'Libraries',
  395. 'description' => 'A library is a collection of features of a given type. For example, a cDNA or BAC clone library.',
  396. 'weight' => '10',
  397. 'name' => 'navigation',
  398. ));
  399. $handler->override_option('tab_options', array(
  400. 'type' => 'none',
  401. 'title' => '',
  402. 'description' => '',
  403. 'weight' => 0,
  404. 'name' => 'navigation',
  405. ));
  406. // Add code specific to a local chado installation
  407. // NOTE: Edit $handler above to $default_handler for the default display
  408. if (tripal_core_chado_schema_exists()) {
  409. // Add nid field
  410. $fields = $view->get_items('field', 'default');
  411. $new_fields = array(
  412. 'nid' => array(
  413. 'label' => 'Nid',
  414. 'alter' => array(
  415. 'alter_text' => 0,
  416. 'text' => '',
  417. 'make_link' => 0,
  418. 'path' => '',
  419. 'absolute' => 0,
  420. 'link_class' => '',
  421. 'alt' => '',
  422. 'rel' => '',
  423. 'prefix' => '',
  424. 'suffix' => '',
  425. 'target' => '',
  426. 'help' => '',
  427. 'trim' => 0,
  428. 'max_length' => '',
  429. 'word_boundary' => 1,
  430. 'ellipsis' => 1,
  431. 'html' => 0,
  432. 'strip_tags' => 0,
  433. ),
  434. 'empty' => '',
  435. 'hide_empty' => 0,
  436. 'empty_zero' => 0,
  437. 'hide_alter_empty' => 1,
  438. 'link_to_node' => 0,
  439. 'exclude' => 1,
  440. 'id' => 'nid',
  441. 'table' => 'node',
  442. 'field' => 'nid',
  443. 'relationship' => 'none',
  444. )
  445. );
  446. $fields = $new_fields + $fields;
  447. // Adds library => Node relationship
  448. $default_handler->override_option('relationships', array(
  449. 'nid' => array(
  450. 'label' => 'Library to Node',
  451. 'required' => 0,
  452. 'id' => 'nid',
  453. 'table' => 'chado_library',
  454. 'field' => 'nid',
  455. 'relationship' => 'none',
  456. ),
  457. ));
  458. // Change analysis.name to have a link to the node
  459. $fields['name_1']['alter']['make_link'] = 1;
  460. $fields['name_1']['alter']['path'] = 'node/[nid]';
  461. $default_handler->override_option('fields', $fields);
  462. // Only show records with published nodes
  463. $filters = $view->get_items('filter', 'default');
  464. $filters['status'] = array(
  465. 'operator' => '=',
  466. 'value' => '1',
  467. 'group' => '0',
  468. 'exposed' => FALSE,
  469. 'expose' => array(
  470. 'operator' => FALSE,
  471. 'label' => '',
  472. ),
  473. 'id' => 'status',
  474. 'table' => 'node',
  475. 'field' => 'status',
  476. 'relationship' => 'none',
  477. );
  478. $default_handler->override_option('filters', $filters);
  479. }
  480. $views[$view->name] = $view;
  481. return $views;
  482. }