tripal_contact.install 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. /**
  3. * @file
  4. * Handles install, uninstall, disable and enable functionality including database tables.
  5. *
  6. * @ingroup tripal_legacy_contact
  7. */
  8. /**
  9. * Implements hook_disable().
  10. * Disable default views when module is disabled
  11. *
  12. * @ingroup tripal_legacy_contact
  13. */
  14. function tripal_contact_disable() {
  15. // Disable all default views provided by this module
  16. require_once("tripal_contact.views_default.inc");
  17. $views = tripal_contact_views_default_views();
  18. foreach (array_keys($views) as $view_name) {
  19. tripal_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
  20. }
  21. }
  22. /**
  23. * Implementation of hook_requirements().
  24. *
  25. * @ingroup tripal_legacy_contact
  26. */
  27. function tripal_contact_requirements($phase) {
  28. $requirements = array();
  29. if ($phase == 'install') {
  30. // make sure chado is installed
  31. if (!$GLOBALS["chado_is_installed"]) {
  32. $requirements ['tripal_contact'] = array(
  33. 'title' => "tripal_contact",
  34. 'value' => "ERROR: Chado must be installed before this module can be enabled",
  35. 'severity' => REQUIREMENT_ERROR,
  36. );
  37. }
  38. }
  39. return $requirements;
  40. }
  41. /**
  42. * Implementation of hook_install().
  43. *
  44. * @ingroup tripal_legacy_contact
  45. */
  46. function tripal_contact_install() {
  47. // Add the contactprop table to Chado.
  48. tripal_contact_add_custom_tables();
  49. // Add loading of the the tripal contact ontology to the job queue.
  50. $obo_path = '{tripal_contact}/files/tcontact.obo';
  51. $obo_id = tripal_insert_obo('Tripal Contacts', $obo_path);
  52. tripal_submit_obo_job(array('obo_id' => $obo_id));
  53. // Add cvterms for relationship types.
  54. tripal_contact_add_cvs();
  55. tripal_contact_add_cvterms();
  56. // Set the default vocabularies.
  57. tripal_set_default_cv('contact', 'type_id', 'tripal_contact');
  58. tripal_set_default_cv('contactprop', 'type_id', 'tripal_contact');
  59. tripal_set_default_cv('contact_relationship', 'type_id', 'contact_relationship');
  60. }
  61. /**
  62. * Implementation of hook_uninstall().
  63. *
  64. * @ingroup tripal_legacy_contact
  65. */
  66. function tripal_contact_uninstall() {
  67. /*
  68. // remove our custom block visibility settings per node type
  69. db_delete('block_node_type')
  70. ->condition('module', 'chado_contact')
  71. ->condition('delta', 'contbase')
  72. ->execute();
  73. */
  74. }
  75. /**
  76. * Adds any cvs needed by this module.
  77. *
  78. * @ingroup tripal_legacy_contact
  79. */
  80. function tripal_contact_add_cvs() {
  81. // Add the cv for contact properties. This is a default vocabulary in the event
  82. // that a user does not want to use the tripal_contact vocabulary
  83. tripal_insert_cv(
  84. 'contact_property',
  85. 'Contains properties for contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
  86. );
  87. // add the cv for the contact type. This is a default vocabulary in the event
  88. // that a user does not want to use the tripal_contact vocabulary
  89. tripal_insert_cv(
  90. 'contact_type',
  91. 'Contains types of contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
  92. );
  93. // Add the cv for the tripal_contact vocabulary which is loaded via the OBO
  94. tripal_insert_cv(
  95. 'tripal_contact',
  96. 'A heirarchical set of terms for describing a contact. It is intended to be used as the default vocabularies in Tripal for contact types and contact properties.'
  97. );
  98. // add the cv for contact relationships
  99. tripal_insert_cv(
  100. 'contact_relationship',
  101. 'Contains types of relationships between contacts.'
  102. );
  103. }
  104. /**
  105. * Adds any cvterms needed by this module.
  106. *
  107. * @ingroup tripal_legacy_contact
  108. */
  109. function tripal_contact_add_cvterms() {
  110. }
  111. /**
  112. * Implementation of hook_schema().
  113. *
  114. * @ingroup tripal_legacy_contact
  115. */
  116. function tripal_contact_schema() {
  117. $schema['chado_contact'] = array(
  118. 'fields' => array(
  119. 'vid' => array(
  120. 'type' => 'int',
  121. 'unsigned' => TRUE,
  122. 'not null' => TRUE,
  123. 'default' => 0
  124. ),
  125. 'nid' => array(
  126. 'type' => 'int',
  127. 'unsigned' => TRUE,
  128. 'not null' => TRUE,
  129. 'default' => 0
  130. ),
  131. 'contact_id' => array(
  132. 'type' => 'int',
  133. 'not null' => TRUE,
  134. 'default' => 0
  135. )
  136. ),
  137. 'indexes' => array(
  138. 'contact_id' => array('contact_id')
  139. ),
  140. 'unique keys' => array(
  141. 'nid_vid' => array('nid', 'vid'),
  142. 'vid' => array('vid')
  143. ),
  144. 'primary key' => array('nid'),
  145. );
  146. return $schema;
  147. }
  148. /**
  149. * Add any custom tables needed by this module.
  150. * - Contactprop: keep track of properties of contact
  151. *
  152. * @ingroup tripal_legacy_contact
  153. */
  154. // This function was moved to tripal_chado/includes/setup/tripal_chado.setup.inc
  155. /* function tripal_contact_add_custom_tables(){
  156. $schema = array (
  157. 'table' => 'contactprop',
  158. 'fields' => array (
  159. 'contactprop_id' => array (
  160. 'type' => 'serial',
  161. 'not null' => true,
  162. ),
  163. 'contact_id' => array (
  164. 'type' => 'int',
  165. 'not null' => true,
  166. ),
  167. 'type_id' => array (
  168. 'type' => 'int',
  169. 'not null' => true,
  170. ),
  171. 'value' => array (
  172. 'type' => 'text',
  173. 'not null' => false,
  174. ),
  175. 'rank' => array (
  176. 'type' => 'int',
  177. 'not null' => true,
  178. 'default' => 0,
  179. ),
  180. ),
  181. 'primary key' => array (
  182. 0 => 'contactprop_id',
  183. ),
  184. 'unique keys' => array (
  185. 'contactprop_c1' => array (
  186. 0 => 'contact_id',
  187. 1 => 'type_id',
  188. 2 => 'rank',
  189. ),
  190. ),
  191. 'indexes' => array (
  192. 'contactprop_idx1' => array (
  193. 0 => 'contact_id',
  194. ),
  195. 'contactprop_idx2' => array (
  196. 0 => 'type_id',
  197. ),
  198. ),
  199. 'foreign keys' => array (
  200. 'cvterm' => array (
  201. 'table' => 'cvterm',
  202. 'columns' => array (
  203. 'type_id' => 'cvterm_id',
  204. ),
  205. ),
  206. 'contact' => array (
  207. 'table' => 'contact',
  208. 'columns' => array (
  209. 'contact_id' => 'contact_id',
  210. ),
  211. ),
  212. ),
  213. );
  214. chado_create_custom_table('contactprop', $schema, TRUE);
  215. } */