tripal_chado.module 48 KB

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