tripal_chado.module 50 KB

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