tripal_views.install 9.6 KB

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