tripal_core.module 12 KB

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