tripal_chado.module 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. <?php
  2. //
  3. // APPLICATION PROGRAMMER INTERFACE
  4. //
  5. // Generic Chado API functions
  6. require_once "api/tripal_chado.api.inc";
  7. require_once 'api/tripal_chado.property.api.inc';
  8. require_once 'api/tripal_chado.query.api.inc';
  9. require_once 'api/tripal_chado.variables.api.inc';
  10. require_once 'api/tripal_chado.schema.api.inc';
  11. require_once 'api/tripal_chado.custom_tables.api.inc';
  12. require_once 'api/tripal_chado.mviews.api.inc';
  13. require_once 'api/tripal_chado.schema_v1.3.api.inc';
  14. require_once 'api/tripal_chado.schema_v1.2.api.inc';
  15. require_once 'api/tripal_chado.schema_v1.11.api.inc';
  16. // Chado module specific API functions
  17. require_once 'api/modules/tripal_chado.analysis.api.inc';
  18. require_once 'api/modules/tripal_chado.contact.api.inc';
  19. require_once 'api/modules/tripal_chado.cv.api.inc';
  20. require_once 'api/modules/tripal_chado.db.api.inc';
  21. require_once 'api/modules/tripal_chado.feature.api.inc';
  22. require_once 'api/modules/tripal_chado.organism.api.inc';
  23. require_once 'api/modules/tripal_chado.pub.api.inc';
  24. require_once 'api/modules/tripal_chado.stock.api.inc';
  25. //
  26. // REQUIRED INCLUDE FILES
  27. //
  28. // These require files implement hooks and therefore must
  29. // ways be included when the module is interpreted.
  30. require_once "includes/tripal_chado.entity.inc";
  31. require_once "includes/tripal_chado.schema.inc";
  32. require_once "includes/tripal_chado.term_storage.inc";
  33. require_once "includes/tripal_chado.field_storage.inc";
  34. require_once "includes/tripal_chado.fields.inc";
  35. tripal_chado_set_globals();
  36. /**
  37. * This function is used to set the global Chado variables
  38. *
  39. * @ingroup tripal_chado
  40. */
  41. function tripal_chado_set_globals() {
  42. // these global variables are meant to be accessed by all Tripal
  43. // modules to find the chado version installed and if Chado is local.
  44. // these variables are stored as globals rather than using the drupal_set_variable
  45. // functions because the Drupal functions make databaes queries and for long
  46. // running loaders we don't want those queries repeatedly.
  47. $GLOBALS["chado_is_installed"] = chado_is_installed();
  48. if ($GLOBALS["chado_is_installed"]) {
  49. $GLOBALS["chado_is_local"] = chado_is_local();
  50. $GLOBALS["chado_version"] = chado_get_version();
  51. $GLOBALS["exact_chado_version"] = chado_get_version(TRUE);
  52. }
  53. }
  54. /**
  55. * Implements hook_init().
  56. * Used to set the search_path, create default content and set default variables.
  57. *
  58. * @ingroup tripal_chado
  59. */
  60. function tripal_chado_init() {
  61. if (user_access('administer tripal')) {
  62. if ($GLOBALS["chado_is_installed"]) {
  63. // Check to see if the Chado and Drupal have been prepared
  64. if (!variable_get('tripal_chado_is_prepared', FALSE)) {
  65. drupal_set_message('Chado is installed but Tripal has not yet prepared Drupal and Chado. Please ' .
  66. l('prepare both Drupal and Chado', 'admin/tripal/storage/chado/chado_prepare') .
  67. ' before continuing.', 'warning');
  68. }
  69. }
  70. else {
  71. drupal_set_message('Tripal cannot find a Chado installation. Please ' .
  72. l('install Chado', 'admin/tripal/storage/chado/chado_install') .
  73. ' before continuing.', 'warning');
  74. }
  75. }
  76. }
  77. /**
  78. * Implements hook_views_api().
  79. *
  80. * Essentially this hook tells drupal that there is views support for
  81. * for this module which then includes tripal_db.views.inc where all the
  82. * views integration code is
  83. *
  84. * @ingroup tripal_feature
  85. */
  86. function tripal_chado_views_api() {
  87. return array(
  88. 'api' => 3.0,
  89. );
  90. }
  91. /**
  92. * Implements hook_menu().
  93. */
  94. function tripal_chado_menu() {
  95. $items = array();
  96. //////////////////////////////////////////////////////////////////////////////
  97. // Chado Storage Backend
  98. //////////////////////////////////////////////////////////////////////////////
  99. $items['admin/tripal/storage/chado'] = array(
  100. 'title' => 'Chado',
  101. 'description' => t("Integrates Chado with Tripal and includes tools to
  102. load data, and extend the chado schema through custom tables &
  103. materialized views."),
  104. 'weight' => -100,
  105. 'access arguments' => array('administer tripal'),
  106. );
  107. $items['admin/tripal/storage/chado/chado_install'] = array(
  108. 'title' => 'Install Chado',
  109. 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'),
  110. 'page callback' => 'drupal_get_form',
  111. 'page arguments' => array('tripal_chado_install_form'),
  112. 'type' => MENU_NORMAL_ITEM,
  113. 'access arguments' => array('install chado'),
  114. 'file' => 'includes/tripal_chado.install.inc',
  115. 'file path' => drupal_get_path('module', 'tripal_chado'),
  116. 'weight' => -100
  117. );
  118. $items['admin/tripal/storage/chado/chado_prepare'] = array(
  119. 'title' => 'Prepare Chado',
  120. 'description' => t('Prepares Drupal to use Chado.'),
  121. 'page callback' => 'drupal_get_form',
  122. 'page arguments' => array('tripal_chado_prepare_form'),
  123. 'type' => MENU_NORMAL_ITEM,
  124. 'access arguments' => array('install chado'),
  125. 'file' => 'includes/tripal_chado.setup.inc',
  126. 'file path' => drupal_get_path('module', 'tripal_chado'),
  127. 'weight' => -99
  128. );
  129. $items['admin/tripal/storage/chado/publish'] = array(
  130. 'title' => 'Publish',
  131. 'description' => t('Publish data that is present in Chado but which does
  132. not yet have a page on this site for viewing. In Tripal v2.0 or
  133. earlier this was refered to as "syncing".'),
  134. 'page callback' => 'drupal_get_form',
  135. 'page arguments' => array('tripal_chado_publish_form'),
  136. 'type' => MENU_NORMAL_ITEM,
  137. 'access arguments' => array('administer tripal'),
  138. 'file' => 'includes/tripal_chado.publish.inc',
  139. 'file path' => drupal_get_path('module', 'tripal_chado'),
  140. 'weight' => -99
  141. );
  142. $items['admin/structure/bio_data/publish'] = array(
  143. 'title' => 'Publish Chado Content',
  144. 'description' => t('Publish data that is present in Chado but which does
  145. not yet have a page on this site for viewing. In Tripal v2.0 or
  146. earlier this was refered to as "syncing".'), 'page callback' => 'drupal_get_form',
  147. 'page callback' => 'drupal_get_form',
  148. 'page arguments' => array('tripal_chado_publish_form'),
  149. 'access arguments' => array('administer tripal'),
  150. 'file' => 'includes/tripal_chado.publish.inc',
  151. 'file path' => drupal_get_path('module', 'tripal_chado'),
  152. 'type' => MENU_LOCAL_ACTION,
  153. 'weight' => 2
  154. );
  155. //////////////////////////////////////////////////////////////////////////////
  156. // Materialized Views
  157. //////////////////////////////////////////////////////////////////////////////
  158. $items['admin/tripal/storage/chado/mviews'] = array(
  159. 'title' => 'Materialized Views',
  160. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  161. 'page callback' => 'tripal_mview_admin_view',
  162. 'access arguments' => array('administer tripal'),
  163. 'type' => MENU_NORMAL_ITEM,
  164. 'file' => 'includes/tripal_chado.mviews.inc',
  165. 'file path' => drupal_get_path('module', 'tripal_chado'),
  166. 'weight' => -10
  167. );
  168. $items['admin/tripal/storage/chado/mviews/help'] = array(
  169. 'title' => 'Help',
  170. 'description' => t('Help for the materialized views management system'),
  171. 'page callback' => 'theme',
  172. 'page arguments' => array('tripal_mviews_help'),
  173. 'access arguments' => array('administer tripal'),
  174. 'type' => MENU_LOCAL_TASK,
  175. 'file' => 'includes/tripal_chado.mviews.inc',
  176. 'file path' => drupal_get_path('module', 'tripal_chado'),
  177. 'weight' => 10
  178. );
  179. $items['admin/tripal/storage/chado/mviews/report/%'] = array(
  180. 'title' => 'Materialized View',
  181. 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'),
  182. 'page callback' => 'tripal_mview_report',
  183. 'page arguments' => array(6),
  184. 'access arguments' => array('administer tripal'),
  185. 'type' => MENU_CALLBACK,
  186. 'file' => 'includes/tripal_chado.mviews.inc',
  187. 'file path' => drupal_get_path('module', 'tripal_chado'),
  188. );
  189. $items['admin/tripal/storage/chado/mviews/new'] = array(
  190. 'title' => 'Create Materialized View',
  191. 'description' => t('Create a new materialized view.'),
  192. 'page callback' => 'drupal_get_form',
  193. 'page arguments' => array('tripal_mviews_form'),
  194. 'access arguments' => array('administer tripal'),
  195. 'type' => MENU_CALLBACK,
  196. 'file' => 'includes/tripal_chado.mviews.inc',
  197. 'file path' => drupal_get_path('module', 'tripal_chado'),
  198. );
  199. $items['admin/tripal/storage/chado/mviews/edit/%'] = array(
  200. 'title' => 'Edit Materialized View',
  201. 'page callback' => 'drupal_get_form',
  202. 'page arguments' => array('tripal_mviews_form', 6),
  203. 'access arguments' => array('administer tripal'),
  204. 'type' => MENU_CALLBACK,
  205. 'file' => 'includes/tripal_chado.mviews.inc',
  206. 'file path' => drupal_get_path('module', 'tripal_chado'),
  207. );
  208. $items['admin/tripal/storage/chado/mviews/update/%'] = array(
  209. 'title' => 'Create Materialized View',
  210. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  211. 'page callback' => 'tripal_mviews_add_populate_job',
  212. 'page arguments' => array(6),
  213. 'access arguments' => array('administer tripal'),
  214. 'type' => MENU_CALLBACK,
  215. 'file' => 'includes/tripal_chado.mviews.inc',
  216. 'file path' => drupal_get_path('module', 'tripal_chado'),
  217. );
  218. $items['admin/tripal/storage/chado/mviews/delete/%'] = array(
  219. 'title' => 'Create Materialized View',
  220. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  221. 'page callback' => 'drupal_get_form',
  222. 'page arguments' => array('tripal_mviews_delete_form', 5),
  223. 'access arguments' => array('administer tripal'),
  224. 'type' => MENU_CALLBACK,
  225. 'file' => 'includes/tripal_chado.mviews.inc',
  226. 'file path' => drupal_get_path('module', 'tripal_chado'),
  227. );
  228. // TODO: complete the code for exporting and importing of MViews.
  229. // Need to address security issues of sharing SQL.
  230. $items['admin/tripal/storage/chado/mviews/import'] = array(
  231. 'title' => 'Import MView',
  232. 'description' => 'Import a materialized view from another Tripal instance.',
  233. 'page callback' => 'drupal_get_form',
  234. 'page arguments' => array('tripal_mviews_import_form'),
  235. 'access arguments' => array('administer tripal'),
  236. 'type' => MENU_CALLBACK,
  237. 'file' => 'includes/tripal_chado.mviews.inc',
  238. 'file path' => drupal_get_path('module', 'tripal_chado'),
  239. );
  240. $items['admin/tripal/storage/chado/mviews/%tblid/export'] = array(
  241. 'title' => 'Export MView',
  242. 'description' => 'Export a materialized view for use by another Tripal instance.',
  243. 'page callback' => 'drupal_get_form',
  244. 'page arguments' => array('tripal_mviews_export_form', 5),
  245. 'access arguments' => array('administer tripal'),
  246. 'type' => MENU_CALLBACK,
  247. 'file' => 'includes/tripal_chado.mviews.inc',
  248. 'file path' => drupal_get_path('module', 'tripal_chado'),
  249. );
  250. //////////////////////////////////////////////////////////////////////////////
  251. // Custom Tables
  252. //////////////////////////////////////////////////////////////////////////////
  253. $items['admin/tripal/storage/chado/custom_tables'] = array(
  254. 'title' => 'Custom Tables',
  255. 'description' => t('Creation of custom tables that are added to Chado database.'),
  256. 'page callback' => 'tripal_custom_table_admin_view',
  257. 'access arguments' => array('administer tripal'),
  258. 'type' => MENU_NORMAL_ITEM,
  259. 'file' => 'includes/tripal_chado.custom_tables.inc',
  260. 'file path' => drupal_get_path('module', 'tripal_chado'),
  261. 'weight' => -10
  262. );
  263. $items['admin/tripal/storage/chado/custom_tables/help'] = array(
  264. 'title' => 'Help',
  265. 'description' => t('Help for the tripal job management system'),
  266. 'page callback' => 'theme',
  267. 'page arguments' => array('tripal_job_help'),
  268. 'access arguments' => array('administer tripal'),
  269. 'type' => MENU_LOCAL_TASK,
  270. 'file' => 'includes/tripal_chado.custom_tables.inc',
  271. 'file path' => drupal_get_path('module', 'tripal_chado'),
  272. 'weight' => 10
  273. );
  274. $items['admin/tripal/storage/chado/custom_tables/view/%'] = array(
  275. 'title' => 'Custom Tables',
  276. 'description' => t('Custom tables are added to Chado.'),
  277. 'page callback' => 'tripal_custom_table_view',
  278. 'page arguments' => array(6),
  279. 'access arguments' => array('administer tripal'),
  280. 'file' => 'includes/tripal_chado.custom_tables.inc',
  281. 'file path' => drupal_get_path('module', 'tripal_chado'),
  282. 'type' => MENU_CALLBACK,
  283. );
  284. $items['admin/tripal/storage/chado/custom_tables/new'] = array(
  285. 'title' => 'Create Custom Table',
  286. 'description' => t('An interface for creating your own custom tables.'),
  287. 'page callback' => 'tripal_custom_table_new_page',
  288. 'access arguments' => array('administer tripal'),
  289. 'file' => 'includes/tripal_chado.custom_tables.inc',
  290. 'file path' => drupal_get_path('module', 'tripal_chado'),
  291. 'type' => MENU_CALLBACK,
  292. );
  293. $items['admin/tripal/storage/chado/custom_tables/edit/%'] = array(
  294. 'title' => 'Edit Custom Table',
  295. 'page callback' => 'drupal_get_form',
  296. 'page arguments' => array('tripal_custom_tables_form', 6),
  297. 'access arguments' => array('administer tripal'),
  298. 'file' => 'includes/tripal_chado.custom_tables.inc',
  299. 'file path' => drupal_get_path('module', 'tripal_chado'),
  300. 'type' => MENU_CALLBACK,
  301. );
  302. $items['admin/tripal/storage/chado/custom_tables/delete/%'] = array(
  303. 'title' => 'Create Custom Table',
  304. 'description' => t('Custom tables are added to Chado.'),
  305. 'page callback' => 'drupal_get_form',
  306. 'page arguments' => array('tripal_custom_tables_delete_form', 6),
  307. 'access arguments' => array('administer tripal'),
  308. 'file' => 'includes/tripal_chado.custom_tables.inc',
  309. 'file path' => drupal_get_path('module', 'tripal_chado'),
  310. 'type' => MENU_CALLBACK,
  311. );
  312. $items['admin/tripal/storage/chado/custom_tables/views/tables/enable'] = array(
  313. 'title' => 'Enable Custom Tables Administrative View',
  314. 'page callback' => 'tripal_enable_view',
  315. 'page arguments' => array('tripal_admin_custom_table', 'admin/tripal/storage/chado/custom_tables'),
  316. 'access arguments' => array('administer tripal'),
  317. 'file' => 'includes/tripal_chado.custom_tables.inc',
  318. 'file path' => drupal_get_path('module', 'tripal_chado'),
  319. 'type' => MENU_CALLBACK,
  320. );
  321. //////////////////////////////////////////////////////////////////////////////
  322. // Data Loaders
  323. //////////////////////////////////////////////////////////////////////////////
  324. $items['admin/tripal/storage/chado/loaders'] = array(
  325. 'title' => 'Data Loaders',
  326. 'description' => t('Tools facilitating data import.'),
  327. 'access arguments' => array('administer tripal'),
  328. 'type' => MENU_NORMAL_ITEM,
  329. 'weight' => 6
  330. );
  331. $items['admin/tripal/storage/chado/loaders/fasta_loader'] = array(
  332. 'title' => 'FASTA file Loader',
  333. 'description' => 'Load sequences from a multi-FASTA file into Chado',
  334. 'page callback' => 'drupal_get_form',
  335. 'page arguments' => array('tripal_feature_fasta_load_form'),
  336. 'access arguments' => array('administer tripal feature'),
  337. 'file' => 'includes/loaders/tripal_chado.fasta_loader.inc',
  338. 'file path' => drupal_get_path('module', 'tripal_chado'),
  339. 'type' => MENU_NORMAL_ITEM,
  340. );
  341. $items['admin/tripal/storage/chado/loaders/gff3_load'] = array(
  342. 'title' => 'GFF3 file Loader',
  343. 'description' => 'Import a GFF3 file into Chado',
  344. 'page callback' => 'drupal_get_form',
  345. 'page arguments' => array('tripal_feature_gff3_load_form'),
  346. 'access arguments' => array('administer tripal feature'),
  347. 'file' => 'includes/loaders/tripal_chado.gff_loader.inc',
  348. 'file path' => drupal_get_path('module', 'tripal_chado'),
  349. 'type' => MENU_NORMAL_ITEM,
  350. );
  351. $items['admin/tripal/storage/chado/loaders/pub'] = array(
  352. 'title' => t('Publication Importers'),
  353. 'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
  354. 'page callback' => 'tripal_pub_importers_list',
  355. 'access arguments' => array('administer tripal pub'),
  356. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  357. 'file path' => drupal_get_path('module', 'tripal_chado'),
  358. 'type' => MENU_NORMAL_ITEM,
  359. 'weight' => 0
  360. );
  361. $items['admin/tripal/storage/chado/loaders/pub/new'] = array(
  362. 'title' => t('Add an Importer'),
  363. 'description' => t('Add a new publication importer.'),
  364. 'page callback' => 'tripal_pub_importer_setup_page',
  365. 'access arguments' => array('administer tripal pub'),
  366. 'type ' => MENU_CALLBACK,
  367. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  368. 'file path' => drupal_get_path('module', 'tripal_chado'),
  369. );
  370. $items['admin/tripal/storage/chado/loaders/pub/edit/%'] = array(
  371. 'page callback' => 'tripal_pub_importer_setup_page',
  372. 'page arguments' => array(6, 7),
  373. 'access arguments' => array('administer tripal pub'),
  374. 'type ' => MENU_CALLBACK,
  375. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  376. 'file path' => drupal_get_path('module', 'tripal_chado'),
  377. );
  378. $items['admin/tripal/storage/chado/loaders/pub/raw/%'] = array(
  379. 'title' => t('Raw Data From Publication Import'),
  380. 'page callback' => 'tripal_get_remote_pub_raw_page',
  381. 'page arguments' => array(6),
  382. 'access arguments' => array('administer tripal pub'),
  383. 'type ' => MENU_CALLBACK,
  384. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  385. 'file path' => drupal_get_path('module', 'tripal_chado'),
  386. );
  387. // add a second link for the importer on the data loaders page
  388. $items['admin/tripal/storage/chado/loaders/pub/import'] = array(
  389. 'title' => t('Publication Importers'),
  390. 'page callback' => 'tripal_pub_importers_list',
  391. 'access arguments' => array('administer tripal pub'),
  392. 'type' => MENU_CALLBACK,
  393. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  394. 'file path' => drupal_get_path('module', 'tripal_chado'),
  395. );
  396. $items['admin/tripal/storage/chado/loaders/pub/submit/%'] = array(
  397. 'page callback' => 'tripal_pub_importer_submit_job',
  398. 'page arguments' => array(7),
  399. 'access arguments' => array('administer tripal pub'),
  400. 'type ' => MENU_CALLBACK,
  401. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  402. 'file path' => drupal_get_path('module', 'tripal_chado'),
  403. );
  404. $items['admin/tripal/storage/chado/loaders/pub/delete/%'] = array(
  405. 'page callback' => 'tripal_pub_importer_delete',
  406. 'page arguments' => array(7),
  407. 'access arguments' => array('administer tripal pub'),
  408. 'type ' => MENU_CALLBACK,
  409. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  410. 'file path' => drupal_get_path('module', 'tripal_chado'),
  411. );
  412. $items['admin/tripal/storage/chado/loaders/pub/changedb'] = array(
  413. 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
  414. 'page arguments' => array(),
  415. 'access arguments' => array('administer tripal pub'),
  416. 'type ' => MENU_CALLBACK,
  417. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  418. 'file path' => drupal_get_path('module', 'tripal_chado'),
  419. );
  420. $items['admin/tripal/storage/chado/loaders/pub/criteria/%/%'] = array(
  421. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  422. 'page arguments' => array(7, 8),
  423. 'access arguments' => array('administer tripal pub'),
  424. 'type ' => MENU_CALLBACK,
  425. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  426. 'file path' => drupal_get_path('module', 'tripal_chado'),
  427. );
  428. //////////////////////////////////////////////////////////////////////////////
  429. // Migrate Content
  430. //////////////////////////////////////////////////////////////////////////////
  431. $items['admin/tripal/storage/chado/migrate'] = array(
  432. 'title' => 'Migrate',
  433. 'description' => t('Migrate Tripal v2 content to Tripal v3'),
  434. 'page callback' => 'drupal_get_form',
  435. 'page arguments' => array('tripal_chado_migrate_form'),
  436. 'type' => MENU_NORMAL_ITEM,
  437. 'access arguments' => array('administer tripal'),
  438. 'file' => 'includes/tripal_chado.migrate.inc',
  439. 'file path' => drupal_get_path('module', 'tripal_chado'),
  440. 'weight' => 10
  441. );
  442. //////////////////////////////////////////////////////////////////////////////
  443. // Auto Completes
  444. //////////////////////////////////////////////////////////////////////////////
  445. $items['admin/tripal/storage/chado/auto_name/dbxref/%/%'] = array(
  446. 'page callback' => 'tripal_autocomplete_dbxref',
  447. 'page arguments' => array(6, 7),
  448. 'access arguments' => array('access content'),
  449. 'file' => 'api/modules/tripal_chado.db.api.inc',
  450. 'file path' => drupal_get_path('module', 'tripal_chado'),
  451. 'type' => MENU_CALLBACK,
  452. );
  453. $items['admin/tripal/storage/chado/auto_name/cvterm/%/%'] = array(
  454. 'page callback' => 'tripal_autocomplete_cvterm',
  455. 'page arguments' => array(6, 7),
  456. 'access arguments' => array('access content'),
  457. 'file' => 'api/modules/tripal_chado.db.api.inc',
  458. 'file path' => drupal_get_path('module', 'tripal_chado'),
  459. 'type' => MENU_CALLBACK,
  460. );
  461. $items['admin/tripal/storage/chado/auto_name/pub/%'] = array(
  462. 'page callback' => 'tripal_autocomplete_pub',
  463. 'page arguments' => array(6),
  464. 'access arguments' => array('access content'),
  465. 'file' => 'api/modules/tripal_chado.pub.api.inc',
  466. 'file path' => drupal_get_path('module', 'tripal_chado'),
  467. 'type' => MENU_CALLBACK,
  468. );
  469. return $items;
  470. }
  471. /**
  472. * Implements hook_permission().
  473. *
  474. * Set the permission types that the chado module uses. Essentially we
  475. * want permissionis that protect creation, editing and deleting of chado
  476. * data objects
  477. *
  478. * @ingroup tripal
  479. */
  480. function tripal_chado_permission() {
  481. return array(
  482. 'install chado' => array(
  483. 'title' => t('Install Chado'),
  484. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  485. ),
  486. 'view chado_ids' => array(
  487. 'title' => t('View Internal IDs'),
  488. 'description' => t('On content pages Tripal will typically provide
  489. a table of information pulled from the Chado database but the
  490. primary key IDs for that data is typically not shown. The
  491. default Tripal templates can show the primary key ID inside of a
  492. blue shaded table row if this permission is enabled. This can
  493. be useful for site developers who might want these IDs when working
  494. with the underlying database.'),
  495. 'restrict access' => TRUE,
  496. )
  497. );
  498. }
  499. /**
  500. * Implements hook_theme().
  501. */
  502. function tripal_chado_theme($existing, $type, $theme, $path) {
  503. $themes = array(
  504. // Theme fields.
  505. 'chado_base__dbxref_id_widget' => array(
  506. 'render element' => 'element',
  507. 'file' => 'includes/fields/chado_base__dbxref_id.inc',
  508. ),
  509. 'chado_linker__dbxref_widget' => array(
  510. 'render element' => 'element',
  511. 'file' => 'includes/fields/chado_linker__dbxref.inc',
  512. ),
  513. 'chado_linker__cvterm_widget' => array(
  514. 'render element' => 'element',
  515. 'file' => 'includes/fields/chado_linker__cvterm.inc',
  516. ),
  517. 'chado_linker__synonym_widget' => array(
  518. 'render element' => 'element',
  519. 'file' => 'includes/fields/chado_linker__synonym.inc',
  520. ),
  521. 'chado_linker__pub_widget' => array(
  522. 'render element' => 'element',
  523. 'file' => 'includes/fields/chado_linker__pub.inc',
  524. ),
  525. 'chado_linker__prop_adder_widget' => array(
  526. 'render element' => 'element',
  527. 'file' => 'includes/fields/chado_linker__prop_adder.inc',
  528. ),
  529. 'tripal_chado_date_combo' => array(
  530. 'render element' => 'element',
  531. 'file' => 'theme/tripal_chado.theme.inc',
  532. ),
  533. // Themed forms
  534. 'tripal_pub_importer_setup_form_elements' => array(
  535. 'render element' => 'form',
  536. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  537. ),
  538. 'tripal_pub_search_setup_form_elements' => array(
  539. 'render element' => 'form',
  540. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  541. ),
  542. );
  543. // Override the theme for each entity to use the legacy modules
  544. // templates.
  545. if (module_exists('tripal_core')) {
  546. $core_path = drupal_get_path('module', 'tripal_core');
  547. // Get the list of node types that have legacy templates.
  548. $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates', array());
  549. // Get the list of TripalEntity bundle.
  550. $bundles = db_select('tripal_bundle', 'tb')
  551. ->fields('tb')
  552. ->execute();
  553. // Iterate through all of the TripalEntity bundles and see which ones
  554. // map to tables that used had Tripal v2 nodes. For those, if the
  555. // legacy support is turned on then we want to use the legacy template.
  556. while ($bundle = $bundles->fetchObject()) {
  557. $chado_table = tripal_get_bundle_variable('chado_table', $bundle->id);
  558. $legacy_template = 'legacy_template--chado_' . $chado_table;
  559. if (key_exists($legacy_template, $enabled_templates) && $enabled_templates[$legacy_template]) {
  560. $themes['TripalEntity__' . $bundle->name] = array(
  561. 'template' => 'node--chado-generic',
  562. 'render element' => 'entity',
  563. 'base hook' => 'entity',
  564. 'path' => "$core_path/theme/templates",
  565. );
  566. }
  567. }
  568. }
  569. return $themes;
  570. }
  571. /**
  572. * Implements hook_preprocess().
  573. *
  574. * This function is used to support legacy Tripal v2 templates
  575. * for use with Tripal v3 entities.
  576. */
  577. function tripal_chado_preprocess(&$variables, $hook) {
  578. if ($hook == 'entity' and array_key_exists('TripalEntity', $variables)) {
  579. // The node--chado-generic template expets there to be a
  580. // teaser and node variables. So, we'll add them.
  581. $variables['teaser'] = FALSE;
  582. $variables['node'] = $variables['TripalEntity'];
  583. }
  584. }
  585. /**
  586. * Implements hook_exclude_type_by_default()
  587. *
  588. * This hooks allows fields of a specified type that match a specified criteria
  589. * to be excluded by default from any table when chado_generate_var() is called.
  590. * Keep in mind that if fields are excluded by default they can always be
  591. * expanded at a later date using chado_expand_var().
  592. *
  593. * Criteria are php strings that evaluate to either TRUE or FALSE. These
  594. * strings are evaluated using drupal_eval() which suppresses syntax errors and
  595. * throws watchdog entries of type php. There are also watchdog entries of type
  596. * tripal stating the exact criteria evaluated. Criteria can
  597. * contain the following tokens:
  598. * - <field_name>
  599. * Replaced by the name of the field to be excluded
  600. * - <field_value>
  601. * Replaced by the value of the field in the current record
  602. * Also keep in mind that if your criteria doesn't contain the
  603. * &gt;field_value&lt; token then it will be evaluated before the query is
  604. * executed and if the field is excluded it won't be included in the
  605. * query.
  606. *
  607. * @return
  608. * An array of type => criteria where the type is excluded if the criteria
  609. * evaluates to TRUE
  610. *
  611. * @ingroup tripal
  612. */
  613. function tripal_chado_exclude_type_by_default() {
  614. return array('text' => 'strlen("<field_value> ") > 250');
  615. }
  616. /**
  617. * Implements hook_job_describe_args().
  618. *
  619. * Describes the arguements for the tripal_populate_mview job to allow for
  620. * greater readability in the jobs details pages.
  621. *
  622. * @param $callback
  623. * The callback of the current tripal job (this is the function that will be
  624. * executed when tripal_launch_jobs.php is run.
  625. * @param $args
  626. * An array of arguments passed in when the job was registered.
  627. *
  628. * @return
  629. * A more readable $args array
  630. *
  631. * @ingroup tripal
  632. */
  633. function tripal_chado_job_describe_args($callback, $args) {
  634. $new_args = array();
  635. if ($callback == 'tripal_populate_mview') {
  636. // get this mview details
  637. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  638. $results = db_query($sql, array(':mview_id' => $args[0]));
  639. $mview = $results->fetchObject();
  640. $new_args['View Name'] = $mview->name;
  641. }
  642. elseif ($callback == 'tripal_install_chado') {
  643. $new_args['Action'] = $args[0];
  644. }
  645. return $new_args;
  646. }
  647. /**
  648. * Remove the nid from chado_entity if it exists when the node is deleted
  649. */
  650. function tripal_chado_node_delete($node) {
  651. $nid = $node->nid;
  652. $sql = "UPDATE chado_entity SET nid = NULL WHERE nid = :nid";
  653. db_query($sql, array('nid' => $nid));
  654. }