tripal_feature.views.inc 12 KB

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