tripal_core.module 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php
  2. /**
  3. * @file
  4. * The Tripal Core module
  5. */
  6. /**
  7. * @defgroup tripal_modules Tripal Modules
  8. * @{
  9. * All documented functions for the various Tripal Modules excluding API functions and Views Integration functions.
  10. * @}
  11. */
  12. /**
  13. * @defgroup tripal_api Tripal API
  14. * @{
  15. * Provides an application programming interface (API) for Tripal
  16. *
  17. * The Tripal API currently provides generic insert/update/select functions for all chado content as
  18. * well as some module specific functions that insert/update/delete/select specific chado content.
  19. *
  20. * This API is currently in its infancy and some necessary functions might be missing. If you find
  21. * a missing function that you think should be included go to the sourceforge feature request
  22. * page and request it's inclusion in the API. Such feature requests with a working function
  23. * definition will be given priority.
  24. * @}
  25. */
  26. /**
  27. * @defgroup tripal_core_api Core Module API
  28. * @ingroup tripal_api
  29. */
  30. /**
  31. * @defgroup tripal_core Tripal Core Module
  32. * @ingroup tripal_modules
  33. */
  34. require_once "api/tripal_core_chado.api.inc";
  35. require_once "api/tripal_core_files.api.inc";
  36. require_once "api/tripal_core_ahah.api.inc";
  37. require_once "api/tripal_core_custom_tables.api.inc";
  38. require_once "api/tripal_core_jobs.api.inc";
  39. require_once "api/tripal_core_mviews.api.inc";
  40. require_once "api/tripal_core_misc.api.inc";
  41. require_once "includes/jobs.php";
  42. require_once "includes/mviews.php";
  43. require_once "includes/custom_tables.php";
  44. require_once "includes/chado_install.php";
  45. /**
  46. * Implements hook_init().
  47. * Used to set the search_path, create default content and set default variables.
  48. *
  49. * @ingroup tripal_core
  50. */
  51. function tripal_core_init() {
  52. global $base_url;
  53. // we need to declare here the persistent_chado global variable
  54. global $persistent_chado;
  55. global $prepared_statements;
  56. $persistent_chado = NULL;
  57. $prepared_statements = array();
  58. // add javascript files
  59. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal.ahah.js');
  60. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  61. // only if the chado database is present.
  62. if (tripal_core_is_chado_installed()) {
  63. // make sure the current version of chado is set
  64. tripal_core_set_chado_version();
  65. if (!db_fetch_object(chado_query("SELECT * FROM {cv} WHERE name = 'tripal'"))) {
  66. $results = chado_query(
  67. "INSERT INTO {cv} (name,definition) ".
  68. "VALUES ('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
  69. }
  70. if (!db_fetch_object(chado_query("SELECT * FROM {db} WHERE name = 'tripal'"))) {
  71. $results = chado_query(
  72. "INSERT INTO {db} (name,description) ".
  73. "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')");
  74. }
  75. }
  76. // add some variables for all javasript to use for building URLs
  77. global $base_url;
  78. $theme_dir = drupal_get_path('theme', 'tripal');
  79. $clean_urls = variable_get('clean_url', 0);
  80. drupal_add_js(
  81. " var baseurl = '$base_url';
  82. var themedir = '$theme_dir';
  83. var isClean = $clean_urls;",
  84. 'inline', 'header');
  85. // make sure the date time settings are the way Tripal will insert them
  86. // otherwise PostgreSQL version that may have a different datestyle setting
  87. // will fail when inserting or updating a date column in a table.
  88. db_query("SET DATESTYLE TO '%s'", 'MDY');
  89. // in the event that an errant Tripal or extension function fails to
  90. // set the postgres search_path back to noraml we do it here on
  91. // init of the core
  92. tripal_db_set_default_search_path();
  93. // create a persistent connection
  94. $connection = tripal_db_persistent_chado();
  95. }
  96. /**
  97. * Implements hook_menu().
  98. * Defines all menu items needed by Tripal Core
  99. *
  100. * @ingroup tripal_core
  101. */
  102. function tripal_core_menu() {
  103. $items = array();
  104. // Triapl setting groups
  105. $items['admin/tripal'] = array(
  106. 'title' => 'Tripal Management',
  107. 'description' => "Manage the behavior or Tripal and its various modules.",
  108. 'position' => 'right',
  109. 'weight' => -5,
  110. 'page callback' => 'system_admin_menu_block_page',
  111. 'access arguments' => array('administer site configuration'),
  112. 'file' => 'system.admin.inc',
  113. 'file path' => drupal_get_path('module', 'system'),
  114. );
  115. $items['admin/tripal/customize'] = array(
  116. 'title' => 'Customize Tripal',
  117. 'position' => 'right',
  118. 'page callback' => 'theme',
  119. 'page arguments' => array('tripal_core_customize'),
  120. 'access arguments' => array('administer site configuration'),
  121. );
  122. $items['tripal_toggle_box_menu/%/%/%'] = array(
  123. 'title' => 'Toggle Box',
  124. 'page callback' => 'tripal_toggle_box_menu',
  125. 'page arguments' => array(1, 2, 3),
  126. 'access arguments' => array('access administration pages'),
  127. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  128. );
  129. $items['admin/tripal/chado_install'] = array(
  130. 'title' => 'Install Chado Schema',
  131. 'description' => 'Installs the Chado database tables, views, etc., inside the current Drupal database',
  132. 'page callback' => 'drupal_get_form',
  133. 'page arguments' => array('tripal_core_chado_load_form'),
  134. 'access arguments' => array('install chado'),
  135. 'type' => MENU_NORMAL_ITEM,
  136. );
  137. // Jobs Management
  138. $items['admin/tripal/tripal_jobs'] = array(
  139. 'title' => 'Jobs',
  140. 'description' => 'Jobs managed by Tripal',
  141. 'page callback' => 'tripal_jobs_report',
  142. 'access arguments' => array('access administration pages'),
  143. 'type' => MENU_NORMAL_ITEM,
  144. );
  145. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  146. 'title' => 'Jobs',
  147. 'description' => 'Cancel a pending job',
  148. 'page callback' => 'tripal_jobs_cancel',
  149. 'page arguments' => array(4),
  150. 'access arguments' => array('access administration pages'),
  151. 'type' => MENU_CALLBACK,
  152. );
  153. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  154. 'title' => 'Jobs',
  155. 'description' => 'Re-run an existing job.',
  156. 'page callback' => 'tripal_jobs_rerun',
  157. 'page arguments' => array(4),
  158. 'access arguments' => array('access administration pages'),
  159. 'type' => MENU_CALLBACK,
  160. );
  161. $items['admin/tripal/tripal_jobs/view/%'] = array(
  162. 'title' => 'Jobs Details',
  163. 'description' => 'View job details.',
  164. 'page callback' => 'tripal_jobs_view',
  165. 'page arguments' => array(4),
  166. 'access arguments' => array('access administration pages'),
  167. 'type' => MENU_CALLBACK,
  168. );
  169. // Materialized Views
  170. $items['admin/tripal/mviews'] = array(
  171. 'title' => 'MViews',
  172. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  173. 'page callback' => 'tripal_mviews_report',
  174. 'access arguments' => array('access administration pages'),
  175. 'type' => MENU_NORMAL_ITEM,
  176. );
  177. $items['admin/tripal/mviews/report/%'] = array(
  178. 'title' => 'Materialized View',
  179. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  180. 'page callback' => 'tripal_mview_report',
  181. 'page arguments' => array(4),
  182. 'access arguments' => array('access administration pages'),
  183. 'type' => MENU_NORMAL_ITEM,
  184. );
  185. $items['admin/tripal/mviews/new'] = array(
  186. 'title' => 'Create MView',
  187. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  188. 'page callback' => 'drupal_get_form',
  189. 'page arguments' => array('tripal_mviews_form'),
  190. 'access arguments' => array('access administration pages'),
  191. 'type' => MENU_CALLBACK,
  192. );
  193. $items['admin/tripal/mviews/edit/%'] = array(
  194. 'title' => 'Edit MView',
  195. 'page callback' => 'drupal_get_form',
  196. 'page arguments' => array('tripal_mviews_form', 4),
  197. 'access arguments' => array('access administration pages'),
  198. 'type' => MENU_NORMAL_ITEM,
  199. );
  200. $items['admin/tripal/mviews/action/%/%'] = array(
  201. 'title' => 'Create MView',
  202. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  203. 'page callback' => 'tripal_mviews_action',
  204. 'page arguments' => array(4, 5, "1"),
  205. 'access arguments' => array('access administration pages'),
  206. 'type' => MENU_CALLBACK,
  207. );
  208. // Custom Tables
  209. $items['admin/tripal/custom_tables'] = array(
  210. 'title' => 'Custom Tables',
  211. 'description' => 'Custom tables are added to Chado.',
  212. 'page callback' => 'tripal_custom_tables_list',
  213. 'access arguments' => array('access administration pages'),
  214. 'type' => MENU_NORMAL_ITEM,
  215. );
  216. $items['admin/tripal/custom_tables/view/%'] = array(
  217. 'title' => 'Custom Tables',
  218. 'description' => 'Custom tables are added to Chado.',
  219. 'page callback' => 'tripal_custom_table_view',
  220. 'page arguments' => array(4),
  221. 'access arguments' => array('access administration pages'),
  222. 'type' => MENU_NORMAL_ITEM,
  223. );
  224. $items['admin/tripal/custom_tables/new'] = array(
  225. 'title' => 'Create Custom Table',
  226. 'description' => 'Custom tables are added to Chado.',
  227. 'page callback' => 'drupal_get_form',
  228. 'page arguments' => array('tripal_custom_tables_form'),
  229. 'access arguments' => array('access administration pages'),
  230. 'type' => MENU_CALLBACK,
  231. );
  232. $items['admin/tripal/custom_tables/edit/%'] = array(
  233. 'title' => 'Edit Custom Table',
  234. 'page callback' => 'drupal_get_form',
  235. 'page arguments' => array('tripal_custom_tables_form', 4),
  236. 'access arguments' => array('access administration pages'),
  237. 'type' => MENU_NORMAL_ITEM,
  238. );
  239. $items['admin/tripal/custom_tables/action/%/%'] = array(
  240. 'title' => 'Create Custom TAble',
  241. 'description' => 'Custom tables are added to Chado.',
  242. 'page callback' => 'tripal_custom_tables_action',
  243. 'page arguments' => array(4, 5, "1"),
  244. 'access arguments' => array('access administration pages'),
  245. 'type' => MENU_CALLBACK,
  246. );
  247. return $items;
  248. }
  249. /**
  250. * Set the permission types that the chado module uses. Essentially we
  251. * want permissionis that protect creation, editing and deleting of chado
  252. * data objects
  253. *
  254. * @ingroup tripal_core
  255. */
  256. function tripal_core_perm() {
  257. return array('install chado');
  258. }
  259. /**
  260. * Implements hook_theme().
  261. * Registers template files/functions used by this module.
  262. *
  263. * @ingroup tripal_core
  264. */
  265. function tripal_core_theme() {
  266. return array(
  267. 'tripal_core_job_view' => array(
  268. 'arguments' => array('job_id' => NULL),
  269. 'template' => 'tripal_core_job_view',
  270. ),
  271. 'tripal_core_customize' => array(
  272. 'arguments' => array('job_id' => NULL),
  273. 'template' => 'tripal_core_customize',
  274. 'path' => drupal_get_path('module', 'tripal_core') . '/theme'
  275. ),
  276. );
  277. }
  278. /**
  279. * Implements hook_job_describe_args().
  280. * Describes the arguements for the tripal_update_mview job to allow for greater
  281. * readability in the jobs details pages.
  282. *
  283. * @param $callback
  284. * The callback of the current tripal job (this is the function that will be executed
  285. * when tripal_launch_jobs.php is run.
  286. * @param $args
  287. * An array of arguments passed in when the job was registered.
  288. *
  289. * @return
  290. * A more readable $args array
  291. *
  292. * @ingroup tripal_core
  293. */
  294. function tripal_core_job_describe_args($callback, $args) {
  295. $new_args = array();
  296. if ($callback == 'tripal_update_mview') {
  297. // get this mview details
  298. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
  299. $mview = db_fetch_object(db_query($sql, $args[0]));
  300. $new_args['View Name'] = $mview->name;
  301. }
  302. elseif ($callback == 'tripal_core_install_chado') {
  303. $new_args['Action'] = $args[0];
  304. }
  305. return $new_args;
  306. }
  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. *
  311. * @todo remove this function
  312. */
  313. function tripal_core_load_gff3($gff_file, $organism_id, $analysis_id, $add_only = 0,
  314. $update = 0, $refresh = 0, $remove = 0, $job = NULL) {
  315. tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_only,
  316. $update, $refresh, $remove, $job);
  317. }
  318. /**
  319. * Implements hook_coder_ignore().
  320. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  321. */
  322. function tripal_core_coder_ignore() {
  323. return array(
  324. 'path' => drupal_get_path('module', 'tripal_core'),
  325. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  326. );
  327. }