tripal_chado.module 47 KB

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