tripal_chado.module 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  1. <?php
  2. // APPLICATION PROGRAMMER INTERFACE -------------
  3. // Chado API
  4. require_once "api/tripal_chado.api.inc";
  5. require_once 'api/tripal_chado.property.api.inc';
  6. require_once 'api/tripal_chado.query.api.inc';
  7. require_once 'api/tripal_chado.variables.api.inc';
  8. require_once 'api/tripal_chado.schema.api.inc';
  9. require_once 'api/tripal_chado.custom_tables.api.inc';
  10. require_once 'api/tripal_chado.mviews.api.inc';
  11. require_once 'api/tripal_chado.schema_v1.3.api.inc';
  12. require_once 'api/tripal_chado.schema_v1.2.api.inc';
  13. require_once 'api/tripal_chado.schema_v1.11.api.inc';
  14. require_once 'api/modules/tripal_chado.analysis.api.inc';
  15. require_once 'api/modules/tripal_chado.contact.api.inc';
  16. require_once 'api/modules/tripal_chado.cv.api.inc';
  17. require_once 'api/modules/tripal_chado.db.api.inc';
  18. require_once 'api/modules/tripal_chado.feature.api.inc';
  19. require_once 'api/modules/tripal_chado.organism.api.inc';
  20. require_once 'api/modules/tripal_chado.pub.api.inc';
  21. require_once 'api/modules/tripal_chado.stock.api.inc';
  22. require_once "includes/tripal_chado.entity.inc";
  23. require_once "includes/tripal_chado.schema.inc";
  24. require_once "includes/tripal_chado.term_storage.inc";
  25. require_once "includes/tripal_chado.field_storage.inc";
  26. tripal_chado_set_globals();
  27. /**
  28. * This function is used to set the global Chado variables
  29. *
  30. * @ingroup tripal_chado
  31. */
  32. function tripal_chado_set_globals() {
  33. // these global variables are meant to be accessed by all Tripal
  34. // modules to find the chado version installed and if Chado is local.
  35. // these variables are stored as globals rather than using the drupal_set_variable
  36. // functions because the Drupal functions make databaes queries and for long
  37. // running loaders we don't want those queries repeatedly.
  38. $GLOBALS["chado_is_installed"] = chado_is_installed();
  39. if ($GLOBALS["chado_is_installed"]) {
  40. $GLOBALS["chado_is_local"] = chado_is_local();
  41. $GLOBALS["chado_version"] = chado_get_version();
  42. $GLOBALS["exact_chado_version"] = chado_get_version(TRUE);
  43. }
  44. }
  45. /**
  46. * Implements hook_init().
  47. * Used to set the search_path, create default content and set default variables.
  48. *
  49. * @ingroup tripal_chado
  50. */
  51. function tripal_chado_init() {
  52. if ($GLOBALS["chado_is_installed"]) {
  53. // Check to see if the Chado and Drupal have been prepared
  54. if (!variable_get('tripal_chado_is_prepared', FALSE)) {
  55. drupal_set_message('Chado is installed but Tripal has not yet prepared Drupal and Chado. Please ' .
  56. l('prepare both Drupal and Chado', 'admin/tripal/storage/chado/chado_prepare') .
  57. ' before continuing.', 'warning');
  58. }
  59. }
  60. else {
  61. drupal_set_message('Tripal cannot find a Chado installation. Please ' .
  62. l('install Chado', 'admin/tripal/storage/chado/chado_install') .
  63. ' before continuing.', 'warning');
  64. }
  65. }
  66. /**
  67. * Implements hook_views_api().
  68. *
  69. * Essentially this hook tells drupal that there is views support for
  70. * for this module which then includes tripal_db.views.inc where all the
  71. * views integration code is
  72. *
  73. * @ingroup tripal_feature
  74. */
  75. function tripal_chado_views_api() {
  76. return array(
  77. 'api' => 3.0,
  78. );
  79. }
  80. /**
  81. * Implements hook_menu().
  82. */
  83. function tripal_chado_menu() {
  84. $items = array();
  85. $items['admin/tripal/storage/term/%/%'] = array(
  86. 'page callback' => 'tripal_autocomplete_cvterm',
  87. 'page arguments' => array(4, 5),
  88. 'access arguments' => array('administer content'),
  89. 'type' => MENU_CALLBACK,
  90. );
  91. //////////////////////////////////////////////////////////////////////////////
  92. // Chado Storage Backend
  93. //////////////////////////////////////////////////////////////////////////////
  94. $items['admin/tripal/storage/chado'] = array(
  95. 'title' => 'Chado',
  96. 'description' => t("Integrates Chado with Tripal and includes tools to
  97. load data, and extend the chado schema through custom tables &
  98. materialized views."),
  99. 'weight' => -100,
  100. 'access arguments' => array('administer tripal'),
  101. );
  102. $items['admin/tripal/storage/chado/chado_install'] = array(
  103. 'title' => 'Install Chado',
  104. 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'),
  105. 'page callback' => 'drupal_get_form',
  106. 'page arguments' => array('tripal_chado_install_form'),
  107. 'type' => MENU_NORMAL_ITEM,
  108. 'access arguments' => array('install chado'),
  109. 'file' => 'includes/tripal_chado.setup.inc',
  110. 'file path' => drupal_get_path('module', 'tripal_chado'),
  111. 'weight' => -100
  112. );
  113. $items['admin/tripal/storage/chado/chado_prepare'] = array(
  114. 'title' => 'Prepare Chado',
  115. 'description' => t('Prepares Drupal to use Chado.'),
  116. 'page callback' => 'drupal_get_form',
  117. 'page arguments' => array('tripal_chado_prepare_form'),
  118. 'type' => MENU_NORMAL_ITEM,
  119. 'access arguments' => array('install chado'),
  120. 'file' => 'includes/tripal_chado.setup.inc',
  121. 'file path' => drupal_get_path('module', 'tripal_chado'),
  122. 'weight' => -99
  123. );
  124. $items['admin/tripal/storage/chado/publish'] = array(
  125. 'title' => 'Publish',
  126. 'description' => t('Publish data that is present in Chado but which does
  127. not yet have a page on this site for viewing. In Tripal v2.0 or
  128. earlier this was refered to as "syncing".'),
  129. 'page callback' => 'drupal_get_form',
  130. 'page arguments' => array('tripal_chado_publish_form'),
  131. 'type' => MENU_NORMAL_ITEM,
  132. 'access arguments' => array('administer tripal'),
  133. 'file' => 'includes/tripal_chado.publish.inc',
  134. 'file path' => drupal_get_path('module', 'tripal_chado'),
  135. 'weight' => -99
  136. );
  137. //////////////////////////////////////////////////////////////////////////////
  138. // Materialized Views
  139. //////////////////////////////////////////////////////////////////////////////
  140. $items['admin/tripal/storage/chado/mviews'] = array(
  141. 'title' => 'Materialized Views',
  142. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  143. 'page callback' => 'tripal_mview_admin_view',
  144. 'access arguments' => array('administer tripal'),
  145. 'type' => MENU_NORMAL_ITEM,
  146. 'file' => 'includes/tripal_chado.mviews.inc',
  147. 'file path' => drupal_get_path('module', 'tripal_chado'),
  148. 'weight' => -10
  149. );
  150. $items['admin/tripal/storage/chado/mviews/help'] = array(
  151. 'title' => 'Help',
  152. 'description' => t('Help for the materialized views management system'),
  153. 'page callback' => 'theme',
  154. 'page arguments' => array('tripal_mviews_help'),
  155. 'access arguments' => array('administer tripal'),
  156. 'type' => MENU_LOCAL_TASK,
  157. 'file' => 'includes/tripal_chado.mviews.inc',
  158. 'file path' => drupal_get_path('module', 'tripal_chado'),
  159. 'weight' => 10
  160. );
  161. $items['admin/tripal/storage/chado/mviews/report/%'] = array(
  162. 'title' => 'Materialized View',
  163. 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'),
  164. 'page callback' => 'tripal_mview_report',
  165. 'page arguments' => array(6),
  166. 'access arguments' => array('administer tripal'),
  167. 'type' => MENU_CALLBACK,
  168. 'file' => 'includes/tripal_chado.mviews.inc',
  169. 'file path' => drupal_get_path('module', 'tripal_chado'),
  170. );
  171. $items['admin/tripal/storage/chado/mviews/new'] = array(
  172. 'title' => 'Create Materialized View',
  173. 'description' => t('Create a new materialized view.'),
  174. 'page callback' => 'drupal_get_form',
  175. 'page arguments' => array('tripal_mviews_form'),
  176. 'access arguments' => array('administer tripal'),
  177. 'type' => MENU_CALLBACK,
  178. 'file' => 'includes/tripal_chado.mviews.inc',
  179. 'file path' => drupal_get_path('module', 'tripal_chado'),
  180. );
  181. $items['admin/tripal/storage/chado/mviews/edit/%'] = array(
  182. 'title' => 'Edit Materialized View',
  183. 'page callback' => 'drupal_get_form',
  184. 'page arguments' => array('tripal_mviews_form', 6),
  185. 'access arguments' => array('administer tripal'),
  186. 'type' => MENU_CALLBACK,
  187. 'file' => 'includes/tripal_chado.mviews.inc',
  188. 'file path' => drupal_get_path('module', 'tripal_chado'),
  189. );
  190. $items['admin/tripal/storage/chado/mviews/update/%'] = array(
  191. 'title' => 'Create Materialized View',
  192. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  193. 'page callback' => 'tripal_mviews_add_populate_job',
  194. 'page arguments' => array(6),
  195. 'access arguments' => array('administer tripal'),
  196. 'type' => MENU_CALLBACK,
  197. 'file' => 'includes/tripal_chado.mviews.inc',
  198. 'file path' => drupal_get_path('module', 'tripal_chado'),
  199. );
  200. $items['admin/tripal/storage/chado/mviews/delete/%'] = array(
  201. 'title' => 'Create Materialized View',
  202. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  203. 'page callback' => 'drupal_get_form',
  204. 'page arguments' => array('tripal_mviews_delete_form', 5),
  205. 'access arguments' => array('administer tripal'),
  206. 'type' => MENU_CALLBACK,
  207. 'file' => 'includes/tripal_chado.mviews.inc',
  208. 'file path' => drupal_get_path('module', 'tripal_chado'),
  209. );
  210. // TODO: complete the code for exporting and importing of MViews.
  211. // Need to address security issues of sharing SQL.
  212. $items['admin/tripal/storage/chado/mviews/import'] = array(
  213. 'title' => 'Import MView',
  214. 'description' => 'Import a materialized view from another Tripal instance.',
  215. 'page callback' => 'drupal_get_form',
  216. 'page arguments' => array('tripal_mviews_import_form'),
  217. 'access arguments' => array('administer tripal'),
  218. 'type' => MENU_CALLBACK,
  219. 'file' => 'includes/tripal_chado.mviews.inc',
  220. 'file path' => drupal_get_path('module', 'tripal_chado'),
  221. );
  222. $items['admin/tripal/storage/chado/mviews/%tblid/export'] = array(
  223. 'title' => 'Export MView',
  224. 'description' => 'Export a materialized view for use by another Tripal instance.',
  225. 'page callback' => 'drupal_get_form',
  226. 'page arguments' => array('tripal_mviews_export_form', 5),
  227. 'access arguments' => array('administer tripal'),
  228. 'type' => MENU_CALLBACK,
  229. 'file' => 'includes/tripal_chado.mviews.inc',
  230. 'file path' => drupal_get_path('module', 'tripal_chado'),
  231. );
  232. //////////////////////////////////////////////////////////////////////////////
  233. // Custom Tables
  234. //////////////////////////////////////////////////////////////////////////////
  235. $items['admin/tripal/storage/chado/custom_tables'] = array(
  236. 'title' => 'Custom Tables',
  237. 'description' => t('Creation of custom tables that are added to Chado database.'),
  238. 'page callback' => 'tripal_custom_table_admin_view',
  239. 'access arguments' => array('administer tripal'),
  240. 'type' => MENU_NORMAL_ITEM,
  241. 'file' => 'includes/tripal_chado.custom_tables.inc',
  242. 'file path' => drupal_get_path('module', 'tripal_chado'),
  243. 'weight' => -10
  244. );
  245. $items['admin/tripal/storage/chado/custom_tables/help'] = array(
  246. 'title' => 'Help',
  247. 'description' => t('Help for the tripal job management system'),
  248. 'page callback' => 'theme',
  249. 'page arguments' => array('tripal_job_help'),
  250. 'access arguments' => array('administer tripal'),
  251. 'type' => MENU_LOCAL_TASK,
  252. 'file' => 'includes/tripal_chado.custom_tables.inc',
  253. 'file path' => drupal_get_path('module', 'tripal_chado'),
  254. 'weight' => 10
  255. );
  256. $items['admin/tripal/storage/chado/custom_tables/view/%'] = array(
  257. 'title' => 'Custom Tables',
  258. 'description' => t('Custom tables are added to Chado.'),
  259. 'page callback' => 'tripal_custom_table_view',
  260. 'page arguments' => array(6),
  261. 'access arguments' => array('administer tripal'),
  262. 'file' => 'includes/tripal_chado.custom_tables.inc',
  263. 'file path' => drupal_get_path('module', 'tripal_chado'),
  264. 'type' => MENU_CALLBACK,
  265. );
  266. $items['admin/tripal/storage/chado/custom_tables/new'] = array(
  267. 'title' => 'Create Custom Table',
  268. 'description' => t('An interface for creating your own custom tables.'),
  269. 'page callback' => 'tripal_custom_table_new_page',
  270. 'access arguments' => array('administer tripal'),
  271. 'file' => 'includes/tripal_chado.custom_tables.inc',
  272. 'file path' => drupal_get_path('module', 'tripal_chado'),
  273. 'type' => MENU_CALLBACK,
  274. );
  275. $items['admin/tripal/storage/chado/custom_tables/edit/%'] = array(
  276. 'title' => 'Edit Custom Table',
  277. 'page callback' => 'drupal_get_form',
  278. 'page arguments' => array('tripal_custom_tables_form', 6),
  279. 'access arguments' => array('administer tripal'),
  280. 'file' => 'includes/tripal_chado.custom_tables.inc',
  281. 'file path' => drupal_get_path('module', 'tripal_chado'),
  282. 'type' => MENU_CALLBACK,
  283. );
  284. $items['admin/tripal/storage/chado/custom_tables/delete/%'] = array(
  285. 'title' => 'Create Custom Table',
  286. 'description' => t('Custom tables are added to Chado.'),
  287. 'page callback' => 'drupal_get_form',
  288. 'page arguments' => array('tripal_custom_tables_delete_form', 6),
  289. 'access arguments' => array('administer tripal'),
  290. 'file' => 'includes/tripal_chado.custom_tables.inc',
  291. 'file path' => drupal_get_path('module', 'tripal_chado'),
  292. 'type' => MENU_CALLBACK,
  293. );
  294. $items['admin/tripal/storage/chado/custom_tables/views/tables/enable'] = array(
  295. 'title' => 'Enable Custom Tables Administrative View',
  296. 'page callback' => 'tripal_enable_view',
  297. 'page arguments' => array('tripal_admin_custom_table', 'admin/tripal/storage/chado/custom_tables'),
  298. 'access arguments' => array('administer tripal'),
  299. 'file' => 'includes/tripal_chado.custom_tables.inc',
  300. 'file path' => drupal_get_path('module', 'tripal_chado'),
  301. 'type' => MENU_CALLBACK,
  302. );
  303. //////////////////////////////////////////////////////////////////////////////
  304. // Data Loaders
  305. //////////////////////////////////////////////////////////////////////////////
  306. $items['admin/tripal/storage/chado/loaders'] = array(
  307. 'title' => 'Data Loaders',
  308. 'description' => t('Tools facilitating data import.'),
  309. 'access arguments' => array('administer tripal'),
  310. 'type' => MENU_NORMAL_ITEM,
  311. 'weight' => 6
  312. );
  313. $items['admin/tripal/storage/chado/loaders/fasta_loader'] = array(
  314. 'title' => 'FASTA file Loader',
  315. 'description' => 'Load sequences from a multi-FASTA file into Chado',
  316. 'page callback' => 'drupal_get_form',
  317. 'page arguments' => array('tripal_feature_fasta_load_form'),
  318. 'access arguments' => array('administer tripal feature'),
  319. 'file' => 'includes/loaders/tripal_chado.fasta_loader.inc',
  320. 'file path' => drupal_get_path('module', 'tripal_chado'),
  321. 'type' => MENU_NORMAL_ITEM,
  322. );
  323. $items['admin/tripal/storage/chado/loaders/gff3_load'] = array(
  324. 'title' => 'GFF3 file Loader',
  325. 'description' => 'Import a GFF3 file into Chado',
  326. 'page callback' => 'drupal_get_form',
  327. 'page arguments' => array('tripal_feature_gff3_load_form'),
  328. 'access arguments' => array('administer tripal feature'),
  329. 'file' => 'includes/loaders/tripal_chado.gff_loader.inc',
  330. 'file path' => drupal_get_path('module', 'tripal_chado'),
  331. 'type' => MENU_NORMAL_ITEM,
  332. );
  333. $items['admin/tripal/storage/chado/loaders/pub'] = array(
  334. 'title' => t('Publication Importers'),
  335. 'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
  336. 'page callback' => 'tripal_pub_importers_list',
  337. 'access arguments' => array('administer tripal pub'),
  338. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  339. 'file path' => drupal_get_path('module', 'tripal_chado'),
  340. 'type' => MENU_NORMAL_ITEM,
  341. 'weight' => 0
  342. );
  343. $items['admin/tripal/storage/chado/loaders/pub/new'] = array(
  344. 'title' => t('Add an Importer'),
  345. 'description' => t('Add a new publication importer.'),
  346. 'page callback' => 'tripal_pub_importer_setup_page',
  347. 'access arguments' => array('administer tripal pub'),
  348. 'type ' => MENU_CALLBACK,
  349. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  350. 'file path' => drupal_get_path('module', 'tripal_chado'),
  351. );
  352. $items['admin/tripal/storage/chado/loaders/pub/edit/%'] = array(
  353. 'page callback' => 'tripal_pub_importer_setup_page',
  354. 'page arguments' => array(6, 7),
  355. 'access arguments' => array('administer tripal pub'),
  356. 'type ' => MENU_CALLBACK,
  357. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  358. 'file path' => drupal_get_path('module', 'tripal_chado'),
  359. );
  360. $items['admin/tripal/storage/chado/loaders/pub/raw/%'] = array(
  361. 'title' => t('Raw Data From Publication Import'),
  362. 'page callback' => 'tripal_get_remote_pub_raw_page',
  363. 'page arguments' => array(6),
  364. 'access arguments' => array('administer tripal pub'),
  365. 'type ' => MENU_CALLBACK,
  366. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  367. 'file path' => drupal_get_path('module', 'tripal_chado'),
  368. );
  369. // add a second link for the importer on the data loaders page
  370. $items['admin/tripal/storage/chado/loaders/pub/import'] = array(
  371. 'title' => t('Publication Importers'),
  372. 'page callback' => 'tripal_pub_importers_list',
  373. 'access arguments' => array('administer tripal pub'),
  374. 'type' => MENU_CALLBACK,
  375. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  376. 'file path' => drupal_get_path('module', 'tripal_chado'),
  377. );
  378. $items['admin/tripal/storage/chado/loaders/pub/submit/%'] = array(
  379. 'page callback' => 'tripal_pub_importer_submit_job',
  380. 'page arguments' => array(7),
  381. 'access arguments' => array('administer tripal pub'),
  382. 'type ' => MENU_CALLBACK,
  383. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  384. 'file path' => drupal_get_path('module', 'tripal_chado'),
  385. );
  386. $items['admin/tripal/storage/chado/loaders/pub/delete/%'] = array(
  387. 'page callback' => 'tripal_pub_importer_delete',
  388. 'page arguments' => array(7),
  389. 'access arguments' => array('administer tripal pub'),
  390. 'type ' => MENU_CALLBACK,
  391. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  392. 'file path' => drupal_get_path('module', 'tripal_chado'),
  393. );
  394. $items['admin/tripal/storage/chado/loaders/pub/changedb'] = array(
  395. 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
  396. 'page arguments' => array(),
  397. 'access arguments' => array('administer tripal pub'),
  398. 'type ' => MENU_CALLBACK,
  399. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  400. 'file path' => drupal_get_path('module', 'tripal_chado'),
  401. );
  402. $items['admin/tripal/storage/chado/loaders/pub/criteria/%/%'] = array(
  403. 'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
  404. 'page arguments' => array(7, 8),
  405. 'access arguments' => array('administer tripal pub'),
  406. 'type ' => MENU_CALLBACK,
  407. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  408. 'file path' => drupal_get_path('module', 'tripal_chado'),
  409. );
  410. //////////////////////////////////////////////////////////////////////////////
  411. // Migrate Content
  412. //////////////////////////////////////////////////////////////////////////////
  413. $items['admin/tripal/storage/chado/migrate'] = array(
  414. 'title' => 'Migrate',
  415. 'description' => t('Migrate Tripal v2 content to Tripal v3'),
  416. 'page callback' => 'drupal_get_form',
  417. 'page arguments' => array('tripal_chado_migrate_form'),
  418. 'type' => MENU_NORMAL_ITEM,
  419. 'access arguments' => array('administer tripal'),
  420. 'file' => 'includes/tripal_chado.migrate.inc',
  421. 'file path' => drupal_get_path('module', 'tripal_chado'),
  422. 'weight' => 10
  423. );
  424. //////////////////////////////////////////////////////////////////////////////
  425. // Auto Completes
  426. //////////////////////////////////////////////////////////////////////////////
  427. $items['admin/tripal/storage/chado/auto_name/dbxref/%/%'] = array(
  428. 'page callback' => 'tripal_autocomplete_dbxref',
  429. 'page arguments' => array(6, 7),
  430. 'access arguments' => array('access content'),
  431. 'file' => 'api/modules/tripal_chado.db.api.inc',
  432. 'file path' => drupal_get_path('module', 'tripal_chado'),
  433. 'type' => MENU_CALLBACK,
  434. );
  435. $items['admin/tripal/storage/chado/auto_name/cvterm/%/%'] = array(
  436. 'page callback' => 'tripal_autocomplete_cvterm',
  437. 'page arguments' => array(6, 7),
  438. 'access arguments' => array('access content'),
  439. 'file' => 'api/modules/tripal_chado.db.api.inc',
  440. 'file path' => drupal_get_path('module', 'tripal_chado'),
  441. 'type' => MENU_CALLBACK,
  442. );
  443. $items['admin/tripal/storage/chado/auto_name/pub/%'] = array(
  444. 'page callback' => 'tripal_autocomplete_pub',
  445. 'page arguments' => array(6),
  446. 'access arguments' => array('access content'),
  447. 'file' => 'api/modules/tripal_chado.pub.api.inc',
  448. 'file path' => drupal_get_path('module', 'tripal_chado'),
  449. 'type' => MENU_CALLBACK,
  450. );
  451. return $items;
  452. }
  453. /**
  454. * Implements hook_permission().
  455. *
  456. * Set the permission types that the chado module uses. Essentially we
  457. * want permissionis that protect creation, editing and deleting of chado
  458. * data objects
  459. *
  460. * @ingroup tripal
  461. */
  462. function tripal_chado_permission() {
  463. return array(
  464. 'install chado' => array(
  465. 'title' => t('Install Chado'),
  466. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  467. ),
  468. 'view chado_ids' => array(
  469. 'title' => t('View Internal IDs'),
  470. 'description' => t('On content pages Tripal will typically provide
  471. a table of information pulled from the Chado database but the
  472. primary key IDs for that data is typically not shown. The
  473. default Tripal templates can show the primary key ID inside of a
  474. blue shaded table row if this permission is enabled. This can
  475. be useful for site developers who might want these IDs when working
  476. with the underlying database.'),
  477. 'restrict access' => TRUE,
  478. )
  479. );
  480. }
  481. /**
  482. * Implements hook_field_info().
  483. */
  484. function tripal_chado_field_info() {
  485. $fields = array(
  486. 'organism_id' => array(
  487. 'label' => t('Organism'),
  488. 'description' => t('A field for specifying an organism.'),
  489. 'default_widget' => 'tripal_chado_organism_select_widget',
  490. 'default_formatter' => 'tripal_chado_organism_formatter',
  491. 'settings' => array(),
  492. 'storage' => array(
  493. 'type' => 'field_chado_storage',
  494. 'module' => 'tripal_chado',
  495. 'active' => TRUE
  496. ),
  497. ),
  498. 'dbxref_id' => array(
  499. 'label' => t('Cross reference'),
  500. 'description' => t('This record can be cross referenced with a record in
  501. another online database. This field is intended for the most prominent
  502. reference. At a minimum, the database and accession must be provided.'),
  503. 'default_widget' => 'tripal_chado_dbxref_id_widget',
  504. 'default_formatter' => 'tripal_chado_dbxref_id_formatter',
  505. 'settings' => array(),
  506. 'storage' => array(
  507. 'type' => 'field_chado_storage',
  508. 'module' => 'tripal_chado',
  509. 'active' => TRUE
  510. ),
  511. ),
  512. 'residues' => array(
  513. 'label' => t('Residues'),
  514. 'description' => t('A field for managing nucleotide and protein residues.'),
  515. 'default_widget' => 'tripal_chado_residue_textarea_widget',
  516. 'default_formatter' => 'tripal_chado_residues_formatter',
  517. 'settings' => array(),
  518. 'storage' => array(
  519. 'type' => 'field_chado_storage',
  520. 'module' => 'tripal_chado',
  521. 'active' => TRUE
  522. ),
  523. ),
  524. 'md5checksum' => array(
  525. 'label' => t('MD5 checksum'),
  526. 'description' => t('A field for generating MD5 checksum for a sequence.'),
  527. 'default_widget' => 'tripal_chado_md5checksum_checkbox_widget',
  528. 'default_formatter' => 'tripal_chado_md5checksum_formatter',
  529. 'settings' => array(),
  530. 'storage' => array(
  531. 'type' => 'field_chado_storage',
  532. 'module' => 'tripal_chado',
  533. 'active' => TRUE
  534. ),
  535. ),
  536. 'seqlen' => array(
  537. 'label' => t('Sequence length'),
  538. 'description' => t('A field for calculating the length of a sequence.'),
  539. 'default_widget' => 'tripal_chado_seqlen_hidden_widget',
  540. 'default_formatter' => 'tripal_chado_seqlen_formatter',
  541. 'settings' => array(),
  542. 'storage' => array(
  543. 'type' => 'field_chado_storage',
  544. 'module' => 'tripal_chado',
  545. 'active' => TRUE
  546. ),
  547. ),
  548. // The field provides a widget for adding new properties
  549. // to an entity that is connected to a base table that has a prop table
  550. // in Chado.
  551. 'kvproperty_adder' => array(
  552. 'label' => t('Add a Property Type'),
  553. 'description' => t('This record may have any number of properties. Use
  554. this field to first add the type.'),
  555. 'default_widget' => 'tripal_chado_kvproperty_adder_widget',
  556. //'default_formatter' => 'tripal_chado_kvproperty_adder_formatter',
  557. 'default_formatter' => 'hidden',
  558. 'settings' => array(),
  559. 'storage' => array(
  560. 'type' => 'field_chado_storage',
  561. 'module' => 'tripal_chado',
  562. 'active' => TRUE
  563. ),
  564. ),
  565. // The field provides form elements for adding a property to an entity
  566. // that in turn gets stored in a prop table of Chado (e.g. featureprop,
  567. // stockprop, etc).
  568. 'kvproperty' => array(
  569. 'label' => t('Add a Property'),
  570. 'description' => t('Add details about this property.'),
  571. 'default_widget' => 'tripal_chado_kvproperty_widget',
  572. 'default_formatter' => 'tripal_chado_kvproperty_formatter',
  573. 'settings' => array(),
  574. 'storage' => array(
  575. 'type' => 'field_chado_storage',
  576. 'module' => 'tripal_chado',
  577. 'active' => TRUE
  578. ),
  579. ),
  580. // The field provides form elements for adding multiple dbxrefs to an
  581. // entity that in turn get stored in a [base]_dbxref table of Chado
  582. // (e.g. organism_dbxref, feature_dbxref). This is different
  583. // from the dbxref_id field as that is specific to a dbxref_id in
  584. // a base table.
  585. 'dbxref' => array(
  586. 'label' => t('Cross references'),
  587. 'description' => t('This record can be cross referenced with a record in
  588. another online database. This field is intended for one or more
  589. references. At a minimum, the database and accession must be provided.'),
  590. 'default_widget' => 'tripal_chado_dbxref_widget',
  591. 'default_formatter' => 'tripal_chado_dbxref_formatter',
  592. 'settings' => array(),
  593. 'storage' => array(
  594. 'type' => 'field_chado_storage',
  595. 'module' => 'tripal_chado',
  596. 'active' => TRUE
  597. ),
  598. ),
  599. // The field provides a widget for adding new vocabularies for cvterm
  600. // linker tables. This will allow cvterms to be grouped by vocabulary
  601. // ('category').
  602. 'cvterm_class_adder' => array(
  603. 'label' => t('Add an Annotation Type'),
  604. 'description' => t('This record may have any number of types of
  605. annotations. Use this field to first add the type.'),
  606. 'default_widget' => 'tripal_chado_cvterm_class_adder_widget',
  607. //'default_formatter' => 'tripal_chado_cvterm_class_adder_formatter',
  608. 'default_formatter' => 'hidden',
  609. 'settings' => array(),
  610. 'storage' => array(
  611. 'type' => 'field_chado_storage',
  612. 'module' => 'tripal_chado',
  613. 'active' => TRUE
  614. ),
  615. ),
  616. // The field provides form elements for adding multiple cvterms to an
  617. // entity that in turn get stored in a [base]_cvterm table of Chado
  618. // (e.g. feature_cvterm).
  619. 'cvterm' => array(
  620. 'label' => t('Annotations'),
  621. 'description' => t('This record can be annotated with terms
  622. from other vocabularies.'),
  623. 'default_widget' => 'tripal_chado_cvterm_widget',
  624. 'default_formatter' => 'tripal_chado_cvterm_formatter',
  625. 'settings' => array(),
  626. 'storage' => array(
  627. 'type' => 'field_chado_storage',
  628. 'module' => 'tripal_chado',
  629. 'active' => TRUE
  630. ),
  631. ),
  632. 'synonym' => array(
  633. 'label' => t('Synonyms'),
  634. 'description' => t('Adds an alternative name (synonym or alias) to this record.'),
  635. 'default_widget' => 'tripal_chado_synonym_widget',
  636. 'default_formatter' => 'tripal_chado_synonym_formatter',
  637. 'settings' => array(),
  638. 'storage' => array(
  639. 'type' => 'field_chado_storage',
  640. 'module' => 'tripal_chado',
  641. 'active' => TRUE
  642. ),
  643. ),
  644. 'pub' => array(
  645. 'label' => t('Publications'),
  646. 'description' => t('Associates a publication (e.g. journal article, conference proceedings, book chapter, etc.) with this record.'),
  647. 'default_widget' => 'tripal_chado_pub_widget',
  648. 'default_formatter' => 'tripal_chado_pub_formatter',
  649. 'settings' => array(),
  650. 'storage' => array(
  651. 'type' => 'field_chado_storage',
  652. 'module' => 'tripal_chado',
  653. 'active' => TRUE
  654. ),
  655. ),
  656. );
  657. return $fields;
  658. }
  659. /**
  660. * Implements hook_field_widget_info().
  661. */
  662. function tripal_chado_field_widget_info() {
  663. return array(
  664. 'tripal_chado_organism_select_widget' => array(
  665. 'label' => t('Organism Select'),
  666. 'field types' => array('organism_id')
  667. ),
  668. 'tripal_chado_dbxref_id_widget' => array(
  669. 'label' => t('Cross reference'),
  670. 'field types' => array('dbxref_id'),
  671. 'description' => t('This record can be cross referenced with a record in
  672. another online database. This field is intended for the most
  673. prominent reference. At a minimum, the database and accession
  674. must be provided.'),
  675. ),
  676. 'tripal_chado_dbxref_widget' => array(
  677. 'label' => t('Cross references'),
  678. 'field types' => array('dbxref'),
  679. 'description' => t('This record can be cross referenced with a record
  680. in another online database. This field is intended for the most
  681. prominent reference. At a minimum, the database and accession
  682. must be provided.'),
  683. ),
  684. 'tripal_chado_cvterm_class_adder_widget' => array(
  685. 'label' => t('Add an Annotation'),
  686. 'field types' => array('cvterm_class_adder'),
  687. ),
  688. 'tripal_chado_cvterm_widget' => array(
  689. 'label' => t('Annotations'),
  690. 'field types' => array('cvterm'),
  691. 'description' => t('This record can be annotated with terms
  692. from other vocabularies.'),
  693. ),
  694. 'tripal_chado_md5checksum_checkbox_widget' => array(
  695. 'label' => t('MD5 Checksum Checkbox'),
  696. 'field types' => array('md5checksum'),
  697. ),
  698. 'tripal_chado_residues_textarea_widget' => array(
  699. 'label' => t('Residues'),
  700. 'field types' => array('residues'),
  701. ),
  702. 'tripal_chado_seqlen_hidden_widget' => array(
  703. 'label' => t('Sequence Length'),
  704. 'field types' => array('seqlen'),
  705. ),
  706. 'tripal_chado_kvproperty_adder_widget' => array(
  707. 'label' => t('Add a Property'),
  708. 'field types' => array('kvproperty_adder'),
  709. ),
  710. 'tripal_chado_kvproperty_widget' => array(
  711. 'label' => t('Property'),
  712. 'field types' => array('kvproperty'),
  713. ),
  714. 'tripal_chado_synonym_widget' => array(
  715. 'label' => t('Synonyms'),
  716. 'field types' => array('synonym'),
  717. ),
  718. 'tripal_chado_pub_widget' => array(
  719. 'label' => t('Publications'),
  720. 'field types' => array('pub'),
  721. ),
  722. );
  723. }
  724. /**
  725. * Implements hook_field_formatter_info().
  726. */
  727. function tripal_chado_field_formatter_info() {
  728. return array(
  729. 'tripal_chado_organism_formatter' => array(
  730. 'label' => t('Organism'),
  731. 'field types' => array('organism_id')
  732. ),
  733. 'tripal_chado_dbxref_id_formatter' => array(
  734. 'label' => t('Cross reference'),
  735. 'field types' => array('dbxref_id')
  736. ),
  737. 'tripal_chado_dbxref_formatter' => array(
  738. 'label' => t('Cross references'),
  739. 'field types' => array('dbxref')
  740. ),
  741. 'tripal_chado_cvterm_class_adder_formatter' => array(
  742. 'label' => t('Add an Annotation'),
  743. 'field types' => array('cvterm_class_adder')
  744. ),
  745. 'tripal_chado_cvterm_formatter' => array(
  746. 'label' => t('Annotations'),
  747. 'field types' => array('cvterm')
  748. ),
  749. 'tripal_chado_md5checksum_formatter' => array(
  750. 'label' => t('MD5 checksum'),
  751. 'field types' => array('md5checksum')
  752. ),
  753. 'tripal_chado_residues_formatter' => array(
  754. 'label' => t('Residues'),
  755. 'field types' => array('residues')
  756. ),
  757. 'tripal_chado_seqlen_formatter' => array(
  758. 'label' => t('Sequence length'),
  759. 'field types' => array('seqlen')
  760. ),
  761. 'tripal_chado_kvproperty_adder_formatter' => array(
  762. 'label' => t('Add a Property'),
  763. 'field types' => array('kvproperty_adder')
  764. ),
  765. 'tripal_chado_kvproperty_formatter' => array(
  766. 'label' => t('Property'),
  767. 'field types' => array('kvproperty')
  768. ),
  769. 'tripal_chado_synonym_formatter' => array(
  770. 'label' => t('Synonyms'),
  771. 'field types' => array('synonym')
  772. ),
  773. 'tripal_chado_pub_formatter' => array(
  774. 'label' => t('Publications'),
  775. 'field types' => array('pub')
  776. ),
  777. );
  778. }
  779. /**
  780. * Implements hook_field_widget_form_alter().
  781. */
  782. function tripal_chado_field_widget_form_alter(&$element, &$form_state, $context) {
  783. if (array_key_exists('#field_name', $element)) {
  784. $field_name = $element['#field_name'];
  785. $matches = array();
  786. if (preg_match('/(.+?)__(.+?)$/', $field_name, $matches)) {
  787. $tablename = $matches[1];
  788. $colname = $matches[2];
  789. $schema = chado_get_schema($tablename);
  790. // The timelastmodified field exists in many Chado tables. We want
  791. // the form element to update to the most recent time rather than the time
  792. // in the database.
  793. if ($colname == 'timelastmodified' and $schema['fields'][$colname]['type'] == 'datetime') {
  794. // We want the default value for the field to be the current time.
  795. $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s", 'UTC');
  796. $element['#date_items']['value'] = $element['#default_value']['value'];
  797. }
  798. // We want the date combo fieldset to be collaspible so we will
  799. // add our own theme_wrapper to replace the one added by the date
  800. // module.
  801. if (array_key_exists($colname, $schema['fields']) and $schema['fields'][$colname]['type'] == 'datetime') {
  802. $element['#theme_wrappers'] = array('tripal_chado_date_combo');
  803. }
  804. }
  805. }
  806. }
  807. /**
  808. * Implements hook_field_formatter_view().
  809. */
  810. function tripal_chado_field_formatter_view($entity_type, $entity, $field,
  811. $instance, $langcode, $items, $display) {
  812. $element = array();
  813. switch ($display['type']) {
  814. case 'tripal_chado_organism_formatter':
  815. module_load_include('inc', 'tripal_chado', 'includes/fields/organism_id');
  816. tripal_chado_organism_select_formatter($element, $entity_type, $entity, $field,
  817. $instance, $langcode, $items, $display);
  818. break;
  819. case 'tripal_chado_dbxref_id_formatter':
  820. module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref_id');
  821. tripal_chado_dbxref_id_formatter($element, $entity_type, $entity, $field,
  822. $instance, $langcode, $items, $display);
  823. break;
  824. case 'tripal_chado_dbxref_formatter':
  825. module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref');
  826. tripal_chado_dbxref_formatter($element, $entity_type, $entity, $field,
  827. $instance, $langcode, $items, $display);
  828. break;
  829. case 'tripal_chado_cvterm_class_adder_formatter':
  830. module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm_class_adder');
  831. tripal_chado_cvterm_class_adder_formatter($element, $entity_type, $entity, $field,
  832. $instance, $langcode, $items, $display);
  833. break;
  834. case 'tripal_chado_cvterm_formatter':
  835. module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm');
  836. tripal_chado_cvterm_formatter($element, $entity_type, $entity, $field,
  837. $instance, $langcode, $items, $display);
  838. break;
  839. case 'tripal_chado_md5checksum_formatter':
  840. module_load_include('inc', 'tripal_chado', 'includes/fields/md5checksum');
  841. tripal_chado_md5checksum_checkbox_formatter($element, $entity_type, $entity, $field,
  842. $instance, $langcode, $items, $display);
  843. break;
  844. case 'tripal_chado_residues_formatter':
  845. module_load_include('inc', 'tripal_chado', 'includes/fields/residues');
  846. tripal_chado_residues_textarea_formatter($element, $entity_type, $entity, $field,
  847. $instance, $langcode, $items, $display);
  848. break;
  849. case 'tripal_chado_seqlen_formatter':
  850. module_load_include('inc', 'tripal_chado', 'includes/fields/seqlen');
  851. tripal_chado_seqlen_hidden_formatter($element, $entity_type, $entity, $field,
  852. $instance, $langcode, $items, $display);
  853. break;
  854. case 'tripal_chado_kvproperty_adder_formatter':
  855. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
  856. tripal_chado_kvproperty_adder_formatter($element, $entity_type, $entity, $field,
  857. $instance, $langcode, $items, $display);
  858. break;
  859. case 'tripal_chado_kvproperty_formatter':
  860. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty');
  861. tripal_chado_kvproperty_formatter($element, $entity_type, $entity, $field,
  862. $instance, $langcode, $items, $display);
  863. break;
  864. case 'tripal_chado_synonym_formatter':
  865. module_load_include('inc', 'tripal_chado', 'includes/fields/synonym');
  866. tripal_chado_synonym_formatter($element, $entity_type, $entity, $field,
  867. $instance, $langcode, $items, $display);
  868. break;
  869. case 'tripal_chado_pub_formatter':
  870. module_load_include('inc', 'tripal_chado', 'includes/fields/pub');
  871. tripal_chado_pub_formatter($element, $entity_type, $entity, $field,
  872. $instance, $langcode, $items, $display);
  873. break;
  874. }
  875. return $element;
  876. }
  877. /**
  878. * Implements hook_field_widget_form().
  879. */
  880. function tripal_chado_field_widget_form(&$form, &$form_state, $field,
  881. $instance, $langcode, $items, $delta, $element) {
  882. $widget = $element;
  883. switch ($instance['widget']['type']) {
  884. case 'tripal_chado_organism_select_widget':
  885. // Make sure the include files get parsed now and for the form submits.
  886. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/organism_id');
  887. module_load_include('inc', 'tripal_chado', 'includes/fields/organism_id');
  888. // Update the widget with the new field.
  889. tripal_chado_organism_select_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  890. break;
  891. case 'tripal_chado_dbxref_id_widget':
  892. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/dbxref_id');
  893. module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref_id');
  894. tripal_chado_dbxref_id_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  895. break;
  896. case 'tripal_chado_dbxref_widget':
  897. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/dbxref');
  898. module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref');
  899. tripal_chado_dbxref_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  900. break;
  901. case 'tripal_chado_cvterm_class_adder_widget':
  902. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/cvterm_class_adder');
  903. module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm_class_adder');
  904. tripal_chado_cvterm_class_adder_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  905. break;
  906. case 'tripal_chado_cvterm_widget':
  907. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/cvterm');
  908. module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm');
  909. tripal_chado_cvterm_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  910. break;
  911. case 'tripal_chado_md5checksum_checkbox_widget':
  912. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/md5checksum');
  913. module_load_include('inc', 'tripal_chado', 'includes/fields/md5checksum');
  914. tripal_chado_md5checksum_checkbox_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  915. break;
  916. case 'tripal_chado_residues_textarea_widget':
  917. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/residues');
  918. module_load_include('inc', 'tripal_chado', 'includes/fields/residues');
  919. tripal_chado_residues_textarea_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  920. break;
  921. case 'tripal_chado_seqlen_hidden_widget':
  922. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/seqlen');
  923. module_load_include('inc', 'tripal_chado', 'includes/fields/seqlen');
  924. tripal_chado_seqlen_hidden_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  925. break;
  926. case 'tripal_chado_kvproperty_adder_widget':
  927. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
  928. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
  929. tripal_chado_kvproperty_adder_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  930. break;
  931. case 'tripal_chado_kvproperty_widget':
  932. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/kvproperty');
  933. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty');
  934. tripal_chado_kvproperty_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  935. break;
  936. case 'tripal_chado_synonym_widget':
  937. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/synonym');
  938. module_load_include('inc', 'tripal_chado', 'includes/fields/synonym');
  939. tripal_chado_synonym_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  940. break;
  941. case 'tripal_chado_pub_widget':
  942. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/pub');
  943. module_load_include('inc', 'tripal_chado', 'includes/fields/pub');
  944. tripal_chado_pub_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  945. break;
  946. }
  947. return $widget;
  948. }
  949. /**
  950. * Implements hook_form_FORM_ID_alter().
  951. *
  952. * The field_ui_display_overview_form is used for formatting the display
  953. * or layout of fields attached to an entity and shown on the entity view page.
  954. *
  955. * This function removes the cvterm class and property adder field as those are
  956. * really not meant for users to show or manage.
  957. */
  958. function tripal_chado_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
  959. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  960. // on the add/edit form of an entity for adding new property fields.
  961. $fields_names = element_children($form['fields']);
  962. foreach ($fields_names as $field_name) {
  963. $field_info = field_info_field($field_name);
  964. if ($field_info['type'] == 'kvproperty_adder') {
  965. unset($form['fields'][$field_name]);
  966. }
  967. if ($field_info['type'] == 'cvterm_class_adder') {
  968. unset($form['fields'][$field_name]);
  969. }
  970. }
  971. }
  972. /**
  973. * Implements hook_form_FORM_ID_alter().
  974. *
  975. * The field_ui_field_overview_form is used for ordering and configuring the
  976. * fields attached to an entity.
  977. *
  978. * This function removes the property adder field as that is really not meant
  979. * for users to show or manage.
  980. */
  981. function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
  982. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  983. // on the add/edit form of an entity for adding new property fields.
  984. $fields_names = element_children($form['fields']);
  985. foreach ($fields_names as $field_name) {
  986. $field_info = field_info_field($field_name);
  987. if ($field_info['type'] == 'kvproperty_adder') {
  988. unset($form['fields'][$field_name]);
  989. }
  990. if ($field_info['type'] == 'cvterm_class_adder') {
  991. unset($form['fields'][$field_name]);
  992. }
  993. }
  994. }
  995. /**
  996. * Implements hook_field_is_empty().
  997. */
  998. function tripal_chado_field_is_empty($item, $field) {
  999. // If there is no value field then the field is empty.
  1000. if (!array_key_exists('value', $item)) {
  1001. return TRUE;
  1002. }
  1003. // Iterate through all of the fields and if at least one has a value
  1004. // the field is not empty.
  1005. foreach ($item as $form_field_name => $value) {
  1006. if (isset($value) and $value != NULL and $value != '') {
  1007. return FALSE;
  1008. }
  1009. }
  1010. // Otherwise, the field is empty.
  1011. return TRUE;
  1012. }
  1013. /**
  1014. * Returns the values of the field from the $form_state.
  1015. */
  1016. function tripal_chado_get_field_form_values($field_name, $form_state, $delta = 0, $child = NULL) {
  1017. $value = NULL;
  1018. // The form_state must have the 'values' key. If not then just return.
  1019. if (!array_key_exists('values', $form_state)) {
  1020. return $value;
  1021. }
  1022. // If the field name is not in the form_state['values'] then return.
  1023. if (!array_key_exists($field_name, $form_state['values'])) {
  1024. return $value;
  1025. }
  1026. // Iterate through the values looking for the field_name provided.
  1027. foreach ($form_state['values'][$field_name] as $langcode => $items) {
  1028. if (!array_key_exists($delta, $items)) {
  1029. continue;
  1030. }
  1031. $item = $items[$delta];
  1032. if ($child){
  1033. if(array_key_exists($child, $item) and $item[$child] != '') {
  1034. $value = $item[$child];
  1035. }
  1036. }
  1037. else {
  1038. $value = $item['value'];
  1039. }
  1040. }
  1041. return $value;
  1042. }
  1043. /**
  1044. * Sets the values of the field from the $form_state.
  1045. */
  1046. function tripal_chado_set_field_form_values($field_name, &$form_state, $newvalue, $delta = 0, $child = NULL) {
  1047. // The form_state must have the 'values' key. If not then just return.
  1048. if (!array_key_exists('values', $form_state)) {
  1049. return FALSE;
  1050. }
  1051. // If the field name is not in the form_state['values'] then reutrn.
  1052. if (!array_key_exists($field_name, $form_state['values'])) {
  1053. return FALSE;
  1054. }
  1055. foreach ($form_state['values'][$field_name] as $langcode => $items) {
  1056. if ($child) {
  1057. $form_state['values'][$field_name][$langcode][$delta][$child] = $newvalue;
  1058. }
  1059. else {
  1060. $form_state['values'][$field_name][$langcode][$delta]['value'] = $newvalue;
  1061. }
  1062. }
  1063. return TRUE;
  1064. }
  1065. /**
  1066. * Implements hook_theme().
  1067. */
  1068. function tripal_chado_theme($existing, $type, $theme, $path) {
  1069. return array(
  1070. // Theme fields.
  1071. 'tripal_chado_dbxref_id_widget' => array(
  1072. 'render element' => 'element',
  1073. 'file' => 'includes/fields/dbxref_id.inc',
  1074. ),
  1075. 'tripal_chado_dbxref_widget' => array(
  1076. 'render element' => 'element',
  1077. 'file' => 'includes/fields/dbxref.inc',
  1078. ),
  1079. 'tripal_chado_cvterm_widget' => array(
  1080. 'render element' => 'element',
  1081. 'file' => 'includes/fields/cvterm.inc',
  1082. ),
  1083. 'tripal_chado_synonym_widget' => array(
  1084. 'render element' => 'element',
  1085. 'file' => 'includes/fields/synonym.inc',
  1086. ),
  1087. 'tripal_chado_pub_widget' => array(
  1088. 'render element' => 'element',
  1089. 'file' => 'includes/fields/pub.inc',
  1090. ),
  1091. 'tripal_chado_kvproperty_addr_widget' => array(
  1092. 'render element' => 'element',
  1093. 'file' => 'includes/fields/dbxref_id.inc',
  1094. ),
  1095. 'tripal_chado_date_combo' => array(
  1096. 'render element' => 'element',
  1097. 'file' => 'theme/tripal_chado.theme.inc',
  1098. ),
  1099. // Themed forms
  1100. 'tripal_pub_importer_setup_form_elements' => array(
  1101. 'render element' => 'form',
  1102. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  1103. ),
  1104. 'tripal_pub_search_setup_form_elements' => array(
  1105. 'render element' => 'form',
  1106. 'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
  1107. ),
  1108. );
  1109. }
  1110. /**
  1111. * Implements hook_add_bundle_fields().
  1112. */
  1113. function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
  1114. $bundle_name = $bundle->name;
  1115. // This array will hold details that map the bundle to tables in Chado.
  1116. $bundle_data = array();
  1117. // Get the cvterm that corresponds to this TripalTerm object.
  1118. $vocab = entity_load('TripalVocab', array($term->vocab_id));
  1119. $vocab = reset($vocab);
  1120. $match = array(
  1121. 'dbxref_id' => array(
  1122. 'db_id' => array(
  1123. 'name' => $vocab->namespace,
  1124. ),
  1125. 'accession' => $term->accession
  1126. ),
  1127. );
  1128. $cvterm = chado_generate_var('cvterm', $match);
  1129. // The organism table does not have a type_id so we won't ever find
  1130. // a record for it in the tripal_cv_defaults table.
  1131. if ($cvterm->name == 'organism') {
  1132. $bundle_data = array(
  1133. 'cv_id' => $cvterm->cv_id->cv_id,
  1134. 'cvterm_id' => $cvterm->cvterm_id,
  1135. 'data_table' => 'organism',
  1136. 'type_table' => 'organism',
  1137. 'field' => '',
  1138. );
  1139. }
  1140. // The analysis table does not have a type_id so we won't ever find
  1141. // a record for it in the tripalcv_defaults table.
  1142. else if ($cvterm->name == 'analysis') {
  1143. $bundle_data = array(
  1144. 'cv_id' => $cvterm->cv_id->cv_id,
  1145. 'cvterm_id' => $cvterm->cvterm_id,
  1146. 'data_table' => 'analysis',
  1147. 'type_table' => 'analysis',
  1148. 'field' => '',
  1149. );
  1150. }
  1151. else if ($cvterm->name == 'project') {
  1152. $bundle_data = array(
  1153. 'cv_id' => $cvterm->cv_id->cv_id,
  1154. 'cvterm_id' => $cvterm->cvterm_id,
  1155. 'data_table' => 'project',
  1156. 'type_table' => 'project',
  1157. 'field' => '',
  1158. );
  1159. }
  1160. else {
  1161. // TODO: WHAT TO DO IF A VOCABULARY IS USED AS A DEFAULT FOR MULTIPLE
  1162. // TABLES.
  1163. // Look to see if this vocabulary is used as a default for any table.
  1164. $default = db_select('tripal_cv_defaults', 't')
  1165. ->fields('t')
  1166. ->condition('cv_id', $cvterm->cv_id->cv_id)
  1167. ->execute()
  1168. ->fetchObject();
  1169. if ($default) {
  1170. $bundle_data = array(
  1171. 'cv_id' => $cvterm->cv_id->cv_id,
  1172. 'cvterm_id' => $cvterm->cvterm_id,
  1173. 'data_table' => $default->table_name,
  1174. 'type_table' => $default->table_name,
  1175. 'field' => $default->field_name,
  1176. );
  1177. }
  1178. }
  1179. // Save the mapping information so that we can reuse it when we need to
  1180. // look things up for later for an entity
  1181. tripal_set_bundle_variable('chado_cvterm_id', $bundle->id, $bundle_data['cvterm_id']);
  1182. tripal_set_bundle_variable('chado_table', $bundle->id, $bundle_data['data_table']);
  1183. tripal_set_bundle_variable('chado_column', $bundle->id, $bundle_data['field']);
  1184. //////////////////////////////////////////////////////////////////////////////
  1185. // ADD FIELDS TO BUNDLE
  1186. ////////////////////////////////////////////////////////////////////////////
  1187. ////
  1188. //
  1189. // Base table fields.
  1190. //
  1191. // Adds the fields for the base table to the entity. Adds fields
  1192. // for all columns including FK fields. Excludes primary key and the
  1193. // type_id field (that's inherent in the bundle).
  1194. tripal_chado_add_bundle_base_fields($entity_type, $bundle_name, $bundle_data);
  1195. ////
  1196. //
  1197. // Property table fields.
  1198. //
  1199. // Check to see if there are any property tables with FKs to this
  1200. // base table. If so, add the fields for that type of table.
  1201. $prop_table = $bundle_data['data_table'] . 'prop';
  1202. if (chado_table_exists($prop_table)) {
  1203. tripal_chado_add_bundle_kvproperty_adder_field($entity_type, $bundle_name, $prop_table, $bundle_data['data_table']);
  1204. }
  1205. ////
  1206. //
  1207. // Dbxref table fields.
  1208. //
  1209. // Check to see if there are any dbxref tables with FKs to this
  1210. // base table. If so, add the fields for that type of table.
  1211. $dbxref_table = $bundle_data['data_table'] . '_dbxref';
  1212. if (chado_table_exists($dbxref_table)) {
  1213. tripal_chado_add_bundle_dbxref_field($entity_type, $bundle_name, $dbxref_table, $bundle_data['data_table']);
  1214. }
  1215. ////
  1216. //
  1217. // Cvterm table fields.
  1218. //
  1219. // Check to see if there are any cvterm tables with FKs to this
  1220. // base table. If so, add the fields for that type of table.
  1221. $cvterm_table = $bundle_data['data_table'] . '_cvterm';
  1222. if (chado_table_exists($cvterm_table)) {
  1223. tripal_chado_add_bundle_cvterm_class_adder_field($entity_type, $bundle_name, $cvterm_table, $bundle_data['data_table']);
  1224. }
  1225. ////
  1226. //
  1227. // Synonym table fields.
  1228. //
  1229. // Check to see if there are any synonym tables with FKs to this
  1230. // base table. If so, add the fields for that type of table.
  1231. $syn_table = $bundle_data['data_table'] . '_synonym';
  1232. if (chado_table_exists($syn_table)) {
  1233. tripal_chado_add_bundle_synonym_field($entity_type, $bundle_name, $syn_table, $bundle_data['data_table']);
  1234. }
  1235. ////
  1236. //
  1237. // Pub table fields.
  1238. //
  1239. // Check to see if there are any pub tables with FKs to this
  1240. // base table. If so, add the fields for that type of table.
  1241. $pub_table = $bundle_data['data_table'] . '_pub';
  1242. if (chado_table_exists($pub_table)) {
  1243. tripal_chado_add_bundle_pub_field($entity_type, $bundle_name, $pub_table, $bundle_data['data_table']);
  1244. }
  1245. }
  1246. /**
  1247. * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
  1248. *
  1249. * @param $entity_type
  1250. * @param $bundle_name
  1251. * @param $base_table
  1252. * @param $dbxref_table
  1253. */
  1254. function tripal_chado_add_bundle_dbxref_field($entity_type_name, $bundle_name, $dbxref_table, $base_table) {
  1255. // We already have a dbxref_id field.
  1256. $field_name = $dbxref_table;
  1257. $schema = chado_get_schema($dbxref_table);
  1258. $pkey = $schema['primary key'][0];
  1259. // Initialize the field array.
  1260. $field_info = array(
  1261. 'field_type' => 'dbxref',
  1262. 'widget_type' => 'tripal_fields_dbxfref_widget',
  1263. 'widget_settings' => array('display_label' => 1),
  1264. 'description' => '',
  1265. 'label' => 'Cross References',
  1266. 'is_required' => 0,
  1267. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  1268. 'storage' => 'field_chado_storage',
  1269. 'field_settings' => array(
  1270. // The Chado table that this field maps to.
  1271. 'chado_table' => $dbxref_table,
  1272. // The column in the chado table that this field maps to.
  1273. 'chado_column' => $pkey,
  1274. // The base table that this field is connected to.
  1275. 'base_table' => $base_table,
  1276. 'semantic_web' => array(
  1277. // The type is the term from a vocabulary that desribes this field..
  1278. 'type' => '',
  1279. // The namepsace for the vocabulary (e.g. 'foaf').
  1280. 'ns' => '',
  1281. // The URL for the namespace. It must be that the type can be
  1282. // appended to the URL.
  1283. 'nsurl' => '',
  1284. ),
  1285. ),
  1286. );
  1287. // If the base table has a 'dbxref_id' then change the label to
  1288. // indicate these are secondary cross references.
  1289. $schema = chado_get_schema($base_table);
  1290. if (array_key_exists('dbxref_id', $schema['fields'])) {
  1291. $field_info['label'] = 'Secondary Cross References';
  1292. }
  1293. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1294. }
  1295. /**
  1296. * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
  1297. *
  1298. * @param $entity_type
  1299. * @param $bundle_name
  1300. * @param $base_table
  1301. * @param $dbxref_table
  1302. */
  1303. function tripal_chado_add_bundle_synonym_field($entity_type_name, $bundle_name, $syn_table, $base_table) {
  1304. // We already have a dbxref_id field.
  1305. $field_name = $syn_table;
  1306. $schema = chado_get_schema($syn_table);
  1307. $pkey = $schema['primary key'][0];
  1308. // Initialize the field array.
  1309. $field_info = array(
  1310. 'field_type' => 'synonym',
  1311. 'widget_type' => 'tripal_fields_synonym_widget',
  1312. 'widget_settings' => array('display_label' => 1),
  1313. 'description' => '',
  1314. 'label' => 'Synonyms',
  1315. 'is_required' => 0,
  1316. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  1317. 'storage' => 'field_chado_storage',
  1318. 'field_settings' => array(
  1319. // The Chado table that this field maps to.
  1320. 'chado_table' => $syn_table,
  1321. // The column in the chado table that this field maps to.
  1322. 'chado_column' => $pkey,
  1323. // The base table that this field is connected to.
  1324. 'base_table' => $base_table,
  1325. 'semantic_web' => array(
  1326. // The type is the term from a vocabulary that desribes this field..
  1327. 'type' => '',
  1328. // The namepsace for the vocabulary (e.g. 'foaf').
  1329. 'ns' => '',
  1330. // The URL for the namespace. It must be that the type can be
  1331. // appended to the URL.
  1332. 'nsurl' => '',
  1333. ),
  1334. ),
  1335. );
  1336. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1337. }
  1338. /**
  1339. * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
  1340. *
  1341. * @param $entity_type
  1342. * @param $bundle_name
  1343. * @param $base_table
  1344. * @param $dbxref_table
  1345. */
  1346. function tripal_chado_add_bundle_pub_field($entity_type_name, $bundle_name, $pub_table, $base_table) {
  1347. // We already have a dbxref_id field.
  1348. $field_name = $pub_table;
  1349. $schema = chado_get_schema($pub_table);
  1350. $pkey = $schema['primary key'][0];
  1351. // Initialize the field array.
  1352. $field_info = array(
  1353. 'field_type' => 'pub',
  1354. 'widget_type' => 'tripal_fields_pub_widget',
  1355. 'widget_settings' => array('display_label' => 1),
  1356. 'description' => '',
  1357. 'label' => 'Publications',
  1358. 'is_required' => 0,
  1359. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  1360. 'storage' => 'field_chado_storage',
  1361. 'field_settings' => array(
  1362. // The Chado table that this field maps to.
  1363. 'chado_table' => $pub_table,
  1364. // The column in the chado table that this field maps to.
  1365. 'chado_column' => $pkey,
  1366. // The base table that this field is connected to.
  1367. 'base_table' => $base_table,
  1368. 'semantic_web' => array(
  1369. // The type is the term from a vocabulary that desribes this field..
  1370. 'type' => '',
  1371. // The namepsace for the vocabulary (e.g. 'foaf').
  1372. 'ns' => '',
  1373. // The URL for the namespace. It must be that the type can be
  1374. // appended to the URL.
  1375. 'nsurl' => '',
  1376. ),
  1377. ),
  1378. );
  1379. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1380. }
  1381. /**
  1382. * Adds the fields for managing properties that are stored in a prop table.
  1383. *
  1384. * @param $entity_type_name
  1385. * @param $bundle_name
  1386. * @param $kv_table
  1387. */
  1388. function tripal_chado_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, $kv_table, $base_table) {
  1389. $field_name = $kv_table;
  1390. // Initialize the field array.
  1391. $field_info = array(
  1392. 'field_type' => 'kvproperty_adder',
  1393. 'widget_type' => 'tripal_fields_kvproperty_adder_widget',
  1394. 'field_settings' => array(
  1395. 'base_table' => $base_table,
  1396. ),
  1397. 'storage' => 'field_chado_storage',
  1398. 'widget_settings' => array('display_label' => 1),
  1399. 'description' => '',
  1400. 'label' => 'Additional Properties',
  1401. 'is_required' => 0,
  1402. );
  1403. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1404. }
  1405. /**
  1406. * Adds the fields for managing properties that are stored in a prop table.
  1407. *
  1408. * @param $entity_type_name
  1409. * @param $bundle_name
  1410. * @param $kv_table
  1411. */
  1412. function tripal_chado_add_bundle_cvterm_class_adder_field($entity_type_name, $bundle_name, $cvterm_table, $base_table) {
  1413. // First add a generic property field so that users can add new property types.
  1414. $field_name = $cvterm_table;
  1415. // Initialize the field array.
  1416. $field_info = array(
  1417. 'field_type' => 'cvterm_class_adder',
  1418. 'widget_type' => 'tripal_fields_cvterm_class_adder_widget',
  1419. 'field_settings' => array(
  1420. 'base_table' => $base_table,
  1421. ),
  1422. 'storage' => 'field_chado_storage',
  1423. 'widget_settings' => array('display_label' => 1),
  1424. 'description' => '',
  1425. 'label' => 'Additional Annotation Types',
  1426. 'is_required' => 0,
  1427. );
  1428. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1429. }
  1430. /**
  1431. * Adds the fields for the base table to the entity.
  1432. */
  1433. function tripal_chado_add_bundle_base_fields($entity_type_name, $bundle_name, $bundle_data) {
  1434. $table_name = $bundle_data['data_table'];
  1435. $type_table = $bundle_data['type_table'];
  1436. $type_field = $bundle_data['field'];
  1437. // Iterate through the columns of the table and see if fields have been
  1438. // created for each one. If not, then create them.
  1439. $schema = chado_get_schema($table_name);
  1440. $columns = $schema['fields'];
  1441. foreach ($columns as $column_name => $details) {
  1442. $field_name = $table_name . '__' . $column_name;
  1443. // Skip the primary key field.
  1444. if ($column_name == $schema['primary key'][0]) {
  1445. continue;
  1446. }
  1447. // Skip the type field.
  1448. if ($table_name == $type_table and $column_name == $type_field) {
  1449. continue;
  1450. }
  1451. // Get the field defaults for this column.
  1452. $field_info = tripal_chado_get_table_column_field_default($table_name, $schema, $column_name);
  1453. // TODO: add in a call to drupal_alter to allow other modules to change
  1454. // the field settings.
  1455. // Determine if the field is required.
  1456. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  1457. $field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
  1458. }
  1459. // If we don't have a field type then we don't need to create a field.
  1460. if (!$field_info['field_type']) {
  1461. // If we don't have a field type but it is required and doesn't have
  1462. // a default value then we are in trouble.
  1463. if ($field_info['is_required'] and !array_key_exists('default', $details)) {
  1464. throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
  1465. array('%table' => $table_name, '%field' => $column_name, '%type' => $details['type'])));
  1466. }
  1467. continue;
  1468. }
  1469. // If this field is a foreign key field then we will have a custom field.
  1470. $is_fk = FALSE;
  1471. if (array_key_exists('foreign keys', $schema)) {
  1472. foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
  1473. if (array_key_exists($column_name, $fk_details['columns'])) {
  1474. $is_fk = TRUE;
  1475. }
  1476. }
  1477. }
  1478. // Add the field to the bundle.
  1479. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1480. }
  1481. }
  1482. /**
  1483. * Returns a $field_info array for a field based on a database column.
  1484. *
  1485. */
  1486. function tripal_chado_get_table_column_field_default($table_name, $schema, $column_name) {
  1487. $details = $schema['fields'][$column_name];
  1488. // Create an array with information about this field.
  1489. $field = array(
  1490. 'field_type' => '',
  1491. 'widget_type' => '',
  1492. 'description' => '',
  1493. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  1494. 'is_required' => 0,
  1495. 'storage' => 'field_chado_storage',
  1496. 'widget_settings' => array(
  1497. 'display_label' => 1
  1498. ),
  1499. 'field_settings' => array(
  1500. // The table in Chado where this field maps to.
  1501. 'chado_table' => $table_name,
  1502. // The column in the Chado table that this field maps to.
  1503. 'chado_column' => $column_name,
  1504. 'semantic_web' => array(
  1505. // The type is the term from a vocabulary that desribes this field..
  1506. 'type' => '',
  1507. // The namepsace for the vocabulary (e.g. 'foaf').
  1508. 'ns' => '',
  1509. // The URL for the namespace. It must be that the type can be
  1510. // appended to the URL.
  1511. 'nsurl' => '',
  1512. ),
  1513. ),
  1514. );
  1515. // Alter the field info array depending on the column details.
  1516. switch($details['type']) {
  1517. case 'char':
  1518. $field['field_type'] = 'text';
  1519. $field['widget_type'] = 'text_textfield';
  1520. $field['field_settings']['max_length'] = $details['length'];
  1521. break;
  1522. case 'varchar':
  1523. $field['field_type'] = 'text';
  1524. $field['widget_type'] = 'text_textfield';
  1525. $field['field_settings']['max_length'] = $details['length'];
  1526. break;
  1527. case 'text':
  1528. $field['field_type'] = 'text';
  1529. $field['widget_type'] = 'text_textarea';
  1530. $field['field_settings']['max_length'] = 17179869184;
  1531. $field['field_settings']['text_processing'] = 1;
  1532. $field['format'] = filter_default_format();
  1533. break;
  1534. case 'blob':
  1535. // not sure how to support a blob field.
  1536. continue;
  1537. break;
  1538. case 'int':
  1539. $field['field_type'] = 'number_integer';
  1540. $field['widget_type'] = 'number';
  1541. break;
  1542. case 'float':
  1543. $field['field_type'] = 'number_float';
  1544. $field['widget_type'] = 'number';
  1545. $field['field_settings']['precision'] = 10;
  1546. $field['field_settings']['scale'] = 2;
  1547. $field['field_settings']['decimal_separator'] = '.';
  1548. break;
  1549. case 'numeric':
  1550. $field['field_type'] = 'number_decimal';
  1551. $field['widget_type'] = 'number';
  1552. break;
  1553. case 'serial':
  1554. // Serial fields are most likely not needed as a field.
  1555. break;
  1556. case 'boolean':
  1557. $field['field_type'] = 'list_boolean';
  1558. $field['widget_type'] = 'options_onoff';
  1559. $field['field_settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  1560. break;
  1561. case 'datetime':
  1562. // Use the Drupal Date and Date API to create the field/widget
  1563. $field['field_type'] = 'datetime';
  1564. $field['widget_type'] = 'date_select';
  1565. $field['widget_settings']['increment'] = 1;
  1566. $field['widget_settings']['tz_handling'] = 'none';
  1567. $field['widget_settings']['collapsible'] = TRUE;
  1568. // TODO: Add settings so that the minutes increment by 1.
  1569. // And turn off the timezone, as the Chado field doesn't support it.
  1570. break;
  1571. }
  1572. // Set some default semantic web information
  1573. if ($column_name == 'name') {
  1574. $field['field_settings']['semantic_web']['type'] = 'name';
  1575. $field['field_settings']['semantic_web']['ns'] = 'foaf';
  1576. $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
  1577. }
  1578. if ($column_name == 'description' or $column_name == 'definition' or
  1579. $column_name == 'comment') {
  1580. $field['field_settings']['semantic_web']['type'] = 'description';
  1581. $field['field_settings']['semantic_web']['ns'] = 'hydra';
  1582. $field['field_settings']['semantic_web']['nsurl'] = 'http://www.w3.org/ns/hydra/core#';
  1583. }
  1584. //
  1585. // GENERIC COLUMNS
  1586. //
  1587. if ($field['field_settings']['chado_column'] =='organism_id') {
  1588. $field['field_type'] = 'organism_id';
  1589. $field['widget_type'] = 'tripal_chado_organism_select_widget';
  1590. $field['label'] = 'Organism';
  1591. $field['description'] = 'Select an organism.';
  1592. }
  1593. elseif ($field['field_settings']['chado_column'] =='dbxref_id') {
  1594. $field['field_type'] = 'dbxref_id';
  1595. $field['widget_type'] = 'tripal_chado_primary_dbxref_widget';
  1596. $field['label'] = 'Cross Reference';
  1597. $field['description'] = 'This record can be cross referenced with a ' .
  1598. 'record in another online database. The primary reference is for the ' .
  1599. 'most prominent reference. At a minimum, the database and accession ' .
  1600. 'must be provided. To remove a set reference, change the database ' .
  1601. 'field to "Select a Database".';
  1602. }
  1603. elseif ($field['label'] == 'Timeaccessioned') {
  1604. $field['label'] = 'Time Accessioned';
  1605. $field['description'] = 'Please enter the time that this record was first added to the database.';
  1606. }
  1607. elseif ($field['label'] == 'Timelastmodified') {
  1608. $field['label'] = 'Time Last Modified';
  1609. $field['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  1610. }
  1611. //
  1612. // ORGANISM TABLE
  1613. //
  1614. elseif ($field['field_settings']['chado_table'] == 'organism' and $field['field_settings']['chado_column'] == 'comment') {
  1615. $field['label'] = 'Description';
  1616. }
  1617. //
  1618. // FEATURE TABLE
  1619. //
  1620. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'uniquename') {
  1621. $field['field_type'] = 'text';
  1622. $field['widget_type'] = 'text_textfield';
  1623. $field['field_settings']['text_processing'] = 0;
  1624. $field['field_settings']['semantic_web']['type'] = 'name';
  1625. $field['field_settings']['semantic_web']['ns'] = 'foaf';
  1626. $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
  1627. }
  1628. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'md5checksum') {
  1629. $field['field_type'] = 'md5checksum';
  1630. $field['widget_type'] = 'tripal_chado_md5checksum_checkbox_widget';
  1631. $field['label'] = 'MD5 Checksum';
  1632. $field['description'] = 'Generate an MD5 checksum for the sequence.';
  1633. }
  1634. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'seqlen') {
  1635. $field['field_type'] = 'seqlen';
  1636. $field['widget_type'] = 'tripal_chado_seqlen_hidden_widget';
  1637. $field['label'] = 'Seqlen';
  1638. $field['description'] = 'The length of the residues.';
  1639. }
  1640. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'residues') {
  1641. $field['field_type'] = 'residues';
  1642. $field['widget_type'] = 'tripal_chado_residues_textarea_widget';
  1643. $field['label'] = 'Residues';
  1644. $field['description'] = 'Please provide an IUPAC compatible residues for this feature. Spaces and new lines are allowed.';
  1645. }
  1646. //
  1647. // ANALYSIS TABLE
  1648. //
  1649. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'program') {
  1650. $field['field_settings']['semantic_web']['type'] = 'SoftwareApplication';
  1651. $field['field_settings']['semantic_web']['ns'] = 'schema';
  1652. $field['field_settings']['semantic_web']['nsurl'] = 'https://schema.org/';
  1653. $field['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
  1654. $field['label'] = 'Program, Pipeline, Workflow or Method Name.';
  1655. }
  1656. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourceuri') {
  1657. $field['field_type'] = 'text';
  1658. $field['widget_type'] = 'text_textfield';
  1659. $field['field_settings']['text_processing'] = 0;
  1660. $field['label'] = 'Source URL';
  1661. $field['description'] = 'The URL where the original source data was derived. Ideally, this should link to the page where more information about the source data can be found.';
  1662. }
  1663. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourcename') {
  1664. $field['label'] = 'Source Name';
  1665. $field['description'] = 'The name of the source data. This could be a file name, data set or a small description for how the data was collected. For long descriptions use the larger description field.';
  1666. }
  1667. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourceversion') {
  1668. $field['label'] = 'Source Version';
  1669. $field['description'] = 'If hte source data set has a version include it here.';
  1670. }
  1671. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'algorithm') {
  1672. $field['label'] = 'Source Version';
  1673. $field['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  1674. }
  1675. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'programversion') {
  1676. $field['label'] = 'Program Version';
  1677. $field['description'] = 'The version of the program used to perform this analysis. (e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter "n/a" if no version is available or applicable.';
  1678. }
  1679. //
  1680. // PROJECT TABLE
  1681. //
  1682. elseif ($field['field_settings']['chado_table'] == 'project' and $field['field_settings']['chado_column'] == 'description') {
  1683. $field['label'] = 'Short Description';
  1684. }
  1685. return $field;
  1686. }
  1687. /**
  1688. * Implements hook_exclude_type_by_default()
  1689. *
  1690. * This hooks allows fields of a specified type that match a specified criteria
  1691. * to be excluded by default from any table when chado_generate_var() is called.
  1692. * Keep in mind that if fields are excluded by default they can always be
  1693. * expanded at a later date using chado_expand_var().
  1694. *
  1695. * Criteria are php strings that evaluate to either TRUE or FALSE. These
  1696. * strings are evaluated using drupal_eval() which suppresses syntax errors and
  1697. * throws watchdog entries of type php. There are also watchdog entries of type
  1698. * tripal stating the exact criteria evaluated. Criteria can
  1699. * contain the following tokens:
  1700. * - <field_name>
  1701. * Replaced by the name of the field to be excluded
  1702. * - <field_value>
  1703. * Replaced by the value of the field in the current record
  1704. * Also keep in mind that if your criteria doesn't contain the
  1705. * &gt;field_value&lt; token then it will be evaluated before the query is
  1706. * executed and if the field is excluded it won't be included in the
  1707. * query.
  1708. *
  1709. * @return
  1710. * An array of type => criteria where the type is excluded if the criteria
  1711. * evaluates to TRUE
  1712. *
  1713. * @ingroup tripal
  1714. */
  1715. function tripal_chado_exclude_type_by_default() {
  1716. return array('text' => 'strlen("<field_value> ") > 250');
  1717. }
  1718. /**
  1719. * Implements hook_job_describe_args().
  1720. *
  1721. * Describes the arguements for the tripal_populate_mview job to allow for
  1722. * greater readability in the jobs details pages.
  1723. *
  1724. * @param $callback
  1725. * The callback of the current tripal job (this is the function that will be
  1726. * executed when tripal_launch_jobs.php is run.
  1727. * @param $args
  1728. * An array of arguments passed in when the job was registered.
  1729. *
  1730. * @return
  1731. * A more readable $args array
  1732. *
  1733. * @ingroup tripal
  1734. */
  1735. function tripal_chado_job_describe_args($callback, $args) {
  1736. $new_args = array();
  1737. if ($callback == 'tripal_populate_mview') {
  1738. // get this mview details
  1739. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  1740. $results = db_query($sql, array(':mview_id' => $args[0]));
  1741. $mview = $results->fetchObject();
  1742. $new_args['View Name'] = $mview->name;
  1743. }
  1744. elseif ($callback == 'tripal_install_chado') {
  1745. $new_args['Action'] = $args[0];
  1746. }
  1747. return $new_args;
  1748. }
  1749. /**
  1750. * Implements hook_entity_property_info_alter().
  1751. *
  1752. * This is being implemented to ensure chado fields are exposed for search api indexing.
  1753. * All fields are available for index by default but the getter function set by default
  1754. * is not actually capable of getting the value from chado. Thus we change the getter
  1755. * function to one that can :-).
  1756. */
  1757. function tripal_chado_entity_property_info_alter(&$info) {
  1758. // Get a list of fields with the chado storage backend.
  1759. // Loop through all of the bundles.
  1760. if (isset($info['TripalEntity']['bundles'])) {
  1761. foreach ($info['TripalEntity']['bundles'] as $bundle_id => $bundle) {
  1762. // Loop through each of the fields for a given bundle.
  1763. foreach ($bundle['properties'] as $field_name => $field_info) {
  1764. // If the field is a chado field, then change the callback.
  1765. // @todo check this properly.
  1766. if (preg_match('/(\w+)__(\w+)/', $field_name, $matches)) {
  1767. $info['TripalEntity']['bundles'][$bundle_id]['properties'][$field_name]['getter callback'] =
  1768. 'tripal_chado_entity_property_get_value';
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. /**
  1775. * Provides a way for the search api to grab the value of a chado field.
  1776. *
  1777. * @param $entity
  1778. * The fully-loaded entity object to be indexed.
  1779. * @param $options
  1780. * Options that can be ued when retrieving the value.
  1781. * @param $field_name
  1782. * The machine name of the field we want to retrieve.
  1783. * @param $entity_type
  1784. * The type of entity (ie: TripalEntity).
  1785. *
  1786. * @return
  1787. * The rendered value of the field specified by $field_name.
  1788. */
  1789. function tripal_chado_entity_property_get_value($entity, $options, $field_name, $entity_type) {
  1790. $display = array(
  1791. 'type' => '',
  1792. 'label' => 'hidden',
  1793. );
  1794. $langcode = LANGUAGE_NONE;
  1795. $items = field_get_items($entity_type, $entity, $field_name);
  1796. if (count($items) == 1) {
  1797. $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
  1798. }
  1799. // @todo: handle fields with multiple values.
  1800. else {
  1801. $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
  1802. drupal_set_message('Tripal Chado currently only supports views integration for single value fields. The first value has been shown.', 'warning');
  1803. }
  1804. return drupal_render($render_array);
  1805. }
  1806. /**
  1807. * Remove the nid from chado_entity if it exists when the node is deleted
  1808. */
  1809. function tripal_chado_node_delete($node) {
  1810. dpm($node);
  1811. $nid = $node->nid;
  1812. $sql = "UPDATE chado_entity SET nid = NULL WHERE nid = :nid";
  1813. db_query($sql, array('nid' => $nid));
  1814. }