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