tripal_chado.module 46 KB

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