tripal_feature.views.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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, 9)) {
  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, 9)) {
  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. $view = new view;
  125. $view->name = 'feature_listing';
  126. $view->description = 'A listing of chado sequence features.';
  127. $view->tag = 'chado default';
  128. $view->base_table = 'feature';
  129. $view->core = 0;
  130. $view->api_version = '2';
  131. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  132. $handler = $view->new_display('default', 'features_all', 'default');
  133. $handler->override_option('fields', array(
  134. 'uniquename' => array(
  135. 'label' => 'Unique Name',
  136. 'alter' => array(
  137. 'alter_text' => 0,
  138. 'text' => '',
  139. 'make_link' => 0,
  140. 'path' => 'node/[nid]',
  141. 'link_class' => '',
  142. 'alt' => '',
  143. 'prefix' => '',
  144. 'suffix' => '',
  145. 'target' => '',
  146. 'help' => '',
  147. 'trim' => 0,
  148. 'max_length' => '',
  149. 'word_boundary' => 1,
  150. 'ellipsis' => 1,
  151. 'html' => 0,
  152. 'strip_tags' => 0,
  153. ),
  154. 'empty' => '',
  155. 'hide_empty' => 0,
  156. 'empty_zero' => 0,
  157. 'link_to_node' => 0,
  158. 'exclude' => 0,
  159. 'id' => 'uniquename',
  160. 'table' => 'feature',
  161. 'field' => 'uniquename',
  162. 'relationship' => 'none',
  163. 'override' => array(
  164. 'button' => 'Override',
  165. ),
  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. 'override' => array(
  197. 'button' => 'Override',
  198. ),
  199. ),
  200. 'name_1' => array(
  201. 'label' => 'Type',
  202. 'alter' => array(
  203. 'alter_text' => 0,
  204. 'text' => '',
  205. 'make_link' => 0,
  206. 'path' => '',
  207. 'link_class' => '',
  208. 'alt' => '',
  209. 'prefix' => '',
  210. 'suffix' => '',
  211. 'target' => '',
  212. 'help' => '',
  213. 'trim' => 0,
  214. 'max_length' => '',
  215. 'word_boundary' => 1,
  216. 'ellipsis' => 1,
  217. 'html' => 0,
  218. 'strip_tags' => 0,
  219. ),
  220. 'empty' => '',
  221. 'hide_empty' => 0,
  222. 'empty_zero' => 0,
  223. 'exclude' => 0,
  224. 'id' => 'name_1',
  225. 'table' => 'cvterm',
  226. 'field' => 'name',
  227. 'relationship' => 'none',
  228. ),
  229. 'common_name' => array(
  230. 'label' => 'Common Name',
  231. 'alter' => array(
  232. 'alter_text' => 0,
  233. 'text' => '',
  234. 'make_link' => 0,
  235. 'path' => '',
  236. 'link_class' => '',
  237. 'alt' => '',
  238. 'prefix' => '',
  239. 'suffix' => '',
  240. 'target' => '',
  241. 'help' => '',
  242. 'trim' => 0,
  243. 'max_length' => '',
  244. 'word_boundary' => 1,
  245. 'ellipsis' => 1,
  246. 'html' => 0,
  247. 'strip_tags' => 0,
  248. ),
  249. 'empty' => '',
  250. 'hide_empty' => 0,
  251. 'empty_zero' => 0,
  252. 'link_to_node' => 1,
  253. 'exclude' => 0,
  254. 'id' => 'common_name',
  255. 'table' => 'organism',
  256. 'field' => 'common_name',
  257. 'relationship' => 'none',
  258. 'override' => array(
  259. 'button' => 'Override',
  260. ),
  261. ),
  262. 'seqlen' => array(
  263. 'label' => 'Sequence Length',
  264. 'alter' => array(
  265. 'alter_text' => 0,
  266. 'text' => '',
  267. 'make_link' => 0,
  268. 'path' => '',
  269. 'link_class' => '',
  270. 'alt' => '',
  271. 'prefix' => '',
  272. 'suffix' => '',
  273. 'target' => '',
  274. 'help' => '',
  275. 'trim' => 0,
  276. 'max_length' => '',
  277. 'word_boundary' => 1,
  278. 'ellipsis' => 1,
  279. 'html' => 0,
  280. 'strip_tags' => 0,
  281. ),
  282. 'empty' => '',
  283. 'hide_empty' => 0,
  284. 'empty_zero' => 0,
  285. 'set_precision' => FALSE,
  286. 'precision' => 0,
  287. 'decimal' => '.',
  288. 'separator' => ',',
  289. 'prefix' => '',
  290. 'suffix' => '',
  291. 'exclude' => 0,
  292. 'id' => 'seqlen',
  293. 'table' => 'feature',
  294. 'field' => 'seqlen',
  295. 'relationship' => 'none',
  296. ),
  297. 'is_obsolete' => array(
  298. 'label' => 'Is Obsolete',
  299. 'alter' => array(
  300. 'alter_text' => 0,
  301. 'text' => '',
  302. 'make_link' => 0,
  303. 'path' => '',
  304. 'absolute' => 0,
  305. 'link_class' => '',
  306. 'alt' => '',
  307. 'rel' => '',
  308. 'prefix' => '',
  309. 'suffix' => '',
  310. 'target' => '',
  311. 'help' => '',
  312. 'trim' => 0,
  313. 'max_length' => '',
  314. 'word_boundary' => 1,
  315. 'ellipsis' => 1,
  316. 'html' => 0,
  317. 'strip_tags' => 0,
  318. ),
  319. 'empty' => '',
  320. 'hide_empty' => 0,
  321. 'empty_zero' => 0,
  322. 'hide_alter_empty' => 1,
  323. 'type' => 'separator',
  324. 'not' => 0,
  325. 'separator' => ', ',
  326. 'exclude' => 0,
  327. 'id' => 'is_obsolete',
  328. 'table' => 'feature',
  329. 'field' => 'is_obsolete',
  330. 'relationship' => 'none',
  331. ),
  332. 'timeaccessioned' => array(
  333. 'label' => 'Accessioned On',
  334. 'alter' => array(
  335. 'alter_text' => 0,
  336. 'text' => '',
  337. 'make_link' => 0,
  338. 'path' => '',
  339. 'absolute' => 0,
  340. 'link_class' => '',
  341. 'alt' => '',
  342. 'rel' => '',
  343. 'prefix' => '',
  344. 'suffix' => '',
  345. 'target' => '',
  346. 'help' => '',
  347. 'trim' => 0,
  348. 'max_length' => '',
  349. 'word_boundary' => 1,
  350. 'ellipsis' => 1,
  351. 'html' => 0,
  352. 'strip_tags' => 0,
  353. ),
  354. 'empty' => '',
  355. 'hide_empty' => 0,
  356. 'empty_zero' => 0,
  357. 'hide_alter_empty' => 1,
  358. 'date_format' => 'large',
  359. 'custom_date_format' => '',
  360. 'type' => 'separator',
  361. 'separator' => ', ',
  362. 'exclude' => 0,
  363. 'id' => 'timeaccessioned',
  364. 'table' => 'feature',
  365. 'field' => 'timeaccessioned',
  366. 'relationship' => 'none',
  367. ),
  368. ));
  369. $handler->override_option('sorts', array(
  370. 'common_name' => array(
  371. 'order' => 'ASC',
  372. 'id' => 'common_name',
  373. 'table' => 'organism',
  374. 'field' => 'common_name',
  375. 'relationship' => 'none',
  376. ),
  377. 'name' => array(
  378. 'order' => 'ASC',
  379. 'id' => 'name',
  380. 'table' => 'cvterm',
  381. 'field' => 'name',
  382. 'relationship' => 'none',
  383. ),
  384. 'name_1' => array(
  385. 'order' => 'ASC',
  386. 'id' => 'name_1',
  387. 'table' => 'feature',
  388. 'field' => 'name',
  389. 'relationship' => 'none',
  390. ),
  391. ));
  392. $handler->override_option('filters', array(
  393. 'common_name' => array(
  394. 'operator' => '=',
  395. 'value' => array(),
  396. 'group' => '0',
  397. 'exposed' => TRUE,
  398. 'expose' => array(
  399. 'use_operator' => 0,
  400. 'operator' => 'common_name_op',
  401. 'identifier' => 'organism',
  402. 'label' => 'Organism Common Name',
  403. 'remember' => 0,
  404. ),
  405. 'case' => 1,
  406. 'id' => 'common_name',
  407. 'table' => 'organism',
  408. 'field' => 'common_name',
  409. 'relationship' => 'none',
  410. 'values_form_type' => 'select',
  411. 'multiple' => 1,
  412. 'optional' => 0,
  413. 'override' => array(
  414. 'button' => 'Override',
  415. ),
  416. 'agg' => array(
  417. 'records_with' => 1,
  418. 'aggregates_with' => 1,
  419. ),
  420. ),
  421. 'type_id' => array(
  422. 'operator' => '=',
  423. 'value' => array(),
  424. 'group' => '0',
  425. 'exposed' => TRUE,
  426. 'expose' => array(
  427. 'use_operator' => 0,
  428. 'operator' => 'type_id_op',
  429. 'identifier' => 'type_id',
  430. 'label' => 'Type',
  431. 'remember' => 0,
  432. ),
  433. 'case' => 1,
  434. 'id' => 'type_id',
  435. 'table' => 'feature',
  436. 'field' => 'type_id',
  437. 'relationship' => 'none',
  438. 'values_form_type' => 'select',
  439. 'multiple' => 1,
  440. 'optional' => 0,
  441. 'show_all' => 0,
  442. 'agg' => array(
  443. 'records_with' => 1,
  444. 'aggregates_with' => 1,
  445. ),
  446. ),
  447. 'name_1' => array(
  448. 'operator' => 'allwords',
  449. 'value' => '',
  450. 'group' => '0',
  451. 'exposed' => TRUE,
  452. 'expose' => array(
  453. 'use_operator' => 0,
  454. 'operator' => 'name_1_op',
  455. 'identifier' => 'name',
  456. 'label' => 'Name Contains',
  457. 'bef_filter_description' => '',
  458. 'remember' => 0,
  459. ),
  460. 'case' => 0,
  461. 'id' => 'name_1',
  462. 'table' => 'feature',
  463. 'field' => 'name',
  464. 'relationship' => 'none',
  465. 'agg' => array(
  466. 'records_with' => 1,
  467. 'aggregates_with' => 1,
  468. ),
  469. ),
  470. 'search_results' => array(
  471. 'operator' => '=',
  472. 'value' => '',
  473. 'group' => '0',
  474. 'exposed' => FALSE,
  475. 'expose' => array(
  476. 'operator' => FALSE,
  477. 'label' => '',
  478. ),
  479. 'id' => 'search_results',
  480. 'table' => 'views',
  481. 'field' => 'search_results',
  482. 'relationship' => 'none',
  483. 'apply_button' => 'Show',
  484. 'no_results_text' => 'Click "Show" to see a list of all features matching the entered criteria. If you leave a any of the criteria blank then the features will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all features will be listed.',
  485. ),
  486. ));
  487. $handler->override_option('access', array(
  488. 'type' => 'perm',
  489. 'perm' => 'access chado_feature content',
  490. ));
  491. $handler->override_option('cache', array(
  492. 'type' => 'none',
  493. ));
  494. $handler->override_option('title', 'Sequence Features');
  495. $handler->override_option('header', 'Click "Show" to see a list of all features matching the entered criteria. If you leave a any of the criteria blank then the features will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all features will be listed.');
  496. $handler->override_option('header_format', '2');
  497. $handler->override_option('header_empty', 0);
  498. $handler->override_option('empty', 'There are currently no features sync\'d with drupal.');
  499. $handler->override_option('empty_format', '2');
  500. $handler->override_option('items_per_page', 50);
  501. $handler->override_option('use_pager', '1');
  502. $handler->override_option('style_plugin', 'table');
  503. $handler->override_option('style_options', array(
  504. 'grouping' => '',
  505. 'override' => 1,
  506. 'sticky' => 0,
  507. 'order' => 'asc',
  508. 'columns' => array(
  509. 'accession' => 'accession',
  510. 'accession_link' => 'accession_link',
  511. 'name' => 'name',
  512. 'uniquename' => 'uniquename',
  513. 'name_1' => 'name_1',
  514. 'common_name' => 'common_name',
  515. 'seqlen' => 'seqlen',
  516. 'is_obsolete' => 'is_obsolete',
  517. 'is_analysis' => 'is_analysis',
  518. 'nid' => 'nid',
  519. ),
  520. 'info' => array(
  521. 'accession' => array(
  522. 'sortable' => 1,
  523. 'separator' => '',
  524. ),
  525. 'accession_link' => array(
  526. 'sortable' => 1,
  527. 'separator' => '',
  528. ),
  529. 'name' => array(
  530. 'sortable' => 1,
  531. 'separator' => '',
  532. ),
  533. 'uniquename' => array(
  534. 'sortable' => 1,
  535. 'separator' => '',
  536. ),
  537. 'name_1' => array(
  538. 'sortable' => 1,
  539. 'separator' => '',
  540. ),
  541. 'common_name' => array(
  542. 'sortable' => 1,
  543. 'separator' => '',
  544. ),
  545. 'seqlen' => array(
  546. 'sortable' => 1,
  547. 'separator' => '',
  548. ),
  549. 'is_obsolete' => array(
  550. 'sortable' => 1,
  551. 'separator' => '',
  552. ),
  553. 'is_analysis' => array(
  554. 'sortable' => 1,
  555. 'separator' => '',
  556. ),
  557. 'nid' => array(
  558. 'separator' => '',
  559. ),
  560. ),
  561. 'default' => '-1',
  562. ));
  563. $handler = $view->new_display('page', 'Page', 'page_1');
  564. $handler->override_option('path', 'features');
  565. $handler->override_option('menu', array(
  566. 'type' => 'normal',
  567. 'title' => 'Features View',
  568. 'description' => 'Provides a table of sequence features',
  569. 'weight' => '0',
  570. 'name' => 'primary-links',
  571. ));
  572. $handler->override_option('tab_options', array(
  573. 'type' => 'none',
  574. 'title' => '',
  575. 'description' => '',
  576. 'weight' => 0,
  577. 'name' => 'navigation',
  578. ));
  579. $views[$view->name] = $view;
  580. return $views;
  581. }