tripal_chado.module 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. $items['admin/tripal/storage/term/%/%'] = array(
  95. 'page callback' => 'tripal_autocomplete_cvterm',
  96. 'page arguments' => array(4, 5),
  97. 'access arguments' => array('administer content'),
  98. 'type' => MENU_CALLBACK,
  99. );
  100. //////////////////////////////////////////////////////////////////////////////
  101. // Chado Storage Backend
  102. //////////////////////////////////////////////////////////////////////////////
  103. $items['admin/tripal/storage/chado'] = array(
  104. 'title' => 'Chado',
  105. 'description' => t("Integrates Chado with Tripal and includes tools to
  106. load data, and extend the chado schema through custom tables &
  107. materialized views."),
  108. 'weight' => -100,
  109. 'access arguments' => array('administer tripal'),
  110. );
  111. $items['admin/tripal/storage/chado/chado_install'] = array(
  112. 'title' => 'Install Chado',
  113. 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'),
  114. 'page callback' => 'drupal_get_form',
  115. 'page arguments' => array('tripal_chado_install_form'),
  116. 'type' => MENU_NORMAL_ITEM,
  117. 'access arguments' => array('install chado'),
  118. 'file' => 'includes/tripal_chado.install.inc',
  119. 'file path' => drupal_get_path('module', 'tripal_chado'),
  120. 'weight' => -100
  121. );
  122. $items['admin/tripal/storage/chado/chado_prepare'] = array(
  123. 'title' => 'Prepare Chado',
  124. 'description' => t('Prepares Drupal to use Chado.'),
  125. 'page callback' => 'drupal_get_form',
  126. 'page arguments' => array('tripal_chado_prepare_form'),
  127. 'type' => MENU_NORMAL_ITEM,
  128. 'access arguments' => array('install chado'),
  129. 'file' => 'includes/tripal_chado.setup.inc',
  130. 'file path' => drupal_get_path('module', 'tripal_chado'),
  131. 'weight' => -99
  132. );
  133. $items['admin/tripal/storage/chado/publish'] = array(
  134. 'title' => 'Publish',
  135. 'description' => t('Publish data that is present in Chado but which does
  136. not yet have a page on this site for viewing. In Tripal v2.0 or
  137. earlier this was refered to as "syncing".'),
  138. 'page callback' => 'drupal_get_form',
  139. 'page arguments' => array('tripal_chado_publish_form'),
  140. 'type' => MENU_NORMAL_ITEM,
  141. 'access arguments' => array('administer tripal'),
  142. 'file' => 'includes/tripal_chado.publish.inc',
  143. 'file path' => drupal_get_path('module', 'tripal_chado'),
  144. 'weight' => -99
  145. );
  146. //////////////////////////////////////////////////////////////////////////////
  147. // Materialized Views
  148. //////////////////////////////////////////////////////////////////////////////
  149. $items['admin/tripal/storage/chado/mviews'] = array(
  150. 'title' => 'Materialized Views',
  151. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  152. 'page callback' => 'tripal_mview_admin_view',
  153. 'access arguments' => array('administer tripal'),
  154. 'type' => MENU_NORMAL_ITEM,
  155. 'file' => 'includes/tripal_chado.mviews.inc',
  156. 'file path' => drupal_get_path('module', 'tripal_chado'),
  157. 'weight' => -10
  158. );
  159. $items['admin/tripal/storage/chado/mviews/help'] = array(
  160. 'title' => 'Help',
  161. 'description' => t('Help for the materialized views management system'),
  162. 'page callback' => 'theme',
  163. 'page arguments' => array('tripal_mviews_help'),
  164. 'access arguments' => array('administer tripal'),
  165. 'type' => MENU_LOCAL_TASK,
  166. 'file' => 'includes/tripal_chado.mviews.inc',
  167. 'file path' => drupal_get_path('module', 'tripal_chado'),
  168. 'weight' => 10
  169. );
  170. $items['admin/tripal/storage/chado/mviews/report/%'] = array(
  171. 'title' => 'Materialized View',
  172. 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'),
  173. 'page callback' => 'tripal_mview_report',
  174. 'page arguments' => array(6),
  175. 'access arguments' => array('administer tripal'),
  176. 'type' => MENU_CALLBACK,
  177. 'file' => 'includes/tripal_chado.mviews.inc',
  178. 'file path' => drupal_get_path('module', 'tripal_chado'),
  179. );
  180. $items['admin/tripal/storage/chado/mviews/new'] = array(
  181. 'title' => 'Create Materialized View',
  182. 'description' => t('Create a new materialized view.'),
  183. 'page callback' => 'drupal_get_form',
  184. 'page arguments' => array('tripal_mviews_form'),
  185. 'access arguments' => array('administer tripal'),
  186. 'type' => MENU_CALLBACK,
  187. 'file' => 'includes/tripal_chado.mviews.inc',
  188. 'file path' => drupal_get_path('module', 'tripal_chado'),
  189. );
  190. $items['admin/tripal/storage/chado/mviews/edit/%'] = array(
  191. 'title' => 'Edit Materialized View',
  192. 'page callback' => 'drupal_get_form',
  193. 'page arguments' => array('tripal_mviews_form', 6),
  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/update/%'] = array(
  200. 'title' => 'Create Materialized View',
  201. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  202. 'page callback' => 'tripal_mviews_add_populate_job',
  203. 'page arguments' => array(6),
  204. 'access arguments' => array('administer tripal'),
  205. 'type' => MENU_CALLBACK,
  206. 'file' => 'includes/tripal_chado.mviews.inc',
  207. 'file path' => drupal_get_path('module', 'tripal_chado'),
  208. );
  209. $items['admin/tripal/storage/chado/mviews/delete/%'] = array(
  210. 'title' => 'Create Materialized View',
  211. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  212. 'page callback' => 'drupal_get_form',
  213. 'page arguments' => array('tripal_mviews_delete_form', 5),
  214. 'access arguments' => array('administer tripal'),
  215. 'type' => MENU_CALLBACK,
  216. 'file' => 'includes/tripal_chado.mviews.inc',
  217. 'file path' => drupal_get_path('module', 'tripal_chado'),
  218. );
  219. // TODO: complete the code for exporting and importing of MViews.
  220. // Need to address security issues of sharing SQL.
  221. $items['admin/tripal/storage/chado/mviews/import'] = array(
  222. 'title' => 'Import MView',
  223. 'description' => 'Import a materialized view from another Tripal instance.',
  224. 'page callback' => 'drupal_get_form',
  225. 'page arguments' => array('tripal_mviews_import_form'),
  226. 'access arguments' => array('administer tripal'),
  227. 'type' => MENU_CALLBACK,
  228. 'file' => 'includes/tripal_chado.mviews.inc',
  229. 'file path' => drupal_get_path('module', 'tripal_chado'),
  230. );
  231. $items['admin/tripal/storage/chado/mviews/%tblid/export'] = array(
  232. 'title' => 'Export MView',
  233. 'description' => 'Export a materialized view for use by another Tripal instance.',
  234. 'page callback' => 'drupal_get_form',
  235. 'page arguments' => array('tripal_mviews_export_form', 5),
  236. 'access arguments' => array('administer tripal'),
  237. 'type' => MENU_CALLBACK,
  238. 'file' => 'includes/tripal_chado.mviews.inc',
  239. 'file path' => drupal_get_path('module', 'tripal_chado'),
  240. );
  241. //////////////////////////////////////////////////////////////////////////////
  242. // Custom Tables
  243. //////////////////////////////////////////////////////////////////////////////
  244. $items['admin/tripal/storage/chado/custom_tables'] = array(
  245. 'title' => 'Custom Tables',
  246. 'description' => t('Creation of custom tables that are added to Chado database.'),
  247. 'page callback' => 'tripal_custom_table_admin_view',
  248. 'access arguments' => array('administer tripal'),
  249. 'type' => MENU_NORMAL_ITEM,
  250. 'file' => 'includes/tripal_chado.custom_tables.inc',
  251. 'file path' => drupal_get_path('module', 'tripal_chado'),
  252. 'weight' => -10
  253. );
  254. $items['admin/tripal/storage/chado/custom_tables/help'] = array(
  255. 'title' => 'Help',
  256. 'description' => t('Help for the tripal job management system'),
  257. 'page callback' => 'theme',
  258. 'page arguments' => array('tripal_job_help'),
  259. 'access arguments' => array('administer tripal'),
  260. 'type' => MENU_LOCAL_TASK,
  261. 'file' => 'includes/tripal_chado.custom_tables.inc',
  262. 'file path' => drupal_get_path('module', 'tripal_chado'),
  263. 'weight' => 10
  264. );
  265. $items['admin/tripal/storage/chado/custom_tables/view/%'] = array(
  266. 'title' => 'Custom Tables',
  267. 'description' => t('Custom tables are added to Chado.'),
  268. 'page callback' => 'tripal_custom_table_view',
  269. 'page arguments' => array(6),
  270. 'access arguments' => array('administer tripal'),
  271. 'file' => 'includes/tripal_chado.custom_tables.inc',
  272. 'file path' => drupal_get_path('module', 'tripal_chado'),
  273. 'type' => MENU_CALLBACK,
  274. );
  275. $items['admin/tripal/storage/chado/custom_tables/new'] = array(
  276. 'title' => 'Create Custom Table',
  277. 'description' => t('An interface for creating your own custom tables.'),
  278. 'page callback' => 'tripal_custom_table_new_page',
  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/edit/%'] = array(
  285. 'title' => 'Edit Custom Table',
  286. 'page callback' => 'drupal_get_form',
  287. 'page arguments' => array('tripal_custom_tables_form', 6),
  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/delete/%'] = array(
  294. 'title' => 'Create Custom Table',
  295. 'description' => t('Custom tables are added to Chado.'),
  296. 'page callback' => 'drupal_get_form',
  297. 'page arguments' => array('tripal_custom_tables_delete_form', 6),
  298. 'access arguments' => array('administer tripal'),
  299. 'file' => 'includes/tripal_chado.custom_tables.inc',
  300. 'file path' => drupal_get_path('module', 'tripal_chado'),
  301. 'type' => MENU_CALLBACK,
  302. );
  303. $items['admin/tripal/storage/chado/custom_tables/views/tables/enable'] = array(
  304. 'title' => 'Enable Custom Tables Administrative View',
  305. 'page callback' => 'tripal_enable_view',
  306. 'page arguments' => array('tripal_admin_custom_table', 'admin/tripal/storage/chado/custom_tables'),
  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. //////////////////////////////////////////////////////////////////////////////
  313. // Data Loaders
  314. //////////////////////////////////////////////////////////////////////////////
  315. $items['admin/tripal/storage/chado/loaders'] = array(
  316. 'title' => 'Data Loaders',
  317. 'description' => t('Tools facilitating data import.'),
  318. 'access arguments' => array('administer tripal'),
  319. 'type' => MENU_NORMAL_ITEM,
  320. 'weight' => 6
  321. );
  322. $items['admin/tripal/storage/chado/loaders/fasta_loader'] = array(
  323. 'title' => 'FASTA file Loader',
  324. 'description' => 'Load sequences from a multi-FASTA file into Chado',
  325. 'page callback' => 'drupal_get_form',
  326. 'page arguments' => array('tripal_feature_fasta_load_form'),
  327. 'access arguments' => array('administer tripal feature'),
  328. 'file' => 'includes/loaders/tripal_chado.fasta_loader.inc',
  329. 'file path' => drupal_get_path('module', 'tripal_chado'),
  330. 'type' => MENU_NORMAL_ITEM,
  331. );
  332. $items['admin/tripal/storage/chado/loaders/gff3_load'] = array(
  333. 'title' => 'GFF3 file Loader',
  334. 'description' => 'Import a GFF3 file into Chado',
  335. 'page callback' => 'drupal_get_form',
  336. 'page arguments' => array('tripal_feature_gff3_load_form'),
  337. 'access arguments' => array('administer tripal feature'),
  338. 'file' => 'includes/loaders/tripal_chado.gff_loader.inc',
  339. 'file path' => drupal_get_path('module', 'tripal_chado'),
  340. 'type' => MENU_NORMAL_ITEM,
  341. );
  342. $items['admin/tripal/storage/chado/loaders/pub'] = array(
  343. 'title' => t('Publication Importers'),
  344. 'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
  345. 'page callback' => 'tripal_pub_importers_list',
  346. 'access arguments' => array('administer tripal pub'),
  347. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  348. 'file path' => drupal_get_path('module', 'tripal_chado'),
  349. 'type' => MENU_NORMAL_ITEM,
  350. 'weight' => 0
  351. );
  352. $items['admin/tripal/storage/chado/loaders/pub/new'] = array(
  353. 'title' => t('Add an Importer'),
  354. 'description' => t('Add a new publication importer.'),
  355. 'page callback' => 'tripal_pub_importer_setup_page',
  356. 'access arguments' => array('administer tripal pub'),
  357. 'type ' => MENU_CALLBACK,
  358. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  359. 'file path' => drupal_get_path('module', 'tripal_chado'),
  360. );
  361. $items['admin/tripal/storage/chado/loaders/pub/edit/%'] = array(
  362. 'page callback' => 'tripal_pub_importer_setup_page',
  363. 'page arguments' => array(6, 7),
  364. 'access arguments' => array('administer tripal pub'),
  365. 'type ' => MENU_CALLBACK,
  366. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  367. 'file path' => drupal_get_path('module', 'tripal_chado'),
  368. );
  369. $items['admin/tripal/storage/chado/loaders/pub/raw/%'] = array(
  370. 'title' => t('Raw Data From Publication Import'),
  371. 'page callback' => 'tripal_get_remote_pub_raw_page',
  372. 'page arguments' => array(6),
  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. // add a second link for the importer on the data loaders page
  379. $items['admin/tripal/storage/chado/loaders/pub/import'] = array(
  380. 'title' => t('Publication Importers'),
  381. 'page callback' => 'tripal_pub_importers_list',
  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. $items['admin/tripal/storage/chado/loaders/pub/submit/%'] = array(
  388. 'page callback' => 'tripal_pub_importer_submit_job',
  389. 'page arguments' => array(7),
  390. 'access arguments' => array('administer tripal pub'),
  391. 'type ' => MENU_CALLBACK,
  392. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  393. 'file path' => drupal_get_path('module', 'tripal_chado'),
  394. );
  395. $items['admin/tripal/storage/chado/loaders/pub/delete/%'] = array(
  396. 'page callback' => 'tripal_pub_importer_delete',
  397. 'page arguments' => array(7),
  398. 'access arguments' => array('administer tripal pub'),
  399. 'type ' => MENU_CALLBACK,
  400. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  401. 'file path' => drupal_get_path('module', 'tripal_chado'),
  402. );
  403. $items['admin/tripal/storage/chado/loaders/pub/changedb'] = array(
  404. 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
  405. 'page arguments' => array(),
  406. 'access arguments' => array('administer tripal pub'),
  407. 'type ' => MENU_CALLBACK,
  408. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  409. 'file path' => drupal_get_path('module', 'tripal_chado'),
  410. );
  411. $items['admin/tripal/storage/chado/loaders/pub/criteria/%/%'] = array(
  412. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  413. 'page arguments' => array(7, 8),
  414. 'access arguments' => array('administer tripal pub'),
  415. 'type ' => MENU_CALLBACK,
  416. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  417. 'file path' => drupal_get_path('module', 'tripal_chado'),
  418. );
  419. //////////////////////////////////////////////////////////////////////////////
  420. // Migrate Content
  421. //////////////////////////////////////////////////////////////////////////////
  422. $items['admin/tripal/storage/chado/migrate'] = array(
  423. 'title' => 'Migrate',
  424. 'description' => t('Migrate Tripal v2 content to Tripal v3'),
  425. 'page callback' => 'drupal_get_form',
  426. 'page arguments' => array('tripal_chado_migrate_form'),
  427. 'type' => MENU_NORMAL_ITEM,
  428. 'access arguments' => array('administer tripal'),
  429. 'file' => 'includes/tripal_chado.migrate.inc',
  430. 'file path' => drupal_get_path('module', 'tripal_chado'),
  431. 'weight' => 10
  432. );
  433. //////////////////////////////////////////////////////////////////////////////
  434. // Auto Completes
  435. //////////////////////////////////////////////////////////////////////////////
  436. $items['admin/tripal/storage/chado/auto_name/dbxref/%/%'] = array(
  437. 'page callback' => 'tripal_autocomplete_dbxref',
  438. 'page arguments' => array(6, 7),
  439. 'access arguments' => array('access content'),
  440. 'file' => 'api/modules/tripal_chado.db.api.inc',
  441. 'file path' => drupal_get_path('module', 'tripal_chado'),
  442. 'type' => MENU_CALLBACK,
  443. );
  444. $items['admin/tripal/storage/chado/auto_name/cvterm/%/%'] = array(
  445. 'page callback' => 'tripal_autocomplete_cvterm',
  446. 'page arguments' => array(6, 7),
  447. 'access arguments' => array('access content'),
  448. 'file' => 'api/modules/tripal_chado.db.api.inc',
  449. 'file path' => drupal_get_path('module', 'tripal_chado'),
  450. 'type' => MENU_CALLBACK,
  451. );
  452. $items['admin/tripal/storage/chado/auto_name/pub/%'] = array(
  453. 'page callback' => 'tripal_autocomplete_pub',
  454. 'page arguments' => array(6),
  455. 'access arguments' => array('access content'),
  456. 'file' => 'api/modules/tripal_chado.pub.api.inc',
  457. 'file path' => drupal_get_path('module', 'tripal_chado'),
  458. 'type' => MENU_CALLBACK,
  459. );
  460. return $items;
  461. }
  462. /**
  463. * Implements hook_permission().
  464. *
  465. * Set the permission types that the chado module uses. Essentially we
  466. * want permissionis that protect creation, editing and deleting of chado
  467. * data objects
  468. *
  469. * @ingroup tripal
  470. */
  471. function tripal_chado_permission() {
  472. return array(
  473. 'install chado' => array(
  474. 'title' => t('Install Chado'),
  475. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  476. ),
  477. 'view chado_ids' => array(
  478. 'title' => t('View Internal IDs'),
  479. 'description' => t('On content pages Tripal will typically provide
  480. a table of information pulled from the Chado database but the
  481. primary key IDs for that data is typically not shown. The
  482. default Tripal templates can show the primary key ID inside of a
  483. blue shaded table row if this permission is enabled. This can
  484. be useful for site developers who might want these IDs when working
  485. with the underlying database.'),
  486. 'restrict access' => TRUE,
  487. )
  488. );
  489. }
  490. /**
  491. * Implements hook_theme().
  492. */
  493. function tripal_chado_theme($existing, $type, $theme, $path) {
  494. return array(
  495. // Theme fields.
  496. 'chado_base__dbxref_id_widget' => array(
  497. 'render element' => 'element',
  498. 'file' => 'includes/fields/chado_base__dbxref_id.inc',
  499. ),
  500. 'chado_linker__dbxref_widget' => array(
  501. 'render element' => 'element',
  502. 'file' => 'includes/fields/chado_linker__dbxref.inc',
  503. ),
  504. 'chado_linker__cvterm_widget' => array(
  505. 'render element' => 'element',
  506. 'file' => 'includes/fields/chado_linker__cvterm.inc',
  507. ),
  508. 'chado_linker__synonym_widget' => array(
  509. 'render element' => 'element',
  510. 'file' => 'includes/fields/chado_linker__synonym.inc',
  511. ),
  512. 'chado_linker__pub_widget' => array(
  513. 'render element' => 'element',
  514. 'file' => 'includes/fields/chado_linker__pub.inc',
  515. ),
  516. 'chado_linker__prop_adder_widget' => array(
  517. 'render element' => 'element',
  518. 'file' => 'includes/fields/chado_linker__prop_adder.inc',
  519. ),
  520. 'tripal_chado_date_combo' => array(
  521. 'render element' => 'element',
  522. 'file' => 'theme/tripal_chado.theme.inc',
  523. ),
  524. // Themed forms
  525. 'tripal_pub_importer_setup_form_elements' => array(
  526. 'render element' => 'form',
  527. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  528. ),
  529. 'tripal_pub_search_setup_form_elements' => array(
  530. 'render element' => 'form',
  531. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  532. ),
  533. );
  534. }
  535. /**
  536. * Implements hook_exclude_type_by_default()
  537. *
  538. * This hooks allows fields of a specified type that match a specified criteria
  539. * to be excluded by default from any table when chado_generate_var() is called.
  540. * Keep in mind that if fields are excluded by default they can always be
  541. * expanded at a later date using chado_expand_var().
  542. *
  543. * Criteria are php strings that evaluate to either TRUE or FALSE. These
  544. * strings are evaluated using drupal_eval() which suppresses syntax errors and
  545. * throws watchdog entries of type php. There are also watchdog entries of type
  546. * tripal stating the exact criteria evaluated. Criteria can
  547. * contain the following tokens:
  548. * - <field_name>
  549. * Replaced by the name of the field to be excluded
  550. * - <field_value>
  551. * Replaced by the value of the field in the current record
  552. * Also keep in mind that if your criteria doesn't contain the
  553. * &gt;field_value&lt; token then it will be evaluated before the query is
  554. * executed and if the field is excluded it won't be included in the
  555. * query.
  556. *
  557. * @return
  558. * An array of type => criteria where the type is excluded if the criteria
  559. * evaluates to TRUE
  560. *
  561. * @ingroup tripal
  562. */
  563. function tripal_chado_exclude_type_by_default() {
  564. return array('text' => 'strlen("<field_value> ") > 250');
  565. }
  566. /**
  567. * Implements hook_job_describe_args().
  568. *
  569. * Describes the arguements for the tripal_populate_mview job to allow for
  570. * greater readability in the jobs details pages.
  571. *
  572. * @param $callback
  573. * The callback of the current tripal job (this is the function that will be
  574. * executed when tripal_launch_jobs.php is run.
  575. * @param $args
  576. * An array of arguments passed in when the job was registered.
  577. *
  578. * @return
  579. * A more readable $args array
  580. *
  581. * @ingroup tripal
  582. */
  583. function tripal_chado_job_describe_args($callback, $args) {
  584. $new_args = array();
  585. if ($callback == 'tripal_populate_mview') {
  586. // get this mview details
  587. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  588. $results = db_query($sql, array(':mview_id' => $args[0]));
  589. $mview = $results->fetchObject();
  590. $new_args['View Name'] = $mview->name;
  591. }
  592. elseif ($callback == 'tripal_install_chado') {
  593. $new_args['Action'] = $args[0];
  594. }
  595. return $new_args;
  596. }
  597. /**
  598. * Implements hook_entity_property_info_alter().
  599. *
  600. * This is being implemented to ensure chado fields are exposed for search api indexing.
  601. * All fields are available for index by default but the getter function set by default
  602. * is not actually capable of getting the value from chado. Thus we change the getter
  603. * function to one that can :-).
  604. */
  605. function tripal_chado_entity_property_info_alter(&$info) {
  606. // Get a list of fields with the chado storage backend.
  607. // Loop through all of the bundles.
  608. if (isset($info['TripalEntity']['bundles'])) {
  609. foreach ($info['TripalEntity']['bundles'] as $bundle_id => $bundle) {
  610. // Loop through each of the fields for a given bundle.
  611. foreach ($bundle['properties'] as $field_name => $field_info) {
  612. // If the field is a chado field, then change the callback.
  613. // @todo check this properly.
  614. if (preg_match('/(\w+)__(\w+)/', $field_name, $matches)) {
  615. $info['TripalEntity']['bundles'][$bundle_id]['properties'][$field_name]['getter callback'] =
  616. 'tripal_chado_entity_property_get_value';
  617. }
  618. }
  619. }
  620. }
  621. }
  622. /**
  623. * Provides a way for the search api to grab the value of a chado field.
  624. *
  625. * @param $entity
  626. * The fully-loaded entity object to be indexed.
  627. * @param $options
  628. * Options that can be ued when retrieving the value.
  629. * @param $field_name
  630. * The machine name of the field we want to retrieve.
  631. * @param $entity_type
  632. * The type of entity (ie: TripalEntity).
  633. *
  634. * @return
  635. * The rendered value of the field specified by $field_name.
  636. */
  637. function tripal_chado_entity_property_get_value($entity, $options, $field_name, $entity_type) {
  638. $display = array(
  639. 'type' => '',
  640. 'label' => 'hidden',
  641. );
  642. $langcode = LANGUAGE_NONE;
  643. $items = field_get_items($entity_type, $entity, $field_name);
  644. if (count($items) == 1) {
  645. $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
  646. }
  647. // @todo: handle fields with multiple values.
  648. else {
  649. $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
  650. drupal_set_message('Tripal Chado currently only supports views integration for single value fields. The first value has been shown.', 'warning');
  651. }
  652. return drupal_render($render_array);
  653. }
  654. /**
  655. * Remove the nid from chado_entity if it exists when the node is deleted
  656. */
  657. function tripal_chado_node_delete($node) {
  658. $nid = $node->nid;
  659. $sql = "UPDATE chado_entity SET nid = NULL WHERE nid = :nid";
  660. db_query($sql, array('nid' => $nid));
  661. }