tripal_core.module 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. // add some variables for all javasript to use for building URLs
  46. global $base_url;
  47. $theme_dir = drupal_get_path('theme', 'tripal');
  48. $clean_urls = variable_get('clean_url', 0);
  49. drupal_add_js("
  50. var baseurl = '$base_url';
  51. var themedir = '$theme_dir';
  52. var isClean = $clean_urls;",'inline');
  53. }
  54. /**
  55. *
  56. *
  57. * @ingroup tripal_core
  58. */
  59. function tripal_core_menu() {
  60. $items = array();
  61. // Triapl setting groups
  62. $items['admin/tripal'] = array(
  63. 'title' => 'Tripal Management',
  64. 'description' => "Manage the behavior or Tripal and its various modules.",
  65. 'position' => 'right',
  66. 'weight' => -5,
  67. 'page callback' => 'system_admin_menu_block_page',
  68. 'access arguments' => array('administer site configuration'),
  69. 'file' => 'system.admin.inc',
  70. 'file path' => drupal_get_path('module', 'system'),
  71. );
  72. $items['admin/tripal/tripal_jobs'] = array(
  73. 'title' => 'Jobs',
  74. 'description' => 'Jobs managed by Tripal',
  75. 'page callback' => 'tripal_jobs_report',
  76. 'access arguments' => array('access administration pages'),
  77. 'type' => MENU_NORMAL_ITEM,
  78. );
  79. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  80. 'title' => 'Jobs',
  81. 'description' => 'Cancel a pending job',
  82. 'page callback' => 'tripal_jobs_cancel',
  83. 'page arguments' => array(4),
  84. 'access arguments' => array('access administration pages'),
  85. 'type' => MENU_CALLBACK,
  86. );
  87. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  88. 'title' => 'Jobs',
  89. 'description' => 'Re-run an existing job.',
  90. 'page callback' => 'tripal_jobs_rerun',
  91. 'page arguments' => array(4),
  92. 'access arguments' => array('access administration pages'),
  93. 'type' => MENU_CALLBACK,
  94. );
  95. $items['admin/tripal/tripal_jobs/view/%'] = array(
  96. 'title' => 'Jobs Details',
  97. 'description' => 'View job details.',
  98. 'page callback' => 'tripal_jobs_view',
  99. 'page arguments' => array(4),
  100. 'access arguments' => array('access administration pages'),
  101. 'type' => MENU_CALLBACK,
  102. );
  103. $items['admin/tripal/tripal_mview/%'] = array(
  104. 'title' => 'Materialized View',
  105. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  106. 'page callback' => 'tripal_mview_report',
  107. 'page arguments' => array(3),
  108. 'access arguments' => array('access administration pages'),
  109. 'type' => MENU_NORMAL_ITEM,
  110. );
  111. $items['admin/tripal/tripal_mviews'] = array(
  112. 'title' => 'Materialized Views',
  113. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  114. 'page callback' => 'tripal_mviews_report',
  115. 'access arguments' => array('access administration pages'),
  116. 'type' => MENU_NORMAL_ITEM,
  117. );
  118. $items['admin/tripal/tripal_mviews/new'] = array(
  119. 'title' => 'Create View',
  120. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  121. 'page callback' => 'drupal_get_form',
  122. 'page arguments' => array('tripal_mviews_form'),
  123. 'access arguments' => array('access administration pages'),
  124. 'type' => MENU_NORMAL_ITEM,
  125. );
  126. $items['admin/tripal/tripal_mviews/edit/%'] = array(
  127. 'title' => 'Edit View',
  128. 'page callback' => 'drupal_get_form',
  129. 'page arguments' => array('tripal_mviews_form',4),
  130. 'access arguments' => array('access administration pages'),
  131. 'type' => MENU_NORMAL_ITEM,
  132. );
  133. $items['admin/tripal/tripal_mviews/action/%/%'] = array(
  134. 'title' => 'Create View',
  135. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  136. 'page callback' => 'tripal_mviews_action',
  137. 'page arguments' => array(4,5),
  138. 'access arguments' => array('access administration pages'),
  139. 'type' => MENU_CALLBACK,
  140. );
  141. $items['tripal_toggle_box_menu/%/%/%'] = array(
  142. 'title' => t('Libraries'),
  143. 'page callback' => 'tripal_toggle_box_menu',
  144. 'page arguments' => array(1,2,3),
  145. 'access arguments' => array('access administration pages'),
  146. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  147. );
  148. $items['admin/tripal/chado_1_11_install'] = array(
  149. 'title' => 'Install Chado v1.11',
  150. 'description' => 'Installs Chado version 1.11 inside the current Drupal database',
  151. 'page callback' => 'drupal_get_form',
  152. 'page arguments' => array('tripal_core_chado_v1_11_load_form'),
  153. 'access arguments' => array('access administration pages'),
  154. 'type' => MENU_NORMAL_ITEM,
  155. );
  156. $items['admin/tripal/bulk_load/create'] = array(
  157. 'title' => 'Create Bulk Loader',
  158. 'description' => 'Create a bulk loader template for loading data into Chado',
  159. 'page callback' => 'tripal_core_bulk_loader_create',
  160. 'access arguments' => array('access administration pages'),
  161. 'type' => MENU_NORMAL_ITEM,
  162. );
  163. $items['admin/tripal/bulk_load/step2_get_type/%'] = array(
  164. 'title' => 'Create Bulk Loader',
  165. 'description' => 'Create a bulk loader template for loading data into Chado',
  166. 'page callback' => 'tripal_core_bulk_loader_ahah_step2_feature_type',
  167. 'page arguments' => array(4),
  168. 'access arguments' => array('access administration pages'),
  169. 'type' => MENU_CALLBACK,
  170. );
  171. $items['test2'] = array(
  172. 'title' => 'test',
  173. 'description' => 'test',
  174. 'page callback' => 'tripal_core_chado_insert_test',
  175. 'access arguments' => array('access administration pages'),
  176. 'type' => MENU_CALLBACK,
  177. );
  178. return $items;
  179. }
  180. /**
  181. *
  182. *
  183. * @param $dbname
  184. * The name of the database to switch to as indicated in settings.php
  185. * Should be either default or chado
  186. *
  187. * @return
  188. * The name of the previously set database
  189. *
  190. * @ingroup tripal_chado_api
  191. */
  192. function tripal_core_is_chado_installed(){
  193. global $db_url, $db_type;
  194. // first check if chado is in the db_url of the
  195. // settings.php file
  196. if(is_array($db_url)){
  197. if(isset($db_url['chado'])){
  198. return true;
  199. }
  200. }
  201. // check to make sure the chado schema exists
  202. $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
  203. if(db_fetch_object(db_query($sql))){
  204. return true;
  205. }
  206. return false;
  207. }
  208. /**
  209. * Implements hook_views_api()
  210. *
  211. * Purpose: Essentially this hook tells drupal that there is views support for
  212. * for this module which then includes tripal_core.views.inc where all the
  213. * views integration code is
  214. *
  215. * @ingroup tripal_core
  216. */
  217. function tripal_core_views_api() {
  218. return array(
  219. 'api' => 2.0,
  220. );
  221. }
  222. /**
  223. *
  224. * @ingroup tripal_core
  225. */
  226. function tripal_core_theme () {
  227. return array(
  228. 'tripal_core_job_view' => array (
  229. 'arguments' => array('job_id'=> null),
  230. 'template' => 'tripal_core_job_view',
  231. ),
  232. );
  233. }
  234. /**
  235. *
  236. * @ingroup tripal_core
  237. */
  238. function tripal_core_job_describe_args($callback,$args){
  239. $new_args = array();
  240. if($callback == 'tripal_update_mview'){
  241. // get this mview details
  242. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
  243. $mview = db_fetch_object(db_query($sql,$args[0]));
  244. $new_args['View Name'] = $mview->name;
  245. }
  246. return $new_args;
  247. }