tripal_core.module 19 KB

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