tripal_core.module 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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_views_integration.inc";
  7. require_once "tripal_core.api.inc";
  8. /**
  9. * @defgroup tripal_modules Tripal Modules
  10. * @{
  11. * All documented functions for the various Tripal Modules
  12. * @}
  13. */
  14. /**
  15. * @defgroup tripal_core Core Tripal Module
  16. * @ingroup tripal_modules
  17. */
  18. /**
  19. *
  20. *
  21. * @ingroup tripal_core
  22. */
  23. function tripal_core_init(){
  24. // the two lines below are necessary to ensure that the search_path
  25. // variable is always set. In the case where a view needs to query the
  26. // chado schema when it is local to the Drupal database. Otherwise the
  27. // search_path isn't set. When tripal_db_set_active is called it
  28. // automatically sets the serach path if chado is local to the
  29. // Drupal database
  30. $previous = tripal_db_set_active('chado');
  31. tripal_db_set_active($previous);
  32. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  33. // only if the chado database is present.
  34. if(tripal_core_is_chado_installed()){
  35. $previous_db = tripal_db_set_active('chado'); // use chado database
  36. if(!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))){
  37. $results = db_query("INSERT INTO {cv} (name,definition) ".
  38. "VALUES ('tripal','Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
  39. }
  40. if(!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))){
  41. $results = db_query("INSERT INTO {db} (name,description) ".
  42. "VALUES ('tripal','Used as a database placeholder for tripal defined objects such as tripal cvterms')");
  43. }
  44. tripal_db_set_active($previous_db); // now use drupal database
  45. }
  46. // add some variables for all javasript to use for building URLs
  47. global $base_url;
  48. $theme_dir = drupal_get_path('theme', 'tripal');
  49. $clean_urls = variable_get('clean_url', 0);
  50. drupal_add_js("
  51. var baseurl = '$base_url';
  52. var themedir = '$theme_dir';
  53. var isClean = $clean_urls;",'inline');
  54. // make sure the date time settings are the way Tripal will insert them
  55. // otherwise PostgreSQL version that may have a different datestyle setting
  56. // will fail when inserting or updating a date column in a table.
  57. db_query("SET DATESTYLE TO '%s'",'MDY');
  58. }
  59. /**
  60. *
  61. *
  62. * @ingroup tripal_core
  63. */
  64. function tripal_core_menu() {
  65. $items = array();
  66. // Triapl setting groups
  67. $items['admin/tripal'] = array(
  68. 'title' => 'Tripal Management',
  69. 'description' => "Manage the behavior or Tripal and its various modules.",
  70. 'position' => 'right',
  71. 'weight' => -5,
  72. 'page callback' => 'system_admin_menu_block_page',
  73. 'access arguments' => array('administer site configuration'),
  74. 'file' => 'system.admin.inc',
  75. 'file path' => drupal_get_path('module', 'system'),
  76. );
  77. $items['admin/tripal/tripal_jobs'] = array(
  78. 'title' => 'Jobs',
  79. 'description' => 'Jobs managed by Tripal',
  80. 'page callback' => 'tripal_jobs_report',
  81. 'access arguments' => array('access administration pages'),
  82. 'type' => MENU_NORMAL_ITEM,
  83. );
  84. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  85. 'title' => 'Jobs',
  86. 'description' => 'Cancel a pending job',
  87. 'page callback' => 'tripal_jobs_cancel',
  88. 'page arguments' => array(4),
  89. 'access arguments' => array('access administration pages'),
  90. 'type' => MENU_CALLBACK,
  91. );
  92. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  93. 'title' => 'Jobs',
  94. 'description' => 'Re-run an existing job.',
  95. 'page callback' => 'tripal_jobs_rerun',
  96. 'page arguments' => array(4),
  97. 'access arguments' => array('access administration pages'),
  98. 'type' => MENU_CALLBACK,
  99. );
  100. $items['admin/tripal/tripal_jobs/view/%'] = array(
  101. 'title' => 'Jobs Details',
  102. 'description' => 'View job details.',
  103. 'page callback' => 'tripal_jobs_view',
  104. 'page arguments' => array(4),
  105. 'access arguments' => array('access administration pages'),
  106. 'type' => MENU_CALLBACK,
  107. );
  108. $items['tripal_toggle_box_menu/%/%/%'] = array(
  109. 'title' => t('Libraries'),
  110. 'page callback' => 'tripal_toggle_box_menu',
  111. 'page arguments' => array(1,2,3),
  112. 'access arguments' => array('access administration pages'),
  113. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  114. );
  115. $items['admin/tripal/chado_1_11_install'] = array(
  116. 'title' => 'Install Chado v1.11',
  117. 'description' => 'Installs Chado version 1.11 inside the current Drupal database',
  118. 'page callback' => 'drupal_get_form',
  119. 'page arguments' => array('tripal_core_chado_v1_11_load_form'),
  120. 'access arguments' => array('access administration pages'),
  121. 'type' => MENU_NORMAL_ITEM,
  122. );
  123. $items['admin/tripal/views'] = array(
  124. 'title' => t('Views'),
  125. 'description' => 'Management of Materialized Views & Integration with Drupal Views',
  126. 'page callback' => 'tripal_core_views_description_page',
  127. 'access arguments' => array('administer site configuration'),
  128. 'type' => MENU_NORMAL_ITEM,
  129. );
  130. $items['admin/tripal/views/mviews'] = array(
  131. 'title' => 'MViews',
  132. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  133. 'page callback' => 'tripal_mviews_report',
  134. 'access arguments' => array('access administration pages'),
  135. 'type' => MENU_NORMAL_ITEM,
  136. );
  137. $items['admin/tripal/views/mviews/report/%'] = array(
  138. 'title' => 'Materialized View',
  139. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  140. 'page callback' => 'tripal_mview_report',
  141. 'page arguments' => array(5),
  142. 'access arguments' => array('access administration pages'),
  143. 'type' => MENU_NORMAL_ITEM,
  144. );
  145. $items['admin/tripal/views/mviews/new'] = array(
  146. 'title' => 'Create MView',
  147. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  148. 'page callback' => 'drupal_get_form',
  149. 'page arguments' => array('tripal_mviews_form'),
  150. 'access arguments' => array('access administration pages'),
  151. 'type' => MENU_NORMAL_ITEM,
  152. );
  153. $items['admin/tripal/views/mviews/edit/%'] = array(
  154. 'title' => 'Edit MView',
  155. 'page callback' => 'drupal_get_form',
  156. 'page arguments' => array('tripal_mviews_form',5),
  157. 'access arguments' => array('access administration pages'),
  158. 'type' => MENU_NORMAL_ITEM,
  159. );
  160. $items['admin/tripal/views/mviews/action/%/%'] = array(
  161. 'title' => 'Create MView',
  162. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  163. 'page callback' => 'tripal_mviews_action',
  164. 'page arguments' => array(5,6),
  165. 'access arguments' => array('access administration pages'),
  166. 'type' => MENU_CALLBACK,
  167. );
  168. $items['admin/tripal/views/integration'] = array(
  169. 'title' => t('Drupal Views Integration'),
  170. 'description' => t('Allows you to select existing materialized views and provide details for integration with Drupal Views.'),
  171. 'page callback' => 'drupal_get_form',
  172. 'page arguments' => array('tripal_core_views_integration_admin_form'),
  173. 'access arguments' => array('manage tripal_views_integration'),
  174. 'type' => MENU_NORMAL_ITEM,
  175. );
  176. $items['admin/tripal/views/integration/mviews'] = array(
  177. 'title' => t('Integrated MViews'),
  178. 'description' => t('Allows you to select existing materialized views and provide details for integration with Drupal Views.'),
  179. 'page callback' => 'drupal_get_form',
  180. 'page arguments' => array('tripal_core_views_integration_admin_form'),
  181. 'access arguments' => array('manage tripal_views_integration'),
  182. 'type' => MENU_NORMAL_ITEM,
  183. );
  184. //page to actually create setup->mview->chado table relationships
  185. $items['admin/tripal/views/integration/mviews/new'] = array(
  186. 'title' => 'Add an MView',
  187. 'page callback' => 'drupal_get_form',
  188. 'page arguments' => array('tripal_core_views_integration_new_setup_form'),
  189. 'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
  190. 'type' => MENU_NORMAL_ITEM,
  191. );
  192. $items['admin/tripal/views/integration/chado'] = array(
  193. 'title' => t('Integrated Chado Table'),
  194. 'description' => t('Tripal Views Setups settings page, allows you to select and create materialized views and chado tables to use for searches.'),
  195. 'page callback' => 'drupal_get_form',
  196. 'page arguments' => array('tripal_core_views_integration_admin_form'),
  197. 'access arguments' => array('manage tripal_views_integration'),
  198. 'type' => MENU_NORMAL_ITEM,
  199. );
  200. $items['admin/tripal/views/integration/chado/new'] = array(
  201. 'title' => 'Add a Chado table',
  202. 'page callback' => 'drupal_get_form',
  203. 'page arguments' => array('tripal_core_views_integration_new_setup_form'),
  204. 'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
  205. 'type' => MENU_NORMAL_ITEM,
  206. );
  207. return $items;
  208. }
  209. /**
  210. * Set the permission types that the chado module uses. Essentially we
  211. * want permissionis that protect creation, editing and deleting of chado
  212. * data objects
  213. *
  214. * @ingroup tripal_core
  215. */
  216. function tripal_core_perm(){
  217. return array(
  218. 'manage tripal_views_integration',
  219. );
  220. }
  221. /**
  222. *
  223. *
  224. * @param $dbname
  225. * The name of the database to switch to as indicated in settings.php
  226. * Should be either default or chado
  227. *
  228. * @return
  229. * The name of the previously set database
  230. *
  231. * @ingroup tripal_chado_api
  232. */
  233. function tripal_core_is_chado_installed(){
  234. global $db_url, $db_type;
  235. // first check if chado is in the db_url of the
  236. // settings.php file
  237. if(is_array($db_url)){
  238. if(isset($db_url['chado'])){
  239. return true;
  240. }
  241. }
  242. // check to make sure the chado schema exists
  243. $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
  244. if(db_fetch_object(db_query($sql))){
  245. return true;
  246. }
  247. return false;
  248. }
  249. /**
  250. * Implements hook_views_api()
  251. *
  252. * Purpose: Essentially this hook tells drupal that there is views support for
  253. * for this module which then includes tripal_core.views.inc where all the
  254. * views integration code is
  255. *
  256. * @ingroup tripal_core
  257. */
  258. function tripal_core_views_api() {
  259. return array(
  260. 'api' => 2.0,
  261. );
  262. }
  263. /**
  264. *
  265. * @ingroup tripal_core
  266. */
  267. function tripal_core_theme () {
  268. return array(
  269. 'tripal_core_job_view' => array (
  270. 'arguments' => array('job_id'=> null),
  271. 'template' => 'tripal_core_job_view',
  272. ),
  273. 'tripal_views_integration_new_setup_form' => array(
  274. 'arguments' => array('form' => NULL),
  275. 'template' => 'tripal_views_integration_fields_form',
  276. ),
  277. );
  278. }
  279. /**
  280. *
  281. * @ingroup tripal_core
  282. */
  283. function tripal_core_job_describe_args($callback,$args){
  284. $new_args = array();
  285. if($callback == 'tripal_update_mview'){
  286. // get this mview details
  287. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
  288. $mview = db_fetch_object(db_query($sql,$args[0]));
  289. $new_args['View Name'] = $mview->name;
  290. }
  291. return $new_args;
  292. }
  293. // this is just a wrapper for backwards compatibility with a naming mistake.
  294. // it can go away in the future as it only is useful for jobs created by v0.3b
  295. function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0,
  296. $update = 0, $refresh = 0, $remove = 0, $job = NULL)
  297. {
  298. tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only,
  299. $update, $refresh, $remove, $job);
  300. }