tripal_chado.module 51 KB

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