tripal_feature.views.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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_feature_views Feature Views Integration
  13. * @ingroup views
  14. * @ingroup tripal_feature
  15. */
  16. /**
  17. * Implements hook_views_data()
  18. *
  19. * Purpose: Describe chado/tripal tables & fields to views
  20. *
  21. * @return: a data array which follows the structure outlined in the
  22. * views2 documentation for this hook. Essentially, it's an array of table
  23. * definitions keyed by chado/tripal table name. Each table definition
  24. * includes basic details about the table, fields in that table and
  25. * relationships between that table and others (joins)
  26. *
  27. * @ingroup tripal_feature_views
  28. */
  29. function tripal_feature_views_data() {
  30. $data = array();
  31. if (module_exists('tripal_views')) {
  32. $tables = array(
  33. 'feature',
  34. );
  35. foreach ($tables as $tablename) {
  36. if (!tripal_views_is_integrated($tablename, 10)) {
  37. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
  38. tripal_views_integration_add_entry($table_integration_array);
  39. }
  40. }
  41. $tables = array(
  42. 'feature_cvterm',
  43. 'feature_cvterm_dbxref',
  44. 'feature_cvterm_pub',
  45. 'feature_cvtermprop',
  46. 'feature_dbxref',
  47. 'feature_pub',
  48. 'feature_pubprop',
  49. 'feature_relationship',
  50. 'feature_relationship_pub',
  51. 'feature_relationshipprop',
  52. 'feature_relationshipprop_pub',
  53. 'feature_synonym',
  54. 'featureloc',
  55. 'featureloc_pub',
  56. 'featureprop',
  57. 'featureprop_pub',
  58. 'featuremap',
  59. 'featuremap_pub',
  60. 'featurepos',
  61. 'featurerange'
  62. );
  63. foreach ($tables as $tablename) {
  64. if (!tripal_views_is_integrated($tablename, 10)) {
  65. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
  66. tripal_views_integration_add_entry($table_integration_array);
  67. }
  68. }
  69. }
  70. return $data;
  71. }
  72. /**
  73. * Implements hook_views_handlers()
  74. *
  75. * Purpose: Register all custom handlers with views
  76. * where a handler describes either "the type of field",
  77. * "how a field should be filtered", "how a field should be sorted"
  78. *
  79. * @return: An array of handler definitions
  80. *
  81. * @ingroup tripal_feature_views
  82. */
  83. function tripal_feature_views_handlers() {
  84. return array(
  85. 'info' => array(
  86. 'path' => drupal_get_path('module', 'tripal_feature') . '/views_handlers',
  87. ),
  88. 'handlers' => array(
  89. 'views_handler_field_residues' => array(
  90. 'parent' => 'views_handler_field',
  91. ),
  92. ),
  93. );
  94. }
  95. /**
  96. * Implementation of hook_views_data_alter().
  97. */
  98. function tripal_feature_views_data_alter(&$data) {
  99. if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  100. // Add featuer relationship to node
  101. $data['node']['feature_chado_nid'] = array(
  102. 'group' => 'Feature',
  103. 'title' => 'Feature Node',
  104. 'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
  105. 'real field' => 'nid',
  106. 'relationship' => array(
  107. 'handler' => 'views_handler_relationship',
  108. 'title' => t('Node => Chado'),
  109. 'label' => t('Node => Chado'),
  110. 'real field' => 'nid',
  111. 'base' => 'chado_feature',
  112. 'base field' => 'nid'
  113. ),
  114. );
  115. }
  116. }
  117. /**
  118. *
  119. * @ingroup tripal_feature_views
  120. */
  121. function tripal_feature_views_default_views() {
  122. $views = array();
  123. // Main default view
  124. // List all cvterms based on cv
  125. $view = new view;
  126. $view->name = 'all_features';
  127. $view->description = 'A listing of all Sequence FEatures';
  128. $view->tag = 'chado';
  129. $view->view_php = '';
  130. $view->base_table = 'feature';
  131. $view->is_cacheable = FALSE;
  132. $view->api_version = 2;
  133. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  134. $handler = $view->new_display('default', 'Defaults', 'default');
  135. $handler->override_option('fields', array(
  136. 'uniquename' => array(
  137. 'label' => 'Unique Name',
  138. 'alter' => array(
  139. 'alter_text' => 0,
  140. 'text' => '',
  141. 'make_link' => 0,
  142. 'path' => '',
  143. 'link_class' => '',
  144. 'alt' => '',
  145. 'prefix' => '',
  146. 'suffix' => '',
  147. 'target' => '',
  148. 'help' => '',
  149. 'trim' => 0,
  150. 'max_length' => '',
  151. 'word_boundary' => 1,
  152. 'ellipsis' => 1,
  153. 'html' => 0,
  154. 'strip_tags' => 0,
  155. ),
  156. 'empty' => '',
  157. 'hide_empty' => 0,
  158. 'empty_zero' => 0,
  159. 'link_to_node' => 1,
  160. 'exclude' => 0,
  161. 'id' => 'uniquename',
  162. 'table' => 'feature',
  163. 'field' => 'uniquename',
  164. 'relationship' => 'none',
  165. ),
  166. 'name' => array(
  167. 'label' => 'Name',
  168. 'alter' => array(
  169. 'alter_text' => 0,
  170. 'text' => '',
  171. 'make_link' => 0,
  172. 'path' => '',
  173. 'link_class' => '',
  174. 'alt' => '',
  175. 'prefix' => '',
  176. 'suffix' => '',
  177. 'target' => '',
  178. 'help' => '',
  179. 'trim' => 0,
  180. 'max_length' => '',
  181. 'word_boundary' => 1,
  182. 'ellipsis' => 1,
  183. 'html' => 0,
  184. 'strip_tags' => 0,
  185. ),
  186. 'empty' => '',
  187. 'hide_empty' => 0,
  188. 'empty_zero' => 0,
  189. 'link_to_node' => 1,
  190. 'exclude' => 0,
  191. 'id' => 'name',
  192. 'table' => 'feature',
  193. 'field' => 'name',
  194. 'relationship' => 'none',
  195. ),
  196. 'common_name' => array(
  197. 'label' => 'Organism',
  198. 'alter' => array(
  199. 'alter_text' => 0,
  200. 'text' => '',
  201. 'make_link' => 0,
  202. 'path' => '',
  203. 'link_class' => '',
  204. 'alt' => '',
  205. 'prefix' => '',
  206. 'suffix' => '',
  207. 'target' => '',
  208. 'help' => '',
  209. 'trim' => 0,
  210. 'max_length' => '',
  211. 'word_boundary' => 1,
  212. 'ellipsis' => 1,
  213. 'html' => 0,
  214. 'strip_tags' => 0,
  215. ),
  216. 'empty' => '',
  217. 'hide_empty' => 0,
  218. 'empty_zero' => 0,
  219. 'link_to_node' => 1,
  220. 'exclude' => 0,
  221. 'id' => 'common_name',
  222. 'table' => 'organism',
  223. 'field' => 'common_name',
  224. 'relationship' => 'none',
  225. ),
  226. 'name_3' => array(
  227. 'label' => 'Type',
  228. 'alter' => array(
  229. 'alter_text' => 0,
  230. 'text' => '',
  231. 'make_link' => 0,
  232. 'path' => '',
  233. 'link_class' => '',
  234. 'alt' => '',
  235. 'prefix' => '',
  236. 'suffix' => '',
  237. 'target' => '',
  238. 'help' => '',
  239. 'trim' => 0,
  240. 'max_length' => '',
  241. 'word_boundary' => 1,
  242. 'ellipsis' => 1,
  243. 'html' => 0,
  244. 'strip_tags' => 0,
  245. ),
  246. 'empty' => '',
  247. 'hide_empty' => 0,
  248. 'empty_zero' => 0,
  249. 'exclude' => 0,
  250. 'id' => 'name_3',
  251. 'table' => 'cvterm',
  252. 'field' => 'name',
  253. 'relationship' => 'none',
  254. ),
  255. 'accession_link' => array(
  256. 'label' => 'External Reference',
  257. 'alter' => array(
  258. 'alter_text' => 0,
  259. 'text' => '',
  260. 'make_link' => 0,
  261. 'path' => '',
  262. 'link_class' => '',
  263. 'alt' => '',
  264. 'prefix' => '',
  265. 'suffix' => '',
  266. 'target' => '',
  267. 'help' => '',
  268. 'trim' => 0,
  269. 'max_length' => '',
  270. 'word_boundary' => 1,
  271. 'ellipsis' => 1,
  272. 'html' => 0,
  273. 'strip_tags' => 0,
  274. ),
  275. 'empty' => '',
  276. 'hide_empty' => 0,
  277. 'empty_zero' => 0,
  278. 'exclude' => 0,
  279. 'id' => 'accession_link',
  280. 'table' => 'dbxref',
  281. 'field' => 'accession_link',
  282. 'relationship' => 'none',
  283. ),
  284. 'name_1' => array(
  285. 'label' => 'Library',
  286. 'alter' => array(
  287. 'alter_text' => 0,
  288. 'text' => '',
  289. 'make_link' => 0,
  290. 'path' => '',
  291. 'link_class' => '',
  292. 'alt' => '',
  293. 'prefix' => '',
  294. 'suffix' => '',
  295. 'target' => '',
  296. 'help' => '',
  297. 'trim' => 0,
  298. 'max_length' => '',
  299. 'word_boundary' => 1,
  300. 'ellipsis' => 1,
  301. 'html' => 0,
  302. 'strip_tags' => 0,
  303. ),
  304. 'empty' => '',
  305. 'hide_empty' => 0,
  306. 'empty_zero' => 0,
  307. 'link_to_node' => 1,
  308. 'exclude' => 0,
  309. 'id' => 'name_1',
  310. 'table' => 'library',
  311. 'field' => 'name',
  312. 'relationship' => 'none',
  313. ),
  314. 'name_2' => array(
  315. 'label' => 'Analysis',
  316. 'alter' => array(
  317. 'alter_text' => 0,
  318. 'text' => '',
  319. 'make_link' => 0,
  320. 'path' => '',
  321. 'link_class' => '',
  322. 'alt' => '',
  323. 'prefix' => '',
  324. 'suffix' => '',
  325. 'target' => '',
  326. 'help' => '',
  327. 'trim' => 0,
  328. 'max_length' => '',
  329. 'word_boundary' => 1,
  330. 'ellipsis' => 1,
  331. 'html' => 0,
  332. 'strip_tags' => 0,
  333. ),
  334. 'empty' => '',
  335. 'hide_empty' => 0,
  336. 'empty_zero' => 0,
  337. 'link_to_node' => 1,
  338. 'exclude' => 0,
  339. 'id' => 'name_2',
  340. 'table' => 'analysis',
  341. 'field' => 'name',
  342. 'relationship' => 'none',
  343. ),
  344. ));
  345. $handler->override_option('filters', array(
  346. 'common_name' => array(
  347. 'operator' => '=',
  348. 'value' => '<select organism>',
  349. 'group' => '0',
  350. 'exposed' => TRUE,
  351. 'expose' => array(
  352. 'use_operator' => 0,
  353. 'operator' => 'common_name_op',
  354. 'identifier' => 'organism',
  355. 'label' => 'Organism',
  356. 'optional' => 1,
  357. 'remember' => 0,
  358. ),
  359. 'case' => 1,
  360. 'id' => 'common_name',
  361. 'table' => 'organism',
  362. 'field' => 'common_name',
  363. 'relationship' => 'none',
  364. ),
  365. 'name' => array(
  366. 'operator' => 'contains',
  367. 'value' => '',
  368. 'group' => '0',
  369. 'exposed' => TRUE,
  370. 'expose' => array(
  371. 'use_operator' => 0,
  372. 'operator' => 'name_op',
  373. 'identifier' => 'name',
  374. 'label' => 'Name Contains',
  375. 'optional' => 1,
  376. 'remember' => 0,
  377. ),
  378. 'case' => 0,
  379. 'id' => 'name',
  380. 'table' => 'feature',
  381. 'field' => 'name',
  382. 'relationship' => 'none',
  383. ),
  384. 'name_1' => array(
  385. 'operator' => 'contains',
  386. 'value' => '',
  387. 'group' => '0',
  388. 'exposed' => TRUE,
  389. 'expose' => array(
  390. 'use_operator' => 0,
  391. 'operator' => 'name_1_op',
  392. 'identifier' => 'library',
  393. 'label' => 'Library Name Contains',
  394. 'optional' => 1,
  395. 'remember' => 0,
  396. ),
  397. 'case' => 0,
  398. 'id' => 'name_1',
  399. 'table' => 'library',
  400. 'field' => 'name',
  401. 'relationship' => 'none',
  402. ),
  403. 'name_2' => array(
  404. 'operator' => 'contains',
  405. 'value' => '',
  406. 'group' => '0',
  407. 'exposed' => TRUE,
  408. 'expose' => array(
  409. 'use_operator' => 0,
  410. 'operator' => 'name_2_op',
  411. 'identifier' => 'analysis',
  412. 'label' => 'Analysis Name Contains',
  413. 'optional' => 1,
  414. 'remember' => 0,
  415. ),
  416. 'case' => 0,
  417. 'id' => 'name_2',
  418. 'table' => 'analysis',
  419. 'field' => 'name',
  420. 'relationship' => 'none',
  421. ),
  422. ));
  423. $handler->override_option('access', array(
  424. 'type' => 'perm',
  425. 'perm' => 'access chado_feature content',
  426. ));
  427. $handler->override_option('cache', array(
  428. 'type' => 'none',
  429. ));
  430. $handler->override_option('title', 'Sequence Features');
  431. $handler->override_option('empty', 'There are no features matching that criteria. Please select a different organism above.');
  432. $handler->override_option('empty_format', '1');
  433. $handler->override_option('items_per_page', 50);
  434. $handler->override_option('style_plugin', 'table');
  435. $handler = $view->new_display('page', 'Page', 'page_1');
  436. $handler->override_option('path', 'features');
  437. $handler->override_option('menu', array(
  438. 'type' => 'normal',
  439. 'title' => 'Sequence Features',
  440. 'description' => '',
  441. 'weight' => '0',
  442. 'name' => 'primary-links',
  443. ));
  444. $handler->override_option('tab_options', array(
  445. 'type' => 'none',
  446. 'title' => '',
  447. 'description' => '',
  448. 'weight' => 0,
  449. 'name' => 'navigation',
  450. ));
  451. $views[$view->name] = $view;
  452. return $views;
  453. }