tripal_core.module 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. require_once "jobs.php";
  3. require_once "mviews.php";
  4. require_once "cvterms.php";
  5. require_once "chado_install.php";
  6. require_once "gff_loader.php";
  7. require_once "bulk_loader.php";
  8. /*************************************************************************
  9. *
  10. */
  11. function tripal_core_init(){
  12. // the two lines below are necessary to ensure that the search_path
  13. // variable is always set. In the case where a view needs to query the
  14. // chado schema when it is local to the Drupal database. Otherwise the
  15. // search_path isn't set. When tripal_db_set_active is called it
  16. // automatically sets the serach path if chado is local to the
  17. // Drupal database
  18. $previous = tripal_db_set_active('chado');
  19. tripal_db_set_active($previous);
  20. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist
  21. $previous_db = tripal_db_set_active('chado'); // use chado database
  22. if(!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))){
  23. $results = db_query("INSERT INTO {cv} (name,definition) ".
  24. "VALUES ('tripal','Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
  25. }
  26. if(!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))){
  27. $results = db_query("INSERT INTO {db} (name,description) ".
  28. "VALUES ('tripal','Used as a database placeholder for tripal defined objects such as tripal cvterms')");
  29. }
  30. tripal_db_set_active($previous_db); // now use drupal database
  31. }
  32. /*************************************************************************
  33. *
  34. */
  35. function tripal_create_moddir($module_name){
  36. // make the data directory for this module
  37. $data_dir = file_directory_path() . "/tripal/$module_name";
  38. if(!file_check_directory($data_dir,FILE_CREATE_DIRECTORY|FILE_MODIFY_PERMISSIONS)){
  39. $message = "Cannot create directory $data_dir. This module may not ".
  40. "behave correctly without this directory. Please create ".
  41. "the directory manually or fix the problem and reinstall.";
  42. drupal_set_message($message,'error');
  43. watchdog('tripal_core',$message,array(),WATCHDOG_ERROR);
  44. }
  45. }
  46. /*************************************************************************
  47. *
  48. */
  49. function tripal_get_moddir($module_name){
  50. $data_dir = file_directory_path() . "/tripal/$module_name";
  51. return $data_dir;
  52. }
  53. /*************************************************************************
  54. *
  55. */
  56. function tripal_core_menu() {
  57. $items = array();
  58. // Triapl setting groups
  59. $items['admin/tripal'] = array(
  60. 'title' => 'Tripal Management',
  61. 'description' => "Manage the behavior or Tripal and its various modules.",
  62. 'position' => 'right',
  63. 'weight' => -5,
  64. 'page callback' => 'system_admin_menu_block_page',
  65. 'access arguments' => array('administer site configuration'),
  66. 'file' => 'system.admin.inc',
  67. 'file path' => drupal_get_path('module', 'system'),
  68. );
  69. // the administative settings menu
  70. /* $items['admin/tripal/tripal_core'] = array(
  71. 'title' => 'Tripal core settings',
  72. 'description' => 'Tripal Settings',
  73. 'page callback' => 'drupal_get_form',
  74. 'page arguments' => array('tripal_core_admin'),
  75. 'access arguments' => array('access administration pages'),
  76. 'type' => MENU_NORMAL_ITEM,
  77. );
  78. */
  79. $items['admin/tripal/tripal_jobs'] = array(
  80. 'title' => 'Jobs',
  81. 'description' => 'Jobs managed by Tripal',
  82. 'page callback' => 'tripal_jobs_report',
  83. 'access arguments' => array('access administration pages'),
  84. 'type' => MENU_NORMAL_ITEM,
  85. );
  86. $items['admin/tripal/tripal_mview/%'] = array(
  87. 'title' => 'Materialized View',
  88. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  89. 'page callback' => 'tripal_mview_report',
  90. 'page arguments' => array(3),
  91. 'access arguments' => array('access administration pages'),
  92. 'type' => MENU_NORMAL_ITEM,
  93. );
  94. $items['admin/tripal/tripal_mviews'] = array(
  95. 'title' => 'Materialized Views',
  96. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  97. 'page callback' => 'tripal_mviews_report',
  98. 'access arguments' => array('access administration pages'),
  99. 'type' => MENU_NORMAL_ITEM,
  100. );
  101. $items['admin/tripal/tripal_mviews/new'] = array(
  102. 'title' => 'Create View',
  103. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  104. 'page callback' => 'drupal_get_form',
  105. 'page arguments' => array('tripal_mviews_form'),
  106. 'access arguments' => array('access administration pages'),
  107. 'type' => MENU_NORMAL_ITEM,
  108. );
  109. $items['admin/tripal/tripal_mviews/edit/%'] = array(
  110. 'title' => 'Edit View',
  111. 'page callback' => 'drupal_get_form',
  112. 'page arguments' => array('tripal_mviews_form',4),
  113. 'access arguments' => array('access administration pages'),
  114. 'type' => MENU_NORMAL_ITEM,
  115. );
  116. $items['admin/tripal/tripal_mviews/action/%/%'] = array(
  117. 'title' => 'Create View',
  118. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  119. 'page callback' => 'tripal_mviews_action',
  120. 'page arguments' => array(4,5),
  121. 'access arguments' => array('access administration pages'),
  122. 'type' => MENU_CALLBACK,
  123. );
  124. $items['tripal_toggle_box_menu/%/%/%'] = array(
  125. 'title' => t('Libraries'),
  126. 'page callback' => 'tripal_toggle_box_menu',
  127. 'page arguments' => array(1,2,3),
  128. 'access arguments' => array('access administration pages'),
  129. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  130. );
  131. $items['admin/tripal/chado_1_11_install'] = array(
  132. 'title' => 'Install Chado v1.11',
  133. 'description' => 'Installs Chado version 1.11 inside the current Drupal database',
  134. 'page callback' => 'drupal_get_form',
  135. 'page arguments' => array('tripal_core_chado_v1_11_load_form'),
  136. 'access arguments' => array('access administration pages'),
  137. 'type' => MENU_NORMAL_ITEM,
  138. );
  139. $items['admin/tripal/gff3_load'] = array(
  140. 'title' => 'Import a GFF3 file',
  141. 'description' => 'Import a GFF3 file into Chado',
  142. 'page callback' => 'drupal_get_form',
  143. 'page arguments' => array('tripal_core_gff3_load_form'),
  144. 'access arguments' => array('access administration pages'),
  145. 'type' => MENU_NORMAL_ITEM,
  146. );
  147. $items['admin/tripal/bulk_load/create'] = array(
  148. 'title' => 'Create Bulk Loader',
  149. 'description' => 'Create a bulk loader template for loading data into Chado',
  150. 'page callback' => 'tripal_core_bulk_loader_create',
  151. 'access arguments' => array('access administration pages'),
  152. 'type' => MENU_NORMAL_ITEM,
  153. );
  154. return $items;
  155. }
  156. /************************************************************************
  157. * The typical display for information on feature, organism, library, etc
  158. * pages is to use the Tripal expandable boxes. However, some sites may
  159. * prefer to use a menu system to keep the pages less cluttered. This
  160. * function provides a common interface for setting a Drupal variable
  161. * that indicates whether or not the content is displayed in a box or as
  162. * a menu item. This function just reverses the setting each time it is
  163. * called
  164. */
  165. function tripal_toggle_box_menu($module,$box_name,$nid){
  166. // if the content is not in a menu then we wnat to turn on the
  167. // menu. If the content is in a menu item then we want to turn
  168. // on the box.
  169. if(strcmp(variable_get("$module-box-$box_name","menu_off"),"menu_off")==0){
  170. variable_set("$module-box-$box_name","menu_on");
  171. } else {
  172. variable_set("$module-box-$box_name","menu_off");
  173. }
  174. drupal_goto("node/$nid");
  175. }
  176. /************************************************************************
  177. *
  178. */
  179. function tripal_core_admin () {
  180. $form['chado_feature_data_url'] = array (
  181. '#title' => t('URL for data files'),
  182. '#type' => t('textfield'),
  183. '#description' => t("This is the base URL location (without a leading forward slash) for where files (e.g. blast .xml files) related to each feature are stored. All files available for download or parsing that a feature needs for display should be located in this base directory."),
  184. '#required' => TRUE,
  185. '#default_value' => variable_get('chado_feature_data_url','sites/default/files/data'),
  186. );
  187. return system_settings_form($form);
  188. }
  189. /************************************************************************
  190. * The tripal_db_set_active function is used to prevent namespace collisions
  191. * when chado and drupal are installed in the same database but in different
  192. * schemas. It is also used for backwards compatibility with older versions
  193. * of tripal or in cases where chado is located outside of the Drupal database.
  194. */
  195. function tripal_db_set_active($dbname){
  196. global $db_url, $db_type;
  197. $chado_exists = 0;
  198. // only postgres can support search paths. So if this is MysQL then
  199. // just run the normal tripal_db_set_active function.
  200. if(strcmp($db_type,'pgsql')==0){
  201. // if the 'chado' database is in the $db_url variable then chado is
  202. // not in the same Drupal database
  203. if(is_array($db_url)){
  204. if(isset($db_url[$dbname])){
  205. return db_set_active($dbname);
  206. }
  207. }
  208. // check to make sure the chado schema exists
  209. $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
  210. if(db_fetch_object(db_query($sql))){
  211. $chado_exists = 1;
  212. }
  213. // here we make the assumption that the default database schema is
  214. // 'public'. This will most likely always be the case but if not,
  215. // then this code will break
  216. if($chado_exists && strcmp($dbname,'chado')==0){
  217. db_query("set search_path to %s",'chado,public');
  218. return 'public,chado';
  219. }
  220. elseif($chado_exists) {
  221. db_query("set search_path to %s",'public,chado');
  222. return 'chado,public';
  223. }
  224. else {
  225. return db_set_active($dbname);
  226. }
  227. }
  228. else return db_set_active($dbname);
  229. }
  230. /*************************************************************************
  231. * Implements hook_views_api()
  232. * Purpose: Essentially this hook tells drupal that there is views support for
  233. * for this module which then includes tripal_core.views.inc where all the
  234. * views integration code is
  235. */
  236. function tripal_core_views_api() {
  237. return array(
  238. 'api' => 2.0,
  239. );
  240. }