tripal_views.install 11 KB

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