tripal_chado.module 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. <?php
  2. /**
  3. * @file
  4. * The Tripal Chado module.
  5. */
  6. /**
  7. * @defgroup tripal_chado Tripal Chado Module
  8. * @ingroup tripal_modules
  9. * @{
  10. * The Tripal Chado module provides functionality for integration with the
  11. * Chado database schema for storing biological content.
  12. * @}
  13. */
  14. /**
  15. * @defgroup tripal_chado_api Chado API
  16. * @{
  17. * The Tripal Chado (tripal_chado) module provides an application programming
  18. * interface (API) to support customizations and creation of new extensions
  19. * using the Chado database schem as a data store.
  20. * @}
  21. */
  22. // Generic Chado API functions
  23. require_once "api/tripal_chado.api.inc";
  24. require_once 'api/tripal_chado.property.api.inc';
  25. require_once 'api/tripal_chado.query.api.inc';
  26. require_once 'api/tripal_chado.entity.api.inc';
  27. require_once 'api/tripal_chado.variables.api.inc';
  28. require_once 'api/tripal_chado.schema.api.inc';
  29. require_once 'api/tripal_chado.custom_tables.api.inc';
  30. require_once 'api/tripal_chado.mviews.api.inc';
  31. require_once 'api/tripal_chado.schema_v1.3.api.inc';
  32. require_once 'api/tripal_chado.schema_v1.2.api.inc';
  33. require_once 'api/tripal_chado.schema_v1.11.api.inc';
  34. require_once 'api/tripal_chado.semweb.api.inc';
  35. require_once 'api/tripal_chado.migrate.api.inc';
  36. require_once 'api/tripal_chado.DEPRECATED.api.inc';
  37. // Chado module specific API functions
  38. require_once 'api/modules/tripal_chado.analysis.api.inc';
  39. require_once 'api/modules/tripal_chado.contact.api.inc';
  40. require_once 'api/modules/tripal_chado.cv.api.inc';
  41. require_once 'api/modules/tripal_chado.db.api.inc';
  42. require_once 'api/modules/tripal_chado.feature.api.inc';
  43. require_once 'api/modules/tripal_chado.organism.api.inc';
  44. require_once 'api/modules/tripal_chado.pub.api.inc';
  45. require_once 'api/modules/tripal_chado.stock.api.inc';
  46. require_once 'api/modules/tripal_chado.phylotree.api.inc';
  47. require_once 'api/modules/tripal_chado.module.DEPRECATED.api.inc';
  48. //
  49. // REQUIRED INCLUDE FILES
  50. //
  51. // These require files implement hooks and therefore must
  52. // ways be included when the module is interpreted.
  53. require_once "includes/tripal_chado.entity.inc";
  54. require_once "includes/tripal_chado.schema.inc";
  55. require_once "includes/tripal_chado.vocab_storage.inc";
  56. require_once "includes/tripal_chado.field_storage.inc";
  57. require_once "includes/tripal_chado.bundle.inc";
  58. require_once "includes/tripal_chado.fields.inc";
  59. require_once "includes/tripal_chado.mapping.inc";
  60. require_once "includes/TripalFields/ChadoField.inc";
  61. require_once "includes/TripalFields/ChadoFieldWidget.inc";
  62. require_once "includes/TripalFields/ChadoFieldFormatter.inc";
  63. require_once "includes/ChadoDatabaseConnection.inc";
  64. tripal_chado_set_globals();
  65. /**
  66. * This function is used to set the global Chado variables
  67. *
  68. * @ingroup tripal_chado
  69. */
  70. function tripal_chado_set_globals() {
  71. // These global variables are meant to be accessed by all Tripal
  72. // modules to find the chado version installed and if Chado is local.
  73. // These variables are stored as globals rather than using the
  74. // drupal_set_variable functions because the Drupal functions make databaes
  75. // queries and for long running loaders we don't want those queries
  76. // repeatedly.
  77. $GLOBALS["chado_is_installed"] = chado_is_installed();
  78. if ($GLOBALS["chado_is_installed"]) {
  79. $GLOBALS["chado_is_local"] = chado_is_local();
  80. $GLOBALS["chado_version"] = chado_get_version();
  81. $GLOBALS["exact_chado_version"] = chado_get_version(TRUE);
  82. $GLOBALS["chado_tables"] = array();
  83. }
  84. }
  85. /**
  86. * Implements hook_init().
  87. *
  88. * @ingroup tripal_chado
  89. */
  90. function tripal_chado_init() {
  91. if (user_access('administer tripal')) {
  92. if ($GLOBALS["chado_is_installed"]) {
  93. // Check to see if the Chado and Drupal have been prepared
  94. if (!variable_get('tripal_chado_is_prepared', FALSE)) {
  95. drupal_set_message('Chado is installed but Tripal has not yet prepared Drupal and Chado. Please ' .
  96. l('prepare both Drupal and Chado', 'admin/tripal/storage/chado/prepare') .
  97. ' before continuing.', 'warning');
  98. }
  99. }
  100. else {
  101. drupal_set_message('Tripal cannot find a Chado installation. Please ' .
  102. l('install Chado', 'admin/tripal/storage/chado/install') .
  103. ' before continuing.', 'warning');
  104. }
  105. }
  106. }
  107. /**
  108. * Implements hook_views_api().
  109. *
  110. * Essentially this hook tells drupal that there is views support for
  111. * for this module which then includes tripal_db.views.inc where all the
  112. * views integration code is
  113. *
  114. * @ingroup tripal_feature
  115. */
  116. function tripal_chado_views_api() {
  117. return array(
  118. 'api' => 3.0,
  119. );
  120. }
  121. /**
  122. * Implements hook_menu().
  123. */
  124. function tripal_chado_menu() {
  125. $items = array();
  126. //////////////////////////////////////////////////////////////////////////////
  127. // Chado Storage Backend
  128. //////////////////////////////////////////////////////////////////////////////
  129. $items['admin/tripal/storage/chado'] = array(
  130. 'title' => 'Chado',
  131. 'description' => t("Integrates Chado with Tripal and includes tools to
  132. load data, and extend the chado schema through custom tables &
  133. materialized views."),
  134. 'weight' => -100,
  135. 'access arguments' => array('administer tripal'),
  136. );
  137. $items['admin/tripal/storage/chado/install'] = array(
  138. 'title' => 'Install Chado',
  139. 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'),
  140. 'page callback' => 'drupal_get_form',
  141. 'page arguments' => array('tripal_chado_load_form'),
  142. 'type' => MENU_NORMAL_ITEM,
  143. 'access arguments' => array('install chado'),
  144. 'file' => 'includes/tripal_chado.install.inc',
  145. 'file path' => drupal_get_path('module', 'tripal_chado'),
  146. 'weight' => -100
  147. );
  148. $items['admin/tripal/storage/chado/prepare'] = array(
  149. 'title' => 'Prepare Chado',
  150. 'description' => t('Prepares Drupal to use Chado.'),
  151. 'page callback' => 'drupal_get_form',
  152. 'page arguments' => array('tripal_chado_prepare_form'),
  153. 'type' => MENU_NORMAL_ITEM,
  154. 'access arguments' => array('install chado'),
  155. 'file' => 'includes/setup/tripal_chado.setup.inc',
  156. 'file path' => drupal_get_path('module', 'tripal_chado'),
  157. 'weight' => -99
  158. );
  159. $items['admin/tripal/storage/chado/publish'] = array(
  160. 'title' => 'Publish',
  161. 'description' => t('Publish data that is present in Chado but which does
  162. not yet have a page on this site for viewing. In Tripal v2.0 or
  163. earlier this was refered to as "syncing".'),
  164. 'page callback' => 'drupal_get_form',
  165. 'page arguments' => array('tripal_chado_publish_form'),
  166. 'type' => MENU_NORMAL_ITEM,
  167. 'access arguments' => array('publish tripal content'),
  168. 'file' => 'includes/tripal_chado.publish.inc',
  169. 'file path' => drupal_get_path('module', 'tripal_chado'),
  170. 'weight' => -99
  171. );
  172. // Adds a +Publish Chado Content link on the 'Tripal Content Types' page.
  173. $items['admin/structure/bio_data/publish'] = array(
  174. 'title' => 'Publish Tripal Content',
  175. 'description' => t('Publish data that is present in Chado but which does
  176. not yet have a page on this site for viewing. In Tripal v2.0 or
  177. earlier this was refered to as "syncing".'),
  178. 'page callback' => 'drupal_get_form',
  179. 'page arguments' => array('tripal_chado_publish_form'),
  180. 'access arguments' => array('publish tripal content'),
  181. 'file' => 'includes/tripal_chado.publish.inc',
  182. 'file path' => drupal_get_path('module', 'tripal_chado'),
  183. 'type' => MENU_LOCAL_ACTION,
  184. 'weight' => 2
  185. );
  186. $items['admin/content/bio_data/publish'] = array(
  187. 'title' => 'Publish Tripal Content',
  188. 'description' => t('Publish data that is present in Chado but which does
  189. not yet have a page on this site for viewing. In Tripal v2.0 or
  190. earlier this was refered to as "syncing".'),
  191. 'page callback' => 'drupal_get_form',
  192. 'page arguments' => array('tripal_chado_publish_form'),
  193. 'access arguments' => array('publish tripal content'),
  194. 'file' => 'includes/tripal_chado.publish.inc',
  195. 'file path' => drupal_get_path('module', 'tripal_chado'),
  196. 'type' => MENU_LOCAL_ACTION,
  197. 'weight' => 2
  198. );
  199. //////////////////////////////////////////////////////////////////////////////
  200. // Materialized Views
  201. //////////////////////////////////////////////////////////////////////////////
  202. $items['admin/tripal/storage/chado/mviews'] = array(
  203. 'title' => 'Materialized Views',
  204. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  205. 'page callback' => 'tripal_mview_admin_view',
  206. 'access arguments' => array('administer chado mviews'),
  207. 'type' => MENU_NORMAL_ITEM,
  208. 'file' => 'includes/tripal_chado.mviews.inc',
  209. 'file path' => drupal_get_path('module', 'tripal_chado'),
  210. 'weight' => -10
  211. );
  212. $items['admin/tripal/storage/chado/mviews/help'] = array(
  213. 'title' => 'Help',
  214. 'description' => t('Help for the materialized views management system'),
  215. 'page callback' => 'theme',
  216. 'page arguments' => array('tripal_mviews_help'),
  217. 'access arguments' => array('administer chado mviews'),
  218. 'type' => MENU_LOCAL_TASK,
  219. 'file' => 'includes/tripal_chado.mviews.inc',
  220. 'file path' => drupal_get_path('module', 'tripal_chado'),
  221. 'weight' => 10
  222. );
  223. $items['admin/tripal/storage/chado/mviews/report/%'] = array(
  224. 'title' => 'Materialized View',
  225. 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'),
  226. 'page callback' => 'tripal_mview_report',
  227. 'page arguments' => array(6),
  228. 'access arguments' => array('administer chado mviews'),
  229. 'type' => MENU_CALLBACK,
  230. 'file' => 'includes/tripal_chado.mviews.inc',
  231. 'file path' => drupal_get_path('module', 'tripal_chado'),
  232. );
  233. $items['admin/tripal/storage/chado/mviews/new'] = array(
  234. 'title' => 'Create Materialized View',
  235. 'description' => t('Create a new materialized view.'),
  236. 'page callback' => 'drupal_get_form',
  237. 'page arguments' => array('tripal_mviews_form'),
  238. 'access arguments' => array('administer chado mviews'),
  239. 'type' => MENU_CALLBACK,
  240. 'file' => 'includes/tripal_chado.mviews.inc',
  241. 'file path' => drupal_get_path('module', 'tripal_chado'),
  242. );
  243. $items['admin/tripal/storage/chado/mviews/edit/%'] = array(
  244. 'title' => 'Edit Materialized View',
  245. 'page callback' => 'drupal_get_form',
  246. 'page arguments' => array('tripal_mviews_form', 6),
  247. 'access arguments' => array('administer chado mviews'),
  248. 'type' => MENU_CALLBACK,
  249. 'file' => 'includes/tripal_chado.mviews.inc',
  250. 'file path' => drupal_get_path('module', 'tripal_chado'),
  251. );
  252. $items['admin/tripal/storage/chado/mviews/update/%'] = array(
  253. 'title' => 'Create Materialized View',
  254. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  255. 'page callback' => 'tripal_mviews_add_populate_job',
  256. 'page arguments' => array(6),
  257. 'access arguments' => array('administer chado mviews'),
  258. 'type' => MENU_CALLBACK,
  259. 'file' => 'includes/tripal_chado.mviews.inc',
  260. 'file path' => drupal_get_path('module', 'tripal_chado'),
  261. );
  262. $items['admin/tripal/storage/chado/mviews/delete/%'] = array(
  263. 'title' => 'Create Materialized View',
  264. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  265. 'page callback' => 'drupal_get_form',
  266. 'page arguments' => array('tripal_mviews_delete_form', 6),
  267. 'access arguments' => array('administer chado mviews'),
  268. 'type' => MENU_CALLBACK,
  269. 'file' => 'includes/tripal_chado.mviews.inc',
  270. 'file path' => drupal_get_path('module', 'tripal_chado'),
  271. );
  272. // TODO: complete the code for exporting and importing of MViews.
  273. // Need to address security issues of sharing SQL.
  274. $items['admin/tripal/storage/chado/mviews/import'] = array(
  275. 'title' => 'Import MView',
  276. 'description' => 'Import a materialized view from another Tripal instance.',
  277. 'page callback' => 'drupal_get_form',
  278. 'page arguments' => array('tripal_mviews_import_form'),
  279. 'access arguments' => array('administer chado mviews'),
  280. 'type' => MENU_CALLBACK,
  281. 'file' => 'includes/tripal_chado.mviews.inc',
  282. 'file path' => drupal_get_path('module', 'tripal_chado'),
  283. );
  284. $items['admin/tripal/storage/chado/mviews/%tblid/export'] = array(
  285. 'title' => 'Export MView',
  286. 'description' => 'Export a materialized view for use by another Tripal instance.',
  287. 'page callback' => 'drupal_get_form',
  288. 'page arguments' => array('tripal_mviews_export_form', 5),
  289. 'access arguments' => array('administer chado mviews'),
  290. 'type' => MENU_CALLBACK,
  291. 'file' => 'includes/tripal_chado.mviews.inc',
  292. 'file path' => drupal_get_path('module', 'tripal_chado'),
  293. );
  294. //////////////////////////////////////////////////////////////////////////////
  295. // Custom Tables
  296. //////////////////////////////////////////////////////////////////////////////
  297. $items['admin/tripal/storage/chado/custom_tables'] = array(
  298. 'title' => 'Custom Tables',
  299. 'description' => t('Creation of custom tables that are added to Chado database.'),
  300. 'page callback' => 'tripal_custom_table_admin_view',
  301. 'access arguments' => array('administer chado custom tables'),
  302. 'type' => MENU_NORMAL_ITEM,
  303. 'file' => 'includes/tripal_chado.custom_tables.inc',
  304. 'file path' => drupal_get_path('module', 'tripal_chado'),
  305. 'weight' => -10
  306. );
  307. $items['admin/tripal/storage/chado/custom_tables/help'] = array(
  308. 'title' => 'Help',
  309. 'description' => t('Help for the tripal job management system'),
  310. 'page callback' => 'theme',
  311. 'page arguments' => array('tripal_job_help'),
  312. 'access arguments' => array('administer chado custom tables'),
  313. 'type' => MENU_LOCAL_TASK,
  314. 'file' => 'includes/tripal_chado.custom_tables.inc',
  315. 'file path' => drupal_get_path('module', 'tripal_chado'),
  316. 'weight' => 10
  317. );
  318. $items['admin/tripal/storage/chado/custom_tables/view/%'] = array(
  319. 'title' => 'Custom Tables',
  320. 'description' => t('Custom tables are added to Chado.'),
  321. 'page callback' => 'tripal_custom_table_view',
  322. 'page arguments' => array(6),
  323. 'access arguments' => array('administer chado custom tables'),
  324. 'file' => 'includes/tripal_chado.custom_tables.inc',
  325. 'file path' => drupal_get_path('module', 'tripal_chado'),
  326. 'type' => MENU_CALLBACK,
  327. );
  328. $items['admin/tripal/storage/chado/custom_tables/new'] = array(
  329. 'title' => 'Create Custom Table',
  330. 'description' => t('An interface for creating your own custom tables.'),
  331. 'page callback' => 'tripal_custom_table_new_page',
  332. 'access arguments' => array('administer chado custom tables'),
  333. 'file' => 'includes/tripal_chado.custom_tables.inc',
  334. 'file path' => drupal_get_path('module', 'tripal_chado'),
  335. 'type' => MENU_CALLBACK,
  336. );
  337. $items['admin/tripal/storage/chado/custom_tables/edit/%'] = array(
  338. 'title' => 'Edit Custom Table',
  339. 'page callback' => 'drupal_get_form',
  340. 'page arguments' => array('tripal_custom_tables_form', 6),
  341. 'access arguments' => array('administer chado custom tables'),
  342. 'file' => 'includes/tripal_chado.custom_tables.inc',
  343. 'file path' => drupal_get_path('module', 'tripal_chado'),
  344. 'type' => MENU_CALLBACK,
  345. );
  346. $items['admin/tripal/storage/chado/custom_tables/delete/%'] = array(
  347. 'title' => 'Create Custom Table',
  348. 'description' => t('Custom tables are added to Chado.'),
  349. 'page callback' => 'drupal_get_form',
  350. 'page arguments' => array('tripal_custom_tables_delete_form', 6),
  351. 'access arguments' => array('administer chado custom tables'),
  352. 'file' => 'includes/tripal_chado.custom_tables.inc',
  353. 'file path' => drupal_get_path('module', 'tripal_chado'),
  354. 'type' => MENU_CALLBACK,
  355. );
  356. $items['admin/tripal/storage/chado/custom_tables/views/tables/enable'] = array(
  357. 'title' => 'Enable Custom Tables Administrative View',
  358. 'page callback' => 'tripal_enable_view',
  359. 'page arguments' => array('tripal_admin_custom_table', 'admin/tripal/storage/chado/custom_tables'),
  360. 'access arguments' => array('administer chado custom tables'),
  361. 'file' => 'includes/tripal_chado.custom_tables.inc',
  362. 'file path' => drupal_get_path('module', 'tripal_chado'),
  363. 'type' => MENU_CALLBACK,
  364. );
  365. //////////////////////////////////////////////////////////////////////////////
  366. // Data Loaders
  367. //////////////////////////////////////////////////////////////////////////////
  368. $items['admin/tripal/loaders/pub'] = array(
  369. 'title' => t('Chado Bulk Publication Importer Callback'),
  370. 'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
  371. 'page callback' => 'tripal_pub_importers_list',
  372. 'access arguments' => array('use chado_pub_bulk importer'),
  373. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  374. 'file path' => drupal_get_path('module', 'tripal_chado'),
  375. 'type' => MENU_CALLBACK,
  376. 'weight' => 0
  377. );
  378. $items['admin/tripal/loaders/pub/new'] = array(
  379. 'title' => t('Add an Importer'),
  380. 'description' => t('Add a new publication importer.'),
  381. 'page callback' => 'tripal_pub_importer_setup_page',
  382. 'access arguments' => array('use chado_pub_bulk importer'),
  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/loaders/pub/edit/%'] = array(
  388. 'page callback' => 'tripal_pub_importer_setup_page',
  389. 'page arguments' => array('edit', 5),
  390. 'access arguments' => array('use chado_pub_bulk importer'),
  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/loaders/pub/raw/%'] = array(
  396. 'page callback' => 'tripal_get_remote_pub_raw_page',
  397. 'page arguments' => array(5),
  398. 'access arguments' => array('use chado_pub_bulk importer'),
  399. 'type ' => MENU_CALLBACK,
  400. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  401. 'file path' => drupal_get_path('module', 'tripal_chado'),
  402. );
  403. // add a second link for the importer on the data loaders page
  404. $items['admin/tripal/loaders/pub/import'] = array(
  405. 'page callback' => 'tripal_pub_importers_list',
  406. 'access arguments' => array('use chado_pub_bulk importer'),
  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/loaders/pub/submit/%'] = array(
  412. 'page callback' => 'tripal_pub_importer_submit_job',
  413. 'page arguments' => array(5),
  414. 'access arguments' => array('use chado_pub_bulk importer'),
  415. 'type ' => MENU_CALLBACK,
  416. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  417. 'file path' => drupal_get_path('module', 'tripal_chado'),
  418. );
  419. $items['admin/tripal/loaders/pub/delete/%'] = array(
  420. 'page callback' => 'tripal_pub_importer_delete',
  421. 'page arguments' => array(5),
  422. 'access arguments' => array('use chado_pub_bulk importer'),
  423. 'type ' => MENU_CALLBACK,
  424. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  425. 'file path' => drupal_get_path('module', 'tripal_chado'),
  426. );
  427. $items['admin/tripal/loaders/pub/changedb'] = array(
  428. 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
  429. 'page arguments' => array(),
  430. 'access arguments' => array('use chado_pub_bulk importer'),
  431. 'type ' => MENU_CALLBACK,
  432. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  433. 'file path' => drupal_get_path('module', 'tripal_chado'),
  434. );
  435. $items['admin/tripal/loaders/pub/criteria/%/%'] = array(
  436. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  437. 'page arguments' => array(5, 6),
  438. 'access arguments' => array('use chado_pub_bulk importer'),
  439. 'type ' => MENU_CALLBACK,
  440. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  441. 'file path' => drupal_get_path('module', 'tripal_chado'),
  442. );
  443. //////////////////////////////////////////////////////////////////////////////
  444. // Migrate Content
  445. //////////////////////////////////////////////////////////////////////////////
  446. $items['admin/tripal/storage/chado/migrate'] = array(
  447. 'title' => 'Migrate',
  448. 'description' => t('Migrate Tripal v2 content to Tripal v3'),
  449. 'page callback' => 'drupal_get_form',
  450. 'page arguments' => array('tripal_chado_migrate_form'),
  451. 'type' => MENU_NORMAL_ITEM,
  452. 'access arguments' => array('administer tripal'),
  453. 'file' => 'includes/tripal_chado.migrate.inc',
  454. 'file path' => drupal_get_path('module', 'tripal_chado'),
  455. 'weight' => 10
  456. );
  457. //////////////////////////////////////////////////////////////////////////////
  458. // Semantic Web Settings
  459. //////////////////////////////////////////////////////////////////////////////
  460. $items['admin/tripal/storage/chado/semweb'] = array(
  461. 'title' => 'Semantic Web',
  462. 'description' => t('Semantic web settings. Set terms used for the web services.'),
  463. 'page callback' => 'drupal_get_form',
  464. 'page arguments' => array('tripal_chado_semweb_form'),
  465. 'type' => MENU_NORMAL_ITEM,
  466. 'access arguments' => array('administer chado semantic web'),
  467. 'file' => 'includes/tripal_chado.semweb.inc',
  468. 'file path' => drupal_get_path('module', 'tripal_chado'),
  469. 'weight' => 10
  470. );
  471. $items['admin/tripal/storage/chado/semweb/edit/%/%'] = array(
  472. 'title' => 'Edit Semantic Web Term',
  473. 'description' => t('Edit terms used for the web services.'),
  474. 'page callback' => 'drupal_get_form',
  475. 'page arguments' => array('tripal_chado_semweb_edit_form', 6, 7),
  476. 'type' => MENU_CALLBACK,
  477. 'access arguments' => array('administer chado semantic web'),
  478. 'file' => 'includes/tripal_chado.semweb.inc',
  479. 'file path' => drupal_get_path('module', 'tripal_chado'),
  480. );
  481. $items['admin/tripal/storage/chado/semweb/reset/%/%'] = array(
  482. 'title' => 'Reset Semantic Web Term',
  483. 'description' => t('Edit terms used for the web services.'),
  484. 'page callback' => 'drupal_get_form',
  485. 'page arguments' => array('tripal_chado_semweb_reset_form', 6, 7),
  486. 'type' => MENU_CALLBACK,
  487. 'access arguments' => array('administer chado semantic web'),
  488. 'file' => 'includes/tripal_chado.semweb.inc',
  489. 'file path' => drupal_get_path('module', 'tripal_chado'),
  490. );
  491. //////////////////////////////////////////////////////////////////////////////
  492. // Auto Completes
  493. //////////////////////////////////////////////////////////////////////////////
  494. $items['admin/tripal/storage/chado/auto_name/dbxref/%/%'] = array(
  495. 'page callback' => 'chado_autocomplete_dbxref',
  496. 'page arguments' => array(6, 7),
  497. 'access arguments' => array('access content'),
  498. 'file' => 'api/modules/tripal_chado.db.api.inc',
  499. 'file path' => drupal_get_path('module', 'tripal_chado'),
  500. 'type' => MENU_CALLBACK,
  501. );
  502. $items['admin/tripal/storage/chado/auto_name/cv/%'] = array(
  503. 'page callback' => 'chado_autocomplete_cv',
  504. 'page arguments' => array(6),
  505. 'access arguments' => array('access content'),
  506. 'file' => 'api/modules/tripal_chado.cv.api.inc',
  507. 'file path' => drupal_get_path('module', 'tripal_chado'),
  508. 'type' => MENU_CALLBACK,
  509. );
  510. $items['admin/tripal/storage/chado/auto_name/cvterm/%/%'] = array(
  511. 'page callback' => 'chado_autocomplete_cvterm',
  512. 'page arguments' => array(6, 7),
  513. 'access arguments' => array('access content'),
  514. 'file' => 'api/modules/tripal_chado.cv.api.inc',
  515. 'file path' => drupal_get_path('module', 'tripal_chado'),
  516. 'type' => MENU_CALLBACK,
  517. );
  518. $items['admin/tripal/storage/chado/auto_name/pub/%'] = array(
  519. 'page callback' => 'chado_autocomplete_pub',
  520. 'page arguments' => array(6),
  521. 'access arguments' => array('access content'),
  522. 'file' => 'api/modules/tripal_chado.pub.api.inc',
  523. 'file path' => drupal_get_path('module', 'tripal_chado'),
  524. 'type' => MENU_CALLBACK,
  525. );
  526. $items['admin/tripal/storage/chado/auto_name/contact/%'] = array(
  527. 'page callback' => 'tripal_autocomplete_contact',
  528. 'page arguments' => array(6),
  529. 'access arguments' => array('access content'),
  530. 'file' => 'api/modules/tripal_chado.contact.api.inc',
  531. 'file path' => drupal_get_path('module', 'tripal_chado'),
  532. 'type' => MENU_CALLBACK,
  533. );
  534. $items['admin/tripal/storage/chado/auto_name/feature/%'] = array(
  535. 'page callback' => 'chado_autocomplete_feature',
  536. 'page arguments' => array(6),
  537. 'access arguments' => array('access content'),
  538. 'file' => 'api/modules/tripal_chado.feature.api.inc',
  539. 'file path' => drupal_get_path('module', 'tripal_chado'),
  540. 'type' => MENU_CALLBACK,
  541. );
  542. $items['admin/tripal/storage/chado/auto_name/organism/%'] = array(
  543. 'page callback' => 'chado_autocomplete_organism',
  544. 'page arguments' => array(6),
  545. 'access arguments' => array('access content'),
  546. 'file' => 'api/modules/tripal_chado.organism.api.inc',
  547. 'file path' => drupal_get_path('module', 'tripal_chado'),
  548. 'type' => MENU_CALLBACK,
  549. );
  550. //////////////////////////////////////////////////////////////////////////////
  551. // Controlled Vocabularies
  552. //////////////////////////////////////////////////////////////////////////////
  553. $items['admin/tripal/loaders/chado_vocabs'] = array(
  554. 'title' => 'Chado Vocabularies',
  555. 'description' => t('Tools facilitating management (including import) of controlled
  556. vocabularies and their terms into Chado.'),
  557. 'access arguments' => array('administer controlled vocabularies'),
  558. 'type' => MENU_NORMAL_ITEM,
  559. 'weight' => 6
  560. );
  561. $items['admin/tripal/loaders/chado_vocabs/chado_cv'] = array(
  562. 'title' => 'Manage Chado CVs',
  563. 'description' => 'View, edit and add controlled vocabularies used by this site.',
  564. 'page callback' => 'tripal_cv_admin_cv_listing',
  565. 'access arguments' => array('administer controlled vocabularies'),
  566. 'file' => 'includes/tripal_chado.cv.inc',
  567. 'file path' => drupal_get_path('module', 'tripal_chado'),
  568. 'type' => MENU_NORMAL_ITEM,
  569. );
  570. $items['admin/tripal/loaders/chado_vocabs/chado_cv/edit/%'] = array(
  571. 'title' => 'Edit a Controlled Vocabulary',
  572. 'description' => 'Edit the details such as name and description for an existing controlled vocabulary.',
  573. 'page callback' => 'drupal_get_form',
  574. 'page arguments' => array('tripal_cv_cv_edit_form', 6),
  575. 'access callback' => 'user_access',
  576. 'access arguments' => array('administer controlled vocabularies'),
  577. 'file' => 'includes/tripal_chado.cv.inc',
  578. 'file path' => drupal_get_path('module', 'tripal_chado'),
  579. 'type' => MENU_CALLBACK,
  580. );
  581. $items['admin/tripal/loaders/chado_vocabs/chado_cv/delete/%'] = array(
  582. 'title' => 'Delete a Controlled Vocabulary',
  583. 'description' => 'Delete a controlled vocabulary.',
  584. 'page callback' => 'drupal_get_form',
  585. 'page arguments' => array('tripal_cv_cv_delete_form', 6),
  586. 'access callback' => 'user_access',
  587. 'access arguments' => array('administer controlled vocabularies'),
  588. 'file' => 'includes/tripal_chado.cv.inc',
  589. 'file path' => drupal_get_path('module', 'tripal_chado'),
  590. 'type' => MENU_CALLBACK,
  591. );
  592. $items['admin/tripal/loaders/chado_vocabs/chado_cv/add'] = array(
  593. 'title' => 'Add a Controlled Vocabulary',
  594. 'description' => 'Manually a new controlled vocabulary.',
  595. 'page callback' => 'drupal_get_form',
  596. 'page arguments' => array('tripal_cv_cv_add_form'),
  597. 'access callback' => 'user_access',
  598. 'access arguments' => array('administer controlled vocabularies'),
  599. 'file' => 'includes/tripal_chado.cv.inc',
  600. 'file path' => drupal_get_path('module', 'tripal_chado'),
  601. 'type' => MENU_CALLBACK,
  602. );
  603. $items['admin/tripal/loaders/chado_vocabs/chado_cv/%/cvterm/add'] = array(
  604. 'title' => 'Add a Controlled Vocabulary Term',
  605. 'description' => 'Add a new controlled vocabulary term.',
  606. 'page callback' => 'drupal_get_form',
  607. 'page arguments' => array('tripal_cv_cvterm_add_form', 5),
  608. 'access arguments' => array('administer controlled vocabularies'),
  609. 'file' => 'includes/tripal_chado.cv.inc',
  610. 'file path' => drupal_get_path('module', 'tripal_chado'),
  611. 'type' => MENU_CALLBACK,
  612. );
  613. $items['admin/tripal/loaders/chado_vocabs/chado_cv/cvterm/add'] = array(
  614. 'title' => 'Add a Controlled Vocabulary Term',
  615. 'description' => 'Add a new controlled vocabulary term.',
  616. 'page callback' => 'drupal_get_form',
  617. 'page arguments' => array('tripal_cv_cvterm_add_form'),
  618. 'access arguments' => array('administer controlled vocabularies'),
  619. 'file' => 'includes/tripal_chado.cv.inc',
  620. 'file path' => drupal_get_path('module', 'tripal_chado'),
  621. 'type' => MENU_CALLBACK,
  622. );
  623. $items['admin/tripal/loaders/chado_vocabs/chado_cv/%/cvterm/edit/%'] = array(
  624. 'title' => 'Edit a Controlled Vocabulary Term',
  625. 'description' => 'Edit an existing controlled vocabulary term.',
  626. 'page callback' => 'drupal_get_form',
  627. 'page arguments' => array('tripal_cv_cvterm_edit_form', 5, 8),
  628. 'access arguments' => array('administer controlled vocabularies'),
  629. 'file' => 'includes/tripal_chado.cv.inc',
  630. 'file path' => drupal_get_path('module', 'tripal_chado'),
  631. 'type' => MENU_CALLBACK,
  632. );
  633. $items['admin/tripal/loaders/chado_vocabs/cvtermpath'] = array(
  634. 'title' => 'Update CV Term Paths',
  635. 'description' => 'The Chado cvtermpath table provides lineage for
  636. controlled vocabulary terms and is useful for quickly finding any
  637. ancestor parent of a term. If controlled vocabularies are loaded
  638. using the OBO Importer then the vocabulary is automatically added to
  639. the cvtermpath table. However, if it is needed, the addition of terms
  640. to the cvtermpath table can be manually executed here.',
  641. 'page callback' => 'drupal_get_form',
  642. 'page arguments' => array('tripal_cv_cvtermpath_form'),
  643. 'access arguments' => array('administer controlled vocabularies'),
  644. 'file' => 'includes/tripal_chado.cv.inc',
  645. 'file path' => drupal_get_path('module', 'tripal_chado'),
  646. 'type' => MENU_NORMAL_ITEM,
  647. );
  648. //////////////////////////////////////////////////////////////////////////////
  649. // Databases
  650. //////////////////////////////////////////////////////////////////////////////
  651. $items['admin/tripal/loaders/chado_db'] = array(
  652. 'title' => 'Chado Databases',
  653. 'description' => 'View, edit and add external databases. When data originates
  654. from a remote online resource (or database) then that database must
  655. be added in order to cross link records in this site to records in
  656. the remote site.',
  657. 'page callback' => 'tripal_chado_admin_db_listing',
  658. 'access arguments' => array('administer db cross-references'),
  659. 'file' => 'includes/tripal_chado.db.inc',
  660. 'file path' => drupal_get_path('module', 'tripal_chado'),
  661. 'type' => MENU_NORMAL_ITEM,
  662. );
  663. $items['admin/tripal/loaders/chado_db/edit/%'] = array(
  664. 'title' => 'Edit a Database Reference',
  665. 'description' => 'Edit existing Database References.',
  666. 'page callback' => 'drupal_get_form',
  667. 'page arguments' => array('tripal_chado_db_edit_form', 5),
  668. 'access callback' => 'user_access',
  669. 'access arguments' => array('administer db cross-references'),
  670. 'file' => 'includes/tripal_chado.db.inc',
  671. 'file path' => drupal_get_path('module', 'tripal_chado'),
  672. 'type' => MENU_CALLBACK,
  673. );
  674. $items['admin/tripal/loaders/chado_db/add'] = array(
  675. 'title' => 'Create a Database Reference',
  676. 'description' => 'Create a new reference to an External Database.',
  677. 'page callback' => 'drupal_get_form',
  678. 'page arguments' => array('tripal_chado_db_add_form'),
  679. 'access callback' => 'user_access',
  680. 'access arguments' => array('administer db cross-references'),
  681. 'file' => 'includes/tripal_chado.db.inc',
  682. 'file path' => drupal_get_path('module', 'tripal_chado'),
  683. 'type' => MENU_CALLBACK,
  684. );
  685. //////////////////////////////////////////////////////////////////////////////
  686. // FEATURES
  687. //////////////////////////////////////////////////////////////////////////////
  688. // the menu link for addressing any feature (by name, uniquename, synonym)
  689. $items['feature/%'] = array(
  690. 'page callback' => 'tripal_feature_match_features_page',
  691. 'page arguments' => array(1),
  692. 'access arguments' => array('access chado_feature content'),
  693. 'type' => MENU_LOCAL_TASK,
  694. );
  695. // the administative settings menu
  696. $items['find/sequences'] = array(
  697. 'title' => 'Sequence Retrieval',
  698. 'description' => 'Download a file of sequences',
  699. 'page callback' => 'drupal_get_form',
  700. 'page arguments' => array('tripal_chado_feature_seq_extract_form'),
  701. 'access arguments' => array('access content'),
  702. 'file' => 'includes/tripal_chado.seq_extract.inc',
  703. 'file path' => drupal_get_path('module', 'tripal_chado'),
  704. 'type' => MENU_CALLBACK,
  705. );
  706. $items['find/sequences/download'] = array(
  707. 'page callback' => 'tripal_chado_feature_seq_extract_download',
  708. 'access arguments' => array('access content'),
  709. 'file' => 'includes/tripal_chado.seq_extract.inc',
  710. 'file path' => drupal_get_path('module', 'tripal_chado'),
  711. 'type' => MENU_CALLBACK,
  712. );
  713. //////////////////////////////////////////////////////////////////////////////
  714. // Publications
  715. //////////////////////////////////////////////////////////////////////////////
  716. $items['find/publications' ]= array(
  717. 'title' => 'Publication Search',
  718. 'description' => ('Search for publications'),
  719. 'page callback' => 'tripal_chado_pub_search_page',
  720. 'access arguments' => array('access content'),
  721. 'file' => 'includes/tripal_chado.pub_search.inc',
  722. 'file path' => drupal_get_path('module', 'tripal_chado'),
  723. 'type' => MENU_CALLBACK
  724. );
  725. $items['find/publications/criteria/%/%'] = array(
  726. 'page callback' => 'tripal_chado_pub_search_page_update_criteria',
  727. 'page arguments' => array(5, 6),
  728. 'access arguments' => array('access content'),
  729. 'file' => 'includes/tripal_chado.pub_search.inc',
  730. 'file path' => drupal_get_path('module', 'tripal_chado'),
  731. 'type ' => MENU_CALLBACK,
  732. );
  733. $items['admin/tripal/storage/chado/pub-search-config'] = array(
  734. 'title' => 'Publication Search Settings',
  735. 'description' => 'Configure the settings for the publication search.',
  736. 'page callback' => 'drupal_get_form',
  737. 'page arguments' => array('tripal_chado_pub_search_admin_form'),
  738. 'file' => 'includes/tripal_chado.pub_search.inc',
  739. 'file path' => drupal_get_path('module', 'tripal_chado'),
  740. 'type' => MENU_NORMAL_ITEM,
  741. 'access arguments' => array('administer tripal'),
  742. );
  743. //////////////////////////////////////////////////////////////////////////////
  744. // Phylogeny
  745. //////////////////////////////////////////////////////////////////////////////
  746. // create a route for viewing json of all phylonodes having this phylotree_id
  747. $items['phylotree/%'] = array(
  748. 'page callback' => 'tripal_phylogeny_ajax_get_tree_json',
  749. 'page arguments' => array(1),
  750. // allow all anonymous http clients
  751. 'access callback' => TRUE,
  752. 'file' => 'includes/tripal_chado.phylotree.inc',
  753. 'file path' => drupal_get_path('module', 'tripal_chado'),
  754. );
  755. $items['admin/tripal/storage/chado/phylogeny'] = array(
  756. 'title' => 'Phylogeny and Taxonomy',
  757. 'description' => 'Settings for display of phylogenetic and taxonomic trees.',
  758. 'page callback' => 'drupal_get_form',
  759. 'page arguments' => array('tripal_phylogeny_default_plots_form'),
  760. 'access arguments' => array('administer tripal'),
  761. 'type' => MENU_NORMAL_ITEM,
  762. 'weight' => 2,
  763. 'file' => 'includes/tripal_chado.phylotree.inc',
  764. 'file path' => drupal_get_path('module', 'tripal_chado'),
  765. );
  766. return $items;
  767. }
  768. /**
  769. * Implements hook_permission().
  770. *
  771. * Set the permission types that the chado module uses. Essentially we
  772. * want permissionis that protect creation, editing and deleting of chado
  773. * data objects
  774. *
  775. * @ingroup tripal
  776. */
  777. function tripal_chado_permission() {
  778. return array(
  779. 'install chado' => array(
  780. 'title' => t('Install Chado'),
  781. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  782. ),
  783. 'view chado_ids' => array(
  784. 'title' => t('View Internal IDs'),
  785. 'description' => t('On content pages Tripal will typically provide
  786. a table of information pulled from the Chado database but the
  787. primary key IDs for that data is typically not shown. The
  788. default Tripal templates can show the primary key ID inside of a
  789. blue shaded table row if this permission is enabled. This can
  790. be useful for site developers who might want these IDs when working
  791. with the underlying database.'),
  792. 'restrict access' => TRUE,
  793. ),
  794. 'administer chado mviews' => array(
  795. 'title' => t('Administer Chado Materialized Views'),
  796. 'description' => t('Allows the user to create, edit and populate materialized views in the Chado databse.'),
  797. ),
  798. 'administer chado custom tables' => array(
  799. 'title' => t('Administer Chado Custom Tables'),
  800. 'description' => t('Allows the user to create, edit and delete custom tables in the Chado database.'),
  801. ),
  802. 'administer db cross-references' => array(
  803. 'title' => t('Administer Chado Databases'),
  804. 'description' => t('Allows the user to create, edit and delete database records in the Chado database.')
  805. ),
  806. 'administer controlled vocabularies' => array(
  807. 'title' => t('Administer Chado Controlled Vocabularies'),
  808. 'description' => t('Allows the user to create, edit and delete controlled vocabularies in the Chado database.')
  809. ),
  810. 'administer chado semantic web' => array(
  811. 'title' => t('Administer Semantic Web and Chado Integration'),
  812. 'description' => t('Allows the user to assign controlled vocabulary terms to tables and table columns in Chado.')
  813. ),
  814. );
  815. }
  816. /**
  817. * Implements hook_theme().
  818. */
  819. function tripal_chado_theme($existing, $type, $theme, $path) {
  820. $themes = array(
  821. // Themed Forms
  822. 'tripal_chado_feature_seq_extract_form' => array(
  823. 'render element' => 'form',
  824. ),
  825. 'tripal_chado_date_combo' => array(
  826. 'render element' => 'element',
  827. 'file' => 'theme/tripal_chado.theme.inc',
  828. ),
  829. // Themed forms
  830. 'tripal_pub_importer_setup_form_elements' => array(
  831. 'render element' => 'form',
  832. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  833. ),
  834. 'tripal_chado_pub_search_setup_form_elements' => array(
  835. 'render element' => 'form',
  836. 'file' => 'includes/tripal_chado.pub_search.inc',
  837. ),
  838. 'tripal_phylogeny_admin_org_color_tables' => array(
  839. 'render element' => 'element',
  840. )
  841. );
  842. // Override the theme for each entity to use the legacy modules
  843. // templates.
  844. if (module_exists('tripal_core')) {
  845. $core_path = drupal_get_path('module', 'tripal_core');
  846. // Get the list of node types that have legacy templates.
  847. $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates', array());
  848. // Get the list of TripalEntity bundle.
  849. $bundles = db_select('tripal_bundle', 'tb')
  850. ->fields('tb')
  851. ->execute();
  852. // Iterate through all of the TripalEntity bundles and see which ones
  853. // map to tables that used to have Tripal v2 nodes. For those, if the
  854. // legacy support is turned on then we want to use the legacy template.
  855. while ($bundle = $bundles->fetchObject()) {
  856. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  857. $vocab = $term->vocab;
  858. $params = array(
  859. 'vocabulary' => $vocab->vocabulary,
  860. 'accession' => $term->accession,
  861. );
  862. $mapped_table = chado_get_cvterm_mapping($params);
  863. // Do not proceed if there is not a mapped_table.
  864. if (!$mapped_table) {
  865. continue;
  866. }
  867. $chado_table = $mapped_table->chado_table;
  868. $legacy_template = 'legacy_template--chado_' . $chado_table;
  869. if (key_exists($legacy_template, $enabled_templates) && $enabled_templates[$legacy_template]) {
  870. $themes['TripalEntity__' . $bundle->name] = array(
  871. 'template' => 'node--chado-generic',
  872. 'render element' => 'entity',
  873. 'base hook' => 'entity',
  874. 'path' => "$core_path/theme/templates",
  875. );
  876. }
  877. }
  878. }
  879. return $themes;
  880. }
  881. /**
  882. * Implements hook_preprocess().
  883. *
  884. * This function is used to support legacy Tripal v2 templates
  885. * for use with Tripal v3 entities.
  886. */
  887. function tripal_chado_preprocess(&$variables, $hook) {
  888. if ($hook == 'entity' and array_key_exists('TripalEntity', $variables)) {
  889. // The node--chado-generic template expets there to be a
  890. // teaser and node variables. So, we'll add them.
  891. $variables['teaser'] = FALSE;
  892. $variables['node'] = $variables['TripalEntity'];
  893. }
  894. }
  895. /**
  896. * Implements hook_exclude_type_by_default()
  897. *
  898. * This hooks allows fields of a specified type that match a specified criteria
  899. * to be excluded by default from any table when chado_generate_var() is called.
  900. * Keep in mind that if fields are excluded by default they can always be
  901. * expanded at a later date using chado_expand_var().
  902. *
  903. * Criteria are php strings that evaluate to either TRUE or FALSE. These
  904. * strings are evaluated using drupal_eval() which suppresses syntax errors and
  905. * throws watchdog entries of type php. There are also watchdog entries of type
  906. * tripal stating the exact criteria evaluated. Criteria can
  907. * contain the following tokens:
  908. * - <field_name>
  909. * Replaced by the name of the field to be excluded
  910. * - <field_value>
  911. * Replaced by the value of the field in the current record
  912. * Also keep in mind that if your criteria doesn't contain the
  913. * &gt;field_value&lt; token then it will be evaluated before the query is
  914. * executed and if the field is excluded it won't be included in the
  915. * query.
  916. *
  917. * @return
  918. * An array of type => criteria where the type is excluded if the criteria
  919. * evaluates to TRUE
  920. *
  921. * @ingroup tripal
  922. */
  923. function tripal_chado_exclude_type_by_default() {
  924. return array('text' => 'strlen("<field_value> ") > 250');
  925. }
  926. /**
  927. * Implements hook_job_describe_args().
  928. *
  929. * Describes the arguments for the chado_populate_mview job to allow for
  930. * greater readability in the jobs details pages.
  931. *
  932. * @param $callback
  933. * The callback of the current tripal job (this is the function that will be
  934. * executed when tripal_launch_jobs.php is run.
  935. * @param $args
  936. * An array of arguments passed in when the job was registered.
  937. *
  938. * @return
  939. * A more readable $args array
  940. *
  941. * @ingroup tripal
  942. */
  943. function tripal_chado_job_describe_args($callback, $args) {
  944. $new_args = array();
  945. if ($callback == 'chado_populate_mview') {
  946. // get this mview details
  947. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  948. $results = db_query($sql, array(':mview_id' => $args[0]));
  949. $mview = $results->fetchObject();
  950. $new_args['View Name'] = $mview->name;
  951. }
  952. elseif ($callback == 'tripal_install_chado') {
  953. $new_args['Action'] = $args[0];
  954. }
  955. return $new_args;
  956. }
  957. /**
  958. * Remove the nid from chado_entity if it exists when the node is deleted
  959. */
  960. function tripal_chado_node_delete($node) {
  961. $nid = $node->nid;
  962. $sql = "UPDATE chado_entity SET nid = NULL WHERE nid = :nid";
  963. //db_query($sql, array('nid' => $nid));
  964. }
  965. /**
  966. *
  967. * Implements hook_form_FORM_ID_alter().
  968. *
  969. * The field_ui_field_edit_form is used for customizing the settings of
  970. * a field attached to an entity.
  971. *
  972. * This alter function disables some of the form widgets when the storage
  973. * backend indicates they are not appropriate.
  974. */
  975. function tripal_chado_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  976. if ($form['#instance']['entity_type'] == 'TripalEntity') {
  977. // For entity fields added by Tripal Entities we don't want the
  978. // the end-user to change the cardinality and the required fields
  979. // such that record can't be saved in Chado.
  980. // TODO: we shouldn't check for specific field types here
  981. // (e.g. chado_linker_prop). That should be done via the TripalField
  982. // functions.
  983. if ($form['#field']['storage']['type'] == 'field_chado_storage' and
  984. $form['#field']['type'] != 'chado_linker__prop') {
  985. $form['field']['cardinality']['#access'] = FALSE;
  986. $form['instance']['required']['#access'] = FALSE;
  987. }
  988. // If this is a Chado field we need to preserve the Chado elements of the
  989. // settings or they will be lost if a user edits the field settings.
  990. if (array_key_exists('chado_table', $form['#instance']['settings'])) {
  991. $form['instance']['settings']['base_table'] = array(
  992. '#type' => 'value',
  993. '#value' => $form['#instance']['settings']['base_table'],
  994. );
  995. $form['instance']['settings']['chado_table'] = array(
  996. '#type' => 'value',
  997. '#value' => $form['#instance']['settings']['chado_table'],
  998. );
  999. $form['instance']['settings']['chado_column'] = array(
  1000. '#type' => 'value',
  1001. '#value' => $form['#instance']['settings']['chado_column'],
  1002. );
  1003. }
  1004. }
  1005. // TODO: don't let the maximum length be larger than the field size.
  1006. }
  1007. /**
  1008. * Uses the value provided in the $id argument to find all features that match
  1009. * that ID by name, featurename or synonym. If it matches uniquenly to a single
  1010. * feature it will redirect to that feature page, otherwise, a list of matching
  1011. * features is shown.
  1012. *
  1013. * @ingroup tripal_feature
  1014. */
  1015. function tripal_feature_match_features_page($id) {
  1016. // first check to see if the URL (e.g. /feature/$id) is already
  1017. // assigned to a node. If so, then just go there. Otherwise,
  1018. // try to find the feature.
  1019. $sql = "
  1020. SELECT source
  1021. FROM {url_alias}
  1022. WHERE alias = :alias
  1023. ";
  1024. $match = db_query($sql, array(':alias' => "feature/$id"))->fetchObject();
  1025. if ($match) {
  1026. drupal_goto($match->source);
  1027. return;
  1028. }
  1029. $sql = "
  1030. SELECT
  1031. F.name, F.uniquename, F.feature_id,
  1032. O.genus, O.species, O.organism_id,
  1033. CVT.cvterm_id, CVT.name as type_name,
  1034. array_agg(S.name) as synonyms
  1035. FROM {feature} F
  1036. INNER JOIN {organism} O on F.organism_id = O.organism_id
  1037. INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
  1038. LEFT JOIN {feature_synonym} FS on FS.feature_id = F.feature_id
  1039. LEFT JOIN {synonym} S on S.synonym_id = FS.synonym_id
  1040. WHERE
  1041. F.uniquename = :uname or
  1042. F.name = :fname or
  1043. S.name = :sname
  1044. GROUP BY F.name, F.uniquename, F.feature_id, O.genus, O.species,
  1045. O.organism_id, CVT.cvterm_id, CVT.name
  1046. ";
  1047. $args = array(':uname' => $id, ':fname' => $id, ':sname' => $id);
  1048. $results = chado_query($sql, $args);
  1049. $num_matches = $results->rowCount();
  1050. // If there are no matches then just return a friendly message.
  1051. if ($num_matches == 0) {
  1052. drupal_set_message("No features matched the given name '$id'", 'warning');
  1053. return "No matches found";
  1054. }
  1055. // if we have more than one match then generate the table, otherwise, redirect
  1056. // to the matched feature
  1057. elseif ($num_matches == 1) {
  1058. $curr_match = $results->fetchObject();
  1059. $entity_id = chado_get_record_entity_by_table('feature', $curr_match->feature_id);
  1060. if ($entity_id) {
  1061. drupal_goto("bio_data/" . $entity_id);
  1062. return;
  1063. }
  1064. // If we are here it's because we couldn't find the entity. Check if a node
  1065. // exists (Tv2 backwards compatibility).
  1066. if (module_exists(tripal_feature)) {
  1067. $nid = chado_get_nid_from_id('feature', $curr_match->feature_id);
  1068. drupal_goto("node/" . $nid);
  1069. return;
  1070. }
  1071. // If we are here it's because we couldn't find an entity_id or an nid
  1072. drupal_set_message("No published features matched the given name '$id'", 'warning');
  1073. return "No matches found";
  1074. }
  1075. elseif ($num_matches > 1) {
  1076. // iterate through the matches and build the table for showing matches
  1077. $header = array('Uniquename', 'Name', 'Type', 'Species', 'Synonyms');
  1078. $rows = array();
  1079. while ($match = $results->fetchObject()) {
  1080. $curr_match = $match;
  1081. $synonyms = $match->synonyms;
  1082. $synonyms = preg_replace('/[\"\{\}]/', '', $synonyms);
  1083. // Build the link to this page.
  1084. $entity_id = chado_get_record_entity_by_table('feature', $curr_match->feature_id);
  1085. $link = '';
  1086. if ($entity_id) {
  1087. $link = "bio_data/" . $entity_id;
  1088. }
  1089. // If we didn't find an entity ID we need to check nodes for
  1090. // backwards compatibility with Tv2.
  1091. if (!$entity_id and module_exists('tripal_feature')) {
  1092. $nid = chado_get_nid_from_id('feature', $curr_match->feature_id);
  1093. $link = "node/" . $nid;
  1094. }
  1095. if (!$link) {
  1096. continue;
  1097. }
  1098. $rows[] = array(
  1099. $match->uniquename,
  1100. l($match->name, $link),
  1101. $match->type_name,
  1102. '<i>' . $match->genus . ' ' . $match->species . '</i>',
  1103. $synonyms,
  1104. );
  1105. $num_matches++;
  1106. }
  1107. $table_attrs = array('class' => 'tripal-data-table');
  1108. $output = "<p>The following features match the name '$id'.</p>";
  1109. $output .= theme_table(array(
  1110. 'header' => $header,
  1111. 'rows' => $rows,
  1112. 'attributes' => $table_attrs,
  1113. 'caption' => $caption
  1114. ));
  1115. return $output;
  1116. }
  1117. }
  1118. /**
  1119. * Implements hook_mail().
  1120. *
  1121. * @ingroup tripal_legacy_pub
  1122. */
  1123. function tripal_chado_mail($key, &$message, $params) {
  1124. $site_name = variable_get('site_name');
  1125. $language = $message['language'];
  1126. switch($key) {
  1127. case 'import_report':
  1128. $content = [];
  1129. $content[] = [
  1130. '#type' => 'markup',
  1131. '#markup' => '<h3>Tripal Bulk Publication Report</h3>'
  1132. ];
  1133. $report = $params['report'];
  1134. foreach ($report as $action => $pubs) {
  1135. if (count($pubs) > 0) {
  1136. $title = count($pubs) . ' publication(s) were ' . $action . ":";
  1137. if ($action == 'error') {
  1138. $title = count($pubs) . ' publications were not imported due to errors:';
  1139. }
  1140. $content[] = [
  1141. '#type' => 'item',
  1142. '#title' => $title,
  1143. '#markup' => theme_item_list([
  1144. 'title' => '',
  1145. 'type' => 'ol',
  1146. 'items' => $pubs,
  1147. 'attributes' => [],
  1148. ]),
  1149. ];
  1150. }
  1151. }
  1152. $content = '<html>' . drupal_render($content) . '</html';
  1153. $message['subject'] = t('Publication import from !site', array('!site' => $site_name));
  1154. if (module_exists('htmlmail') or module_exists('mimemail')) {
  1155. $headers = array(
  1156. 'MIME-Version' => '1.0',
  1157. 'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
  1158. 'Content-Transfer-Encoding' => '8Bit',
  1159. 'X-Mailer' => 'Drupal'
  1160. );
  1161. foreach ($headers as $key => $value) {
  1162. $message['headers'][$key] = $value;
  1163. }
  1164. $message['body'][] = $content;
  1165. }
  1166. else {
  1167. $message['body'][] = drupal_html_to_text($content);
  1168. }
  1169. break;
  1170. }
  1171. }