tripal_views.install 11 KB

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