tripal_chado.module 51 KB

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