tripal_core.module 9.5 KB

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