tripal_chado.module 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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. // ways 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/ChadoDatabaseConnection.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/changedb'] = array(
  430. 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
  431. 'page arguments' => array(),
  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. $items['admin/tripal/loaders/pub/criteria/%/%'] = array(
  438. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  439. 'page arguments' => array(5, 6),
  440. 'access arguments' => array('use chado_pub_bulk importer'),
  441. 'type ' => MENU_CALLBACK,
  442. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  443. 'file path' => drupal_get_path('module', 'tripal_chado'),
  444. );
  445. //////////////////////////////////////////////////////////////////////////////
  446. // Migrate Content
  447. //////////////////////////////////////////////////////////////////////////////
  448. $items['admin/tripal/storage/chado/migrate'] = array(
  449. 'title' => 'Migrate',
  450. 'description' => t('Migrate Tripal v2 content to Tripal v3'),
  451. 'page callback' => 'drupal_get_form',
  452. 'page arguments' => array('tripal_chado_migrate_form'),
  453. 'type' => MENU_NORMAL_ITEM,
  454. 'access arguments' => array('administer tripal'),
  455. 'file' => 'includes/tripal_chado.migrate.inc',
  456. 'file path' => drupal_get_path('module', 'tripal_chado'),
  457. 'weight' => 10
  458. );
  459. //////////////////////////////////////////////////////////////////////////////
  460. // Semantic Web Settings
  461. //////////////////////////////////////////////////////////////////////////////
  462. $items['admin/tripal/storage/chado/semweb'] = array(
  463. 'title' => 'Semantic Web',
  464. 'description' => t('Semantic web settings. Set terms used for the web services.'),
  465. 'page callback' => 'drupal_get_form',
  466. 'page arguments' => array('tripal_chado_semweb_form'),
  467. 'type' => MENU_NORMAL_ITEM,
  468. 'access arguments' => array('administer chado semantic web'),
  469. 'file' => 'includes/tripal_chado.semweb.inc',
  470. 'file path' => drupal_get_path('module', 'tripal_chado'),
  471. 'weight' => 10
  472. );
  473. $items['admin/tripal/storage/chado/semweb/edit/%/%'] = array(
  474. 'title' => 'Edit Semantic Web Term',
  475. 'description' => t('Edit terms used for the web services.'),
  476. 'page callback' => 'drupal_get_form',
  477. 'page arguments' => array('tripal_chado_semweb_edit_form', 6, 7),
  478. 'type' => MENU_CALLBACK,
  479. 'access arguments' => array('administer chado semantic web'),
  480. 'file' => 'includes/tripal_chado.semweb.inc',
  481. 'file path' => drupal_get_path('module', 'tripal_chado'),
  482. );
  483. $items['admin/tripal/storage/chado/semweb/reset/%/%'] = array(
  484. 'title' => 'Reset Semantic Web Term',
  485. 'description' => t('Edit terms used for the web services.'),
  486. 'page callback' => 'drupal_get_form',
  487. 'page arguments' => array('tripal_chado_semweb_reset_form', 6, 7),
  488. 'type' => MENU_CALLBACK,
  489. 'access arguments' => array('administer chado semantic web'),
  490. 'file' => 'includes/tripal_chado.semweb.inc',
  491. 'file path' => drupal_get_path('module', 'tripal_chado'),
  492. );
  493. //////////////////////////////////////////////////////////////////////////////
  494. // Auto Completes
  495. //////////////////////////////////////////////////////////////////////////////
  496. $items['admin/tripal/storage/chado/auto_name/dbxref/%/%'] = array(
  497. 'page callback' => 'chado_autocomplete_dbxref',
  498. 'page arguments' => array(6, 7),
  499. 'access arguments' => array('access content'),
  500. 'file' => 'api/modules/tripal_chado.db.api.inc',
  501. 'file path' => drupal_get_path('module', 'tripal_chado'),
  502. 'type' => MENU_CALLBACK,
  503. );
  504. $items['admin/tripal/storage/chado/auto_name/cv/%'] = array(
  505. 'page callback' => 'chado_autocomplete_cv',
  506. 'page arguments' => array(6),
  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/cvterm/%/%'] = array(
  513. 'page callback' => 'chado_autocomplete_cvterm',
  514. 'page arguments' => array(6, 7),
  515. 'access arguments' => array('access content'),
  516. 'file' => 'api/modules/tripal_chado.cv.api.inc',
  517. 'file path' => drupal_get_path('module', 'tripal_chado'),
  518. 'type' => MENU_CALLBACK,
  519. );
  520. $items['admin/tripal/storage/chado/auto_name/pub/%'] = array(
  521. 'page callback' => 'chado_autocomplete_pub',
  522. 'page arguments' => array(6),
  523. 'access arguments' => array('access content'),
  524. 'file' => 'api/modules/tripal_chado.pub.api.inc',
  525. 'file path' => drupal_get_path('module', 'tripal_chado'),
  526. 'type' => MENU_CALLBACK,
  527. );
  528. $items['admin/tripal/storage/chado/auto_name/contact/%'] = array(
  529. 'page callback' => 'tripal_autocomplete_contact',
  530. 'page arguments' => array(6),
  531. 'access arguments' => array('access content'),
  532. 'file' => 'api/modules/tripal_chado.contact.api.inc',
  533. 'file path' => drupal_get_path('module', 'tripal_chado'),
  534. 'type' => MENU_CALLBACK,
  535. );
  536. $items['admin/tripal/storage/chado/auto_name/feature/%'] = array(
  537. 'page callback' => 'chado_autocomplete_feature',
  538. 'page arguments' => array(6),
  539. 'access arguments' => array('access content'),
  540. 'file' => 'api/modules/tripal_chado.feature.api.inc',
  541. 'file path' => drupal_get_path('module', 'tripal_chado'),
  542. 'type' => MENU_CALLBACK,
  543. );
  544. $items['admin/tripal/storage/chado/auto_name/organism/%'] = array(
  545. 'page callback' => 'chado_autocomplete_organism',
  546. 'page arguments' => array(6),
  547. 'access arguments' => array('access content'),
  548. 'file' => 'api/modules/tripal_chado.organism.api.inc',
  549. 'file path' => drupal_get_path('module', 'tripal_chado'),
  550. 'type' => MENU_CALLBACK,
  551. );
  552. //////////////////////////////////////////////////////////////////////////////
  553. // Controlled Vocabularies
  554. //////////////////////////////////////////////////////////////////////////////
  555. $items['admin/tripal/loaders/chado_vocabs'] = array(
  556. 'title' => 'Chado Vocabularies',
  557. 'description' => t('Tools facilitating management (including import) of controlled
  558. vocabularies and their terms into Chado.'),
  559. 'access arguments' => array('administer controlled vocabularies'),
  560. 'type' => MENU_NORMAL_ITEM,
  561. 'weight' => 6
  562. );
  563. $items['admin/tripal/loaders/chado_vocabs/chado_cv'] = array(
  564. 'title' => 'Manage Chado CVs',
  565. 'description' => 'View, edit and add controlled vocabularies used by this site.',
  566. 'page callback' => 'tripal_cv_admin_cv_listing',
  567. 'access arguments' => array('administer controlled vocabularies'),
  568. 'file' => 'includes/tripal_chado.cv.inc',
  569. 'file path' => drupal_get_path('module', 'tripal_chado'),
  570. 'type' => MENU_NORMAL_ITEM,
  571. );
  572. $items['admin/tripal/loaders/chado_vocabs/chado_cv/edit/%'] = array(
  573. 'title' => 'Edit a Controlled Vocabulary',
  574. 'description' => 'Edit the details such as name and description for an existing controlled vocabulary.',
  575. 'page callback' => 'drupal_get_form',
  576. 'page arguments' => array('tripal_cv_cv_edit_form', 6),
  577. 'access callback' => 'user_access',
  578. 'access arguments' => array('administer controlled vocabularies'),
  579. 'file' => 'includes/tripal_chado.cv.inc',
  580. 'file path' => drupal_get_path('module', 'tripal_chado'),
  581. 'type' => MENU_CALLBACK,
  582. );
  583. $items['admin/tripal/loaders/chado_vocabs/chado_cv/delete/%'] = array(
  584. 'title' => 'Delete a Controlled Vocabulary',
  585. 'description' => 'Delete a controlled vocabulary.',
  586. 'page callback' => 'drupal_get_form',
  587. 'page arguments' => array('tripal_cv_cv_delete_form', 6),
  588. 'access callback' => 'user_access',
  589. 'access arguments' => array('administer controlled vocabularies'),
  590. 'file' => 'includes/tripal_chado.cv.inc',
  591. 'file path' => drupal_get_path('module', 'tripal_chado'),
  592. 'type' => MENU_CALLBACK,
  593. );
  594. $items['admin/tripal/loaders/chado_vocabs/chado_cv/add'] = array(
  595. 'title' => 'Add a Controlled Vocabulary',
  596. 'description' => 'Manually a new controlled vocabulary.',
  597. 'page callback' => 'drupal_get_form',
  598. 'page arguments' => array('tripal_cv_cv_add_form'),
  599. 'access callback' => 'user_access',
  600. 'access arguments' => array('administer controlled vocabularies'),
  601. 'file' => 'includes/tripal_chado.cv.inc',
  602. 'file path' => drupal_get_path('module', 'tripal_chado'),
  603. 'type' => MENU_CALLBACK,
  604. );
  605. $items['admin/tripal/loaders/chado_vocabs/chado_cv/%/cvterm/add'] = array(
  606. 'title' => 'Add a Controlled Vocabulary Term',
  607. 'description' => 'Add a new controlled vocabulary term.',
  608. 'page callback' => 'drupal_get_form',
  609. 'page arguments' => array('tripal_cv_cvterm_add_form', 5),
  610. 'access arguments' => array('administer controlled vocabularies'),
  611. 'file' => 'includes/tripal_chado.cv.inc',
  612. 'file path' => drupal_get_path('module', 'tripal_chado'),
  613. 'type' => MENU_CALLBACK,
  614. );
  615. $items['admin/tripal/loaders/chado_vocabs/chado_cv/cvterm/add'] = array(
  616. 'title' => 'Add a Controlled Vocabulary Term',
  617. 'description' => 'Add a new controlled vocabulary term.',
  618. 'page callback' => 'drupal_get_form',
  619. 'page arguments' => array('tripal_cv_cvterm_add_form'),
  620. 'access arguments' => array('administer controlled vocabularies'),
  621. 'file' => 'includes/tripal_chado.cv.inc',
  622. 'file path' => drupal_get_path('module', 'tripal_chado'),
  623. 'type' => MENU_CALLBACK,
  624. );
  625. $items['admin/tripal/loaders/chado_vocabs/chado_cv/%/cvterm/edit/%'] = array(
  626. 'title' => 'Edit a Controlled Vocabulary Term',
  627. 'description' => 'Edit an existing controlled vocabulary term.',
  628. 'page callback' => 'drupal_get_form',
  629. 'page arguments' => array('tripal_cv_cvterm_edit_form', 5, 8),
  630. 'access arguments' => array('administer controlled vocabularies'),
  631. 'file' => 'includes/tripal_chado.cv.inc',
  632. 'file path' => drupal_get_path('module', 'tripal_chado'),
  633. 'type' => MENU_CALLBACK,
  634. );
  635. $items['admin/tripal/loaders/chado_vocabs/cvtermpath'] = array(
  636. 'title' => 'Update CV Term Paths',
  637. 'description' => 'The Chado cvtermpath table provides lineage for
  638. controlled vocabulary terms and is useful for quickly finding any
  639. ancestor parent of a term. If controlled vocabularies are loaded
  640. using the OBO Importer then the vocabulary is automatically added to
  641. the cvtermpath table. However, if it is needed, the addition of terms
  642. to the cvtermpath table can be manually executed here.',
  643. 'page callback' => 'drupal_get_form',
  644. 'page arguments' => array('tripal_cv_cvtermpath_form'),
  645. 'access arguments' => array('administer controlled vocabularies'),
  646. 'file' => 'includes/tripal_chado.cv.inc',
  647. 'file path' => drupal_get_path('module', 'tripal_chado'),
  648. 'type' => MENU_NORMAL_ITEM,
  649. );
  650. //////////////////////////////////////////////////////////////////////////////
  651. // Databases
  652. //////////////////////////////////////////////////////////////////////////////
  653. $items['admin/tripal/loaders/chado_db'] = array(
  654. 'title' => 'Chado Databases',
  655. 'description' => 'View, edit and add external databases. When data originates
  656. from a remote online resource (or database) then that database must
  657. be added in order to cross link records in this site to records in
  658. the remote site.',
  659. 'page callback' => 'tripal_chado_admin_db_listing',
  660. 'access arguments' => array('administer db cross-references'),
  661. 'file' => 'includes/tripal_chado.db.inc',
  662. 'file path' => drupal_get_path('module', 'tripal_chado'),
  663. 'type' => MENU_NORMAL_ITEM,
  664. );
  665. $items['admin/tripal/loaders/chado_db/edit/%'] = array(
  666. 'title' => 'Edit a Database Reference',
  667. 'description' => 'Edit existing Database References.',
  668. 'page callback' => 'drupal_get_form',
  669. 'page arguments' => array('tripal_chado_db_edit_form', 5),
  670. 'access callback' => 'user_access',
  671. 'access arguments' => array('administer db cross-references'),
  672. 'file' => 'includes/tripal_chado.db.inc',
  673. 'file path' => drupal_get_path('module', 'tripal_chado'),
  674. 'type' => MENU_CALLBACK,
  675. );
  676. $items['admin/tripal/loaders/chado_db/add'] = array(
  677. 'title' => 'Create a Database Reference',
  678. 'description' => 'Create a new reference to an External Database.',
  679. 'page callback' => 'drupal_get_form',
  680. 'page arguments' => array('tripal_chado_db_add_form'),
  681. 'access callback' => 'user_access',
  682. 'access arguments' => array('administer db cross-references'),
  683. 'file' => 'includes/tripal_chado.db.inc',
  684. 'file path' => drupal_get_path('module', 'tripal_chado'),
  685. 'type' => MENU_CALLBACK,
  686. );
  687. //////////////////////////////////////////////////////////////////////////////
  688. // FEATURES
  689. //////////////////////////////////////////////////////////////////////////////
  690. // the menu link for addressing any feature (by name, uniquename, synonym)
  691. $items['feature/%'] = array(
  692. 'page callback' => 'tripal_feature_match_features_page',
  693. 'page arguments' => array(1),
  694. 'access arguments' => array('access chado_feature content'),
  695. 'type' => MENU_LOCAL_TASK,
  696. );
  697. // the administative settings menu
  698. $items['find/sequences'] = array(
  699. 'title' => 'Sequence Retrieval',
  700. 'description' => 'Download a file of sequences',
  701. 'page callback' => 'drupal_get_form',
  702. 'page arguments' => array('tripal_chado_feature_seq_extract_form'),
  703. 'access arguments' => array('access content'),
  704. 'file' => 'includes/tripal_chado.seq_extract.inc',
  705. 'file path' => drupal_get_path('module', 'tripal_chado'),
  706. 'type' => MENU_CALLBACK,
  707. );
  708. $items['find/sequences/download'] = array(
  709. 'page callback' => 'tripal_chado_feature_seq_extract_download',
  710. 'access arguments' => array('access content'),
  711. 'file' => 'includes/tripal_chado.seq_extract.inc',
  712. 'file path' => drupal_get_path('module', 'tripal_chado'),
  713. 'type' => MENU_CALLBACK,
  714. );
  715. //////////////////////////////////////////////////////////////////////////////
  716. // Publications
  717. //////////////////////////////////////////////////////////////////////////////
  718. $items['find/publications' ]= array(
  719. 'title' => 'Publication Search',
  720. 'description' => ('Search for publications'),
  721. 'page callback' => 'tripal_chado_pub_search_page',
  722. 'access arguments' => array('access content'),
  723. 'file' => 'includes/tripal_chado.pub_search.inc',
  724. 'file path' => drupal_get_path('module', 'tripal_chado'),
  725. 'type' => MENU_CALLBACK
  726. );
  727. $items['find/publications/criteria/%/%'] = array(
  728. 'page callback' => 'tripal_chado_pub_search_page_update_criteria',
  729. 'page arguments' => array(5, 6),
  730. 'access arguments' => array('access content'),
  731. 'file' => 'includes/tripal_chado.pub_search.inc',
  732. 'file path' => drupal_get_path('module', 'tripal_chado'),
  733. 'type ' => MENU_CALLBACK,
  734. );
  735. $items['admin/tripal/storage/chado/pub-search-config'] = array(
  736. 'title' => 'Publication Search Settings',
  737. 'description' => 'Configure the settings for the publication search.',
  738. 'page callback' => 'drupal_get_form',
  739. 'page arguments' => array('tripal_chado_pub_search_admin_form'),
  740. 'file' => 'includes/tripal_chado.pub_search.inc',
  741. 'file path' => drupal_get_path('module', 'tripal_chado'),
  742. 'type' => MENU_NORMAL_ITEM,
  743. 'access arguments' => array('administer tripal'),
  744. );
  745. //////////////////////////////////////////////////////////////////////////////
  746. // Phylogeny
  747. //////////////////////////////////////////////////////////////////////////////
  748. // create a route for viewing json of all phylonodes having this phylotree_id
  749. $items['phylotree/%'] = array(
  750. 'page callback' => 'tripal_phylogeny_ajax_get_tree_json',
  751. 'page arguments' => array(1),
  752. // allow all anonymous http clients
  753. 'access callback' => TRUE,
  754. 'file' => 'includes/tripal_chado.phylotree.inc',
  755. 'file path' => drupal_get_path('module', 'tripal_chado'),
  756. );
  757. $items['admin/tripal/storage/chado/phylogeny'] = array(
  758. 'title' => 'Phylogeny and Taxonomy',
  759. 'description' => 'Settings for display of phylogenetic and taxonomic trees.',
  760. 'page callback' => 'drupal_get_form',
  761. 'page arguments' => array('tripal_phylogeny_default_plots_form'),
  762. 'access arguments' => array('administer tripal'),
  763. 'type' => MENU_NORMAL_ITEM,
  764. 'weight' => 2,
  765. 'file' => 'includes/tripal_chado.phylotree.inc',
  766. 'file path' => drupal_get_path('module', 'tripal_chado'),
  767. );
  768. return $items;
  769. }
  770. /**
  771. * Implements hook_permission().
  772. *
  773. * Set the permission types that the chado module uses. Essentially we
  774. * want permissionis that protect creation, editing and deleting of chado
  775. * data objects
  776. *
  777. * @ingroup tripal
  778. */
  779. function tripal_chado_permission() {
  780. return array(
  781. 'install chado' => array(
  782. 'title' => t('Install Chado'),
  783. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  784. ),
  785. 'view chado_ids' => array(
  786. 'title' => t('View Internal IDs'),
  787. 'description' => t('On content pages Tripal will typically provide
  788. a table of information pulled from the Chado database but the
  789. primary key IDs for that data is typically not shown. The
  790. default Tripal templates can show the primary key ID inside of a
  791. blue shaded table row if this permission is enabled. This can
  792. be useful for site developers who might want these IDs when working
  793. with the underlying database.'),
  794. 'restrict access' => TRUE,
  795. ),
  796. 'administer chado mviews' => array(
  797. 'title' => t('Administer Chado Materialized Views'),
  798. 'description' => t('Allows the user to create, edit and populate materialized views in the Chado databse.'),
  799. ),
  800. 'administer chado custom tables' => array(
  801. 'title' => t('Administer Chado Custom Tables'),
  802. 'description' => t('Allows the user to create, edit and delete custom tables in the Chado database.'),
  803. ),
  804. 'administer db cross-references' => array(
  805. 'title' => t('Administer Chado Databases'),
  806. 'description' => t('Allows the user to create, edit and delete database records in the Chado database.')
  807. ),
  808. 'administer controlled vocabularies' => array(
  809. 'title' => t('Administer Chado Controlled Vocabularies'),
  810. 'description' => t('Allows the user to create, edit and delete controlled vocabularies in the Chado database.')
  811. ),
  812. 'administer chado semantic web' => array(
  813. 'title' => t('Administer Semantic Web and Chado Integration'),
  814. 'description' => t('Allows the user to assign controlled vocabulary terms to tables and table columns in Chado.')
  815. ),
  816. );
  817. }
  818. /**
  819. * Implements hook_theme().
  820. */
  821. function tripal_chado_theme($existing, $type, $theme, $path) {
  822. $themes = array(
  823. // Themed Forms
  824. 'tripal_chado_feature_seq_extract_form' => array(
  825. 'render element' => 'form',
  826. ),
  827. 'tripal_chado_date_combo' => array(
  828. 'render element' => 'element',
  829. 'file' => 'theme/tripal_chado.theme.inc',
  830. ),
  831. // Themed forms
  832. 'tripal_pub_importer_setup_form_elements' => array(
  833. 'render element' => 'form',
  834. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  835. ),
  836. 'tripal_chado_pub_search_setup_form_elements' => array(
  837. 'render element' => 'form',
  838. 'file' => 'includes/tripal_chado.pub_search.inc',
  839. ),
  840. 'tripal_phylogeny_admin_org_color_tables' => array(
  841. 'render element' => 'element',
  842. )
  843. );
  844. // Override the theme for each entity to use the legacy modules
  845. // templates.
  846. if (module_exists('tripal_core')) {
  847. $core_path = drupal_get_path('module', 'tripal_core');
  848. // Get the list of node types that have legacy templates.
  849. $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates', array());
  850. // Get the list of TripalEntity bundle.
  851. $bundles = db_select('tripal_bundle', 'tb')
  852. ->fields('tb')
  853. ->execute();
  854. // Iterate through all of the TripalEntity bundles and see which ones
  855. // map to tables that used to have Tripal v2 nodes. For those, if the
  856. // legacy support is turned on then we want to use the legacy template.
  857. while ($bundle = $bundles->fetchObject()) {
  858. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  859. $vocab = $term->vocab;
  860. $params = array(
  861. 'vocabulary' => $vocab->vocabulary,
  862. 'accession' => $term->accession,
  863. );
  864. $mapped_table = chado_get_cvterm_mapping($params);
  865. // Do not proceed if there is not a mapped_table.
  866. if (!$mapped_table) {
  867. continue;
  868. }
  869. $chado_table = $mapped_table->chado_table;
  870. $legacy_template = 'legacy_template--chado_' . $chado_table;
  871. if (key_exists($legacy_template, $enabled_templates) && $enabled_templates[$legacy_template]) {
  872. $themes['TripalEntity__' . $bundle->name] = array(
  873. 'template' => 'node--chado-generic',
  874. 'render element' => 'entity',
  875. 'base hook' => 'entity',
  876. 'path' => "$core_path/theme/templates",
  877. );
  878. }
  879. }
  880. }
  881. return $themes;
  882. }
  883. /**
  884. * Implements hook_preprocess().
  885. *
  886. * This function is used to support legacy Tripal v2 templates
  887. * for use with Tripal v3 entities.
  888. */
  889. function tripal_chado_preprocess(&$variables, $hook) {
  890. if ($hook == 'entity' and array_key_exists('TripalEntity', $variables)) {
  891. // The node--chado-generic template expets there to be a
  892. // teaser and node variables. So, we'll add them.
  893. $variables['teaser'] = FALSE;
  894. $variables['node'] = $variables['TripalEntity'];
  895. }
  896. }
  897. /**
  898. * Implements hook_exclude_type_by_default()
  899. *
  900. * This hooks allows fields of a specified type that match a specified criteria
  901. * to be excluded by default from any table when chado_generate_var() is called.
  902. * Keep in mind that if fields are excluded by default they can always be
  903. * expanded at a later date using chado_expand_var().
  904. *
  905. * Criteria are php strings that evaluate to either TRUE or FALSE. These
  906. * strings are evaluated using drupal_eval() which suppresses syntax errors and
  907. * throws watchdog entries of type php. There are also watchdog entries of type
  908. * tripal stating the exact criteria evaluated. Criteria can
  909. * contain the following tokens:
  910. * - <field_name>
  911. * Replaced by the name of the field to be excluded
  912. * - <field_value>
  913. * Replaced by the value of the field in the current record
  914. * Also keep in mind that if your criteria doesn't contain the
  915. * &gt;field_value&lt; token then it will be evaluated before the query is
  916. * executed and if the field is excluded it won't be included in the
  917. * query.
  918. *
  919. * @return
  920. * An array of type => criteria where the type is excluded if the criteria
  921. * evaluates to TRUE
  922. *
  923. * @ingroup tripal
  924. */
  925. function tripal_chado_exclude_type_by_default() {
  926. return array('text' => 'strlen("<field_value> ") > 250');
  927. }
  928. /**
  929. * Implements hook_job_describe_args().
  930. *
  931. * Describes the arguments for the chado_populate_mview job to allow for
  932. * greater readability in the jobs details pages.
  933. *
  934. * @param $callback
  935. * The callback of the current tripal job (this is the function that will be
  936. * executed when tripal_launch_jobs.php is run.
  937. * @param $args
  938. * An array of arguments passed in when the job was registered.
  939. *
  940. * @return
  941. * A more readable $args array
  942. *
  943. * @ingroup tripal
  944. */
  945. function tripal_chado_job_describe_args($callback, $args) {
  946. $new_args = array();
  947. if ($callback == 'chado_populate_mview') {
  948. // get this mview details
  949. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  950. $results = db_query($sql, array(':mview_id' => $args[0]));
  951. $mview = $results->fetchObject();
  952. $new_args['View Name'] = $mview->name;
  953. }
  954. elseif ($callback == 'tripal_install_chado') {
  955. $new_args['Action'] = $args[0];
  956. }
  957. return $new_args;
  958. }
  959. /**
  960. * Remove the nid from chado_entity if it exists when the node is deleted
  961. */
  962. function tripal_chado_node_delete($node) {
  963. $nid = $node->nid;
  964. $sql = "UPDATE chado_entity SET nid = NULL WHERE nid = :nid";
  965. //db_query($sql, array('nid' => $nid));
  966. }
  967. /**
  968. *
  969. * Implements hook_form_FORM_ID_alter().
  970. *
  971. * The field_ui_field_edit_form is used for customizing the settings of
  972. * a field attached to an entity.
  973. *
  974. * This alter function disables some of the form widgets when the storage
  975. * backend indicates they are not appropriate.
  976. */
  977. function tripal_chado_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  978. if ($form['#instance']['entity_type'] == 'TripalEntity') {
  979. // For entity fields added by Tripal Entities we don't want the
  980. // the end-user to change the cardinality and the required fields
  981. // such that record can't be saved in Chado.
  982. // TODO: we shouldn't check for specific field types here
  983. // (e.g. chado_linker_prop). That should be done via the TripalField
  984. // functions.
  985. if ($form['#field']['storage']['type'] == 'field_chado_storage' and
  986. $form['#field']['type'] != 'chado_linker__prop') {
  987. $form['field']['cardinality']['#access'] = FALSE;
  988. $form['instance']['required']['#access'] = FALSE;
  989. }
  990. // If this is a Chado field we need to preserve the Chado elements of the
  991. // settings or they will be lost if a user edits the field settings.
  992. if (array_key_exists('chado_table', $form['#instance']['settings'])) {
  993. $form['instance']['settings']['base_table'] = array(
  994. '#type' => 'value',
  995. '#value' => $form['#instance']['settings']['base_table'],
  996. );
  997. $form['instance']['settings']['chado_table'] = array(
  998. '#type' => 'value',
  999. '#value' => $form['#instance']['settings']['chado_table'],
  1000. );
  1001. $form['instance']['settings']['chado_column'] = array(
  1002. '#type' => 'value',
  1003. '#value' => $form['#instance']['settings']['chado_column'],
  1004. );
  1005. }
  1006. }
  1007. // TODO: don't let the maximum length be larger than the field size.
  1008. }
  1009. /**
  1010. * Uses the value provided in the $id argument to find all features that match
  1011. * that ID by name, featurename or synonym. If it matches uniquenly to a single
  1012. * feature it will redirect to that feature page, otherwise, a list of matching
  1013. * features is shown.
  1014. *
  1015. * @ingroup tripal_feature
  1016. */
  1017. function tripal_feature_match_features_page($id) {
  1018. // first check to see if the URL (e.g. /feature/$id) is already
  1019. // assigned to a node. If so, then just go there. Otherwise,
  1020. // try to find the feature.
  1021. $sql = "
  1022. SELECT source
  1023. FROM {url_alias}
  1024. WHERE alias = :alias
  1025. ";
  1026. $match = db_query($sql, array(':alias' => "feature/$id"))->fetchObject();
  1027. if ($match) {
  1028. drupal_goto($match->source);
  1029. return;
  1030. }
  1031. $sql = "
  1032. SELECT
  1033. F.name, F.uniquename, F.feature_id,
  1034. O.genus, O.species, O.organism_id,
  1035. CVT.cvterm_id, CVT.name as type_name,
  1036. array_agg(S.name) as synonyms
  1037. FROM {feature} F
  1038. INNER JOIN {organism} O on F.organism_id = O.organism_id
  1039. INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
  1040. LEFT JOIN {feature_synonym} FS on FS.feature_id = F.feature_id
  1041. LEFT JOIN {synonym} S on S.synonym_id = FS.synonym_id
  1042. WHERE
  1043. F.uniquename = :uname or
  1044. F.name = :fname or
  1045. S.name = :sname
  1046. GROUP BY F.name, F.uniquename, F.feature_id, O.genus, O.species,
  1047. O.organism_id, CVT.cvterm_id, CVT.name
  1048. ";
  1049. $args = array(':uname' => $id, ':fname' => $id, ':sname' => $id);
  1050. $results = chado_query($sql, $args);
  1051. $num_matches = $results->rowCount();
  1052. // If there are no matches then just return a friendly message.
  1053. if ($num_matches == 0) {
  1054. drupal_set_message("No features matched the given name '$id'", 'warning');
  1055. return "No matches found";
  1056. }
  1057. // if we have more than one match then generate the table, otherwise, redirect
  1058. // to the matched feature
  1059. elseif ($num_matches == 1) {
  1060. $curr_match = $results->fetchObject();
  1061. $entity_id = chado_get_record_entity_by_table('feature', $curr_match->feature_id);
  1062. if ($entity_id) {
  1063. drupal_goto("bio_data/" . $entity_id);
  1064. return;
  1065. }
  1066. // If we are here it's because we couldn't find the entity. Check if a node
  1067. // exists (Tv2 backwards compatibility).
  1068. if (module_exists(tripal_feature)) {
  1069. $nid = chado_get_nid_from_id('feature', $curr_match->feature_id);
  1070. drupal_goto("node/" . $nid);
  1071. return;
  1072. }
  1073. // If we are here it's because we couldn't find an entity_id or an nid
  1074. drupal_set_message("No published features matched the given name '$id'", 'warning');
  1075. return "No matches found";
  1076. }
  1077. elseif ($num_matches > 1) {
  1078. // iterate through the matches and build the table for showing matches
  1079. $header = array('Uniquename', 'Name', 'Type', 'Species', 'Synonyms');
  1080. $rows = array();
  1081. while ($match = $results->fetchObject()) {
  1082. $curr_match = $match;
  1083. $synonyms = $match->synonyms;
  1084. $synonyms = preg_replace('/[\"\{\}]/', '', $synonyms);
  1085. // Build the link to this page.
  1086. $entity_id = chado_get_record_entity_by_table('feature', $curr_match->feature_id);
  1087. $link = '';
  1088. if ($entity_id) {
  1089. $link = "bio_data/" . $entity_id;
  1090. }
  1091. // If we didn't find an entity ID we need to check nodes for
  1092. // backwards compatibility with Tv2.
  1093. if (!$entity_id and module_exists('tripal_feature')) {
  1094. $nid = chado_get_nid_from_id('feature', $curr_match->feature_id);
  1095. $link = "node/" . $nid;
  1096. }
  1097. if (!$link) {
  1098. continue;
  1099. }
  1100. $rows[] = array(
  1101. $match->uniquename,
  1102. l($match->name, $link),
  1103. $match->type_name,
  1104. '<i>' . $match->genus . ' ' . $match->species . '</i>',
  1105. $synonyms,
  1106. );
  1107. $num_matches++;
  1108. }
  1109. $table_attrs = array('class' => 'tripal-data-table');
  1110. $output = "<p>The following features match the name '$id'.</p>";
  1111. $output .= theme_table(array(
  1112. 'header' => $header,
  1113. 'rows' => $rows,
  1114. 'attributes' => $table_attrs,
  1115. 'caption' => $caption
  1116. ));
  1117. return $output;
  1118. }
  1119. }
  1120. /**
  1121. * Implements hook_mail().
  1122. *
  1123. * @ingroup tripal_legacy_pub
  1124. */
  1125. function tripal_chado_mail($key, &$message, $params) {
  1126. $site_name = variable_get('site_name');
  1127. $language = $message['language'];
  1128. switch($key) {
  1129. case 'import_report':
  1130. $content = [];
  1131. $content[] = [
  1132. '#type' => 'markup',
  1133. '#markup' => '<h3>Tripal Bulk Publication Report</h3>'
  1134. ];
  1135. $report = $params['report'];
  1136. foreach ($report as $action => $pubs) {
  1137. if (count($pubs) > 0) {
  1138. $title = count($pubs) . ' publication(s) were ' . $action . ":";
  1139. if ($action == 'error') {
  1140. $title = count($pubs) . ' publications were not imported due to errors:';
  1141. }
  1142. $content[] = [
  1143. '#type' => 'item',
  1144. '#title' => $title,
  1145. '#markup' => theme_item_list([
  1146. 'title' => '',
  1147. 'type' => 'ol',
  1148. 'items' => $pubs,
  1149. 'attributes' => [],
  1150. ]),
  1151. ];
  1152. }
  1153. }
  1154. $content = '<html>' . drupal_render($content) . '</html';
  1155. $message['subject'] = t('Publication import from !site', array('!site' => $site_name));
  1156. if (module_exists('htmlmail') or module_exists('mimemail')) {
  1157. $headers = array(
  1158. 'MIME-Version' => '1.0',
  1159. 'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
  1160. 'Content-Transfer-Encoding' => '8Bit',
  1161. 'X-Mailer' => 'Drupal'
  1162. );
  1163. foreach ($headers as $key => $value) {
  1164. $message['headers'][$key] = $value;
  1165. }
  1166. $message['body'][] = $content;
  1167. }
  1168. else {
  1169. $message['body'][] = drupal_html_to_text($content);
  1170. }
  1171. break;
  1172. }
  1173. }