tripal_contact.install 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * @file
  4. * This file contains all the functions which describe and implement drupal database tables
  5. * needed by this module. This module was developed by Chad N.A. Krilow and Lacey-Anne Sanderson,
  6. * University of Saskatchewan.
  7. *
  8. * The contact manamgenet module allows you to sync data in a chado/Tripal instance with
  9. * multiple contact/mysql instances as well as manage and create such contact instances
  10. */
  11. /**
  12. * Implementation of hook_requirements().
  13. *
  14. */
  15. function tripal_contact_requirements($phase) {
  16. $requirements = array();
  17. if ($phase == 'install') {
  18. // make sure chado is installed
  19. if (!tripal_core_is_chado_installed()) {
  20. $requirements ['tripal_contact'] = array(
  21. 'title' => "tripal_contact",
  22. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  23. 'severity' => REQUIREMENT_ERROR,
  24. );
  25. }
  26. }
  27. return $requirements;
  28. }
  29. /**
  30. * Implementation of hook_install().
  31. */
  32. function tripal_contact_install() {
  33. // create the module's data directory
  34. tripal_create_moddir('tripal_contact');
  35. // add the contactprop table to Chado
  36. tripal_contact_add_custom_tables();
  37. // add loading of the the tripal contact ontology to the job queue
  38. $obo_path = realpath('./') . '/' . drupal_get_path('module', 'tripal_contact') . '/files/tcontact.obo';
  39. $obo_id = tripal_cv_add_obo_ref('Tripal Contacts', $obo_path);
  40. tripal_cv_submit_obo_job($obo_id);
  41. }
  42. /**
  43. * Implementation of hook_uninstall().
  44. */
  45. function tripal_contact_uninstall() {
  46. }
  47. /**
  48. * Implementation of hook_schema().
  49. */
  50. function tripal_contact_schema() {
  51. $schema['chado_contact'] = array(
  52. 'fields' => array(
  53. 'vid' => array(
  54. 'type' => 'int',
  55. 'unsigned' => TRUE,
  56. 'not null' => TRUE,
  57. 'default' => 0
  58. ),
  59. 'nid' => array(
  60. 'type' => 'int',
  61. 'unsigned' => TRUE,
  62. 'not null' => TRUE,
  63. 'default' => 0
  64. ),
  65. 'contact_id' => array(
  66. 'type' => 'int',
  67. 'not null' => TRUE,
  68. 'default' => 0
  69. )
  70. ),
  71. 'indexes' => array(
  72. 'contact_id' => array('contact_id')
  73. ),
  74. 'unique keys' => array(
  75. 'nid_vid' => array('nid', 'vid'),
  76. 'vid' => array('vid')
  77. ),
  78. 'primary key' => array('nid'),
  79. );
  80. return $schema;
  81. }
  82. /*
  83. *
  84. */
  85. function tripal_contact_add_custom_tables(){
  86. $schema = array (
  87. 'table' => 'contactprop',
  88. 'fields' => array (
  89. 'contactprop_id' => array (
  90. 'type' => 'serial',
  91. 'not null' => true,
  92. ),
  93. 'contact_id' => array (
  94. 'type' => 'int',
  95. 'not null' => true,
  96. ),
  97. 'type_id' => array (
  98. 'type' => 'int',
  99. 'not null' => true,
  100. ),
  101. 'value' => array (
  102. 'type' => 'text',
  103. 'not null' => false,
  104. ),
  105. 'rank' => array (
  106. 'type' => 'int',
  107. 'not null' => true,
  108. 'default' => 0,
  109. ),
  110. ),
  111. 'primary key' => array (
  112. 0 => 'contactprop_id',
  113. ),
  114. 'unique keys' => array (
  115. 'contactprop_c1' => array (
  116. 0 => 'contact_id',
  117. 1 => 'type_id',
  118. 2 => 'rank',
  119. ),
  120. ),
  121. 'indexes' => array (
  122. 'contactprop_idx1' => array (
  123. 0 => 'contact_id',
  124. ),
  125. 'contactprop_idx2' => array (
  126. 0 => 'type_id',
  127. ),
  128. ),
  129. 'foreign keys' => array (
  130. 'cvterm' => array (
  131. 'table' => 'cvterm',
  132. 'columns' => array (
  133. 'type_id' => 'cvterm_id',
  134. ),
  135. ),
  136. 'contact' => array (
  137. 'table' => 'contact',
  138. 'columns' => array (
  139. 'contact_id' => 'contact_id',
  140. ),
  141. ),
  142. ),
  143. );
  144. tripal_core_create_custom_table('contactprop', $schema, TRUE);
  145. }