tripal_stock.views.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions for views integration of
  5. * chado/tripal stock 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_stock_views Stock Views Integration
  13. * @ingroup views
  14. */
  15. /**
  16. * Implements hook_views_data(): Describe chado/tripal tables & fields to views
  17. *
  18. * @return array
  19. * A data array which follows the structure outlined in the
  20. * views2 documentation for this hook. Essentially, it's an array of table
  21. * definitions keyed by chado/tripal table name. Each table definition
  22. * includes basic details about the table, fields in that table and
  23. * relationships between that table and others (joins)
  24. *
  25. * @ingroup tripal_stock_views
  26. */
  27. function tripal_stock_views_data() {
  28. $data = array();
  29. if (module_exists('tripal_views')) {
  30. $tablename = 'stock';
  31. $priority = 9;
  32. // check to see if the table is integrated. If it is then integrate it's
  33. // corresponding 'chado_[table]' table.
  34. if (!tripal_views_is_integrated($tablename, $priority)) {
  35. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority);
  36. // Add in node relationships if chado is in the same db as drupal
  37. if (tripal_core_chado_schema_exists()) {
  38. $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array);
  39. foreach ($integrations as $integration) {
  40. tripal_views_integration_add_entry($integration);
  41. }
  42. }
  43. else {
  44. tripal_views_integration_add_entry($table_integration_array);
  45. }
  46. }
  47. $tablename = 'stockcollection';
  48. $priority = 9;
  49. if (!tripal_views_is_integrated($tablename, $priority)) {
  50. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority);
  51. tripal_views_integration_add_entry($table_integration_array);
  52. }
  53. $tables = array(
  54. 'stock_cvterm',
  55. 'stock_dbxref',
  56. 'stock_genotype',
  57. 'stock_pub',
  58. 'stock_relationship',
  59. 'stock_relationship_pub',
  60. 'stockcollection_stock',
  61. 'stockcollectionprop',
  62. 'stockprop',
  63. 'stockprop_pub'
  64. );
  65. foreach ($tables as $tablename) {
  66. $priority = 9;
  67. if (!tripal_views_is_integrated($tablename, $priority)) {
  68. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE, $priority);
  69. tripal_views_integration_add_entry($table_integration_array);
  70. }
  71. }
  72. }
  73. return $data;
  74. }
  75. /**
  76. * Implementation of hook_views_data_alter().
  77. */
  78. function tripal_stock_views_data_alter(&$data) {
  79. if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  80. // Add featuer relationship to node
  81. $data['node']['stock_chado_nid'] = array(
  82. 'group' => 'Stock',
  83. 'title' => 'Stock Node',
  84. 'help' => 'Links Chado Stock Fields/Data to the Nodes in the current View.',
  85. 'real field' => 'nid',
  86. 'relationship' => array(
  87. 'handler' => 'views_handler_relationship',
  88. 'title' => t('Node => Chado'),
  89. 'label' => t('Node => Chado'),
  90. 'real field' => 'nid',
  91. 'base' => 'chado_stock',
  92. 'base field' => 'nid'
  93. ),
  94. );
  95. }
  96. }
  97. /**
  98. *
  99. * @ingroup tripal_stock_views
  100. */
  101. function tripal_stock_views_default_views() {
  102. $views = array();
  103. if (!module_exists('tripal_views')) {
  104. return $views;
  105. }
  106. // Main default view
  107. $view = new view;
  108. $view->name = 'stock_listing';
  109. $view->description = 'This view lists all stocks by default.';
  110. $view->tag = 'chado default';
  111. $view->base_table = 'stock';
  112. $view->core = 0;
  113. $view->api_version = '2';
  114. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  115. $handler = $view->new_display('default', 'Defaults', 'default');
  116. $handler->override_option('fields', array(
  117. 'uniquename' => array(
  118. 'label' => 'Unique Name',
  119. 'alter' => array(
  120. 'alter_text' => 0,
  121. 'text' => '',
  122. 'make_link' => 0,
  123. 'path' => '',
  124. 'link_class' => '',
  125. 'alt' => '',
  126. 'prefix' => '',
  127. 'suffix' => '',
  128. 'target' => '',
  129. 'help' => '',
  130. 'trim' => 0,
  131. 'max_length' => '',
  132. 'word_boundary' => 1,
  133. 'ellipsis' => 1,
  134. 'html' => 0,
  135. 'strip_tags' => 0,
  136. ),
  137. 'empty' => '',
  138. 'hide_empty' => 0,
  139. 'empty_zero' => 0,
  140. 'link_to_node' => 1,
  141. 'exclude' => 0,
  142. 'id' => 'uniquename',
  143. 'table' => 'stock',
  144. 'field' => 'uniquename',
  145. 'relationship' => 'none',
  146. ),
  147. 'name_2' => array(
  148. 'label' => 'Name',
  149. 'alter' => array(
  150. 'alter_text' => 0,
  151. 'text' => '',
  152. 'make_link' => 0,
  153. 'path' => '',
  154. 'link_class' => '',
  155. 'alt' => '',
  156. 'prefix' => '',
  157. 'suffix' => '',
  158. 'target' => '',
  159. 'help' => '',
  160. 'trim' => 0,
  161. 'max_length' => '',
  162. 'word_boundary' => 1,
  163. 'ellipsis' => 1,
  164. 'html' => 0,
  165. 'strip_tags' => 0,
  166. ),
  167. 'empty' => '',
  168. 'hide_empty' => 0,
  169. 'empty_zero' => 0,
  170. 'link_to_node' => 1,
  171. 'exclude' => 0,
  172. 'id' => 'name_2',
  173. 'table' => 'stock',
  174. 'field' => 'name',
  175. 'relationship' => 'none',
  176. ),
  177. 'name' => array(
  178. 'label' => 'Type',
  179. 'alter' => array(
  180. 'alter_text' => 0,
  181. 'text' => '',
  182. 'make_link' => 0,
  183. 'path' => '',
  184. 'link_class' => '',
  185. 'alt' => '',
  186. 'prefix' => '',
  187. 'suffix' => '',
  188. 'target' => '',
  189. 'help' => '',
  190. 'trim' => 0,
  191. 'max_length' => '',
  192. 'word_boundary' => 1,
  193. 'ellipsis' => 1,
  194. 'html' => 0,
  195. 'strip_tags' => 0,
  196. ),
  197. 'empty' => '',
  198. 'hide_empty' => 0,
  199. 'empty_zero' => 0,
  200. 'exclude' => 0,
  201. 'id' => 'name',
  202. 'table' => 'cvterm',
  203. 'field' => 'name',
  204. 'relationship' => 'none',
  205. ),
  206. 'common_name' => array(
  207. 'label' => 'Organism',
  208. 'alter' => array(
  209. 'alter_text' => 0,
  210. 'text' => '',
  211. 'make_link' => 0,
  212. 'path' => '',
  213. 'link_class' => '',
  214. 'alt' => '',
  215. 'prefix' => '',
  216. 'suffix' => '',
  217. 'target' => '',
  218. 'help' => '',
  219. 'trim' => 0,
  220. 'max_length' => '',
  221. 'word_boundary' => 1,
  222. 'ellipsis' => 1,
  223. 'html' => 0,
  224. 'strip_tags' => 0,
  225. ),
  226. 'empty' => '',
  227. 'hide_empty' => 0,
  228. 'empty_zero' => 0,
  229. 'link_to_node' => 1,
  230. 'exclude' => 0,
  231. 'id' => 'common_name',
  232. 'table' => 'organism',
  233. 'field' => 'common_name',
  234. 'relationship' => 'none',
  235. ),
  236. ));
  237. $handler->override_option('sorts', array(
  238. 'common_name' => array(
  239. 'order' => 'ASC',
  240. 'id' => 'common_name',
  241. 'table' => 'organism',
  242. 'field' => 'common_name',
  243. 'relationship' => 'none',
  244. ),
  245. 'uniquename' => array(
  246. 'order' => 'ASC',
  247. 'id' => 'uniquename',
  248. 'table' => 'stock',
  249. 'field' => 'uniquename',
  250. 'relationship' => 'none',
  251. ),
  252. ));
  253. $handler->override_option('filters', array(
  254. 'common_name' => array(
  255. 'operator' => '=',
  256. 'value' => array(),
  257. 'group' => '0',
  258. 'exposed' => TRUE,
  259. 'expose' => array(
  260. 'use_operator' => 0,
  261. 'operator' => 'common_name_op',
  262. 'identifier' => 'organism_common_name',
  263. 'label' => 'Organism',
  264. 'remember' => 0,
  265. ),
  266. 'case' => 1,
  267. 'id' => 'common_name',
  268. 'table' => 'organism',
  269. 'field' => 'common_name',
  270. 'relationship' => 'none',
  271. 'values_form_type' => 'select',
  272. 'multiple' => 1,
  273. 'optional' => 0,
  274. 'agg' => array(
  275. 'records_with' => 1,
  276. 'aggregates_with' => 1,
  277. ),
  278. ),
  279. 'search_results' => array(
  280. 'operator' => '=',
  281. 'value' => '',
  282. 'group' => '0',
  283. 'exposed' => FALSE,
  284. 'expose' => array(
  285. 'operator' => FALSE,
  286. 'label' => '',
  287. ),
  288. 'id' => 'search_results',
  289. 'table' => 'views',
  290. 'field' => 'search_results',
  291. 'relationship' => 'none',
  292. 'apply_button' => 'Show',
  293. 'no_results_text' => 'Click "Show" to see a list of all stocks matching the entered criteria. If you leave a any of the criteria blank then the stocks will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all stocks will be listed.',
  294. ),
  295. 'type_id' => array(
  296. 'operator' => '=',
  297. 'value' => '',
  298. 'group' => '0',
  299. 'exposed' => TRUE,
  300. 'expose' => array(
  301. 'use_operator' => 0,
  302. 'operator' => 'type_id_op',
  303. 'identifier' => 'type_id',
  304. 'label' => 'Type',
  305. 'remember' => 0,
  306. ),
  307. 'case' => 1,
  308. 'id' => 'type_id',
  309. 'table' => 'stock',
  310. 'field' => 'type_id',
  311. 'relationship' => 'none',
  312. 'values_form_type' => 'select',
  313. 'multiple' => 1,
  314. 'optional' => 0,
  315. 'show_all' => 0,
  316. 'agg' => array(
  317. 'records_with' => 1,
  318. 'aggregates_with' => 1,
  319. ),
  320. ),
  321. 'name' => array(
  322. 'operator' => '~',
  323. 'value' => '',
  324. 'group' => '0',
  325. 'exposed' => TRUE,
  326. 'expose' => array(
  327. 'use_operator' => 0,
  328. 'operator' => 'name_op',
  329. 'identifier' => 'name',
  330. 'label' => 'Name Contains',
  331. 'remember' => 0,
  332. ),
  333. 'case' => 0,
  334. 'id' => 'name',
  335. 'table' => 'stock',
  336. 'field' => 'name',
  337. 'relationship' => 'none',
  338. 'agg' => array(
  339. 'records_with' => 1,
  340. 'aggregates_with' => 1,
  341. ),
  342. ),
  343. ));
  344. $handler->override_option('access', array(
  345. 'type' => 'perm',
  346. 'perm' => 'access chado_stock content',
  347. ));
  348. $handler->override_option('cache', array(
  349. 'type' => 'none',
  350. ));
  351. $handler->override_option('title', 'Stocks');
  352. $handler->override_option('header', 'Click "Show" to see a list of all stocks matching the entered criteria. If you leave a any of the criteria blank then the stocks will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all stocks will be listed.');
  353. $handler->override_option('header_format', '2');
  354. $handler->override_option('header_empty', 0);
  355. $handler->override_option('empty', 'No stocks match the supplied criteria.');
  356. $handler->override_option('empty_format', '1');
  357. $handler->override_option('items_per_page', 50);
  358. $handler->override_option('use_pager', '1');
  359. $handler->override_option('style_plugin', 'table');
  360. $handler->override_option('style_options', array(
  361. 'grouping' => '',
  362. 'override' => 1,
  363. 'sticky' => 0,
  364. 'order' => 'asc',
  365. 'columns' => array(
  366. 'uniquename' => 'uniquename',
  367. 'name_2' => 'name_2',
  368. 'name' => 'name',
  369. 'common_name' => 'common_name',
  370. 'all_dbxref' => 'all_dbxref',
  371. 'all_properties' => 'all_properties',
  372. 'all_relationships' => 'all_relationships',
  373. ),
  374. 'info' => array(
  375. 'uniquename' => array(
  376. 'sortable' => 1,
  377. 'separator' => '',
  378. ),
  379. 'name_2' => array(
  380. 'sortable' => 1,
  381. 'separator' => '',
  382. ),
  383. 'name' => array(
  384. 'sortable' => 1,
  385. 'separator' => '',
  386. ),
  387. 'common_name' => array(
  388. 'sortable' => 1,
  389. 'separator' => '',
  390. ),
  391. 'all_dbxref' => array(
  392. 'separator' => '',
  393. ),
  394. 'all_properties' => array(
  395. 'separator' => '',
  396. ),
  397. 'all_relationships' => array(
  398. 'separator' => '',
  399. ),
  400. ),
  401. 'default' => '-1',
  402. ));
  403. $default_handler = $handler;
  404. $handler = $view->new_display('page', 'Page', 'page_1');
  405. $handler->override_option('path', 'chado/stocks');
  406. $handler->override_option('menu', array(
  407. 'type' => 'normal',
  408. 'title' => 'Stocks',
  409. 'description' => 'A stock is the physical entities, either living or preserved, held by collections and can be globally identified by the combination of organism, uniquename and stock type.',
  410. 'weight' => '10',
  411. 'name' => 'navigation',
  412. ));
  413. $handler->override_option('tab_options', array(
  414. 'type' => 'none',
  415. 'title' => '',
  416. 'description' => '',
  417. 'weight' => 0,
  418. 'name' => 'navigation',
  419. ));
  420. // Add code specific to a local chado installation
  421. // NOTE: Edit $handler above to $default_handler for the default display
  422. if (tripal_core_chado_schema_exists()) {
  423. // Add nid field
  424. $fields = $view->get_items('field', 'default');
  425. $new_fields = array(
  426. 'nid' => array(
  427. 'label' => 'Nid',
  428. 'alter' => array(
  429. 'alter_text' => 0,
  430. 'text' => '',
  431. 'make_link' => 0,
  432. 'path' => '',
  433. 'absolute' => 0,
  434. 'link_class' => '',
  435. 'alt' => '',
  436. 'rel' => '',
  437. 'prefix' => '',
  438. 'suffix' => '',
  439. 'target' => '',
  440. 'help' => '',
  441. 'trim' => 0,
  442. 'max_length' => '',
  443. 'word_boundary' => 1,
  444. 'ellipsis' => 1,
  445. 'html' => 0,
  446. 'strip_tags' => 0,
  447. ),
  448. 'empty' => '',
  449. 'hide_empty' => 0,
  450. 'empty_zero' => 0,
  451. 'hide_alter_empty' => 1,
  452. 'link_to_node' => 0,
  453. 'exclude' => 1,
  454. 'id' => 'nid',
  455. 'table' => 'node',
  456. 'field' => 'nid',
  457. 'relationship' => 'none',
  458. )
  459. );
  460. $fields = $new_fields + $fields;
  461. // Change analysis.name to have a link to the node
  462. $fields['name_2']['alter']['link_to_node'] = 1;
  463. $default_handler->override_option('fields', $fields);
  464. // Adds stock => Node relationship
  465. $default_handler->override_option('relationships', array(
  466. 'nid' => array(
  467. 'label' => 'Stock to Node',
  468. 'required' => 0,
  469. 'id' => 'nid',
  470. 'table' => 'chado_stock',
  471. 'field' => 'nid',
  472. 'relationship' => 'none',
  473. ),
  474. ));
  475. // Only show records with published nodes
  476. /**
  477. $filters = $view->get_items('filter', 'default');
  478. $filters['status'] = array(
  479. 'operator' => '=',
  480. 'value' => '1',
  481. 'group' => '0',
  482. 'exposed' => FALSE,
  483. 'expose' => array(
  484. 'operator' => FALSE,
  485. 'label' => '',
  486. ),
  487. 'id' => 'status',
  488. 'table' => 'node',
  489. 'field' => 'status',
  490. 'relationship' => 'none',
  491. );
  492. $default_handler->override_option('filters', $filters);
  493. */
  494. }
  495. $views[$view->name] = $view;
  496. return $views;
  497. }