tripal_core.module 18 KB

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