tripal_chado.module 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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 ($GLOBALS["chado_is_installed"]) {
  62. // Check to see if the Chado and Drupal have been prepared
  63. if (!variable_get('tripal_chado_is_prepared', FALSE)) {
  64. drupal_set_message('Chado is installed but Tripal has not yet prepared Drupal and Chado. Please ' .
  65. l('prepare both Drupal and Chado', 'admin/tripal/storage/chado/chado_prepare') .
  66. ' before continuing.', 'warning');
  67. }
  68. }
  69. else {
  70. drupal_set_message('Tripal cannot find a Chado installation. Please ' .
  71. l('install Chado', 'admin/tripal/storage/chado/chado_install') .
  72. ' before continuing.', 'warning');
  73. }
  74. }
  75. /**
  76. * Implements hook_views_api().
  77. *
  78. * Essentially this hook tells drupal that there is views support for
  79. * for this module which then includes tripal_db.views.inc where all the
  80. * views integration code is
  81. *
  82. * @ingroup tripal_feature
  83. */
  84. function tripal_chado_views_api() {
  85. return array(
  86. 'api' => 3.0,
  87. );
  88. }
  89. /**
  90. * Implements hook_menu().
  91. */
  92. function tripal_chado_menu() {
  93. $items = array();
  94. //////////////////////////////////////////////////////////////////////////////
  95. // Chado Storage Backend
  96. //////////////////////////////////////////////////////////////////////////////
  97. $items['admin/tripal/storage/chado'] = array(
  98. 'title' => 'Chado',
  99. 'description' => t("Integrates Chado with Tripal and includes tools to
  100. load data, and extend the chado schema through custom tables &
  101. materialized views."),
  102. 'weight' => -100,
  103. 'access arguments' => array('administer tripal'),
  104. );
  105. $items['admin/tripal/storage/chado/chado_install'] = array(
  106. 'title' => 'Install Chado',
  107. 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'),
  108. 'page callback' => 'drupal_get_form',
  109. 'page arguments' => array('tripal_chado_install_form'),
  110. 'type' => MENU_NORMAL_ITEM,
  111. 'access arguments' => array('install chado'),
  112. 'file' => 'includes/tripal_chado.install.inc',
  113. 'file path' => drupal_get_path('module', 'tripal_chado'),
  114. 'weight' => -100
  115. );
  116. $items['admin/tripal/storage/chado/chado_prepare'] = array(
  117. 'title' => 'Prepare Chado',
  118. 'description' => t('Prepares Drupal to use Chado.'),
  119. 'page callback' => 'drupal_get_form',
  120. 'page arguments' => array('tripal_chado_prepare_form'),
  121. 'type' => MENU_NORMAL_ITEM,
  122. 'access arguments' => array('install chado'),
  123. 'file' => 'includes/tripal_chado.setup.inc',
  124. 'file path' => drupal_get_path('module', 'tripal_chado'),
  125. 'weight' => -99
  126. );
  127. $items['admin/tripal/storage/chado/publish'] = array(
  128. 'title' => 'Publish',
  129. 'description' => t('Publish data that is present in Chado but which does
  130. not yet have a page on this site for viewing. In Tripal v2.0 or
  131. earlier this was refered to as "syncing".'),
  132. 'page callback' => 'drupal_get_form',
  133. 'page arguments' => array('tripal_chado_publish_form'),
  134. 'type' => MENU_NORMAL_ITEM,
  135. 'access arguments' => array('administer tripal'),
  136. 'file' => 'includes/tripal_chado.publish.inc',
  137. 'file path' => drupal_get_path('module', 'tripal_chado'),
  138. 'weight' => -99
  139. );
  140. $items['admin/structure/bio_data/publish'] = array(
  141. 'title' => 'Publish Chado Content',
  142. 'description' => t('Publish data that is present in Chado but which does
  143. not yet have a page on this site for viewing. In Tripal v2.0 or
  144. earlier this was refered to as "syncing".'), 'page callback' => 'drupal_get_form',
  145. 'page callback' => 'drupal_get_form',
  146. 'page arguments' => array('tripal_chado_publish_form'),
  147. 'access arguments' => array('administer tripal'),
  148. 'file' => 'includes/tripal_chado.publish.inc',
  149. 'file path' => drupal_get_path('module', 'tripal_chado'),
  150. 'type' => MENU_LOCAL_ACTION,
  151. 'weight' => 2
  152. );
  153. //////////////////////////////////////////////////////////////////////////////
  154. // Materialized Views
  155. //////////////////////////////////////////////////////////////////////////////
  156. $items['admin/tripal/storage/chado/mviews'] = array(
  157. 'title' => 'Materialized Views',
  158. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  159. 'page callback' => 'tripal_mview_admin_view',
  160. 'access arguments' => array('administer tripal'),
  161. 'type' => MENU_NORMAL_ITEM,
  162. 'file' => 'includes/tripal_chado.mviews.inc',
  163. 'file path' => drupal_get_path('module', 'tripal_chado'),
  164. 'weight' => -10
  165. );
  166. $items['admin/tripal/storage/chado/mviews/help'] = array(
  167. 'title' => 'Help',
  168. 'description' => t('Help for the materialized views management system'),
  169. 'page callback' => 'theme',
  170. 'page arguments' => array('tripal_mviews_help'),
  171. 'access arguments' => array('administer tripal'),
  172. 'type' => MENU_LOCAL_TASK,
  173. 'file' => 'includes/tripal_chado.mviews.inc',
  174. 'file path' => drupal_get_path('module', 'tripal_chado'),
  175. 'weight' => 10
  176. );
  177. $items['admin/tripal/storage/chado/mviews/report/%'] = array(
  178. 'title' => 'Materialized View',
  179. 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'),
  180. 'page callback' => 'tripal_mview_report',
  181. 'page arguments' => array(6),
  182. 'access arguments' => array('administer tripal'),
  183. 'type' => MENU_CALLBACK,
  184. 'file' => 'includes/tripal_chado.mviews.inc',
  185. 'file path' => drupal_get_path('module', 'tripal_chado'),
  186. );
  187. $items['admin/tripal/storage/chado/mviews/new'] = array(
  188. 'title' => 'Create Materialized View',
  189. 'description' => t('Create a new materialized view.'),
  190. 'page callback' => 'drupal_get_form',
  191. 'page arguments' => array('tripal_mviews_form'),
  192. 'access arguments' => array('administer tripal'),
  193. 'type' => MENU_CALLBACK,
  194. 'file' => 'includes/tripal_chado.mviews.inc',
  195. 'file path' => drupal_get_path('module', 'tripal_chado'),
  196. );
  197. $items['admin/tripal/storage/chado/mviews/edit/%'] = array(
  198. 'title' => 'Edit Materialized View',
  199. 'page callback' => 'drupal_get_form',
  200. 'page arguments' => array('tripal_mviews_form', 6),
  201. 'access arguments' => array('administer tripal'),
  202. 'type' => MENU_CALLBACK,
  203. 'file' => 'includes/tripal_chado.mviews.inc',
  204. 'file path' => drupal_get_path('module', 'tripal_chado'),
  205. );
  206. $items['admin/tripal/storage/chado/mviews/update/%'] = array(
  207. 'title' => 'Create Materialized View',
  208. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  209. 'page callback' => 'tripal_mviews_add_populate_job',
  210. 'page arguments' => array(6),
  211. 'access arguments' => array('administer tripal'),
  212. 'type' => MENU_CALLBACK,
  213. 'file' => 'includes/tripal_chado.mviews.inc',
  214. 'file path' => drupal_get_path('module', 'tripal_chado'),
  215. );
  216. $items['admin/tripal/storage/chado/mviews/delete/%'] = array(
  217. 'title' => 'Create Materialized View',
  218. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  219. 'page callback' => 'drupal_get_form',
  220. 'page arguments' => array('tripal_mviews_delete_form', 5),
  221. 'access arguments' => array('administer tripal'),
  222. 'type' => MENU_CALLBACK,
  223. 'file' => 'includes/tripal_chado.mviews.inc',
  224. 'file path' => drupal_get_path('module', 'tripal_chado'),
  225. );
  226. // TODO: complete the code for exporting and importing of MViews.
  227. // Need to address security issues of sharing SQL.
  228. $items['admin/tripal/storage/chado/mviews/import'] = array(
  229. 'title' => 'Import MView',
  230. 'description' => 'Import a materialized view from another Tripal instance.',
  231. 'page callback' => 'drupal_get_form',
  232. 'page arguments' => array('tripal_mviews_import_form'),
  233. 'access arguments' => array('administer tripal'),
  234. 'type' => MENU_CALLBACK,
  235. 'file' => 'includes/tripal_chado.mviews.inc',
  236. 'file path' => drupal_get_path('module', 'tripal_chado'),
  237. );
  238. $items['admin/tripal/storage/chado/mviews/%tblid/export'] = array(
  239. 'title' => 'Export MView',
  240. 'description' => 'Export a materialized view for use by another Tripal instance.',
  241. 'page callback' => 'drupal_get_form',
  242. 'page arguments' => array('tripal_mviews_export_form', 5),
  243. 'access arguments' => array('administer tripal'),
  244. 'type' => MENU_CALLBACK,
  245. 'file' => 'includes/tripal_chado.mviews.inc',
  246. 'file path' => drupal_get_path('module', 'tripal_chado'),
  247. );
  248. //////////////////////////////////////////////////////////////////////////////
  249. // Custom Tables
  250. //////////////////////////////////////////////////////////////////////////////
  251. $items['admin/tripal/storage/chado/custom_tables'] = array(
  252. 'title' => 'Custom Tables',
  253. 'description' => t('Creation of custom tables that are added to Chado database.'),
  254. 'page callback' => 'tripal_custom_table_admin_view',
  255. 'access arguments' => array('administer tripal'),
  256. 'type' => MENU_NORMAL_ITEM,
  257. 'file' => 'includes/tripal_chado.custom_tables.inc',
  258. 'file path' => drupal_get_path('module', 'tripal_chado'),
  259. 'weight' => -10
  260. );
  261. $items['admin/tripal/storage/chado/custom_tables/help'] = array(
  262. 'title' => 'Help',
  263. 'description' => t('Help for the tripal job management system'),
  264. 'page callback' => 'theme',
  265. 'page arguments' => array('tripal_job_help'),
  266. 'access arguments' => array('administer tripal'),
  267. 'type' => MENU_LOCAL_TASK,
  268. 'file' => 'includes/tripal_chado.custom_tables.inc',
  269. 'file path' => drupal_get_path('module', 'tripal_chado'),
  270. 'weight' => 10
  271. );
  272. $items['admin/tripal/storage/chado/custom_tables/view/%'] = array(
  273. 'title' => 'Custom Tables',
  274. 'description' => t('Custom tables are added to Chado.'),
  275. 'page callback' => 'tripal_custom_table_view',
  276. 'page arguments' => array(6),
  277. 'access arguments' => array('administer tripal'),
  278. 'file' => 'includes/tripal_chado.custom_tables.inc',
  279. 'file path' => drupal_get_path('module', 'tripal_chado'),
  280. 'type' => MENU_CALLBACK,
  281. );
  282. $items['admin/tripal/storage/chado/custom_tables/new'] = array(
  283. 'title' => 'Create Custom Table',
  284. 'description' => t('An interface for creating your own custom tables.'),
  285. 'page callback' => 'tripal_custom_table_new_page',
  286. 'access arguments' => array('administer tripal'),
  287. 'file' => 'includes/tripal_chado.custom_tables.inc',
  288. 'file path' => drupal_get_path('module', 'tripal_chado'),
  289. 'type' => MENU_CALLBACK,
  290. );
  291. $items['admin/tripal/storage/chado/custom_tables/edit/%'] = array(
  292. 'title' => 'Edit Custom Table',
  293. 'page callback' => 'drupal_get_form',
  294. 'page arguments' => array('tripal_custom_tables_form', 6),
  295. 'access arguments' => array('administer tripal'),
  296. 'file' => 'includes/tripal_chado.custom_tables.inc',
  297. 'file path' => drupal_get_path('module', 'tripal_chado'),
  298. 'type' => MENU_CALLBACK,
  299. );
  300. $items['admin/tripal/storage/chado/custom_tables/delete/%'] = array(
  301. 'title' => 'Create Custom Table',
  302. 'description' => t('Custom tables are added to Chado.'),
  303. 'page callback' => 'drupal_get_form',
  304. 'page arguments' => array('tripal_custom_tables_delete_form', 6),
  305. 'access arguments' => array('administer tripal'),
  306. 'file' => 'includes/tripal_chado.custom_tables.inc',
  307. 'file path' => drupal_get_path('module', 'tripal_chado'),
  308. 'type' => MENU_CALLBACK,
  309. );
  310. $items['admin/tripal/storage/chado/custom_tables/views/tables/enable'] = array(
  311. 'title' => 'Enable Custom Tables Administrative View',
  312. 'page callback' => 'tripal_enable_view',
  313. 'page arguments' => array('tripal_admin_custom_table', 'admin/tripal/storage/chado/custom_tables'),
  314. 'access arguments' => array('administer tripal'),
  315. 'file' => 'includes/tripal_chado.custom_tables.inc',
  316. 'file path' => drupal_get_path('module', 'tripal_chado'),
  317. 'type' => MENU_CALLBACK,
  318. );
  319. //////////////////////////////////////////////////////////////////////////////
  320. // Data Loaders
  321. //////////////////////////////////////////////////////////////////////////////
  322. $items['admin/tripal/storage/chado/loaders'] = array(
  323. 'title' => 'Data Loaders',
  324. 'description' => t('Tools facilitating data import.'),
  325. 'access arguments' => array('administer tripal'),
  326. 'type' => MENU_NORMAL_ITEM,
  327. 'weight' => 6
  328. );
  329. $items['admin/tripal/storage/chado/loaders/fasta_loader'] = array(
  330. 'title' => 'FASTA file Loader',
  331. 'description' => 'Load sequences from a multi-FASTA file into Chado',
  332. 'page callback' => 'drupal_get_form',
  333. 'page arguments' => array('tripal_feature_fasta_load_form'),
  334. 'access arguments' => array('administer tripal feature'),
  335. 'file' => 'includes/loaders/tripal_chado.fasta_loader.inc',
  336. 'file path' => drupal_get_path('module', 'tripal_chado'),
  337. 'type' => MENU_NORMAL_ITEM,
  338. );
  339. $items['admin/tripal/storage/chado/loaders/gff3_load'] = array(
  340. 'title' => 'GFF3 file Loader',
  341. 'description' => 'Import a GFF3 file into Chado',
  342. 'page callback' => 'drupal_get_form',
  343. 'page arguments' => array('tripal_feature_gff3_load_form'),
  344. 'access arguments' => array('administer tripal feature'),
  345. 'file' => 'includes/loaders/tripal_chado.gff_loader.inc',
  346. 'file path' => drupal_get_path('module', 'tripal_chado'),
  347. 'type' => MENU_NORMAL_ITEM,
  348. );
  349. $items['admin/tripal/storage/chado/loaders/pub'] = array(
  350. 'title' => t('Publication Importers'),
  351. 'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
  352. 'page callback' => 'tripal_pub_importers_list',
  353. 'access arguments' => array('administer tripal pub'),
  354. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  355. 'file path' => drupal_get_path('module', 'tripal_chado'),
  356. 'type' => MENU_NORMAL_ITEM,
  357. 'weight' => 0
  358. );
  359. $items['admin/tripal/storage/chado/loaders/pub/new'] = array(
  360. 'title' => t('Add an Importer'),
  361. 'description' => t('Add a new publication importer.'),
  362. 'page callback' => 'tripal_pub_importer_setup_page',
  363. 'access arguments' => array('administer tripal pub'),
  364. 'type ' => MENU_CALLBACK,
  365. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  366. 'file path' => drupal_get_path('module', 'tripal_chado'),
  367. );
  368. $items['admin/tripal/storage/chado/loaders/pub/edit/%'] = array(
  369. 'page callback' => 'tripal_pub_importer_setup_page',
  370. 'page arguments' => array(6, 7),
  371. 'access arguments' => array('administer tripal pub'),
  372. 'type ' => MENU_CALLBACK,
  373. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  374. 'file path' => drupal_get_path('module', 'tripal_chado'),
  375. );
  376. $items['admin/tripal/storage/chado/loaders/pub/raw/%'] = array(
  377. 'title' => t('Raw Data From Publication Import'),
  378. 'page callback' => 'tripal_get_remote_pub_raw_page',
  379. 'page arguments' => array(6),
  380. 'access arguments' => array('administer tripal pub'),
  381. 'type ' => MENU_CALLBACK,
  382. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  383. 'file path' => drupal_get_path('module', 'tripal_chado'),
  384. );
  385. // add a second link for the importer on the data loaders page
  386. $items['admin/tripal/storage/chado/loaders/pub/import'] = array(
  387. 'title' => t('Publication Importers'),
  388. 'page callback' => 'tripal_pub_importers_list',
  389. 'access arguments' => array('administer tripal pub'),
  390. 'type' => MENU_CALLBACK,
  391. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  392. 'file path' => drupal_get_path('module', 'tripal_chado'),
  393. );
  394. $items['admin/tripal/storage/chado/loaders/pub/submit/%'] = array(
  395. 'page callback' => 'tripal_pub_importer_submit_job',
  396. 'page arguments' => array(7),
  397. 'access arguments' => array('administer tripal pub'),
  398. 'type ' => MENU_CALLBACK,
  399. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  400. 'file path' => drupal_get_path('module', 'tripal_chado'),
  401. );
  402. $items['admin/tripal/storage/chado/loaders/pub/delete/%'] = array(
  403. 'page callback' => 'tripal_pub_importer_delete',
  404. 'page arguments' => array(7),
  405. 'access arguments' => array('administer tripal pub'),
  406. 'type ' => MENU_CALLBACK,
  407. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  408. 'file path' => drupal_get_path('module', 'tripal_chado'),
  409. );
  410. $items['admin/tripal/storage/chado/loaders/pub/changedb'] = array(
  411. 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
  412. 'page arguments' => array(),
  413. 'access arguments' => array('administer tripal pub'),
  414. 'type ' => MENU_CALLBACK,
  415. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  416. 'file path' => drupal_get_path('module', 'tripal_chado'),
  417. );
  418. $items['admin/tripal/storage/chado/loaders/pub/criteria/%/%'] = array(
  419. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  420. 'page arguments' => array(7, 8),
  421. 'access arguments' => array('administer tripal pub'),
  422. 'type ' => MENU_CALLBACK,
  423. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  424. 'file path' => drupal_get_path('module', 'tripal_chado'),
  425. );
  426. //////////////////////////////////////////////////////////////////////////////
  427. // Migrate Content
  428. //////////////////////////////////////////////////////////////////////////////
  429. $items['admin/tripal/storage/chado/migrate'] = array(
  430. 'title' => 'Migrate',
  431. 'description' => t('Migrate Tripal v2 content to Tripal v3'),
  432. 'page callback' => 'drupal_get_form',
  433. 'page arguments' => array('tripal_chado_migrate_form'),
  434. 'type' => MENU_NORMAL_ITEM,
  435. 'access arguments' => array('administer tripal'),
  436. 'file' => 'includes/tripal_chado.migrate.inc',
  437. 'file path' => drupal_get_path('module', 'tripal_chado'),
  438. 'weight' => 10
  439. );
  440. //////////////////////////////////////////////////////////////////////////////
  441. // Auto Completes
  442. //////////////////////////////////////////////////////////////////////////////
  443. $items['admin/tripal/storage/chado/auto_name/dbxref/%/%'] = array(
  444. 'page callback' => 'tripal_autocomplete_dbxref',
  445. 'page arguments' => array(6, 7),
  446. 'access arguments' => array('access content'),
  447. 'file' => 'api/modules/tripal_chado.db.api.inc',
  448. 'file path' => drupal_get_path('module', 'tripal_chado'),
  449. 'type' => MENU_CALLBACK,
  450. );
  451. $items['admin/tripal/storage/chado/auto_name/cvterm/%/%'] = array(
  452. 'page callback' => 'tripal_autocomplete_cvterm',
  453. 'page arguments' => array(6, 7),
  454. 'access arguments' => array('access content'),
  455. 'file' => 'api/modules/tripal_chado.db.api.inc',
  456. 'file path' => drupal_get_path('module', 'tripal_chado'),
  457. 'type' => MENU_CALLBACK,
  458. );
  459. $items['admin/tripal/storage/chado/auto_name/pub/%'] = array(
  460. 'page callback' => 'tripal_autocomplete_pub',
  461. 'page arguments' => array(6),
  462. 'access arguments' => array('access content'),
  463. 'file' => 'api/modules/tripal_chado.pub.api.inc',
  464. 'file path' => drupal_get_path('module', 'tripal_chado'),
  465. 'type' => MENU_CALLBACK,
  466. );
  467. return $items;
  468. }
  469. /**
  470. * Implements hook_permission().
  471. *
  472. * Set the permission types that the chado module uses. Essentially we
  473. * want permissionis that protect creation, editing and deleting of chado
  474. * data objects
  475. *
  476. * @ingroup tripal
  477. */
  478. function tripal_chado_permission() {
  479. return array(
  480. 'install chado' => array(
  481. 'title' => t('Install Chado'),
  482. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  483. ),
  484. 'view chado_ids' => array(
  485. 'title' => t('View Internal IDs'),
  486. 'description' => t('On content pages Tripal will typically provide
  487. a table of information pulled from the Chado database but the
  488. primary key IDs for that data is typically not shown. The
  489. default Tripal templates can show the primary key ID inside of a
  490. blue shaded table row if this permission is enabled. This can
  491. be useful for site developers who might want these IDs when working
  492. with the underlying database.'),
  493. 'restrict access' => TRUE,
  494. )
  495. );
  496. }
  497. /**
  498. * Implements hook_theme().
  499. */
  500. function tripal_chado_theme($existing, $type, $theme, $path) {
  501. $themes = array(
  502. // Theme fields.
  503. 'chado_base__dbxref_id_widget' => array(
  504. 'render element' => 'element',
  505. 'file' => 'includes/fields/chado_base__dbxref_id.inc',
  506. ),
  507. 'chado_linker__dbxref_widget' => array(
  508. 'render element' => 'element',
  509. 'file' => 'includes/fields/chado_linker__dbxref.inc',
  510. ),
  511. 'chado_linker__cvterm_widget' => array(
  512. 'render element' => 'element',
  513. 'file' => 'includes/fields/chado_linker__cvterm.inc',
  514. ),
  515. 'chado_linker__synonym_widget' => array(
  516. 'render element' => 'element',
  517. 'file' => 'includes/fields/chado_linker__synonym.inc',
  518. ),
  519. 'chado_linker__pub_widget' => array(
  520. 'render element' => 'element',
  521. 'file' => 'includes/fields/chado_linker__pub.inc',
  522. ),
  523. 'chado_linker__prop_adder_widget' => array(
  524. 'render element' => 'element',
  525. 'file' => 'includes/fields/chado_linker__prop_adder.inc',
  526. ),
  527. 'tripal_chado_date_combo' => array(
  528. 'render element' => 'element',
  529. 'file' => 'theme/tripal_chado.theme.inc',
  530. ),
  531. // Themed forms
  532. 'tripal_pub_importer_setup_form_elements' => array(
  533. 'render element' => 'form',
  534. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  535. ),
  536. 'tripal_pub_search_setup_form_elements' => array(
  537. 'render element' => 'form',
  538. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  539. ),
  540. );
  541. // Override the theme for each entity to use the legacy modules
  542. // templates.
  543. $core_path = drupal_get_path('module', 'tripal_core');
  544. $bundles = db_select('tripal_bundle', 'tb')
  545. ->fields('tb')
  546. ->execute();
  547. while ($bundle = $bundles->fetchObject()) {
  548. $themes['TripalEntity__' . $bundle->name] = array(
  549. 'template' => 'node--chado-generic',
  550. 'render element' => 'entity',
  551. 'base hook' => 'entity',
  552. 'path' => "$core_path/theme/templates",
  553. );
  554. }
  555. return $themes;
  556. }
  557. /**
  558. * Implements hook_exclude_type_by_default()
  559. *
  560. * This hooks allows fields of a specified type that match a specified criteria
  561. * to be excluded by default from any table when chado_generate_var() is called.
  562. * Keep in mind that if fields are excluded by default they can always be
  563. * expanded at a later date using chado_expand_var().
  564. *
  565. * Criteria are php strings that evaluate to either TRUE or FALSE. These
  566. * strings are evaluated using drupal_eval() which suppresses syntax errors and
  567. * throws watchdog entries of type php. There are also watchdog entries of type
  568. * tripal stating the exact criteria evaluated. Criteria can
  569. * contain the following tokens:
  570. * - <field_name>
  571. * Replaced by the name of the field to be excluded
  572. * - <field_value>
  573. * Replaced by the value of the field in the current record
  574. * Also keep in mind that if your criteria doesn't contain the
  575. * &gt;field_value&lt; token then it will be evaluated before the query is
  576. * executed and if the field is excluded it won't be included in the
  577. * query.
  578. *
  579. * @return
  580. * An array of type => criteria where the type is excluded if the criteria
  581. * evaluates to TRUE
  582. *
  583. * @ingroup tripal
  584. */
  585. function tripal_chado_exclude_type_by_default() {
  586. return array('text' => 'strlen("<field_value> ") > 250');
  587. }
  588. /**
  589. * Implements hook_job_describe_args().
  590. *
  591. * Describes the arguements for the tripal_populate_mview job to allow for
  592. * greater readability in the jobs details pages.
  593. *
  594. * @param $callback
  595. * The callback of the current tripal job (this is the function that will be
  596. * executed when tripal_launch_jobs.php is run.
  597. * @param $args
  598. * An array of arguments passed in when the job was registered.
  599. *
  600. * @return
  601. * A more readable $args array
  602. *
  603. * @ingroup tripal
  604. */
  605. function tripal_chado_job_describe_args($callback, $args) {
  606. $new_args = array();
  607. if ($callback == 'tripal_populate_mview') {
  608. // get this mview details
  609. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  610. $results = db_query($sql, array(':mview_id' => $args[0]));
  611. $mview = $results->fetchObject();
  612. $new_args['View Name'] = $mview->name;
  613. }
  614. elseif ($callback == 'tripal_install_chado') {
  615. $new_args['Action'] = $args[0];
  616. }
  617. return $new_args;
  618. }
  619. /**
  620. * Implements hook_entity_property_info_alter().
  621. *
  622. * This is being implemented to ensure chado fields are exposed for search api indexing.
  623. * All fields are available for index by default but the getter function set by default
  624. * is not actually capable of getting the value from chado. Thus we change the getter
  625. * function to one that can :-).
  626. */
  627. function tripal_chado_entity_property_info_alter(&$info) {
  628. // Get a list of fields with the chado storage backend.
  629. // Loop through all of the bundles.
  630. if (isset($info['TripalEntity']['bundles'])) {
  631. foreach ($info['TripalEntity']['bundles'] as $bundle_id => $bundle) {
  632. // Loop through each of the fields for a given bundle.
  633. foreach ($bundle['properties'] as $field_name => $field_info) {
  634. // If the field is a chado field, then change the callback.
  635. // @todo check this properly.
  636. if (preg_match('/(\w+)__(\w+)/', $field_name, $matches)) {
  637. $info['TripalEntity']['bundles'][$bundle_id]['properties'][$field_name]['getter callback'] =
  638. 'tripal_chado_entity_property_get_value';
  639. }
  640. }
  641. }
  642. }
  643. }
  644. /**
  645. * Provides a way for the search api to grab the value of a chado field.
  646. *
  647. * @param $entity
  648. * The fully-loaded entity object to be indexed.
  649. * @param $options
  650. * Options that can be ued when retrieving the value.
  651. * @param $field_name
  652. * The machine name of the field we want to retrieve.
  653. * @param $entity_type
  654. * The type of entity (ie: TripalEntity).
  655. *
  656. * @return
  657. * The rendered value of the field specified by $field_name.
  658. */
  659. function tripal_chado_entity_property_get_value($entity, $options, $field_name, $entity_type) {
  660. $display = array(
  661. 'type' => '',
  662. 'label' => 'hidden',
  663. );
  664. $langcode = LANGUAGE_NONE;
  665. $items = field_get_items($entity_type, $entity, $field_name);
  666. if (count($items) == 1) {
  667. $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
  668. }
  669. // @todo: handle fields with multiple values.
  670. else {
  671. $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
  672. drupal_set_message('Tripal Chado currently only supports views integration for single value fields. The first value has been shown.', 'warning');
  673. }
  674. return drupal_render($render_array);
  675. }
  676. /**
  677. * Remove the nid from chado_entity if it exists when the node is deleted
  678. */
  679. function tripal_chado_node_delete($node) {
  680. $nid = $node->nid;
  681. $sql = "UPDATE chado_entity SET nid = NULL WHERE nid = :nid";
  682. db_query($sql, array('nid' => $nid));
  683. }
  684. /**
  685. * Implements hook_entity_view().
  686. *
  687. * This function is used to support legacy Tripal v2 templates
  688. * for use with Tripal v3 entities.
  689. */
  690. function tripal_chado_entity_view($entity, $type, $view_mode, $langcode) {
  691. // If this entity is a TripalEntity and is a full view, then
  692. // we want to support the legacy view, but only if the legacy
  693. // module is enabled (the functions exist).
  694. if ($type =='TripalEntity') {
  695. // Use the generic template to render the fields
  696. if ($view_mode == 'full') {
  697. // Get the Chado table for this data type.
  698. $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle));
  699. $chado_table = tripal_get_bundle_variable('chado_table', $bundle->id);
  700. $chado_field = tripal_get_bundle_variable('chado_column', $bundle->id);
  701. // TODO remove the fields added by the chado_field_storage.
  702. // If the legacy module is enabled then we can make this
  703. // entity look like a node and use the legacy node_view hooks to
  704. // use the legacy templates.
  705. $function_name = 'tripal_core_node_view';
  706. if (function_exists($function_name)) {
  707. $entity->type = 'chado_' . $chado_table;
  708. $entity->$chado_table = $entity->chado_record;
  709. $function_name($entity, $view_mode, $langcode);
  710. }
  711. // Now call the module's hook.
  712. $function_name = 'tripal_' . $chado_table . '_node_view';
  713. if (function_exists($function_name)) {
  714. $function_name($entity, $view_mode, $langcode);
  715. }
  716. }
  717. }
  718. }
  719. /**
  720. * Implements hook_entity_view_alter().
  721. *
  722. * This function is used to support legacy Tripal v2 templates
  723. * for use with Tripal v3 entities.
  724. */
  725. function tripal_chado_entity_view_alter(&$build) {
  726. // For the legacy support, we need to make sure the TOC
  727. // is built.
  728. module_load_include('inc', 'tripal_core', 'includes/tripal_core.toc');
  729. if (function_exists('tripal_core_node_view_build_toc')) {
  730. // The tripal_core_node_view_build_toc expects a #node
  731. // and an nid property as part of the entity. However,
  732. // we don't want to support use of node IDs with entities
  733. // because that could cause problems, so always set the
  734. // nid to NULL.
  735. $build['#entity']->nid = NULL;
  736. $build['#node'] = $build['#entity'];
  737. tripal_core_node_view_build_toc($build);
  738. }
  739. }
  740. /**
  741. * Implements hook_preprocess().
  742. *
  743. * This function is used to support legacy Tripal v2 templates
  744. * for use with Tripal v3 entities.
  745. */
  746. function tripal_chado_preprocess(&$variables, $hook) {
  747. if ($hook == 'entity' and array_key_exists('TripalEntity', $variables)) {
  748. // The node--chado-generic template expets there to be a
  749. // teaser and node variables. So, we'll add them.
  750. $variables['teaser'] = FALSE;
  751. $variables['node'] = $variables['TripalEntity'];
  752. }
  753. }