tripal_chado.module 43 KB

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