tripal_views.install 11 KB

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