tripal_core.module 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. require_once "jobs.php";
  3. require_once "mviews.php";
  4. require_once "cvterms.php";
  5. require_once "chado_install.php";
  6. require_once "tripal_core.api.inc";
  7. /**
  8. * @defgroup tripal_modules Tripal Modules
  9. * @{
  10. * All documented functions for the various Tripal Modules
  11. * @}
  12. */
  13. /**
  14. * @defgroup tripal_core Core Tripal Module
  15. * @ingroup tripal_modules
  16. */
  17. /**
  18. *
  19. *
  20. * @ingroup tripal_core
  21. */
  22. function tripal_core_init(){
  23. // the two lines below are necessary to ensure that the search_path
  24. // variable is always set. In the case where a view needs to query the
  25. // chado schema when it is local to the Drupal database. Otherwise the
  26. // search_path isn't set. When tripal_db_set_active is called it
  27. // automatically sets the serach path if chado is local to the
  28. // Drupal database
  29. $previous = tripal_db_set_active('chado');
  30. tripal_db_set_active($previous);
  31. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  32. // only if the chado database is present.
  33. if(tripal_core_is_chado_installed()){
  34. $previous_db = tripal_db_set_active('chado'); // use chado database
  35. if(!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))){
  36. $results = db_query("INSERT INTO {cv} (name,definition) ".
  37. "VALUES ('tripal','Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
  38. }
  39. if(!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))){
  40. $results = db_query("INSERT INTO {db} (name,description) ".
  41. "VALUES ('tripal','Used as a database placeholder for tripal defined objects such as tripal cvterms')");
  42. }
  43. tripal_db_set_active($previous_db); // now use drupal database
  44. }
  45. }
  46. /**
  47. *
  48. *
  49. * @ingroup tripal_core
  50. */
  51. function tripal_core_menu() {
  52. $items = array();
  53. // Triapl setting groups
  54. $items['admin/tripal'] = array(
  55. 'title' => 'Tripal Management',
  56. 'description' => "Manage the behavior or Tripal and its various modules.",
  57. 'position' => 'right',
  58. 'weight' => -5,
  59. 'page callback' => 'system_admin_menu_block_page',
  60. 'access arguments' => array('administer site configuration'),
  61. 'file' => 'system.admin.inc',
  62. 'file path' => drupal_get_path('module', 'system'),
  63. );
  64. $items['admin/tripal/tripal_jobs'] = array(
  65. 'title' => 'Jobs',
  66. 'description' => 'Jobs managed by Tripal',
  67. 'page callback' => 'tripal_jobs_report',
  68. 'access arguments' => array('access administration pages'),
  69. 'type' => MENU_NORMAL_ITEM,
  70. );
  71. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  72. 'title' => 'Jobs',
  73. 'description' => 'Cancel a pending job',
  74. 'page callback' => 'tripal_jobs_cancel',
  75. 'page arguments' => array(4),
  76. 'access arguments' => array('access administration pages'),
  77. 'type' => MENU_CALLBACK,
  78. );
  79. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  80. 'title' => 'Jobs',
  81. 'description' => 'Re-run an existing job.',
  82. 'page callback' => 'tripal_jobs_rerun',
  83. 'page arguments' => array(4),
  84. 'access arguments' => array('access administration pages'),
  85. 'type' => MENU_CALLBACK,
  86. );
  87. $items['admin/tripal/tripal_jobs/view/%'] = array(
  88. 'title' => 'Jobs Details',
  89. 'description' => 'View job details.',
  90. 'page callback' => 'tripal_jobs_view',
  91. 'page arguments' => array(4),
  92. 'access arguments' => array('access administration pages'),
  93. 'type' => MENU_CALLBACK,
  94. );
  95. $items['admin/tripal/tripal_mview/%'] = array(
  96. 'title' => 'Materialized View',
  97. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  98. 'page callback' => 'tripal_mview_report',
  99. 'page arguments' => array(3),
  100. 'access arguments' => array('access administration pages'),
  101. 'type' => MENU_NORMAL_ITEM,
  102. );
  103. $items['admin/tripal/tripal_mviews'] = array(
  104. 'title' => 'Materialized Views',
  105. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  106. 'page callback' => 'tripal_mviews_report',
  107. 'access arguments' => array('access administration pages'),
  108. 'type' => MENU_NORMAL_ITEM,
  109. );
  110. $items['admin/tripal/tripal_mviews/new'] = array(
  111. 'title' => 'Create View',
  112. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  113. 'page callback' => 'drupal_get_form',
  114. 'page arguments' => array('tripal_mviews_form'),
  115. 'access arguments' => array('access administration pages'),
  116. 'type' => MENU_NORMAL_ITEM,
  117. );
  118. $items['admin/tripal/tripal_mviews/edit/%'] = array(
  119. 'title' => 'Edit View',
  120. 'page callback' => 'drupal_get_form',
  121. 'page arguments' => array('tripal_mviews_form',4),
  122. 'access arguments' => array('access administration pages'),
  123. 'type' => MENU_NORMAL_ITEM,
  124. );
  125. $items['admin/tripal/tripal_mviews/action/%/%'] = array(
  126. 'title' => 'Create View',
  127. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  128. 'page callback' => 'tripal_mviews_action',
  129. 'page arguments' => array(4,5),
  130. 'access arguments' => array('access administration pages'),
  131. 'type' => MENU_CALLBACK,
  132. );
  133. $items['tripal_toggle_box_menu/%/%/%'] = array(
  134. 'title' => t('Libraries'),
  135. 'page callback' => 'tripal_toggle_box_menu',
  136. 'page arguments' => array(1,2,3),
  137. 'access arguments' => array('access administration pages'),
  138. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  139. );
  140. $items['admin/tripal/chado_1_11_install'] = array(
  141. 'title' => 'Install Chado v1.11',
  142. 'description' => 'Installs Chado version 1.11 inside the current Drupal database',
  143. 'page callback' => 'drupal_get_form',
  144. 'page arguments' => array('tripal_core_chado_v1_11_load_form'),
  145. 'access arguments' => array('access administration pages'),
  146. 'type' => MENU_NORMAL_ITEM,
  147. );
  148. $items['admin/tripal/bulk_load/create'] = array(
  149. 'title' => 'Create Bulk Loader',
  150. 'description' => 'Create a bulk loader template for loading data into Chado',
  151. 'page callback' => 'tripal_core_bulk_loader_create',
  152. 'access arguments' => array('access administration pages'),
  153. 'type' => MENU_NORMAL_ITEM,
  154. );
  155. $items['admin/tripal/bulk_load/step2_get_type/%'] = array(
  156. 'title' => 'Create Bulk Loader',
  157. 'description' => 'Create a bulk loader template for loading data into Chado',
  158. 'page callback' => 'tripal_core_bulk_loader_ahah_step2_feature_type',
  159. 'page arguments' => array(4),
  160. 'access arguments' => array('access administration pages'),
  161. 'type' => MENU_CALLBACK,
  162. );
  163. $items['test2'] = array(
  164. 'title' => 'test',
  165. 'description' => 'test',
  166. 'page callback' => 'tripal_core_chado_insert_test',
  167. 'access arguments' => array('access administration pages'),
  168. 'type' => MENU_CALLBACK,
  169. );
  170. return $items;
  171. }
  172. /**
  173. *
  174. *
  175. * @param $dbname
  176. * The name of the database to switch to as indicated in settings.php
  177. * Should be either default or chado
  178. *
  179. * @return
  180. * The name of the previously set database
  181. *
  182. * @ingroup tripal_chado_api
  183. */
  184. function tripal_core_is_chado_installed(){
  185. global $db_url, $db_type;
  186. // first check if chado is in the db_url of the
  187. // settings.php file
  188. if(is_array($db_url)){
  189. if(isset($db_url['chado'])){
  190. return true;
  191. }
  192. }
  193. // check to make sure the chado schema exists
  194. $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
  195. if(db_fetch_object(db_query($sql))){
  196. return true;
  197. }
  198. return false;
  199. }
  200. /**
  201. * Implements hook_views_api()
  202. *
  203. * Purpose: Essentially this hook tells drupal that there is views support for
  204. * for this module which then includes tripal_core.views.inc where all the
  205. * views integration code is
  206. *
  207. * @ingroup tripal_core
  208. */
  209. function tripal_core_views_api() {
  210. return array(
  211. 'api' => 2.0,
  212. );
  213. }
  214. /**
  215. *
  216. * @ingroup tripal_core
  217. */
  218. function tripal_core_theme () {
  219. return array(
  220. 'tripal_core_job_view' => array (
  221. 'arguments' => array('job_id'=> null),
  222. 'template' => 'tripal_core_job_view',
  223. ),
  224. );
  225. }