tripal_core.module 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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_custom_tables.api.inc";
  37. require_once "api/tripal_core_jobs.api.inc";
  38. require_once "api/tripal_core_mviews.api.inc";
  39. require_once "api/tripal_core_misc.api.inc";
  40. require_once "api/tripal_core_properties.api.inc";
  41. require_once "includes/jobs.inc";
  42. require_once "includes/mviews.inc";
  43. require_once "includes/custom_tables.inc";
  44. require_once "includes/chado_install.inc";
  45. require_once "includes/form_elements.inc";
  46. tripal_core_set_globals();
  47. /**
  48. * Implements hook_init().
  49. * Used to set the search_path, create default content and set default variables.
  50. *
  51. * @ingroup tripal_core
  52. */
  53. function tripal_core_init() {
  54. global $base_url;
  55. // add javascript files
  56. drupal_add_js(drupal_get_path('module', 'tripal_core') . '/theme/js/tripal.js');
  57. drupal_add_css(drupal_get_path('module', 'tripal_core') . '/theme/css/tripal.css');
  58. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  59. // only if the chado database is present.
  60. if ($GLOBALS["chado_is_installed"]) {
  61. // if the Tripal cv is missing then add
  62. $results = chado_query("SELECT * FROM {cv} WHERE name = 'tripal'");
  63. $tripal_cv = $results->fetchObject();
  64. if (!$tripal_cv) {
  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. }
  70. // if the Tripal db is missing then add it
  71. $results = chado_query("SELECT * FROM {db} WHERE name = 'tripal'");
  72. $tripal_db = $results->fetchObject();
  73. if (!$tripal_db) {
  74. $results = chado_query(
  75. "INSERT INTO {db} (name,description) " .
  76. "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')"
  77. );
  78. }
  79. }
  80. // add some variables for all javasript to use for building URLs
  81. $theme_dir = drupal_get_path('theme', 'tripal');
  82. $clean_urls = variable_get('clean_url', 0);
  83. drupal_add_js(
  84. " var baseurl = '$base_url';
  85. var themedir = '$theme_dir';
  86. var isClean = $clean_urls;",
  87. 'inline', 'header');
  88. // make sure the date time settings are the way Tripal will insert them
  89. // otherwise PostgreSQL version that may have a different datestyle setting
  90. // will fail when inserting or updating a date column in a table.
  91. db_query("SET DATESTYLE TO :style", array(':style' => 'MDY'));
  92. // If we want AHAH elements on the node forms (e.g. chado_pub form) then we need to include
  93. // the node.pages file. Otherwise this error message is given:
  94. //
  95. // warning: call_user_func_array() expects parameter 1 to be a valid callback,
  96. // function 'node_form' not found or invalid function name
  97. // in /var/www/includes/form.inc on line 382.
  98. module_load_include('inc', 'node', 'node.pages');
  99. }
  100. /**
  101. * Implements hook_menu().
  102. * Defines all menu items needed by Tripal Core
  103. *
  104. * @ingroup tripal_core
  105. */
  106. function tripal_core_menu() {
  107. $items = array();
  108. // Triapl setting groups
  109. $items['admin/tripal'] = array(
  110. 'title' => 'Tripal',
  111. 'description' => "Manage the behavior or Tripal and its various modules.",
  112. 'weight' => -8,
  113. 'page callback' => 'system_admin_menu_block_page',
  114. 'access arguments' => array('administer site configuration'),
  115. 'file' => 'system.admin.inc',
  116. 'file path' => drupal_get_path('module', 'system'),
  117. );
  118. $items['admin/tripal/schema'] = array(
  119. 'title' => 'Chado Schema',
  120. 'description' => "Tools to extend the chado schema through custom tables & materialized views.",
  121. 'weight' => -2,
  122. 'access arguments' => array('administer site configuration'),
  123. );
  124. $items['admin/tripal/chado'] = array(
  125. 'title' => 'Chado Modules',
  126. 'description' => 'Configuration for specific chado data types such as Vocabularies, Features, etc.',
  127. 'access arguments' => array('access administration pages'),
  128. 'type' => MENU_NORMAL_ITEM,
  129. 'weight' => -6
  130. );
  131. $items['admin/tripal/loaders'] = array(
  132. 'title' => 'Chado Data Loaders',
  133. 'description' => 'Tools facilitating loading data into the chado database. Includes a generic tab-delimited loader (Bulk Loader).',
  134. 'access arguments' => array('access administration pages'),
  135. 'type' => MENU_NORMAL_ITEM,
  136. 'weight' => -4
  137. );
  138. $items['admin/tripal/extension'] = array(
  139. 'title' => 'Extension Modules',
  140. 'description' => 'Configuration for Tripal extension modules.',
  141. 'access arguments' => array('access administration pages'),
  142. 'type' => MENU_NORMAL_ITEM,
  143. 'weight' => 0
  144. );
  145. // Tripal Setup
  146. $items['admin/tripal/setup'] = array(
  147. 'title' => 'Setup Tripal',
  148. 'description' => 'Tools for initial setup of Tripal',
  149. 'access arguments' => array('administer site configuration'),
  150. 'weight' => -8
  151. );
  152. $items['admin/tripal/setup/customize'] = array(
  153. 'title' => 'Customize Tripal',
  154. 'description' => 'Information on how to customize tripal',
  155. 'page callback' => 'theme',
  156. 'page arguments' => array('tripal_core_customize'),
  157. 'access arguments' => array('administer site configuration'),
  158. 'weight' => 10
  159. );
  160. $items['admin/tripal/setup/chado_install'] = array(
  161. 'title' => 'Install Chado Schema',
  162. 'description' => 'Installs the Chado database tables, views, etc., inside the current Drupal database',
  163. 'page callback' => 'drupal_get_form',
  164. 'page arguments' => array('tripal_core_chado_load_form'),
  165. 'access arguments' => array('install chado'),
  166. 'type' => MENU_NORMAL_ITEM,
  167. 'weight' => -10
  168. );
  169. // Jobs Management
  170. $items['admin/tripal/tripal_jobs'] = array(
  171. 'title' => 'Jobs',
  172. 'description' => 'Jobs managed by Tripal',
  173. 'page callback' => 'tripal_jobs_admin_view',
  174. 'access arguments' => array('access administration pages'),
  175. 'type' => MENU_NORMAL_ITEM,
  176. 'weight' => -10
  177. );
  178. $items['admin/tripal/tripal_jobs/help'] = array(
  179. 'title' => 'Help',
  180. 'description' => 'Help for the tripal job management system',
  181. 'page callback' => 'theme',
  182. 'page arguments' => array('tripal_core_job_help'),
  183. 'access arguments' => array('access administration pages'),
  184. 'type' => MENU_LOCAL_TASK,
  185. 'weight' => 10
  186. );
  187. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  188. 'title' => 'Jobs',
  189. 'description' => 'Cancel a pending job',
  190. 'page callback' => 'tripal_jobs_cancel',
  191. 'page arguments' => array(4),
  192. 'access arguments' => array('access administration pages'),
  193. 'type' => MENU_CALLBACK,
  194. );
  195. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  196. 'title' => 'Jobs',
  197. 'description' => 'Re-run an existing job.',
  198. 'page callback' => 'tripal_jobs_rerun',
  199. 'page arguments' => array(4),
  200. 'access arguments' => array('access administration pages'),
  201. 'type' => MENU_CALLBACK,
  202. );
  203. $items['admin/tripal/tripal_jobs/view/%'] = array(
  204. 'title' => 'Jobs Details',
  205. 'description' => 'View job details.',
  206. 'page callback' => 'tripal_jobs_view',
  207. 'page arguments' => array(4),
  208. 'access arguments' => array('access administration pages'),
  209. 'type' => MENU_CALLBACK,
  210. );
  211. $items['admin/tripal/tripal_jobs/views/jobs/enable'] = array(
  212. 'title' => 'Enable Jobs Administrative View',
  213. 'page callback' => 'tripal_views_admin_enable_view',
  214. 'page arguments' => array('tripal_core_admin_jobs', 'admin/tripal/tripal_jobs'),
  215. 'access arguments' => array('access administration pages'),
  216. 'type' => MENU_CALLBACK,
  217. );
  218. // Materialized Views
  219. $items['admin/tripal/schema/mviews'] = array(
  220. 'title' => 'Materialized Views',
  221. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  222. 'page callback' => 'tripal_mview_admin_view',
  223. 'access arguments' => array('access administration pages'),
  224. 'type' => MENU_NORMAL_ITEM,
  225. 'weight' => -10
  226. );
  227. $items['admin/tripal/schema/mviews/help'] = array(
  228. 'title' => 'Help',
  229. 'description' => 'Help for the materialized views management system',
  230. 'page callback' => 'theme',
  231. 'page arguments' => array('tripal_core_mviews_help'),
  232. 'access arguments' => array('access administration pages'),
  233. 'type' => MENU_LOCAL_TASK,
  234. 'weight' => 10
  235. );
  236. /**
  237. $items['admin/tripal/schema/mviews/list'] = array(
  238. 'title' => 'List Materialized Views',
  239. 'description' => 'A list of existing materialized views with the ability to edit & delete existing materialized views.',
  240. 'page callback' => 'tripal_mviews_report',
  241. 'access arguments' => array('access administration pages'),
  242. 'type' => MENU_NORMAL_ITEM,
  243. 'weight' => -10
  244. );
  245. */
  246. $items['admin/tripal/schema/mviews/report/%'] = array(
  247. 'title' => 'Materialized View',
  248. 'description' => 'Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.',
  249. 'page callback' => 'tripal_mview_report',
  250. 'page arguments' => array(5),
  251. 'access arguments' => array('access administration pages'),
  252. 'type' => MENU_CALLBACK,
  253. );
  254. $items['admin/tripal/schema/mviews/new'] = array(
  255. 'title' => 'Create Materialized View',
  256. 'description' => 'Create a new materialized view.',
  257. 'page callback' => 'drupal_get_form',
  258. 'page arguments' => array('tripal_mviews_form'),
  259. 'access arguments' => array('access administration pages'),
  260. 'type' => MENU_CALLBACK,
  261. );
  262. $items['admin/tripal/schema/mviews/edit/%'] = array(
  263. 'title' => 'Edit Materialized View',
  264. 'page callback' => 'drupal_get_form',
  265. 'page arguments' => array('tripal_mviews_form', 5),
  266. 'access arguments' => array('access administration pages'),
  267. 'type' => MENU_CALLBACK,
  268. );
  269. $items['admin/tripal/schema/mviews/action/%/%'] = array(
  270. 'title' => 'Create Materialized View',
  271. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  272. 'page callback' => 'tripal_mviews_action',
  273. 'page arguments' => array(5, 6, "1"),
  274. 'access arguments' => array('access administration pages'),
  275. 'type' => MENU_CALLBACK,
  276. );
  277. // Custom Tables
  278. $items['admin/tripal/schema/custom_tables'] = array(
  279. 'title' => 'Custom Tables',
  280. 'description' => 'Creation of custom tables that are added to Chado database.',
  281. 'page callback' => 'tripal_custom_table_admin_view',
  282. 'access arguments' => array('access administration pages'),
  283. 'type' => MENU_NORMAL_ITEM,
  284. 'weight' => -10
  285. );
  286. $items['admin/tripal/schema/custom_tables/help'] = array(
  287. 'title' => 'Help',
  288. 'description' => 'Help for the tripal job management system',
  289. 'page callback' => 'theme',
  290. 'page arguments' => array('tripal_core_job_help'),
  291. 'access arguments' => array('access administration pages'),
  292. 'type' => MENU_LOCAL_TASK,
  293. 'weight' => 10
  294. );
  295. /**
  296. $items['admin/tripal/schema/custom_tables/list'] = array(
  297. 'title' => 'List of Custom Tables',
  298. 'description' => 'Provides a list of all custom tables created by Tripal and allows for editing or removing existing custom tables.',
  299. 'page callback' => 'tripal_custom_tables_list',
  300. 'access arguments' => array('access administration pages'),
  301. 'type' => MENU_NORMAL_ITEM,
  302. 'weight' => -10
  303. );
  304. */
  305. $items['admin/tripal/schema/custom_tables/view/%'] = array(
  306. 'title' => 'Custom Tables',
  307. 'description' => 'Custom tables are added to Chado.',
  308. 'page callback' => 'tripal_custom_table_view',
  309. 'page arguments' => array(4),
  310. 'access arguments' => array('access administration pages'),
  311. 'type' => MENU_CALLBACK,
  312. );
  313. $items['admin/tripal/schema/custom_tables/new'] = array(
  314. 'title' => 'Create Custom Table',
  315. 'description' => 'An interface for creating your own custom tables.',
  316. 'page callback' => 'tripal_custom_table_new_page',
  317. 'access arguments' => array('access administration pages'),
  318. 'type' => MENU_CALLBACK,
  319. );
  320. $items['admin/tripal/schema/custom_tables/edit/%'] = array(
  321. 'title' => 'Edit Custom Table',
  322. 'page callback' => 'drupal_get_form',
  323. 'page arguments' => array('tripal_custom_tables_form', 4),
  324. 'access arguments' => array('access administration pages'),
  325. 'type' => MENU_CALLBACK,
  326. );
  327. $items['admin/tripal/schema/custom_tables/action/%/%'] = array(
  328. 'title' => 'Create Custom Table',
  329. 'description' => 'Custom tables are added to Chado.',
  330. 'page callback' => 'tripal_custom_tables_action',
  331. 'page arguments' => array(4, 5, "1"),
  332. 'access arguments' => array('access administration pages'),
  333. 'type' => MENU_CALLBACK,
  334. );
  335. $items['admin/tripal/schema/custom_tables/views/tables/enable'] = array(
  336. 'title' => 'Enable Custom Tables Administrative View',
  337. 'page callback' => 'tripal_views_admin_enable_view',
  338. 'page arguments' => array('tripal_core_admin_custom_table', 'admin/tripal/schema/custom_tables'),
  339. 'access arguments' => array('access administration pages'),
  340. 'type' => MENU_CALLBACK,
  341. );
  342. return $items;
  343. }
  344. /**
  345. * Set the permission types that the chado module uses. Essentially we
  346. * want permissionis that protect creation, editing and deleting of chado
  347. * data objects
  348. *
  349. * @ingroup tripal_core
  350. */
  351. function tripal_core_permission() {
  352. return array(
  353. 'install chado' => array(
  354. 'title' => t('Install Chado'),
  355. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  356. ),
  357. );
  358. }
  359. /**
  360. * Implements hook_theme().
  361. * Registers template files/functions used by this module.
  362. *
  363. * @ingroup tripal_core
  364. */
  365. function tripal_core_theme($existing, $type, $theme, $path) {
  366. return array(
  367. 'tripal_core_customize' => array(
  368. 'arguments' => array('job_id' => NULL),
  369. 'template' => 'tripal_core_customize',
  370. 'path' => "$path/theme"
  371. ),
  372. 'theme_file_upload_combo' => array(
  373. 'render element' => 'element',
  374. ),
  375. 'theme_sequence_combo' => array(
  376. 'render element' => 'element',
  377. ),
  378. 'tripal_core_jobs_help' => array(
  379. 'template' => 'tripal_core_jobs_help',
  380. 'variables' => array(NULL),
  381. 'path' => "$path/theme"
  382. ),
  383. 'tripal_core_customtables_help' => array(
  384. 'template' => 'tripal_core_customtables_help',
  385. 'variables' => array(NULL),
  386. 'path' => "$path/theme"
  387. ),
  388. // form theme
  389. 'tripal_core_properties_form' => array(
  390. 'render element' => 'form',
  391. ),
  392. );
  393. }
  394. /**
  395. * Implements hook_job_describe_args().
  396. * Describes the arguements for the tripal_update_mview job to allow for greater
  397. * readability in the jobs details pages.
  398. *
  399. * @param $callback
  400. * The callback of the current tripal job (this is the function that will be executed
  401. * when tripal_launch_jobs.php is run.
  402. * @param $args
  403. * An array of arguments passed in when the job was registered.
  404. *
  405. * @return
  406. * A more readable $args array
  407. *
  408. * @ingroup tripal_core
  409. */
  410. function tripal_core_job_describe_args($callback, $args) {
  411. $new_args = array();
  412. if ($callback == 'tripal_update_mview') {
  413. // get this mview details
  414. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  415. $results = db_query($sql, array(':mview_id' => $args[0]));
  416. $mview = $results->fetchObject();
  417. $new_args['View Name'] = $mview->name;
  418. }
  419. elseif ($callback == 'tripal_core_install_chado') {
  420. $new_args['Action'] = $args[0];
  421. }
  422. return $new_args;
  423. }
  424. /**
  425. * this is just a wrapper for backwards compatibility with a naming mistake.
  426. * it can go away in the future as it only is useful for jobs created by v0.3b
  427. *
  428. * @todo remove this function
  429. */
  430. function tripal_core_load_gff3($gff_file, $organism_id, $analysis_id, $add_only = 0,
  431. $update = 0, $refresh = 0, $remove = 0, $job = NULL) {
  432. tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_only,
  433. $update, $refresh, $remove, $job);
  434. }
  435. /**
  436. * Implements hook_coder_ignore().
  437. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  438. */
  439. function tripal_core_coder_ignore() {
  440. return array(
  441. 'path' => drupal_get_path('module', 'tripal_core'),
  442. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  443. );
  444. }
  445. /**
  446. * Implements hook_views_api()
  447. * Purpose: Essentially this hook tells drupal that there is views support for
  448. * for this module which then includes tripal_db.views.inc where all the
  449. * views integration code is
  450. *
  451. * @ingroup tripal_organism
  452. */
  453. function tripal_core_views_api() {
  454. return array(
  455. 'api' => 3.0,
  456. );
  457. }