tripal_chado_views.install 8.4 KB

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