tripal_feature.views.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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_readable_date' => array(
  60. 'parent' => 'views_handler_field',
  61. ),
  62. 'views_handler_field_residues' => array(
  63. 'parent' => 'views_handler_field',
  64. ),
  65. ),
  66. );
  67. }
  68. /**
  69. * Implementation of hook_views_data_alter().
  70. */
  71. function tripal_feature_views_data_alter(&$data) {
  72. if( !(is_array($db_url) and array_key_exists('chado',$db_url)) ){
  73. // Add featuer relationship to node
  74. $data['node']['feature_chado_nid'] = array(
  75. 'group' => 'Feature',
  76. 'title' => 'Feature Node',
  77. 'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
  78. 'real field' => 'nid',
  79. 'relationship' => array(
  80. 'handler' => 'views_handler_relationship',
  81. 'title' => t('Node => Chado'),
  82. 'label' => t('Node => Chado'),
  83. 'real field' => 'nid',
  84. 'base' => 'chado_feature',
  85. 'base field' => 'nid'
  86. ),
  87. );
  88. }
  89. }
  90. /**
  91. *
  92. * @ingroup tripal_feature_views
  93. */
  94. function tripal_feature_views_default_views () {
  95. $views = array();
  96. // Main default view
  97. // List all cvterms based on cv
  98. $view = new view;
  99. $view->name = 'all_features';
  100. $view->description = 'A listing of all Sequence FEatures';
  101. $view->tag = 'chado';
  102. $view->view_php = '';
  103. $view->base_table = 'feature';
  104. $view->is_cacheable = FALSE;
  105. $view->api_version = 2;
  106. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  107. $handler = $view->new_display('default', 'Defaults', 'default');
  108. $handler->override_option('fields', array(
  109. 'uniquename' => array(
  110. 'label' => 'Unique Name',
  111. 'alter' => array(
  112. 'alter_text' => 0,
  113. 'text' => '',
  114. 'make_link' => 0,
  115. 'path' => '',
  116. 'link_class' => '',
  117. 'alt' => '',
  118. 'prefix' => '',
  119. 'suffix' => '',
  120. 'target' => '',
  121. 'help' => '',
  122. 'trim' => 0,
  123. 'max_length' => '',
  124. 'word_boundary' => 1,
  125. 'ellipsis' => 1,
  126. 'html' => 0,
  127. 'strip_tags' => 0,
  128. ),
  129. 'empty' => '',
  130. 'hide_empty' => 0,
  131. 'empty_zero' => 0,
  132. 'link_to_node' => 1,
  133. 'exclude' => 0,
  134. 'id' => 'uniquename',
  135. 'table' => 'feature',
  136. 'field' => 'uniquename',
  137. 'relationship' => 'none',
  138. ),
  139. 'name' => array(
  140. 'label' => 'Name',
  141. 'alter' => array(
  142. 'alter_text' => 0,
  143. 'text' => '',
  144. 'make_link' => 0,
  145. 'path' => '',
  146. 'link_class' => '',
  147. 'alt' => '',
  148. 'prefix' => '',
  149. 'suffix' => '',
  150. 'target' => '',
  151. 'help' => '',
  152. 'trim' => 0,
  153. 'max_length' => '',
  154. 'word_boundary' => 1,
  155. 'ellipsis' => 1,
  156. 'html' => 0,
  157. 'strip_tags' => 0,
  158. ),
  159. 'empty' => '',
  160. 'hide_empty' => 0,
  161. 'empty_zero' => 0,
  162. 'link_to_node' => 1,
  163. 'exclude' => 0,
  164. 'id' => 'name',
  165. 'table' => 'feature',
  166. 'field' => 'name',
  167. 'relationship' => 'none',
  168. ),
  169. 'common_name' => array(
  170. 'label' => 'Organism',
  171. 'alter' => array(
  172. 'alter_text' => 0,
  173. 'text' => '',
  174. 'make_link' => 0,
  175. 'path' => '',
  176. 'link_class' => '',
  177. 'alt' => '',
  178. 'prefix' => '',
  179. 'suffix' => '',
  180. 'target' => '',
  181. 'help' => '',
  182. 'trim' => 0,
  183. 'max_length' => '',
  184. 'word_boundary' => 1,
  185. 'ellipsis' => 1,
  186. 'html' => 0,
  187. 'strip_tags' => 0,
  188. ),
  189. 'empty' => '',
  190. 'hide_empty' => 0,
  191. 'empty_zero' => 0,
  192. 'link_to_node' => 1,
  193. 'exclude' => 0,
  194. 'id' => 'common_name',
  195. 'table' => 'organism',
  196. 'field' => 'common_name',
  197. 'relationship' => 'none',
  198. ),
  199. 'name_3' => array(
  200. 'label' => 'Type',
  201. 'alter' => array(
  202. 'alter_text' => 0,
  203. 'text' => '',
  204. 'make_link' => 0,
  205. 'path' => '',
  206. 'link_class' => '',
  207. 'alt' => '',
  208. 'prefix' => '',
  209. 'suffix' => '',
  210. 'target' => '',
  211. 'help' => '',
  212. 'trim' => 0,
  213. 'max_length' => '',
  214. 'word_boundary' => 1,
  215. 'ellipsis' => 1,
  216. 'html' => 0,
  217. 'strip_tags' => 0,
  218. ),
  219. 'empty' => '',
  220. 'hide_empty' => 0,
  221. 'empty_zero' => 0,
  222. 'exclude' => 0,
  223. 'id' => 'name_3',
  224. 'table' => 'cvterm',
  225. 'field' => 'name',
  226. 'relationship' => 'none',
  227. ),
  228. 'accession_link' => array(
  229. 'label' => 'External Reference',
  230. 'alter' => array(
  231. 'alter_text' => 0,
  232. 'text' => '',
  233. 'make_link' => 0,
  234. 'path' => '',
  235. 'link_class' => '',
  236. 'alt' => '',
  237. 'prefix' => '',
  238. 'suffix' => '',
  239. 'target' => '',
  240. 'help' => '',
  241. 'trim' => 0,
  242. 'max_length' => '',
  243. 'word_boundary' => 1,
  244. 'ellipsis' => 1,
  245. 'html' => 0,
  246. 'strip_tags' => 0,
  247. ),
  248. 'empty' => '',
  249. 'hide_empty' => 0,
  250. 'empty_zero' => 0,
  251. 'exclude' => 0,
  252. 'id' => 'accession_link',
  253. 'table' => 'dbxref',
  254. 'field' => 'accession_link',
  255. 'relationship' => 'none',
  256. ),
  257. 'name_1' => array(
  258. 'label' => 'Library',
  259. 'alter' => array(
  260. 'alter_text' => 0,
  261. 'text' => '',
  262. 'make_link' => 0,
  263. 'path' => '',
  264. 'link_class' => '',
  265. 'alt' => '',
  266. 'prefix' => '',
  267. 'suffix' => '',
  268. 'target' => '',
  269. 'help' => '',
  270. 'trim' => 0,
  271. 'max_length' => '',
  272. 'word_boundary' => 1,
  273. 'ellipsis' => 1,
  274. 'html' => 0,
  275. 'strip_tags' => 0,
  276. ),
  277. 'empty' => '',
  278. 'hide_empty' => 0,
  279. 'empty_zero' => 0,
  280. 'link_to_node' => 1,
  281. 'exclude' => 0,
  282. 'id' => 'name_1',
  283. 'table' => 'library',
  284. 'field' => 'name',
  285. 'relationship' => 'none',
  286. ),
  287. 'name_2' => array(
  288. 'label' => 'Analysis',
  289. 'alter' => array(
  290. 'alter_text' => 0,
  291. 'text' => '',
  292. 'make_link' => 0,
  293. 'path' => '',
  294. 'link_class' => '',
  295. 'alt' => '',
  296. 'prefix' => '',
  297. 'suffix' => '',
  298. 'target' => '',
  299. 'help' => '',
  300. 'trim' => 0,
  301. 'max_length' => '',
  302. 'word_boundary' => 1,
  303. 'ellipsis' => 1,
  304. 'html' => 0,
  305. 'strip_tags' => 0,
  306. ),
  307. 'empty' => '',
  308. 'hide_empty' => 0,
  309. 'empty_zero' => 0,
  310. 'link_to_node' => 1,
  311. 'exclude' => 0,
  312. 'id' => 'name_2',
  313. 'table' => 'analysis',
  314. 'field' => 'name',
  315. 'relationship' => 'none',
  316. ),
  317. ));
  318. $handler->override_option('filters', array(
  319. 'common_name' => array(
  320. 'operator' => '=',
  321. 'value' => '<select organism>',
  322. 'group' => '0',
  323. 'exposed' => TRUE,
  324. 'expose' => array(
  325. 'use_operator' => 0,
  326. 'operator' => 'common_name_op',
  327. 'identifier' => 'organism',
  328. 'label' => 'Organism',
  329. 'optional' => 1,
  330. 'remember' => 0,
  331. ),
  332. 'case' => 1,
  333. 'id' => 'common_name',
  334. 'table' => 'organism',
  335. 'field' => 'common_name',
  336. 'relationship' => 'none',
  337. ),
  338. 'name' => array(
  339. 'operator' => 'contains',
  340. 'value' => '',
  341. 'group' => '0',
  342. 'exposed' => TRUE,
  343. 'expose' => array(
  344. 'use_operator' => 0,
  345. 'operator' => 'name_op',
  346. 'identifier' => 'name',
  347. 'label' => 'Name Contains',
  348. 'optional' => 1,
  349. 'remember' => 0,
  350. ),
  351. 'case' => 0,
  352. 'id' => 'name',
  353. 'table' => 'feature',
  354. 'field' => 'name',
  355. 'relationship' => 'none',
  356. ),
  357. 'name_1' => array(
  358. 'operator' => 'contains',
  359. 'value' => '',
  360. 'group' => '0',
  361. 'exposed' => TRUE,
  362. 'expose' => array(
  363. 'use_operator' => 0,
  364. 'operator' => 'name_1_op',
  365. 'identifier' => 'library',
  366. 'label' => 'Library Name Contains',
  367. 'optional' => 1,
  368. 'remember' => 0,
  369. ),
  370. 'case' => 0,
  371. 'id' => 'name_1',
  372. 'table' => 'library',
  373. 'field' => 'name',
  374. 'relationship' => 'none',
  375. ),
  376. 'name_2' => array(
  377. 'operator' => 'contains',
  378. 'value' => '',
  379. 'group' => '0',
  380. 'exposed' => TRUE,
  381. 'expose' => array(
  382. 'use_operator' => 0,
  383. 'operator' => 'name_2_op',
  384. 'identifier' => 'analysis',
  385. 'label' => 'Analysis Name Contains',
  386. 'optional' => 1,
  387. 'remember' => 0,
  388. ),
  389. 'case' => 0,
  390. 'id' => 'name_2',
  391. 'table' => 'analysis',
  392. 'field' => 'name',
  393. 'relationship' => 'none',
  394. ),
  395. ));
  396. $handler->override_option('access', array(
  397. 'type' => 'perm',
  398. 'perm' => 'access chado_feature content',
  399. ));
  400. $handler->override_option('cache', array(
  401. 'type' => 'none',
  402. ));
  403. $handler->override_option('title', 'Sequence Features');
  404. $handler->override_option('empty', 'There are no features matching that criteria. Please select a different organism above.');
  405. $handler->override_option('empty_format', '1');
  406. $handler->override_option('items_per_page', 50);
  407. $handler->override_option('style_plugin', 'table');
  408. $handler = $view->new_display('page', 'Page', 'page_1');
  409. $handler->override_option('path', 'features');
  410. $handler->override_option('menu', array(
  411. 'type' => 'normal',
  412. 'title' => 'Sequence Features',
  413. 'description' => '',
  414. 'weight' => '0',
  415. 'name' => 'primary-links',
  416. ));
  417. $handler->override_option('tab_options', array(
  418. 'type' => 'none',
  419. 'title' => '',
  420. 'description' => '',
  421. 'weight' => 0,
  422. 'name' => 'navigation',
  423. ));
  424. $views[$view->name] = $view;
  425. return $views;
  426. }