tripal_chado.module 46 KB

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