tripal_feature.views.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. require_once('views/feature.views.inc');
  30. require_once('views/chado_feature.views.inc');
  31. require_once('views/misc_tables.views.inc');
  32. function tripal_feature_views_data() {
  33. $data = array();
  34. $data = array_merge($data, retrieve_feature_views_data());
  35. $data = array_merge($data, retrieve_chado_feature_views_data());
  36. $data = array_merge($data, retrieve_feature_misc_tables_views_data());
  37. return $data;
  38. }
  39. /**
  40. * Implements hook_views_handlers()
  41. *
  42. * Purpose: Register all custom handlers with views
  43. * where a handler describes either "the type of field",
  44. * "how a field should be filtered", "how a field should be sorted"
  45. *
  46. * @return: An array of handler definitions
  47. *
  48. * @ingroup tripal_feature_views
  49. */
  50. function tripal_feature_views_handlers() {
  51. return array(
  52. 'info' => array(
  53. 'path' => drupal_get_path('module', 'tripal_feature') . '/views/handlers',
  54. ),
  55. 'handlers' => array(
  56. 'views_handler_field_computed_feature_nid' => array(
  57. 'parent' => 'views_handler_field_numeric',
  58. ),
  59. 'views_handler_field_residues' => array(
  60. 'parent' => 'views_handler_field',
  61. ),
  62. ),
  63. );
  64. }
  65. /**
  66. * Implementation of hook_views_data_alter().
  67. */
  68. function tripal_feature_views_data_alter(&$data) {
  69. if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  70. // Add featuer relationship to node
  71. $data['node']['feature_chado_nid'] = array(
  72. 'group' => 'Feature',
  73. 'title' => 'Feature Node',
  74. 'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
  75. 'real field' => 'nid',
  76. 'relationship' => array(
  77. 'handler' => 'views_handler_relationship',
  78. 'title' => t('Node => Chado'),
  79. 'label' => t('Node => Chado'),
  80. 'real field' => 'nid',
  81. 'base' => 'chado_feature',
  82. 'base field' => 'nid'
  83. ),
  84. );
  85. }
  86. }
  87. /**
  88. *
  89. * @ingroup tripal_feature_views
  90. */
  91. function tripal_feature_views_default_views() {
  92. $views = array();
  93. // Main default view
  94. // List all cvterms based on cv
  95. $view = new view;
  96. $view->name = 'all_features';
  97. $view->description = 'A listing of all Sequence FEatures';
  98. $view->tag = 'chado';
  99. $view->view_php = '';
  100. $view->base_table = 'feature';
  101. $view->is_cacheable = FALSE;
  102. $view->api_version = 2;
  103. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  104. $handler = $view->new_display('default', 'Defaults', 'default');
  105. $handler->override_option('fields', array(
  106. 'uniquename' => array(
  107. 'label' => 'Unique Name',
  108. 'alter' => array(
  109. 'alter_text' => 0,
  110. 'text' => '',
  111. 'make_link' => 0,
  112. 'path' => '',
  113. 'link_class' => '',
  114. 'alt' => '',
  115. 'prefix' => '',
  116. 'suffix' => '',
  117. 'target' => '',
  118. 'help' => '',
  119. 'trim' => 0,
  120. 'max_length' => '',
  121. 'word_boundary' => 1,
  122. 'ellipsis' => 1,
  123. 'html' => 0,
  124. 'strip_tags' => 0,
  125. ),
  126. 'empty' => '',
  127. 'hide_empty' => 0,
  128. 'empty_zero' => 0,
  129. 'link_to_node' => 1,
  130. 'exclude' => 0,
  131. 'id' => 'uniquename',
  132. 'table' => 'feature',
  133. 'field' => 'uniquename',
  134. 'relationship' => 'none',
  135. ),
  136. 'name' => array(
  137. 'label' => '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' => 'name',
  162. 'table' => 'feature',
  163. 'field' => 'name',
  164. 'relationship' => 'none',
  165. ),
  166. 'common_name' => array(
  167. 'label' => 'Organism',
  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' => 'common_name',
  192. 'table' => 'organism',
  193. 'field' => 'common_name',
  194. 'relationship' => 'none',
  195. ),
  196. 'name_3' => array(
  197. 'label' => 'Type',
  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. 'exclude' => 0,
  220. 'id' => 'name_3',
  221. 'table' => 'cvterm',
  222. 'field' => 'name',
  223. 'relationship' => 'none',
  224. ),
  225. 'accession_link' => array(
  226. 'label' => 'External Reference',
  227. 'alter' => array(
  228. 'alter_text' => 0,
  229. 'text' => '',
  230. 'make_link' => 0,
  231. 'path' => '',
  232. 'link_class' => '',
  233. 'alt' => '',
  234. 'prefix' => '',
  235. 'suffix' => '',
  236. 'target' => '',
  237. 'help' => '',
  238. 'trim' => 0,
  239. 'max_length' => '',
  240. 'word_boundary' => 1,
  241. 'ellipsis' => 1,
  242. 'html' => 0,
  243. 'strip_tags' => 0,
  244. ),
  245. 'empty' => '',
  246. 'hide_empty' => 0,
  247. 'empty_zero' => 0,
  248. 'exclude' => 0,
  249. 'id' => 'accession_link',
  250. 'table' => 'dbxref',
  251. 'field' => 'accession_link',
  252. 'relationship' => 'none',
  253. ),
  254. 'name_1' => array(
  255. 'label' => 'Library',
  256. 'alter' => array(
  257. 'alter_text' => 0,
  258. 'text' => '',
  259. 'make_link' => 0,
  260. 'path' => '',
  261. 'link_class' => '',
  262. 'alt' => '',
  263. 'prefix' => '',
  264. 'suffix' => '',
  265. 'target' => '',
  266. 'help' => '',
  267. 'trim' => 0,
  268. 'max_length' => '',
  269. 'word_boundary' => 1,
  270. 'ellipsis' => 1,
  271. 'html' => 0,
  272. 'strip_tags' => 0,
  273. ),
  274. 'empty' => '',
  275. 'hide_empty' => 0,
  276. 'empty_zero' => 0,
  277. 'link_to_node' => 1,
  278. 'exclude' => 0,
  279. 'id' => 'name_1',
  280. 'table' => 'library',
  281. 'field' => 'name',
  282. 'relationship' => 'none',
  283. ),
  284. 'name_2' => array(
  285. 'label' => 'Analysis',
  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_2',
  310. 'table' => 'analysis',
  311. 'field' => 'name',
  312. 'relationship' => 'none',
  313. ),
  314. ));
  315. $handler->override_option('filters', array(
  316. 'common_name' => array(
  317. 'operator' => '=',
  318. 'value' => '<select organism>',
  319. 'group' => '0',
  320. 'exposed' => TRUE,
  321. 'expose' => array(
  322. 'use_operator' => 0,
  323. 'operator' => 'common_name_op',
  324. 'identifier' => 'organism',
  325. 'label' => 'Organism',
  326. 'optional' => 1,
  327. 'remember' => 0,
  328. ),
  329. 'case' => 1,
  330. 'id' => 'common_name',
  331. 'table' => 'organism',
  332. 'field' => 'common_name',
  333. 'relationship' => 'none',
  334. ),
  335. 'name' => array(
  336. 'operator' => 'contains',
  337. 'value' => '',
  338. 'group' => '0',
  339. 'exposed' => TRUE,
  340. 'expose' => array(
  341. 'use_operator' => 0,
  342. 'operator' => 'name_op',
  343. 'identifier' => 'name',
  344. 'label' => 'Name Contains',
  345. 'optional' => 1,
  346. 'remember' => 0,
  347. ),
  348. 'case' => 0,
  349. 'id' => 'name',
  350. 'table' => 'feature',
  351. 'field' => 'name',
  352. 'relationship' => 'none',
  353. ),
  354. 'name_1' => array(
  355. 'operator' => 'contains',
  356. 'value' => '',
  357. 'group' => '0',
  358. 'exposed' => TRUE,
  359. 'expose' => array(
  360. 'use_operator' => 0,
  361. 'operator' => 'name_1_op',
  362. 'identifier' => 'library',
  363. 'label' => 'Library Name Contains',
  364. 'optional' => 1,
  365. 'remember' => 0,
  366. ),
  367. 'case' => 0,
  368. 'id' => 'name_1',
  369. 'table' => 'library',
  370. 'field' => 'name',
  371. 'relationship' => 'none',
  372. ),
  373. 'name_2' => array(
  374. 'operator' => 'contains',
  375. 'value' => '',
  376. 'group' => '0',
  377. 'exposed' => TRUE,
  378. 'expose' => array(
  379. 'use_operator' => 0,
  380. 'operator' => 'name_2_op',
  381. 'identifier' => 'analysis',
  382. 'label' => 'Analysis Name Contains',
  383. 'optional' => 1,
  384. 'remember' => 0,
  385. ),
  386. 'case' => 0,
  387. 'id' => 'name_2',
  388. 'table' => 'analysis',
  389. 'field' => 'name',
  390. 'relationship' => 'none',
  391. ),
  392. ));
  393. $handler->override_option('access', array(
  394. 'type' => 'perm',
  395. 'perm' => 'access chado_feature content',
  396. ));
  397. $handler->override_option('cache', array(
  398. 'type' => 'none',
  399. ));
  400. $handler->override_option('title', 'Sequence Features');
  401. $handler->override_option('empty', 'There are no features matching that criteria. Please select a different organism above.');
  402. $handler->override_option('empty_format', '1');
  403. $handler->override_option('items_per_page', 50);
  404. $handler->override_option('style_plugin', 'table');
  405. $handler = $view->new_display('page', 'Page', 'page_1');
  406. $handler->override_option('path', 'features');
  407. $handler->override_option('menu', array(
  408. 'type' => 'normal',
  409. 'title' => 'Sequence Features',
  410. 'description' => '',
  411. 'weight' => '0',
  412. 'name' => 'primary-links',
  413. ));
  414. $handler->override_option('tab_options', array(
  415. 'type' => 'none',
  416. 'title' => '',
  417. 'description' => '',
  418. 'weight' => 0,
  419. 'name' => 'navigation',
  420. ));
  421. $views[$view->name] = $view;
  422. return $views;
  423. }