tripal_views.install 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?php
  2. /**
  3. * @file
  4. * Functions related to installing/uninstalling this module
  5. */
  6. /**
  7. * Implementation of hook_requirements().
  8. *
  9. * @ingroup tripal_views
  10. */
  11. function tripal_views_requirements($phase) {
  12. $requirements = array();
  13. if ($phase == 'install') {
  14. // make sure chado is installed
  15. if (!$GLOBALS["chado_is_installed"]) {
  16. $requirements ['tripal_views'] = array(
  17. 'title' => "tripal_views",
  18. 'value' => "ERROR: Chado must be installed before this module can be enabled",
  19. 'severity' => REQUIREMENT_ERROR,
  20. );
  21. }
  22. }
  23. return $requirements;
  24. }
  25. /**
  26. * Implementation of hook_install().
  27. *
  28. * @ingroup tripal_views
  29. */
  30. function tripal_views_install() {
  31. // we want views to pick up our changes
  32. views_invalidate_cache();
  33. }
  34. /**
  35. * Implementation of hook_schema().
  36. *
  37. * @ingroup tripal_views
  38. */
  39. function tripal_views_schema() {
  40. $schema = tripal_views_get_schemas();
  41. return $schema;
  42. }
  43. /**
  44. * This function simply defines all tables needed for the module to work
  45. * correctly. By putting the table definitions in a separate function we
  46. * can easily provide the entire list for hook_install or individual
  47. * tables for an update.
  48. *
  49. * @ingroup tripal_views
  50. */
  51. function tripal_views_get_schemas() {
  52. $schema = array();
  53. $temp = tripal_views_views_schema();
  54. foreach ($temp as $table => $arr) {
  55. $schema[$table] = $arr;
  56. }
  57. return $schema;
  58. }
  59. /**
  60. * Tripal Views Update for 6.x-0.4
  61. * - Add priority field to tripal_views
  62. * - Add handler field to tripal_views_join
  63. * - Add tripal_views_field table to keep track of fields for views integration
  64. *
  65. * @ingroup tripal_views
  66. */
  67. function tripal_views_update_6040() {
  68. // Add Priority to tripal_views
  69. db_add_field(
  70. 'tripal_views',
  71. 'priority',
  72. array('type' => 'int')
  73. );
  74. db_add_unique_key('tripal_views', 'priority', array('table_name', 'priority'));
  75. db_add_index('tripal_views', 'priority', array('table_name', 'priority'));
  76. // Add handler to tripal_views_join
  77. db_add_field(
  78. 'tripal_views_join',
  79. 'handler',
  80. array(
  81. 'type' => 'varchar',
  82. 'length' => '255',
  83. 'not null' => TRUE,
  84. 'default' => ''
  85. )
  86. );
  87. // Add tripal_views_field to keep track of fields for views integration
  88. $schema = tripal_views_views_schema();
  89. db_create_table('tripal_views_field', $schema['tripal_views_field']);
  90. // Add base_table TRUE/FALSE to tripal_views
  91. db_add_field(
  92. 'tripal_views',
  93. 'base_table',
  94. array(
  95. 'type' => 'int',
  96. 'not null ' => TRUE,
  97. 'default' => 1
  98. )
  99. );
  100. // Add arguments to joins
  101. db_add_field(
  102. 'tripal_views_join',
  103. 'arguments',
  104. array(
  105. 'description' => 'arguments that may get passed to the handler',
  106. 'type' => 'text',
  107. 'size' => 'normal'
  108. )
  109. );
  110. return t('Updated Tripal Views to handle multiple Integrations and keep track of fields.');
  111. }
  112. /**
  113. * Tripal Views Update for 7.x-2.0
  114. * - Add relationship_only field to tripal_views_join
  115. * - Add relationship_handler field to tripal_views_join
  116. *
  117. */
  118. function tripal_views_update_7200() {
  119. // Add relationship_handler to tripal_views_join
  120. db_add_field(
  121. 'tripal_views_join',
  122. 'relationship_handler',
  123. array(
  124. 'type' => 'varchar',
  125. 'length' => '255',
  126. 'not null' => TRUE,
  127. 'default' => 'views_handler_relationship'
  128. )
  129. );
  130. // Add relationship_only to tripal_views_join
  131. db_add_field(
  132. 'tripal_views_join',
  133. 'relationship_only',
  134. array(
  135. 'type' => 'int',
  136. 'not null ' => TRUE,
  137. 'default' => 0
  138. )
  139. );
  140. return t('Updated Tripal Views to better handle relationships. Relationships are now handled through joins rather than handlers (backwards compatible).');
  141. }
  142. /**
  143. * Describe the Tripal Views Schema
  144. *
  145. * Tables include:
  146. * - tripal_views: main table for views integration setups
  147. * - tripal_views_field: keeps track of all fields related to a given views integration setup
  148. * - tripal_views_join: keeps track of joins between the current views integration setup
  149. * and other tables.
  150. * - tripal_views_handlers: keeps track of which handlers to use for a given field
  151. *
  152. * @ingroup tripal_views
  153. */
  154. function tripal_views_views_schema() {
  155. $schema = array();
  156. $schema['tripal_views'] = array(
  157. 'description' => 'contains the setups, their materialized view id and base table name that was used.',
  158. 'fields' => array(
  159. 'setup_id' => array(
  160. 'description' => 'the id of the setup',
  161. 'type' => 'serial',
  162. 'unsigned' => TRUE,
  163. 'not null' => TRUE,
  164. ),
  165. 'mview_id' => array(
  166. 'description' => 'the materialized view used for this setup',
  167. 'type' => 'int',
  168. 'unsigned' => TRUE,
  169. ),
  170. 'base_table' => array(
  171. 'description' => 'either TRUE (1) or FALSE (0) depending on whether the current table should be a bast table of a View',
  172. 'type' => 'int',
  173. 'not null ' => TRUE,
  174. 'default' => 1
  175. ),
  176. 'table_name' => array(
  177. 'description' => 'the table name being integrated.',
  178. 'type' => 'varchar',
  179. 'length' => 255,
  180. 'not null' => TRUE,
  181. 'default' => '',
  182. ),
  183. 'priority' => array(
  184. 'description' => 'when there are 2+ entries for the same table, the entry with the lightest (drupal-style) priority is used.',
  185. 'type' => 'int',
  186. ),
  187. 'name' => array(
  188. 'description' => 'Human readable name of this setup',
  189. 'type' => 'varchar',
  190. 'length' => 255,
  191. 'not null' => TRUE,
  192. 'default' => '',
  193. ),
  194. 'comment' => array(
  195. 'description' => 'add notes about this views setup',
  196. 'type' => 'text',
  197. 'size' => 'normal',
  198. 'not null' => FALSE,
  199. 'default' => '',
  200. ),
  201. ),
  202. 'unique_keys' => array(
  203. 'setup_id' => array('setup_id'),
  204. 'priority' => array('table_name', 'priority'),
  205. ),
  206. 'indexes' => array(
  207. 'priority' => array('table_name', 'priority'),
  208. ),
  209. 'primary key' => array('setup_id'),
  210. );
  211. $schema['tripal_views_field'] = array(
  212. 'description' => 'keep track of fields available for a given table',
  213. 'fields' => array(
  214. 'setup_id' => array(
  215. 'description' => 'the id of the setup',
  216. 'type' => 'int',
  217. 'unsigned' => TRUE,
  218. 'not null' => TRUE,
  219. ),
  220. 'column_name' => array(
  221. 'description' => 'the name of the field in the database',
  222. 'type' => 'varchar',
  223. 'length' => '255',
  224. 'not null' => TRUE,
  225. ),
  226. 'name' => array(
  227. 'description' => 'the human-readable name of the field',
  228. 'type' => 'varchar',
  229. 'length' => '255',
  230. 'not null' => TRUE,
  231. ),
  232. 'description' => array(
  233. 'description' => 'A short description of the field -seen under the field in the views UI',
  234. 'type' => 'varchar',
  235. 'length' => '255',
  236. 'not null' => TRUE,
  237. ),
  238. 'type' => array(
  239. 'description' => 'the database type of this field (ie: int, varchar)',
  240. 'type' => 'varchar',
  241. 'length' => '50',
  242. 'not null' => TRUE,
  243. ),
  244. ),
  245. 'primary key' => array('setup_id', 'column_name')
  246. );
  247. $schema['tripal_views_join'] = array(
  248. 'description' => 'coordinate the joining of tables',
  249. 'fields' => array(
  250. 'view_join_id' => array(
  251. 'description' => 'the id of the join',
  252. 'type' => 'serial',
  253. 'unsigned' => TRUE,
  254. 'not null' => TRUE,
  255. ),
  256. 'setup_id' => array(
  257. 'description' => 'setup id from tripal_views table',
  258. 'type' => 'int',
  259. 'unsigned' => TRUE,
  260. 'not null' => TRUE,
  261. ),
  262. 'base_table' => array(
  263. 'description' => 'the name of the base table',
  264. 'type' => 'varchar',
  265. 'length' => '255',
  266. 'not null' => TRUE,
  267. 'default' => '',
  268. ),
  269. 'base_field' => array(
  270. 'description' => 'the name of the base table column that will be joined',
  271. 'type' => 'varchar',
  272. 'length' => '255',
  273. 'not null' => TRUE,
  274. 'default' => '',
  275. ),
  276. 'left_table' => array(
  277. 'description' => 'the table on which to perform a left join',
  278. 'type' => 'varchar',
  279. 'length' => '255',
  280. 'not null' => TRUE,
  281. 'default' => '',
  282. ),
  283. 'left_field' => array(
  284. 'description' => 'the column on which to perform a left join',
  285. 'type' => 'varchar',
  286. 'length' => '255',
  287. 'not null' => TRUE,
  288. 'default' => '',
  289. ),
  290. 'handler' => array(
  291. 'description' => 'the name of the handler',
  292. 'type' => 'varchar',
  293. 'length' => '255',
  294. 'not null' => TRUE,
  295. 'default' => '',
  296. ),
  297. 'relationship_handler' => array(
  298. 'type' => 'varchar',
  299. 'length' => '255',
  300. 'not null' => TRUE,
  301. 'default' => 'views_handler_relationship'
  302. ),
  303. 'relationship_only' => array(
  304. 'type' => 'int',
  305. 'not null ' => TRUE,
  306. 'default' => 0
  307. ),
  308. 'arguments' => array(
  309. 'description' => 'arguments that may get passed to the handler',
  310. 'type' => 'text',
  311. 'size' => 'normal',
  312. ),
  313. ),
  314. 'unique_keys' => array(
  315. 'setup_id' => array('view_join_id'),
  316. ),
  317. 'primary key' => array('view_join_id'),
  318. );
  319. $schema['tripal_views_handlers'] = array(
  320. 'description' => 'in formation for views: column and views handler name',
  321. 'fields' => array(
  322. 'handler_id' => array(
  323. 'description' => 'the id of the handler',
  324. 'type' => 'serial',
  325. 'unsigned' => TRUE,
  326. 'not null' => TRUE,
  327. ),
  328. 'setup_id' => array(
  329. 'description' => 'setup id from the tripal_views table',
  330. 'type' => 'int',
  331. 'unsigned' => TRUE,
  332. 'not null' => TRUE,
  333. ),
  334. 'column_name' => array(
  335. 'description' => '',
  336. 'type' => 'varchar',
  337. 'length' => '255',
  338. 'not null' => TRUE,
  339. 'default' => '',
  340. ),
  341. 'handler_type' => array(
  342. 'description' => 'identifies the type of hander (e.g. field, filter, sort, argument, relationship, etc.)',
  343. 'type' => 'varchar',
  344. 'length' => '50',
  345. 'not null' => TRUE,
  346. 'default' => '',
  347. ),
  348. 'handler_name' => array(
  349. 'description' => 'the name of the handler',
  350. 'type' => 'varchar',
  351. 'length' => '255',
  352. 'not null' => TRUE,
  353. 'default' => '',
  354. ),
  355. 'arguments' => array(
  356. 'description' => 'arguments that may get passed to the handler',
  357. 'type' => 'text',
  358. 'size' => 'normal',
  359. 'not null' => FALSE,
  360. 'default' => '',
  361. ),
  362. ),
  363. 'unique_keys' => array(
  364. 'setup_id' => array('handler_id'),
  365. ),
  366. 'primary key' => array('handler_id'),
  367. );
  368. return $schema;
  369. }