tripal_feature.views.inc 12 KB

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