tripal_chado.module 27 KB

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