tripal_core.module 12 KB

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