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_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. * Tripal Views Update for 7.x-2.0
  95. * - Add relationship_only field to tripal_views_join
  96. * - Add relationship_handler field to tripal_views_join
  97. */
  98. function tripal_views_update_7020() {
  99. // Add relationship_handler to tripal_views_join
  100. db_add_field(
  101. 'tripal_views_join',
  102. 'relationship_handler',
  103. array(
  104. 'type' => 'varchar',
  105. 'length' => '255',
  106. 'not null' => TRUE,
  107. 'default' => 'views_handler_relationship'
  108. )
  109. );
  110. // Add relationship_only to tripal_views_join
  111. db_add_field(
  112. 'tripal_views_join',
  113. 'relationship_only',
  114. array(
  115. 'type' => 'int',
  116. 'not null ' => TRUE,
  117. 'default' => 0
  118. )
  119. );
  120. return t('Updated Tripal Views to better handle relationships. Relationships are now handled through joins rather than handlers (backwards compatible).');
  121. }
  122. /**
  123. * Describe the Tripal Views Schema
  124. *
  125. * Tables include:
  126. * - tripal_views: main table for views integration setups
  127. * - tripal_views_field: keeps track of all fields related to a given views integration setup
  128. * - tripal_views_join: keeps track of joins between the current views integration setup
  129. * and other tables.
  130. * - tripal_views_handlers: keeps track of which handlers to use for a given field
  131. *
  132. * @ingroup tripal_views
  133. */
  134. function tripal_views_views_schema() {
  135. $schema = array();
  136. $schema['tripal_views'] = array(
  137. 'description' => 'contains the setups, their materialized view id and base table name that was used.',
  138. 'fields' => array(
  139. 'setup_id' => array(
  140. 'description' => 'the id of the setup',
  141. 'type' => 'serial',
  142. 'unsigned' => TRUE,
  143. 'not null' => TRUE,
  144. ),
  145. 'mview_id' => array(
  146. 'description' => 'the materialized view used for this setup',
  147. 'type' => 'int',
  148. 'unsigned' => TRUE,
  149. ),
  150. 'base_table' => array(
  151. 'description' => 'either TRUE (1) or FALSE (0) depending on whether the current table should be a bast table of a View',
  152. 'type' => 'int',
  153. 'not null ' => TRUE,
  154. 'default' => 1
  155. ),
  156. 'table_name' => array(
  157. 'description' => 'the table name being integrated.',
  158. 'type' => 'varchar',
  159. 'length' => 255,
  160. 'not null' => TRUE,
  161. 'default' => '',
  162. ),
  163. 'priority' => array(
  164. 'description' => 'when there are 2+ entries for the same table, the entry with the lightest (drupal-style) priority is used.',
  165. 'type' => 'int',
  166. ),
  167. 'name' => array(
  168. 'description' => 'Human readable name of this setup',
  169. 'type' => 'varchar',
  170. 'length' => 255,
  171. 'not null' => TRUE,
  172. 'default' => '',
  173. ),
  174. 'comment' => array(
  175. 'description' => 'add notes about this views setup',
  176. 'type' => 'text',
  177. 'size' => 'normal',
  178. 'not null' => FALSE,
  179. 'default' => '',
  180. ),
  181. ),
  182. 'unique_keys' => array(
  183. 'setup_id' => array('setup_id'),
  184. 'priority' => array('table_name', 'priority'),
  185. ),
  186. 'indexes' => array(
  187. 'priority' => array('table_name', 'priority'),
  188. ),
  189. 'primary key' => array('setup_id'),
  190. );
  191. $schema['tripal_views_field'] = array(
  192. 'description' => 'keep track of fields available for a given table',
  193. 'fields' => array(
  194. 'setup_id' => array(
  195. 'description' => 'the id of the setup',
  196. 'type' => 'int',
  197. 'unsigned' => TRUE,
  198. 'not null' => TRUE,
  199. ),
  200. 'column_name' => array(
  201. 'description' => 'the name of the field in the database',
  202. 'type' => 'varchar',
  203. 'length' => '255',
  204. 'not null' => TRUE,
  205. ),
  206. 'name' => array(
  207. 'description' => 'the human-readable name of the field',
  208. 'type' => 'varchar',
  209. 'length' => '255',
  210. 'not null' => TRUE,
  211. ),
  212. 'description' => array(
  213. 'description' => 'A short description of the field -seen under the field in the views UI',
  214. 'type' => 'varchar',
  215. 'length' => '255',
  216. 'not null' => TRUE,
  217. ),
  218. 'type' => array(
  219. 'description' => 'the database type of this field (ie: int, varchar)',
  220. 'type' => 'varchar',
  221. 'length' => '50',
  222. 'not null' => TRUE,
  223. ),
  224. ),
  225. 'primary key' => array('setup_id', 'column_name')
  226. );
  227. $schema['tripal_views_join'] = array(
  228. 'description' => 'coordinate the joining of tables',
  229. 'fields' => array(
  230. 'view_join_id' => array(
  231. 'description' => 'the id of the join',
  232. 'type' => 'serial',
  233. 'unsigned' => TRUE,
  234. 'not null' => TRUE,
  235. ),
  236. 'setup_id' => array(
  237. 'description' => 'setup id from tripal_views table',
  238. 'type' => 'int',
  239. 'unsigned' => TRUE,
  240. 'not null' => TRUE,
  241. ),
  242. 'base_table' => array(
  243. 'description' => 'the name of the base table',
  244. 'type' => 'varchar',
  245. 'length' => '255',
  246. 'not null' => TRUE,
  247. 'default' => '',
  248. ),
  249. 'base_field' => array(
  250. 'description' => 'the name of the base table column that will be joined',
  251. 'type' => 'varchar',
  252. 'length' => '255',
  253. 'not null' => TRUE,
  254. 'default' => '',
  255. ),
  256. 'left_table' => array(
  257. 'description' => 'the table on which to perform a left join',
  258. 'type' => 'varchar',
  259. 'length' => '255',
  260. 'not null' => TRUE,
  261. 'default' => '',
  262. ),
  263. 'left_field' => array(
  264. 'description' => 'the column on which to perform a left join',
  265. 'type' => 'varchar',
  266. 'length' => '255',
  267. 'not null' => TRUE,
  268. 'default' => '',
  269. ),
  270. 'handler' => array(
  271. 'description' => 'the name of the handler',
  272. 'type' => 'varchar',
  273. 'length' => '255',
  274. 'not null' => TRUE,
  275. 'default' => '',
  276. ),
  277. 'relationship_handler' => array(
  278. 'type' => 'varchar',
  279. 'length' => '255',
  280. 'not null' => TRUE,
  281. 'default' => 'views_handler_relationship'
  282. ),
  283. 'relationship_only' => array(
  284. 'type' => 'int',
  285. 'not null ' => TRUE,
  286. 'default' => 0
  287. ),
  288. 'arguments' => array(
  289. 'description' => 'arguments that may get passed to the handler',
  290. 'type' => 'text',
  291. 'size' => 'normal',
  292. ),
  293. ),
  294. 'unique_keys' => array(
  295. 'setup_id' => array('view_join_id'),
  296. ),
  297. 'primary key' => array('view_join_id'),
  298. );
  299. $schema['tripal_views_handlers'] = array(
  300. 'description' => 'in formation for views: column and views handler name',
  301. 'fields' => array(
  302. 'handler_id' => array(
  303. 'description' => 'the id of the handler',
  304. 'type' => 'serial',
  305. 'unsigned' => TRUE,
  306. 'not null' => TRUE,
  307. ),
  308. 'setup_id' => array(
  309. 'description' => 'setup id from the tripal_views table',
  310. 'type' => 'int',
  311. 'unsigned' => TRUE,
  312. 'not null' => TRUE,
  313. ),
  314. 'column_name' => array(
  315. 'description' => '',
  316. 'type' => 'varchar',
  317. 'length' => '255',
  318. 'not null' => TRUE,
  319. 'default' => '',
  320. ),
  321. 'handler_type' => array(
  322. 'description' => 'identifies the type of hander (e.g. field, filter, sort, argument, relationship, etc.)',
  323. 'type' => 'varchar',
  324. 'length' => '50',
  325. 'not null' => TRUE,
  326. 'default' => '',
  327. ),
  328. 'handler_name' => array(
  329. 'description' => 'the name of the handler',
  330. 'type' => 'varchar',
  331. 'length' => '255',
  332. 'not null' => TRUE,
  333. 'default' => '',
  334. ),
  335. 'arguments' => array(
  336. 'description' => 'arguments that may get passed to the handler',
  337. 'type' => 'text',
  338. 'size' => 'normal',
  339. 'not null' => FALSE,
  340. 'default' => '',
  341. ),
  342. ),
  343. 'unique_keys' => array(
  344. 'setup_id' => array('handler_id'),
  345. ),
  346. 'primary key' => array('handler_id'),
  347. );
  348. return $schema;
  349. }
  350. /**
  351. * Implementation of hook_requirements().
  352. *
  353. */
  354. function tripal_views_requirements($phase) {
  355. $requirements = array();
  356. if ($phase == 'install') {
  357. // make sure chado is installed
  358. $version = tripal_get_set_chado_version(TRUE);
  359. if ($version == 'not installed') {
  360. $requirements ['tripal_views'] = array(
  361. 'title' => "tripal_views",
  362. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  363. 'severity' => REQUIREMENT_ERROR,
  364. );
  365. }
  366. }
  367. return $requirements;
  368. }