tripal_chado.fields.inc 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614
  1. <?php
  2. /**
  3. * Implements hook_bundle_fields_info().
  4. *
  5. * This is a Tripal defined hook that supports integration with the
  6. * TripalEntity field.
  7. */
  8. function tripal_chado_bundle_fields_info($entity_type, $bundle) {
  9. $chado_bundle = db_select('chado_bundle', 'cb')
  10. ->fields('cb')
  11. ->condition('bundle_id', $bundle->id)
  12. ->execute()
  13. ->fetchObject();
  14. // Get the details about the mapping of this bundle to the Chado table:
  15. $details = array(
  16. 'chado_cvterm_id' => $chado_bundle->type_id,
  17. 'chado_table' => $chado_bundle->data_table,
  18. 'chado_type_table' => $chado_bundle->type_linker_table,
  19. 'chado_type_column' => $chado_bundle->type_column,
  20. 'chado_type_value' => $chado_bundle->type_value,
  21. );
  22. $info = array();
  23. // Create the fields for each column in the table.
  24. tripal_chado_bundle_fields_info_base($info, $details, $entity_type, $bundle);
  25. // Create custom fields.
  26. tripal_chado_bundle_fields_info_custom($info, $details, $entity_type, $bundle);
  27. // Create fields for linking tables.
  28. tripal_chado_bundle_fields_info_linker($info, $details, $entity_type, $bundle);
  29. return $info;
  30. }
  31. /**
  32. *
  33. * @param unknown $details
  34. */
  35. function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $bundle) {
  36. $table_name = $details['chado_table'];
  37. $type_table = $details['chado_type_table'];
  38. $type_column = $details['chado_type_column'];
  39. $cvterm_id = $details['chado_cvterm_id'];
  40. $type_value = $details['chado_type_value'];
  41. // Iterate through the columns of the table and see if fields have been
  42. // created for each one. If not, then create them.
  43. $schema = chado_get_schema($table_name);
  44. if (!$schema) {
  45. return;
  46. }
  47. $pkey = $schema['primary key'][0];
  48. // Get the list of columns for this table and create a new field for each one.
  49. $columns = $schema['fields'];
  50. foreach ($columns as $column_name => $details) {
  51. // Skip the source columns in the analysis table. We have a custom
  52. // field for those columns
  53. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  54. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  55. continue;
  56. }
  57. // Skip the infraspecific type_id and name from the organism table as we
  58. // have a special field for those.
  59. if ($table_name == 'organism' and ($column_name == 'type_id' or
  60. $column_name == 'infraspecific_name')) {
  61. continue;
  62. }
  63. // Skip the cvterm.is_relationshptype.
  64. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  65. continue;
  66. }
  67. // The biosourceprovider_id and taxon_id are handled by custom fields.
  68. if ($table_name == 'biomaterial' and (
  69. $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
  70. continue;
  71. }
  72. // Don't create base fields for the primary key and the type_id field.
  73. if ($column_name == $pkey or $column_name == $type_column) {
  74. continue;
  75. }
  76. $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  77. if (!$cvterm) {
  78. tripal_report_error('tripal', TRIPAL_ERROR,
  79. 'Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  80. array('%table_name' => $table_name, '%column_name' => $column_name));
  81. drupal_set_message(t('Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  82. array('%table_name' => $table_name, '%column_name' => $column_name)), 'error');
  83. continue;
  84. }
  85. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  86. $field_name = substr($field_name, 0, 32);
  87. // Skip the primary key field.
  88. if ($column_name == $schema['primary key'][0]) {
  89. continue;
  90. }
  91. // If the type_id defines the content type and it's part of the
  92. // base table and this column is the type_id then skip it.
  93. if (!$type_table and $type_column and $column_name == $type_column) {
  94. continue;
  95. }
  96. // Skip the type ID as it will be handled by a custom field.
  97. if ($column_name == 'type_id') {
  98. continue;
  99. }
  100. // Set some defaults for the field.
  101. $base_info = array(
  102. 'field_name' => $field_name,
  103. 'type' => '',
  104. 'cardinality' => 1,
  105. 'locked' => FALSE,
  106. 'storage' => array(
  107. 'type' => 'field_chado_storage',
  108. 'sql' => array(),
  109. ),
  110. );
  111. // Alter the field info array depending on the column details.
  112. switch($details['type']) {
  113. case 'char':
  114. $base_info['type'] = 'text';
  115. $base_info['settings']['max_length'] = $details['length'];
  116. break;
  117. case 'varchar':
  118. $base_info['type'] = 'text';
  119. $base_info['settings']['max_length'] = $details['length'];
  120. break;
  121. case 'text':
  122. $base_info['type'] = 'text';
  123. $base_info['settings']['max_length'] = 17179869184;
  124. $base_info['settings']['text_processing'] = 1;
  125. break;
  126. case 'blob':
  127. // not sure how to support a blob field.
  128. continue;
  129. break;
  130. case 'int':
  131. $base_info['type'] = 'number_integer';
  132. break;
  133. case 'float':
  134. $base_info['type'] = 'number_float';
  135. $base_info['settings']['precision'] = 10;
  136. $base_info['settings']['scale'] = 2;
  137. $base_info['settings']['decimal_separator'] = '.';
  138. break;
  139. case 'numeric':
  140. $base_info['type'] = 'number_decimal';
  141. break;
  142. case 'serial':
  143. // Serial fields are most likely not needed as a field.
  144. break;
  145. case 'boolean':
  146. $base_info['type'] = 'list_boolean';
  147. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  148. break;
  149. case 'datetime':
  150. // Use the Drupal Date and Date API to create the field/widget
  151. $base_info['type'] = 'datetime';
  152. break;
  153. }
  154. // Set some defaults for biomaterial table
  155. if ($table_name == 'biomaterial' and $column_name == 'name') {
  156. $base_info['type'] = 'text';
  157. $base_info['settings']['max_length'] = '2048';
  158. $base_info['settings']['text_processing'] = 0;
  159. }
  160. // Set some default semantic web information
  161. if ($column_name == 'uniquename') {
  162. $base_info['settings']['text_processing'] = 0;
  163. }
  164. // Sometimes the boolean fields are listed as integer. We need to
  165. // correct for that.
  166. if ($column_name == 'is_obsolete' or $column_name == 'is_analysis' or
  167. $column_name == 'is_relationshiptype' or $column_name == 'is_for_definition' or
  168. $column_name == 'is_view' or $column_name == 'is_updateable') {
  169. $base_info['type'] = 'list_boolean';
  170. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  171. }
  172. //
  173. // PUB TABLE
  174. //
  175. if ($table_name == 'pub' and (
  176. $column_name == 'uniquename' or $column_name == 'title' or
  177. $column_name == 'volumetitle')) {
  178. $base_info['type'] = 'text';
  179. $base_info['settings']['text_processing'] = 0;
  180. }
  181. $info[$field_name] = $base_info;
  182. }
  183. }
  184. /**
  185. *
  186. * @param unknown $details
  187. */
  188. function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type, $bundle) {
  189. $table_name = $details['chado_table'];
  190. $type_table = $details['chado_type_table'];
  191. $type_column = $details['chado_type_column'];
  192. $cvterm_id = $details['chado_cvterm_id'];
  193. $type_value = $details['chado_type_value'];
  194. $schema = chado_get_schema($table_name);
  195. // Handle type_id fields that are not the type_column.
  196. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column) {
  197. $field_name = 'schema__additional_type';
  198. $field_type = 'schema__additional_type';
  199. $info[$field_name] = array(
  200. 'field_name' => $field_name,
  201. 'type' => $field_type,
  202. 'cardinality' => 1,
  203. 'locked' => FALSE,
  204. 'storage' => array(
  205. 'type' => 'field_chado_storage',
  206. ),
  207. );
  208. }
  209. // BASE ORGANISM_ID
  210. if ($table_name != 'organism' and
  211. (array_key_exists('organism_id', $schema['fields']) or
  212. array_key_exists('taxon_id', $schema['fields']))) {
  213. $field_name = 'obi__organism';
  214. $field_type = 'obi__organism';
  215. $info[$field_name] = array(
  216. 'field_name' => $field_name,
  217. 'type' => $field_type,
  218. 'cardinality' => 1,
  219. 'locked' => FALSE,
  220. 'storage' => array(
  221. 'type' => 'field_chado_storage',
  222. ),
  223. );
  224. }
  225. if ($table_name == 'biomaterial') {
  226. $field_name = 'biomaterial__provider_id';
  227. $field_type = 'local__contact';
  228. $info[$field_name] = array(
  229. 'field_name' => $field_name,
  230. 'type' => $field_type,
  231. 'cardinality' => 1,
  232. 'locked' => FALSE,
  233. 'storage' => array(
  234. 'type' => 'field_chado_storage',
  235. ),
  236. );
  237. }
  238. // BASE ORGANISM_ID
  239. if ($table_name == 'cvterm') {
  240. $field_name = 'sio__vocabulary';
  241. $field_type = 'sio__vocabulary';
  242. $info[$field_name] = array(
  243. 'field_name' => $field_name,
  244. 'type' => $field_type,
  245. 'cardinality' => 1,
  246. 'locked' => FALSE,
  247. 'storage' => array(
  248. 'type' => 'field_chado_storage',
  249. ),
  250. );
  251. }
  252. // BASE DBXREF
  253. if (array_key_exists('dbxref_id', $schema['fields'])) {
  254. $field_name = 'data__accession';
  255. $field_type = 'data__accession';
  256. $info[$field_name] = array(
  257. 'field_name' => $field_name,
  258. 'type' => $field_type,
  259. 'cardinality' => 1,
  260. 'locked' => FALSE,
  261. 'storage' => array(
  262. 'type' => 'field_chado_storage',
  263. ),
  264. );
  265. }
  266. // FEATURE MD5CHECKSUM
  267. if ($table_name == 'feature') {
  268. $field_name = 'data__sequence_checksum';
  269. $field_type = 'data__sequence_checksum';
  270. $info[$field_name] = array(
  271. 'field_name' => $field_name,
  272. 'type' => $field_type,
  273. 'cardinality' => 1,
  274. 'locked' => FALSE,
  275. 'storage' => array(
  276. 'type' => 'field_chado_storage',
  277. ),
  278. );
  279. }
  280. // FEATURE RESIDUES
  281. if ($table_name == 'feature') {
  282. $field_name = 'data__sequence';
  283. $field_type = 'data__sequence';
  284. $info[$field_name] = array(
  285. 'field_name' => $field_name,
  286. 'type' => $field_type,
  287. 'cardinality' => 1,
  288. 'locked' => FALSE,
  289. 'storage' => array(
  290. 'type' => 'field_chado_storage',
  291. ),
  292. );
  293. }
  294. // FEATURE SEQLEN
  295. if ($table_name == 'feature') {
  296. $field_name = 'data__sequence_length';
  297. $field_type = 'data__sequence_length';
  298. $info[$field_name] = array(
  299. 'field_name' => $field_name,
  300. 'type' => $field_type,
  301. 'cardinality' => 1,
  302. 'locked' => FALSE,
  303. 'storage' => array(
  304. 'type' => 'field_chado_storage',
  305. ),
  306. );
  307. }
  308. // PROTEIN & CDS
  309. if ($table_name == 'feature' and
  310. ($bundle->label == 'mRNA' or $bundle->label == 'transcript')) {
  311. $field_name = 'data__protein_sequence';
  312. $field_type = 'data__protein_sequence';
  313. $info[$field_name] = array(
  314. 'field_name' => $field_name,
  315. 'type' => $field_type,
  316. 'cardinality' => 1,
  317. 'locked' => FALSE,
  318. 'storage' => array(
  319. 'type' => 'field_chado_storage',
  320. ),
  321. );
  322. // $field_name = 'so__cds';
  323. // $field_type = 'so__cds';
  324. // $info[$field_name] = array(
  325. // 'field_name' => $field_name,
  326. // 'type' => $field_type,
  327. // 'cardinality' => 1,
  328. // 'locked' => FALSE,
  329. // 'storage' => array(
  330. // 'type' => 'field_chado_storage',
  331. // ),
  332. // );
  333. }
  334. // // GENE TRANSCRIPTS
  335. // $rel_table = $table_name . '_relationship';
  336. // if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  337. // $field_name = 'so__transcript';
  338. // $field_type = 'so__transcript';
  339. // $info[$field_name] = array(
  340. // 'field_name' => $field_name,
  341. // 'type' => $field_type,
  342. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  343. // 'locked' => FALSE,
  344. // 'storage' => array(
  345. // 'type' => 'field_chado_storage',
  346. // ),
  347. // );
  348. // }
  349. // ORGANISM TYPE_ID
  350. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  351. $field_name = 'taxrank__infraspecific_taxon';
  352. $field_type = 'taxrank__infraspecific_taxon';
  353. $info[$field_name] = array(
  354. 'field_name' => $field_name,
  355. 'type' => $field_type,
  356. 'cardinality' => 1,
  357. 'locked' => FALSE,
  358. 'storage' => array(
  359. 'type' => 'field_chado_storage',
  360. ),
  361. );
  362. }
  363. // FEATUREMAP UNITTYPE_ID
  364. if ($table_name == 'featuremap') {
  365. $field_name = 'uo__unit';
  366. $field_type = 'uo__unit';
  367. $info[$field_name] = array(
  368. 'field_name' => $field_name,
  369. 'type' => $field_type,
  370. 'cardinality' => 1,
  371. 'locked' => FALSE,
  372. 'storage' => array(
  373. 'type' => 'field_chado_storage',
  374. ),
  375. );
  376. }
  377. // Analysis source
  378. if ($table_name == 'analysis') {
  379. $field_name = 'local__source_data';
  380. $field_type = 'local__source_data';
  381. $info[$field_name] = array(
  382. 'field_name' => $field_name,
  383. 'type' => $field_type,
  384. 'cardinality' => 1,
  385. 'locked' => FALSE,
  386. 'storage' => array(
  387. 'type' => 'field_chado_storage',
  388. ),
  389. );
  390. }
  391. // Add an image field to the Organism type. This is a Drupal field and
  392. // not stored in Chado, but is used for backwards compatibility.
  393. if ($table_name == 'organism') {
  394. $field_name = 'data__image';
  395. $info[$field_name] = array(
  396. 'field_name' => $field_name,
  397. 'type' => 'image',
  398. 'cardinality' => 1,
  399. 'locked' => FALSE,
  400. 'storage' => array(
  401. 'type' => 'field_sql_storage',
  402. ),
  403. );
  404. }
  405. // Add field for viewing the phylogenetic tree.
  406. if ($table_name == 'phylotree') {
  407. $field_name = 'operation__phylotree_vis';
  408. $field_type = 'operation__phylotree_vis';
  409. $info[$field_name] = array(
  410. 'field_name' => $field_name,
  411. 'type' => $field_type,
  412. 'cardinality' => 1,
  413. 'locked' => FALSE,
  414. 'storage' => array(
  415. 'type' => 'field_chado_storage',
  416. ),
  417. );
  418. }
  419. //protocol
  420. if ($table_name == 'protocol' and array_key_exists('protocol_id', $schema['fields'])) {
  421. $field_name = 'sep__protocol';
  422. $field_type = 'sep__protocol';
  423. $info[$field_name] = array(
  424. 'field_name' => $field_name,
  425. 'type' => $field_type,
  426. 'cardinality' => 1,
  427. 'locked' => FALSE,
  428. 'storage' => array(
  429. 'type' => 'field_chado_storage',
  430. ),
  431. );
  432. }
  433. }
  434. /**
  435. *
  436. * @param $details
  437. */
  438. function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type, $bundle) {
  439. $table_name = $details['chado_table'];
  440. $type_table = $details['chado_type_table'];
  441. $type_column = $details['chado_type_column'];
  442. $cvterm_id = $details['chado_cvterm_id'];
  443. $type_value = $details['chado_type_value'];
  444. // CONTACTS
  445. $contact_table = $table_name . '_contact';
  446. if (chado_table_exists($contact_table)) {
  447. $schema = chado_get_schema($contact_table);
  448. $pkey = $schema['primary key'][0];
  449. $field_name = $table_name . '_contact';
  450. $field_type = 'chado_linker__contact';
  451. $info[$field_name] = array(
  452. 'field_name' => $field_name,
  453. 'type' => $field_type,
  454. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  455. 'locked' => FALSE,
  456. 'storage' => array(
  457. 'type' => 'field_chado_storage',
  458. ),
  459. );
  460. }
  461. // DBXREF
  462. $dbxref_table = $table_name . '_dbxref';
  463. if (chado_table_exists($dbxref_table)) {
  464. $field_name = 'sbo__database_cross_reference';
  465. $field_type = 'sbo__database_cross_reference';
  466. $info[$field_name] = array(
  467. 'field_name' => $field_name,
  468. 'type' => $field_type,
  469. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  470. 'locked' => FALSE,
  471. 'storage' => array(
  472. 'type' => 'field_chado_storage',
  473. ),
  474. );
  475. }
  476. // EXPRESSION
  477. // TODO: this should only show up on gene or mRNA bunldes, not every feature.
  478. // $expression_table = $table_name . '_expression';
  479. // if (chado_table_exists($expression_table)) {
  480. // $field_name = 'go__gene_expression';
  481. // $field_type = 'go__gene_expression';
  482. // $info[$field_name] = array(
  483. // 'field_name' => $field_name,
  484. // 'type' => $field_type,
  485. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  486. // 'locked' => FALSE,
  487. // 'storage' => array(
  488. // 'type' => 'field_chado_storage',
  489. // ),
  490. // );
  491. // }
  492. // FEATURELOC
  493. if ($table_name == 'feature') {
  494. $field_name = 'data__sequence_coordinates';
  495. $field_type = 'data__sequence_coordinates';
  496. $info[$field_name] = array(
  497. 'field_name' => $field_name,
  498. 'type' => $field_type,
  499. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  500. 'locked' => FALSE,
  501. 'storage' => array(
  502. 'type' => 'field_chado_storage',
  503. ),
  504. );
  505. }
  506. // FEATUREPOS
  507. if ($table_name == 'feature') {
  508. $field_name = 'ogi__location_on_map';
  509. $field_type = 'ogi__location_on_map';
  510. $info[$field_name] = array(
  511. 'field_name' => $field_name,
  512. 'type' => $field_type,
  513. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  514. 'locked' => FALSE,
  515. 'storage' => array(
  516. 'type' => 'field_chado_storage',
  517. ),
  518. );
  519. }
  520. // // GENOTYPE
  521. // $genotype_table = $table_name . '_genotype';
  522. // if (chado_table_exists($genotype_table)) {
  523. // $field_name = 'so__genotype';
  524. // $field_type = 'so__genotype';
  525. // $info[$field_name] = array(
  526. // 'field_name' => $field_name,
  527. // 'type' => $field_type,
  528. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  529. // 'locked' => FALSE,
  530. // 'storage' => array(
  531. // 'type' => 'field_chado_storage',
  532. // ),
  533. // );
  534. // }
  535. // // PHENOTYPE
  536. // $phenotype_table = $table_name . '_phenotype';
  537. // if (chado_table_exists($phenotype_table)) {
  538. // $field_name = 'sbo__phenotype';
  539. // $field_type = 'sbo__phenotype';
  540. // $info[$field_name] = array(
  541. // 'field_name' => $field_name,
  542. // 'type' => $field_type,
  543. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  544. // 'locked' => FALSE,
  545. // 'storage' => array(
  546. // 'type' => 'field_chado_storage',
  547. // ),
  548. // );
  549. // }
  550. // PROPERTIES
  551. $prop_table = $table_name . 'prop';
  552. if (chado_table_exists($prop_table)) {
  553. // Get the list of existing property types for this table.
  554. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  555. $props = chado_query($sql);
  556. while ($prop = $props->fetchObject()) {
  557. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  558. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  559. // tripal_analysis_interpro modules store results in the analysisprop
  560. // table which is probably not the best place, but we don't want to
  561. // create a ton of fields for this, so skip them.
  562. if ($prop_table == 'analysisprop' and
  563. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  564. $term->dbxref_id->db_id->name == 'tripal')) {
  565. continue;
  566. }
  567. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  568. $field_name = substr($field_name, 0, 32);
  569. $field_type = 'chado_linker__prop';
  570. $info[$field_name] = array(
  571. 'field_name' => $field_name,
  572. 'type' => $field_type,
  573. 'cardinality' => 1,
  574. 'locked' => FALSE,
  575. 'storage' => array(
  576. 'type' => 'field_chado_storage',
  577. ),
  578. );
  579. }
  580. }
  581. // CVTERMS
  582. $term_table = $table_name . '_cvterm';
  583. if (chado_table_exists($term_table)) {
  584. $schema = chado_get_schema($term_table);
  585. $pkey = $schema['primary key'][0];
  586. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  587. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  588. $field_name = 'sio__annotation';
  589. $field_type = 'sio__annotation';
  590. $info[$field_name] = array(
  591. 'field_name' => $field_name,
  592. 'type' => $field_type,
  593. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  594. 'locked' => FALSE,
  595. 'storage' => array(
  596. 'type' => 'field_chado_storage',
  597. ),
  598. );
  599. }
  600. // PUBLICATIONS
  601. $pub_table = $table_name . '_pub';
  602. if (chado_table_exists($pub_table)) {
  603. $field_name = 'schema__publication';
  604. $field_type = 'schema__publication';
  605. $info[$field_name] = array(
  606. 'field_name' => $field_name,
  607. 'type' => $field_type,
  608. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  609. 'locked' => FALSE,
  610. 'storage' => array(
  611. 'type' => 'field_chado_storage',
  612. ),
  613. );
  614. }
  615. // PUBLICATIONS (in reverse)
  616. // We want to be able to show all of the content that a publication links
  617. // to. The sio__references field does that.
  618. if ($table_name == 'pub') {
  619. $field_name = 'sio__references';
  620. $field_type = 'sio__references';
  621. $info[$field_name] = array(
  622. 'field_name' => $field_name,
  623. 'type' => $field_type,
  624. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  625. 'locked' => FALSE,
  626. 'storage' => array(
  627. 'type' => 'field_chado_storage',
  628. ),
  629. );
  630. }
  631. // RELATIONSHIPS
  632. // If the linker table does not exists then we don't want to add attach.
  633. $rel_table = $table_name . '_relationship';
  634. if (chado_table_exists($rel_table)) {
  635. $field_name = 'sbo__relationship';
  636. $field_type = 'sbo__relationship';
  637. $info[$field_name] = array(
  638. 'field_name' => $field_name,
  639. 'type' => $field_type,
  640. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  641. 'locked' => FALSE,
  642. 'storage' => array(
  643. 'type' => 'field_chado_storage',
  644. ),
  645. );
  646. }
  647. // SYNONYMS
  648. $syn_table = $table_name . '_synonym';
  649. if (chado_table_exists($syn_table)) {
  650. $field_name = 'schema__alternate_name';
  651. $field_type = 'schema__alternate_name';
  652. $info[$field_name] = array(
  653. 'field_name' => $field_name,
  654. 'type' => $field_type,
  655. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  656. 'locked' => FALSE,
  657. 'storage' => array(
  658. 'type' => 'field_chado_storage',
  659. ),
  660. 'settings' => array(
  661. ),
  662. );
  663. }
  664. }
  665. /**
  666. * Impelments hook_create_tripalfield_instance().
  667. *
  668. * This is a Tripal defined hook that supports integration with the
  669. * TripalEntity field.
  670. */
  671. function tripal_chado_bundle_instances_info($entity_type, $bundle) {
  672. $chado_bundle = db_select('chado_bundle', 'cb')
  673. ->fields('cb')
  674. ->condition('bundle_id', $bundle->id)
  675. ->execute()
  676. ->fetchObject();
  677. $details = array(
  678. 'chado_cvterm_id' => $chado_bundle->type_id,
  679. 'chado_table' => $chado_bundle->data_table,
  680. 'chado_type_table' => $chado_bundle->type_linker_table,
  681. 'chado_type_column' => $chado_bundle->type_column,
  682. 'chado_type_value' => $chado_bundle->type_value,
  683. );
  684. $info = array();
  685. tripal_chado_bundle_instances_info_base($info, $entity_type, $bundle, $details);
  686. tripal_chado_bundle_instances_info_custom($info, $entity_type, $bundle, $details);
  687. tripal_chado_bundle_instances_info_linker($info, $entity_type, $bundle, $details);
  688. return $info;
  689. }
  690. /**
  691. * Helper function for the hook_create_tripalfield_instance().
  692. *
  693. * Add the field instances that corresond to the columns of the base table.
  694. *
  695. * @param $entity_type
  696. * @param $bundle
  697. * @param $details
  698. */
  699. function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle, $details) {
  700. $fields = array();
  701. // Get Chado information
  702. $table_name = $details['chado_table'];
  703. $type_table = $details['chado_type_table'];
  704. $type_column = $details['chado_type_column'];
  705. $cvterm_id = $details['chado_cvterm_id'];
  706. $type_value = $details['chado_type_value'];
  707. // Iterate through the columns of the table and see if fields have been
  708. // created for each one. If not, then create them.
  709. $schema = chado_get_schema($table_name);
  710. if (!$schema) {
  711. return;
  712. }
  713. $pkey = $schema['primary key'][0];
  714. $columns = $schema['fields'];
  715. foreach ($columns as $column_name => $details) {
  716. // Skip the source columns in the analysis table. We have a custom
  717. // field for those columns
  718. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  719. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  720. continue;
  721. }
  722. // Skip the infraspecific type_id and name from the organism table as we
  723. // have a special field for those.
  724. if ($table_name == 'organism' and ($column_name == 'type_id' or
  725. $column_name == 'infraspecific_name')) {
  726. continue;
  727. }
  728. // Skip the cvterm.is_relationshptype.
  729. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  730. continue;
  731. }
  732. // The biosourceprovider_id and taxon_id are handled by custom fields.
  733. if ($table_name == 'biomaterial' and (
  734. $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
  735. continue;
  736. }
  737. // Don't create base fields for the primary key and the type_id field.
  738. if ($column_name == $pkey or $column_name == $type_column) {
  739. continue;
  740. }
  741. $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  742. if (!$cvterm) {
  743. // We already provided an error when creating the base field. So
  744. // don't create another one here.
  745. continue;
  746. }
  747. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  748. $field_name = substr($field_name, 0, 32);
  749. // Skip the primary key field.
  750. if ($column_name == $schema['primary key'][0]) {
  751. continue;
  752. }
  753. // If the type_id defines the content type and it's part of the
  754. // base table and this column is the type_id then skip it.
  755. if (!$type_table and $type_column and $column_name == $type_column) {
  756. continue;
  757. }
  758. // Skip the type ID as it will be handled by a custom field.
  759. if ($column_name == 'type_id') {
  760. continue;
  761. }
  762. $base_info = array(
  763. 'field_name' => $field_name,
  764. 'entity_type' => 'TripalEntity',
  765. 'bundle' => $bundle->name,
  766. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  767. 'description' => '',
  768. 'required' => FALSE,
  769. 'settings' => array(
  770. 'auto_attach' => TRUE,
  771. 'term_vocabulary' => $cvterm->dbxref_id->db_id->name,
  772. 'term_name' => $cvterm->name,
  773. 'term_accession' => $cvterm->dbxref_id->accession,
  774. 'chado_table' => $table_name,
  775. 'chado_column' => $column_name,
  776. 'base_table' => $table_name,
  777. ),
  778. 'widget' => array(
  779. 'settings' => array(
  780. 'display_label' => 1,
  781. ),
  782. ),
  783. 'display' => array(
  784. 'default' => array(
  785. 'label' => 'inline',
  786. 'region' =>'Left',
  787. 'settings' => array(),
  788. ),
  789. ),
  790. );
  791. // Determine if the field is required.
  792. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  793. $base_info['required'] = TRUE;
  794. }
  795. // Alter the field info array depending on the column details.
  796. switch($details['type']) {
  797. case 'char':
  798. $base_info['widget']['type'] = 'text_textfield';
  799. break;
  800. case 'varchar':
  801. $base_info['widget']['type'] = 'text_textfield';
  802. break;
  803. case 'text':
  804. $base_info['display']['default']['label'] = 'above';
  805. $base_info['widget']['type'] = 'text_textarea';
  806. $base_info['settings']['text_processing'] = '1';
  807. $base_info['settings']['format'] = 'full_html';
  808. break;
  809. case 'blob':
  810. // not sure how to support a blob field.
  811. continue;
  812. break;
  813. case 'int':
  814. $base_info['widget']['type'] = 'number';
  815. break;
  816. case 'float':
  817. $base_info['widget']['type'] = 'number';
  818. break;
  819. case 'numeric':
  820. $base_info['widget']['type'] = 'number';
  821. break;
  822. case 'serial':
  823. // Serial fields are most likely not needed as a field.
  824. break;
  825. case 'boolean':
  826. $base_info['widget']['type'] = 'options_onoff';
  827. $base_info['required'] = FALSE;
  828. break;
  829. case 'datetime':
  830. $base_info['widget']['type'] = 'date_select';
  831. $base_info['widget']['settings']['increment'] = 1;
  832. $base_info['widget']['settings']['tz_handling'] = 'none';
  833. $base_info['widget']['settings']['collapsible'] = TRUE;
  834. // TODO: Add settings so that the minutes increment by 1.
  835. // And turn off the timezone, as the Chado field doesn't support it.
  836. break;
  837. }
  838. // Set some default semantic web information
  839. if ($column_name == 'uniquename') {
  840. $base_info['label'] = 'Identifier';
  841. $base_info['widget']['type'] = 'text_textfield';
  842. if ($details['type'] == 'text') {
  843. unset($base_info['display']['default']['label']);
  844. unset($base_info['settings']['text_processing']);
  845. unset($base_info['settings']['format']);
  846. }
  847. }
  848. if ($base_info['label'] == 'Timeaccessioned') {
  849. $base_info['label'] = 'Time Accessioned';
  850. $base_info['description'] = 'Please enter the time that this record was first added to the database.';
  851. }
  852. if ($base_info['label'] == 'Timelastmodified') {
  853. $base_info['label'] = 'Time Last Modified';
  854. $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  855. }
  856. // Sometimes the boolean fields are listed as integer. We need to
  857. // correct for that.
  858. if ($column_name == 'is_obsolete' or $column_name == 'is_analysis' or
  859. $column_name == 'is_relationshiptype' or $column_name == 'is_for_definition' or
  860. $column_name == 'is_view' or $column_name == 'is_updateable') {
  861. $base_info['widget']['type'] = 'options_onoff';
  862. $base_info['required'] = FALSE;
  863. }
  864. //
  865. // ORGANISM TABLE
  866. //
  867. if ($table_name == 'organism' and $column_name == 'comment') {
  868. $base_info['label'] = 'Description';
  869. }
  870. //
  871. // BIOMATERIAL TABLE
  872. //
  873. if ($table_name == 'biomaterial' and $column_name == 'name') {
  874. $base_info['widget'] = array();
  875. $base_info['widget']['type'] = 'text_textfield';
  876. unset($base_info['display']['default']['label']);
  877. unset($base_info['settings']['text_processing']);
  878. unset($base_info['settings']['format']);
  879. }
  880. //
  881. // FEATUREMAP TABLE
  882. //
  883. if ($table_name == 'featuremap' and $column_name == 'name') {
  884. $base_info['required'] = TRUE;
  885. }
  886. //
  887. // PUB TABLE
  888. //
  889. if ($table_name == 'pub') {
  890. if ($column_name == 'title' or $column_name == 'type_id') {
  891. $base_info['required'] = TRUE;
  892. }
  893. if($column_name == 'uniquename' or $column_name == 'title' or $column_name == 'volumetitle') {
  894. $base_info['widget']['type'] = 'text_textfield';
  895. $base_info['settings']['text_processing'] = '0';
  896. }
  897. if($column_name == 'uniquename') {
  898. $base_info['label'] = 'Unique Local Identifier';
  899. $base_info['required'] = TRUE;
  900. $base_info['description'] = 'This publication is housed in Chado whic requires a unique identifer (or name) be provided for every publication. This identifier need not be shown to end-users but it is required. Each site must decide on a format for this unique name.';
  901. }
  902. if($column_name == 'title') {
  903. $base_info['description'] = 'The title of the published work.';
  904. }
  905. if($column_name == 'series_name') {
  906. $base_info['description'] = 'The name media that produces a series of publications (e.g. journal, conference proceedings, etc.).';
  907. }
  908. if($column_name == 'issue') {
  909. $base_info['description'] = 'The issue of the series (e.g. journal) where the publication was printed.';
  910. }
  911. if($column_name == 'volume') {
  912. $base_info['description'] = 'The volume of the series (e.g. journal) where the publication was printed.';
  913. }
  914. if($column_name == 'pyear') {
  915. $base_info['label'] = 'Publication Year';
  916. $base_info['required'] = TRUE;
  917. }
  918. if($column_name == 'pages') {
  919. $base_info['label'] = 'Page Numbers';
  920. }
  921. if($column_name == 'pubplace') {
  922. $base_info['label'] = 'Publication Location';
  923. }
  924. if($column_name == 'volumetitle') {
  925. $base_info['label'] = 'Volumn Title';
  926. $base_info['label'] = 'The title of the volume (if applicable).';
  927. }
  928. if($column_name == 'miniref') {
  929. $base_info['label'] = 'Mini Local identifier';
  930. $base_info['description'] = 'Some sites use small identifiers for each publication. if your site uses this please provide the proper miniref for this publication.';
  931. }
  932. }
  933. //
  934. // ANALYSIS TABLE
  935. //
  936. if ($table_name == 'analysis' and $column_name == 'name') {
  937. $base_info['required'] = TRUE;
  938. }
  939. if ($table_name == 'analysis' and $column_name == 'program') {
  940. $base_info['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.';
  941. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
  942. }
  943. if ($table_name == 'analysis' and $column_name == 'algorithm') {
  944. $base_info['label'] = 'Algorithm';
  945. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  946. }
  947. if ($table_name == 'analysis' and $column_name == 'programversion') {
  948. $base_info['label'] = 'Program Version';
  949. $base_info['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.';
  950. }
  951. if ($table_name == 'analysis' and $column_name == 'timeexecuted') {
  952. $base_info['label'] = 'Date Performed';
  953. $base_info['description'] = 'The date and time when the analysis was performed.';
  954. }
  955. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  956. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  957. // Skip the source columns in the analysis table. We have a custom
  958. // field for those columns
  959. continue;
  960. }
  961. //
  962. // PROJECT TABLE
  963. //
  964. if ($table_name == 'project' and $column_name == 'description') {
  965. $base_info['label'] = 'Short Description';
  966. }
  967. //
  968. // CONTACT TABLE
  969. //
  970. if ($table_name == 'contact' and $column_name == 'description') {
  971. $base_info['label'] = 'Short Description';
  972. }
  973. $info[$field_name] = $base_info;
  974. }
  975. }
  976. /**
  977. * Helper function for the hook_create_tripalfield_instance().
  978. *
  979. * Adds custom fields for base fields. These override the settings provided
  980. * in the tripal_chado_create_tripalfield_instance_base() function.
  981. *
  982. * @param $entity_type
  983. * @param $bundle
  984. * @param $details
  985. */
  986. function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle, $details) {
  987. $table_name = $details['chado_table'];
  988. $type_table = $details['chado_type_table'];
  989. $type_column = $details['chado_type_column'];
  990. $cvterm_id = $details['chado_cvterm_id'];
  991. $type_value = $details['chado_type_value'];
  992. $schema = chado_get_schema($table_name);
  993. // An additional type for publications
  994. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column) {
  995. $field_name = 'schema__additional_type';
  996. $is_required = FALSE;
  997. if (array_key_exists('not null', $schema['fields']['type_id']) and
  998. $schema['fields']['type_id']['not null']) {
  999. $is_required = TRUE;
  1000. }
  1001. $label = ucwords(preg_replace('/_/', ' ', $table_name)) . ' Type';
  1002. $default_vocab = '';
  1003. $parent_term = '';
  1004. switch($table_name) {
  1005. case 'pub':
  1006. $default_vocab = 'tripal_pub';
  1007. $label = 'Publication Type';
  1008. $parent_term = 'TPUB:0000015';
  1009. $description = 'Select the type.';
  1010. break;
  1011. case 'contact':
  1012. $default_vocab = 'tripal_contact';
  1013. $parent_term = 'TContact:0000001';
  1014. $description = 'Select the type.';
  1015. break;
  1016. default:
  1017. $description = t('Enter the name of the term that specifies the type. ' .
  1018. 'The type must be the name of a term in a controlled vocabulary and ' .
  1019. 'the controlled vocabulary should already be loaded into this site.');
  1020. }
  1021. $info[$field_name] = array(
  1022. 'field_name' => $field_name,
  1023. 'entity_type' => $entity_type,
  1024. 'bundle' => $bundle->name,
  1025. 'label' => $label,
  1026. 'description' => $description,
  1027. 'required' => $is_required,
  1028. 'settings' => array(
  1029. 'auto_attach' => TRUE,
  1030. 'chado_table' => $table_name,
  1031. 'chado_column' => 'type_id',
  1032. 'base_table' => $table_name,
  1033. 'vocabulary' => $default_vocab,
  1034. 'parent_term' => $parent_term,
  1035. ),
  1036. 'widget' => array(
  1037. 'type' => 'schema__additional_type_widget',
  1038. 'settings' => array(
  1039. 'display_label' => 1,
  1040. ),
  1041. ),
  1042. 'display' => array(
  1043. 'default' => array(
  1044. 'label' => 'inline',
  1045. 'type' => 'schema__additional_type_formatter',
  1046. 'settings' => array(),
  1047. ),
  1048. ),
  1049. );
  1050. }
  1051. // BASE ORGANISM_ID
  1052. if ($table_name != 'organism' and
  1053. (array_key_exists('organism_id', $schema['fields']) or
  1054. array_key_exists('taxon_id', $schema['fields']))) {
  1055. $field_name = 'obi__organism';
  1056. $is_required = FALSE;
  1057. $table_column = 'organism_id';
  1058. if ($table_name == 'biomaterial') {
  1059. $is_required = FALSE;
  1060. $table_column = 'taxon_id';
  1061. }
  1062. elseif (array_key_exists('not null', $schema['fields']['organism_id']) and
  1063. $schema['fields']['organism_id']['not null']) {
  1064. $is_required = TRUE;
  1065. }
  1066. $info[$field_name] = array(
  1067. 'field_name' => $field_name,
  1068. 'entity_type' => $entity_type,
  1069. 'bundle' => $bundle->name,
  1070. 'label' => 'Organism',
  1071. 'description' => 'The full scientific name for a species..',
  1072. 'required' => $is_required,
  1073. 'settings' => array(
  1074. 'auto_attach' => TRUE,
  1075. 'chado_table' => $table_name,
  1076. 'chado_column' => $table_column,
  1077. 'base_table' => $table_name,
  1078. ),
  1079. 'widget' => array(
  1080. 'type' => 'obi__organism_widget',
  1081. 'settings' => array(
  1082. 'display_label' => 1,
  1083. ),
  1084. ),
  1085. 'display' => array(
  1086. 'default' => array(
  1087. 'label' => 'inline',
  1088. 'type' => 'obi__organism_formatter',
  1089. 'settings' => array(),
  1090. ),
  1091. ),
  1092. );
  1093. }
  1094. if ($table_name == 'biomaterial') {
  1095. $field_name = 'biomaterial__provider_id';
  1096. $field_type = 'local__contact';
  1097. $info[$field_name] = array(
  1098. 'field_name' => $field_name,
  1099. 'entity_type' => $entity_type,
  1100. 'bundle' => $bundle->name,
  1101. 'label' => 'Contact',
  1102. 'description' => 'An indviddual or organization that serves as a contact for this record.',
  1103. 'required' => FALSE,
  1104. 'settings' => array(
  1105. 'auto_attach' => FALSE,
  1106. 'chado_table' => 'biomaterial',
  1107. 'chado_column' => 'biosourceprovider_id',
  1108. 'base_table' => 'biomaterial',
  1109. ),
  1110. 'widget' => array(
  1111. 'type' => 'local__contact_widget',
  1112. 'settings' => array(
  1113. 'display_label' => 1,
  1114. ),
  1115. ),
  1116. 'display' => array(
  1117. 'default' => array(
  1118. 'label' => 'inline',
  1119. 'type' => 'local__contact_formatter',
  1120. 'settings' => array(),
  1121. ),
  1122. ),
  1123. );
  1124. }
  1125. // BASE CVTERM
  1126. if ($table_name == 'cvterm') {
  1127. $field_name = 'sio__vocabulary';
  1128. $is_required = TRUE;
  1129. $info[$field_name] = array(
  1130. 'field_name' => $field_name,
  1131. 'entity_type' => $entity_type,
  1132. 'bundle' => $bundle->name,
  1133. 'label' => 'Vocabulary',
  1134. 'description' => 'A controlled vocabulary.',
  1135. 'required' => $is_required,
  1136. 'settings' => array(
  1137. 'auto_attach' => TRUE,
  1138. 'chado_table' => $table_name,
  1139. 'chado_column' => 'cv_id',
  1140. 'base_table' => $table_name,
  1141. ),
  1142. 'widget' => array(
  1143. 'type' => 'sio__vocabulary_widget',
  1144. 'settings' => array(
  1145. 'display_label' => 1,
  1146. ),
  1147. ),
  1148. 'display' => array(
  1149. 'default' => array(
  1150. 'label' => 'inline',
  1151. 'type' => 'sio__vocabulary_formatter',
  1152. 'settings' => array(),
  1153. ),
  1154. ),
  1155. );
  1156. }
  1157. // BASE DBXREF
  1158. if (array_key_exists('dbxref_id', $schema['fields'])) {
  1159. $field_name = 'data__accession';
  1160. $info[$field_name] = array(
  1161. 'field_name' => $field_name,
  1162. 'entity_type' => $entity_type,
  1163. 'bundle' => $bundle->name,
  1164. 'label' => 'Accession',
  1165. 'description' => 'This field specifies the unique stable accession (ID) for
  1166. this record. It requires that this site have a database entry.',
  1167. 'required' => FALSE,
  1168. 'settings' => array(
  1169. 'auto_attach' => TRUE,
  1170. 'chado_table' => $table_name,
  1171. 'chado_column' => 'dbxref_id',
  1172. 'base_table' => $table_name,
  1173. ),
  1174. 'widget' => array(
  1175. 'type' => 'data__accession_widget',
  1176. 'settings' => array(
  1177. 'display_label' => 1,
  1178. ),
  1179. ),
  1180. 'display' => array(
  1181. 'default' => array(
  1182. 'label' => 'inline',
  1183. 'type' => 'data__accession_formatter',
  1184. 'settings' => array(),
  1185. ),
  1186. ),
  1187. );
  1188. }
  1189. // FEATURE MD5CHECKSUM
  1190. if ($table_name == 'feature') {
  1191. $field_name = 'data__sequence_checksum';
  1192. $info[$field_name] = array(
  1193. 'field_name' => $field_name,
  1194. 'entity_type' => $entity_type,
  1195. 'bundle' => $bundle->name,
  1196. 'label' => 'Sequence Checksum',
  1197. 'description' => 'The MD5 checksum for the sequence. The checksum here
  1198. will always be unique for the raw unformatted sequence. To verify that the
  1199. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  1200. to calculate the value. If the value calculated is identical the one shown
  1201. here, then the downloaded sequence is uncorrupted.',
  1202. 'required' => FALSE,
  1203. 'settings' => array(
  1204. 'auto_attach' => TRUE,
  1205. 'chado_table' => $table_name,
  1206. 'chado_column' => 'md5checksum',
  1207. 'base_table' => $table_name,
  1208. ),
  1209. 'widget' => array(
  1210. 'type' => 'data__sequence_checksum_widget',
  1211. 'settings' => array(
  1212. 'display_label' => 1,
  1213. 'md5_fieldname' => 'feature__md5checksum',
  1214. ),
  1215. ),
  1216. 'display' => array(
  1217. 'default' => array(
  1218. 'label' => 'inline',
  1219. 'type' => 'data__sequence_checksum_formatter',
  1220. 'settings' => array(),
  1221. ),
  1222. ),
  1223. );
  1224. }
  1225. // FEATURE RESIDUES
  1226. if ($table_name == 'feature') {
  1227. $field_name = 'data__sequence';
  1228. $info[$field_name] = array(
  1229. 'field_name' => $field_name,
  1230. 'entity_type' => $entity_type,
  1231. 'bundle' => $bundle->name,
  1232. 'label' => 'Sequence',
  1233. 'description' => 'One or more molecular sequences, possibly with associated annotation.',
  1234. 'required' => FALSE,
  1235. 'settings' => array(
  1236. 'auto_attach' => FALSE,
  1237. 'chado_table' => $table_name,
  1238. 'chado_column' => 'residues',
  1239. 'base_table' => $table_name,
  1240. ),
  1241. 'widget' => array(
  1242. 'type' => 'data__sequence_widget',
  1243. 'settings' => array(
  1244. 'display_label' => 1,
  1245. ),
  1246. ),
  1247. 'display' => array(
  1248. 'default' => array(
  1249. 'label' => 'above',
  1250. 'type' => 'data__sequence_formatter',
  1251. 'settings' => array(),
  1252. ),
  1253. ),
  1254. );
  1255. }
  1256. // FEATURE SEQLEN
  1257. if ($table_name == 'feature') {
  1258. $field_name = 'data__sequence_length';
  1259. $info[$field_name] = array(
  1260. 'field_name' => $field_name,
  1261. 'entity_type' => $entity_type,
  1262. 'bundle' => $bundle->name,
  1263. 'label' => 'Sequence Length',
  1264. 'description' => 'The number of residues in the raw sequence. This length
  1265. is only for the assigned raw sequence and does not represent the length of any
  1266. sequences derived from alignments. If this value is zero but aligned sequences
  1267. are present then this record has no official assigned sequence.',
  1268. 'required' => FALSE,
  1269. 'settings' => array(
  1270. 'auto_attach' => TRUE,
  1271. 'chado_table' => $table_name,
  1272. 'chado_column' => 'seqlen',
  1273. 'base_table' => $table_name,
  1274. ),
  1275. 'widget' => array(
  1276. 'type' => 'data__sequence_length_widget',
  1277. 'settings' => array(
  1278. 'display_label' => 1,
  1279. ),
  1280. ),
  1281. 'display' => array(
  1282. 'default' => array(
  1283. 'label' => 'inline',
  1284. 'type' => 'data__sequence_length_formatter',
  1285. 'settings' => array(),
  1286. ),
  1287. ),
  1288. );
  1289. }
  1290. // PROTEIN & CDS SEQUENCES.
  1291. if ($table_name == 'feature' and
  1292. ($bundle->label == 'mRNA' or $bundle->label == 'transcript')) {
  1293. $field_name = 'data__protein_sequence';
  1294. $info[$field_name] = array(
  1295. 'field_name' => $field_name,
  1296. 'entity_type' => $entity_type,
  1297. 'bundle' => $bundle->name,
  1298. 'label' => 'Protein Sequence',
  1299. 'description' => 'Protein sequences.',
  1300. 'required' => FALSE,
  1301. 'settings' => array(
  1302. 'auto_attach' => FALSE,
  1303. 'chado_table' => 'feature',
  1304. 'chado_column' => 'residues',
  1305. 'base_table' => 'feature',
  1306. ),
  1307. 'widget' => array(
  1308. 'type' => 'data__protein_sequence_widget',
  1309. 'settings' => array(
  1310. 'display_label' => 1,
  1311. ),
  1312. ),
  1313. 'display' => array(
  1314. 'default' => array(
  1315. 'label' => 'above',
  1316. 'type' => 'data__protein_sequence_formatter',
  1317. 'settings' => array(),
  1318. ),
  1319. ),
  1320. );
  1321. // $field_name = 'so__cds';
  1322. // $info[$field_name] = array(
  1323. // 'field_name' => $field_name,
  1324. // 'entity_type' => $entity_type,
  1325. // 'bundle' => $bundle->name,
  1326. // 'label' => 'Coding Sequence',
  1327. // 'description' => 'Coding sequences.',
  1328. // 'required' => FALSE,
  1329. // 'settings' => array(
  1330. // 'auto_attach' => FALSE,
  1331. // 'chado_table' => 'featureloc',
  1332. // 'chado_column' => '',
  1333. // 'base_table' => 'featureloc',
  1334. // ),
  1335. // 'widget' => array(
  1336. // 'type' => 'so__cds_widget',
  1337. // 'settings' => array(
  1338. // 'display_label' => 1,
  1339. // ),
  1340. // ),
  1341. // 'display' => array(
  1342. // 'default' => array(
  1343. // 'label' => 'above',
  1344. // 'type' => 'so__cds_formatter',
  1345. // 'settings' => array(),
  1346. // ),
  1347. // ),
  1348. // );
  1349. }
  1350. // // GENE TRANSCRIPTS
  1351. // $rel_table = $table_name . '_relationship';
  1352. // if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  1353. // $field_name = 'so__transcript';
  1354. // $info[$field_name] = array(
  1355. // 'field_name' => $field_name,
  1356. // 'entity_type' => $entity_type,
  1357. // 'bundle' => $bundle->name,
  1358. // 'label' => 'Transcripts',
  1359. // 'description' => 'Transcripts that are part of this gene.',
  1360. // 'required' => FALSE,
  1361. // 'settings' => array(
  1362. // 'auto_attach' => FALSE,
  1363. // 'chado_table' => $rel_table,
  1364. // 'chado_column' => '',
  1365. // 'base_table' => $table_name,
  1366. // ),
  1367. // 'widget' => array(
  1368. // 'type' => 'so__transcript_widget',
  1369. // 'settings' => array(
  1370. // 'display_label' => 1,
  1371. // ),
  1372. // ),
  1373. // 'display' => array(
  1374. // 'default' => array(
  1375. // 'label' => 'above',
  1376. // 'type' => 'so__transcript_formatter',
  1377. // 'settings' => array(),
  1378. // ),
  1379. // ),
  1380. // );
  1381. // }
  1382. // ORGANISM TYPE_ID
  1383. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  1384. $field_name = 'taxrank__infraspecific_taxon';
  1385. $info[$field_name] = array(
  1386. 'field_name' => $field_name,
  1387. 'entity_type' => $entity_type,
  1388. 'bundle' => $bundle->name,
  1389. 'label' => 'Infraspecific Taxon',
  1390. 'description' => 'The Infraspecific Taxon.',
  1391. 'required' => FALSE,
  1392. 'settings' => array(
  1393. 'auto_attach' => TRUE,
  1394. 'chado_table' => 'organism',
  1395. 'chado_column' => 'type_id',
  1396. 'base_table' => 'organism',
  1397. ),
  1398. 'widget' => array(
  1399. 'type' => 'taxrank__infraspecific_taxon_widget',
  1400. 'settings' => array(
  1401. 'display_label' => 1,
  1402. ),
  1403. ),
  1404. 'display' => array(
  1405. 'default' => array(
  1406. 'label' => 'inline',
  1407. 'type' => 'taxrank__infraspecific_taxon_formatter',
  1408. 'settings' => array(),
  1409. ),
  1410. ),
  1411. );
  1412. }
  1413. // FEATURE MAP UNITS
  1414. if ($table_name == 'featuremap') {
  1415. $field_name = 'uo__unit';
  1416. $info[$field_name] = array(
  1417. 'field_name' => $field_name,
  1418. 'entity_type' => $entity_type,
  1419. 'bundle' => $bundle->name,
  1420. 'label' => 'Units',
  1421. 'description' => 'The map\'s unit type.',
  1422. 'required' => TRUE,
  1423. 'settings' => array(
  1424. 'auto_attach' => TRUE,
  1425. 'chado_table' => $table_name,
  1426. 'chado_column' => 'unittype_id',
  1427. 'base_table' => $table_name,
  1428. ),
  1429. 'widget' => array(
  1430. 'type' => 'uo__unit_widget',
  1431. 'settings' => array(
  1432. 'display_label' => 1,
  1433. ),
  1434. ),
  1435. 'display' => array(
  1436. 'default' => array(
  1437. 'label' => 'inline',
  1438. 'type' => 'uo__unit_formatter',
  1439. 'settings' => array(),
  1440. ),
  1441. ),
  1442. );
  1443. }
  1444. // the analysis source.
  1445. if ($table_name == 'analysis') {
  1446. $field_name = 'local__source_data';
  1447. $info[$field_name] = array(
  1448. 'field_name' => $field_name,
  1449. 'entity_type' => $entity_type,
  1450. 'bundle' => $bundle->name,
  1451. 'label' => 'Data Source',
  1452. 'description' => 'The source where data was obtained for this analysis.',
  1453. 'required' => FALSE,
  1454. 'settings' => array(
  1455. 'auto_attach' => TRUE,
  1456. 'chado_table' => $table_name,
  1457. 'chado_column' => 'analysis_id',
  1458. 'base_table' => $table_name,
  1459. ),
  1460. 'widget' => array(
  1461. 'type' => 'local__source_data_widget',
  1462. 'settings' => array(
  1463. 'display_label' => 1,
  1464. ),
  1465. ),
  1466. 'display' => array(
  1467. 'default' => array(
  1468. 'label' => 'inline',
  1469. 'type' => 'local__source_data_formatter',
  1470. 'settings' => array(),
  1471. ),
  1472. ),
  1473. );
  1474. }
  1475. // Add an image field to the Organism type. This is a Drupal field and
  1476. // not stored in Chado, but is used for backwards compatibility.
  1477. if ($table_name == 'organism') {
  1478. $field_name = 'data__image';
  1479. $info[$field_name] = array(
  1480. 'field_name' => $field_name,
  1481. 'entity_type' => $entity_type,
  1482. 'bundle' => $bundle->name,
  1483. 'label' => 'Organism Image',
  1484. 'description' => 'An image for the organism',
  1485. 'required' => FALSE,
  1486. 'settings' => array(
  1487. 'term_vocabulary' => 'data',
  1488. 'term_name' => 'Image',
  1489. 'term_accession' => '2968',
  1490. ),
  1491. 'display' => array(
  1492. 'default' => array(
  1493. 'label' => 'hidden',
  1494. ),
  1495. ),
  1496. );
  1497. }
  1498. // Phylotree Viewer
  1499. if ($table_name == 'phylotree') {
  1500. $field_name = 'operation__phylotree_vis';
  1501. $schema = chado_get_schema('phylotree');
  1502. $pkey = $schema['primary key'][0];
  1503. $info[$field_name] = array(
  1504. 'field_name' => $field_name,
  1505. 'entity_type' => $entity_type,
  1506. 'bundle' => $bundle->name,
  1507. 'label' => 'Tree View',
  1508. 'description' => 'Rendering of a phylogenetic tree.',
  1509. 'required' => FALSE,
  1510. 'settings' => array(
  1511. 'auto_attach' => FALSE,
  1512. 'chado_table' => 'phylotree',
  1513. 'chado_column' => 'type_id',
  1514. 'base_table' => 'phylotree',
  1515. ),
  1516. 'widget' => array(
  1517. 'type' => 'operation__phylotree_vis_widget',
  1518. 'settings' => array(
  1519. 'display_label' => 0,
  1520. ),
  1521. ),
  1522. 'display' => array(
  1523. 'default' => array(
  1524. 'label' => 'hidden',
  1525. 'type' => 'operation__phylotree_vis_formatter',
  1526. 'settings' => array(),
  1527. ),
  1528. ),
  1529. );
  1530. }
  1531. // PROTOCOL FIELD
  1532. if ($table_name != 'protocol' and
  1533. (array_key_exists('protocol_id', $schema['fields']))) {
  1534. $field_name = 'sep__protocol';
  1535. $is_required = FALSE;
  1536. $table_column = 'protocol_id';
  1537. if (array_key_exists('not null', $schema['fields']['protocol_id']) and
  1538. $schema['fields']['protocol_id']['not null']) {
  1539. $is_required = TRUE;
  1540. }
  1541. $info[$field_name] = array(
  1542. 'field_name' => $field_name,
  1543. 'entity_type' => $entity_type,
  1544. 'bundle' => $bundle->name,
  1545. 'label' => 'Protocol',
  1546. 'description' => 'The parameterizable description of a process',
  1547. 'required' => $is_required,
  1548. 'settings' => array(
  1549. 'auto_attach' => TRUE,
  1550. 'chado_table' => $table_name,
  1551. 'chado_column' => $table_column,
  1552. 'base_table' => $table_name,
  1553. ),
  1554. 'widget' => array(
  1555. 'type' => 'sep__protocol_widget',
  1556. 'settings' => array(
  1557. 'display_label' => 1,
  1558. ),
  1559. ),
  1560. 'display' => array(
  1561. 'default' => array(
  1562. 'label' => 'inline',
  1563. 'type' => 'sep__protocol_formatter',
  1564. 'settings' => array(),
  1565. ),
  1566. ),
  1567. );
  1568. }
  1569. }
  1570. /**
  1571. *
  1572. * @param unknown $entity_type
  1573. * @param unknown $bundle
  1574. * @param unknown $details
  1575. */
  1576. function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle, $details) {
  1577. $table_name = $details['chado_table'];
  1578. $type_table = $details['chado_type_table'];
  1579. $type_column = $details['chado_type_column'];
  1580. $cvterm_id = $details['chado_cvterm_id'];
  1581. $type_value = $details['chado_type_value'];
  1582. // CONTACTS
  1583. $contact_table = $table_name . '_contact';
  1584. if (chado_table_exists($contact_table)) {
  1585. $field_name = $table_name . '_contact';
  1586. $info[$field_name] = $info[$field_name] = array(
  1587. 'field_name' => $field_name,
  1588. 'entity_type' => $entity_type,
  1589. 'bundle' => $bundle->name,
  1590. 'label' => 'Contact',
  1591. 'description' => 'Associates an indviddual or organization with this record',
  1592. 'required' => FALSE,
  1593. 'settings' => array(
  1594. 'auto_attach' => FALSE,
  1595. 'chado_table' => $contact_table,
  1596. 'base_table' => $table_name,
  1597. 'chado_column' => 'contact_id',
  1598. ),
  1599. 'widget' => array(
  1600. 'type' => 'local__contact_widget',
  1601. 'settings' => array(
  1602. 'display_label' => 1,
  1603. ),
  1604. ),
  1605. 'display' => array(
  1606. 'default' => array(
  1607. 'label' => 'hidden',
  1608. 'type' => 'local__contact_formatter',
  1609. 'settings' => array(),
  1610. ),
  1611. ),
  1612. );
  1613. }
  1614. // DBXREF
  1615. $dbxref_table = $table_name . '_dbxref';
  1616. if (chado_table_exists($dbxref_table)) {
  1617. $field_name = 'sbo__database_cross_reference';
  1618. $schema = chado_get_schema($dbxref_table);
  1619. $pkey = $schema['primary key'][0];
  1620. $info[$field_name] = array(
  1621. 'field_name' => $field_name,
  1622. 'entity_type' => $entity_type,
  1623. 'bundle' => $bundle->name,
  1624. 'label' => 'Cross Reference',
  1625. 'description' => 'The IDs where this record may be available in other external online databases.',
  1626. 'required' => FALSE,
  1627. 'settings' => array(
  1628. 'auto_attach' => FALSE,
  1629. 'chado_table' => $dbxref_table,
  1630. 'chado_column' => $pkey,
  1631. 'base_table' => $table_name,
  1632. ),
  1633. 'widget' => array(
  1634. 'type' => 'sbo__database_cross_reference_widget',
  1635. 'settings' => array(
  1636. 'display_label' => 1,
  1637. ),
  1638. ),
  1639. 'display' => array(
  1640. 'default' => array(
  1641. 'label' => 'hidden',
  1642. 'type' => 'sbo__database_cross_reference_formatter',
  1643. 'settings' => array(),
  1644. ),
  1645. ),
  1646. );
  1647. }
  1648. // EXPRESSION
  1649. // TODO: this should only show up on gene or mRNA and the GO must be
  1650. // laoded or this field will crash things.
  1651. // $expression_table = $table_name . '_expression';
  1652. // if (chado_table_exists($expression_table)) {
  1653. // $field_name = 'go__gene_expression';
  1654. // $schema = chado_get_schema($expression_table);
  1655. // $pkey = $schema['primary key'][0];
  1656. // $info[$field_name] = array(
  1657. // 'field_name' => $field_name,
  1658. // 'entity_type' => $entity_type,
  1659. // 'bundle' => $bundle->name,
  1660. // 'label' => 'Gene expression',
  1661. // 'description' => 'Information about the expression of this record.',
  1662. // 'required' => FALSE,
  1663. // 'settings' => array(
  1664. // 'auto_attach' => FALSE,
  1665. // 'chado_table' => $expression_table,
  1666. // 'chado_column' => $pkey,
  1667. // 'base_table' => $table_name,
  1668. // ),
  1669. // 'widget' => array(
  1670. // 'type' => 'go__gene_expression_widget',
  1671. // 'settings' => array(
  1672. // 'display_label' => 1,
  1673. // ),
  1674. // ),
  1675. // 'display' => array(
  1676. // 'default' => array(
  1677. // 'label' => 'above',
  1678. // 'type' => 'go__gene_expression_formatter',
  1679. // 'settings' => array(),
  1680. // ),
  1681. // ),
  1682. // );
  1683. // }
  1684. // FEATURELOC
  1685. if ($table_name == 'feature') {
  1686. $field_name = 'data__sequence_coordinates';
  1687. $schema = chado_get_schema('featureloc');
  1688. $pkey = $schema['primary key'][0];
  1689. $info[$field_name] = array(
  1690. 'field_name' => $field_name,
  1691. 'entity_type' => $entity_type,
  1692. 'bundle' => $bundle->name,
  1693. 'label' => 'Sequence Coordinates',
  1694. 'description' => 'The locations on other genomic sequences where this
  1695. record has been aligned.',
  1696. 'required' => FALSE,
  1697. 'settings' => array(
  1698. 'auto_attach' => FALSE,
  1699. 'chado_table' => 'featureloc',
  1700. 'chado_column' => $pkey,
  1701. 'base_table' => 'feature',
  1702. ),
  1703. 'widget' => array(
  1704. 'type' => 'data__sequence_coordinates_widget',
  1705. 'settings' => array(
  1706. 'display_label' => 1,
  1707. ),
  1708. ),
  1709. 'display' => array(
  1710. 'default' => array(
  1711. 'label' => 'hidden',
  1712. 'type' => 'data__sequence_coordinates_formatter',
  1713. 'settings' => array(),
  1714. ),
  1715. ),
  1716. );
  1717. }
  1718. // FEATUREPOS
  1719. if ($table_name == 'feature') {
  1720. $field_name = 'ogi__location_on_map';
  1721. $schema = chado_get_schema('featurepos');
  1722. $pkey = $schema['primary key'][0];
  1723. $info[$field_name] = array(
  1724. 'field_name' => $field_name,
  1725. 'entity_type' => $entity_type,
  1726. 'bundle' => $bundle->name,
  1727. 'label' => 'Location on Map',
  1728. 'description' => 'The positions on a genetic map.',
  1729. 'required' => FALSE,
  1730. 'settings' => array(
  1731. 'auto_attach' => FALSE,
  1732. 'chado_table' => 'featurepos',
  1733. 'chado_column' => $pkey,
  1734. 'base_table' => 'feature',
  1735. ),
  1736. 'widget' => array(
  1737. 'type' => 'ogi__location_on_map_widget',
  1738. 'settings' => array(
  1739. 'display_label' => 1,
  1740. ),
  1741. ),
  1742. 'display' => array(
  1743. 'default' => array(
  1744. 'label' => 'hidden',
  1745. 'type' => 'ogi__location_on_map_formatter',
  1746. 'settings' => array(),
  1747. ),
  1748. ),
  1749. );
  1750. }
  1751. // // GENOTYPE
  1752. // $genotype_table = $table_name . '_genotype';
  1753. // if (chado_table_exists($genotype_table)) {
  1754. // $field_name = 'so__genotype';
  1755. // $schema = chado_get_schema($genotype_table);
  1756. // $pkey = $schema['primary key'][0];
  1757. // $info[$field_name] = array(
  1758. // 'field_name' => $field_name,
  1759. // 'entity_type' => $entity_type,
  1760. // 'bundle' => $bundle->name,
  1761. // 'label' => 'Genotype',
  1762. // 'description' => 'The genotypes associated with this record.',
  1763. // 'required' => FALSE,
  1764. // 'settings' => array(
  1765. // 'auto_attach' => FALSE,
  1766. // 'chado_table' => $genotype_table,
  1767. // 'chado_column' => $pkey,
  1768. // 'base_table' => $table_name,
  1769. // ),
  1770. // 'widget' => array(
  1771. // 'type' => 'so__genotype_widget',
  1772. // 'settings' => array(
  1773. // 'display_label' => 1,
  1774. // ),
  1775. // ),
  1776. // 'display' => array(
  1777. // 'default' => array(
  1778. // 'label' => 'hidden',
  1779. // 'type' => 'so__genotype_formatter',
  1780. // 'settings' => array(),
  1781. // ),
  1782. // ),
  1783. // );
  1784. // }
  1785. // // PHENOTYPE
  1786. // $phenotype_table = $table_name . '_phenotype';
  1787. // if (chado_table_exists($phenotype_table)) {
  1788. // $field_name = 'sbo__phenotype';
  1789. // $schema = chado_get_schema($phenotype_table);
  1790. // $pkey = $schema['primary key'][0];
  1791. // $info[$field_name] = array(
  1792. // 'field_name' => $field_name,
  1793. // 'entity_type' => $entity_type,
  1794. // 'bundle' => $bundle->name,
  1795. // 'label' => 'Phenotype',
  1796. // 'description' => 'The phenotypes associated with this record.',
  1797. // 'required' => FALSE,
  1798. // 'settings' => array(
  1799. // 'auto_attach' => FALSE,
  1800. // 'chado_table' => $phenotype_table,
  1801. // 'chado_column' => $pkey,
  1802. // 'base_table' => $table_name,
  1803. // ),
  1804. // 'widget' => array(
  1805. // 'type' => 'sbo__phenotype_widget',
  1806. // 'settings' => array(
  1807. // 'display_label' => 1,
  1808. // ),
  1809. // ),
  1810. // 'display' => array(
  1811. // 'default' => array(
  1812. // 'label' => 'hidden',
  1813. // 'type' => 'sbo__phenotype_formatter',
  1814. // 'settings' => array(),
  1815. // ),
  1816. // ),
  1817. // );
  1818. // }
  1819. // PROPERTIES
  1820. $prop_table = $table_name . 'prop';
  1821. if (chado_table_exists($prop_table)) {
  1822. $tschema = chado_get_schema($table_name);
  1823. $schema = chado_get_schema($prop_table);
  1824. $tpkey = $tschema['primary key'][0];
  1825. $pkey = $schema['primary key'][0];
  1826. // Property tables can be a bit tricky because not all property types
  1827. // in the prop table are appropriate for each type of data. Also som
  1828. // bundle types are resolved via a property. So, we have to distinguish
  1829. // between these two cases.
  1830. $sql = '';
  1831. $args = array();
  1832. // First, is this the case where all of the records in the table are
  1833. // of this type? If so, then all properties apply
  1834. if (!$type_column) {
  1835. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  1836. $props = chado_query($sql, $args);
  1837. }
  1838. // Second, if this is the case where a content type is uniquely identified
  1839. // by a type_id value in the base table, then only properties associated
  1840. // with that type ID should be used.
  1841. else if ($type_column and !$type_table) {
  1842. $sql = "
  1843. SELECT DISTINCT P.type_id
  1844. FROM {" . $prop_table . "} P
  1845. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  1846. WHERE T.$type_column = :cvterm_id
  1847. ";
  1848. $args[':cvterm_id'] = $cvterm_id;
  1849. $props = chado_query($sql, $args);
  1850. }
  1851. // Third, if this is the case where a content type is uniquely identified
  1852. // via a term/value pair in the prop table.
  1853. else if ($type_column and $type_table == $prop_table and !empty($type_value)) {
  1854. $sql = "
  1855. SELECT DISTINCT P2.type_id
  1856. FROM {" . $prop_table . "} P1
  1857. INNER JOIN {" . $table_name . "} T on T.$tpkey = P1.$tpkey
  1858. INNER JOIN {" . $prop_table . "} P2 on T.$tpkey = P2.$tpkey
  1859. WHERE P1.$type_column = :cvterm_id AND P1.value = :prop_value AND
  1860. P2.type_id != P1.type_id
  1861. ";
  1862. $args[':cvterm_id'] = $cvterm_id;
  1863. $args[':prop_value'] = $type_value;
  1864. $props = chado_query($sql, $args);
  1865. }
  1866. // Fourth, if this is the case where the content type is uinquely identifed
  1867. // via another table (e.g. cvterm linking table) and not this prop table.
  1868. else if ($type_column and $type_table != $prop_table and empty($type_value)) {
  1869. $sql = "
  1870. SELECT DISTINCT P.type_id
  1871. FROM {" . $prop_table . "} P
  1872. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  1873. INNER JOIN {" . $type_table . "} TT on TT.$tpkey = T.$tpkey
  1874. WHERE TT.$type_column = :cvterm_id
  1875. ";
  1876. $args[':cvterm_id'] = $cvterm_id;
  1877. $props = chado_query($sql, $args);
  1878. }
  1879. else {
  1880. // Do nothing;
  1881. }
  1882. if ($props) {
  1883. while ($prop = $props->fetchObject()) {
  1884. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  1885. $term = chado_expand_var($term, 'field', 'cvterm.definition');
  1886. // Skip the Publiation Type property for pubs as this is
  1887. // already handled by the pub.type_id field.
  1888. if ($term->name == 'Publication Type' and $term->cv_id->name == 'tripal_pub') {
  1889. continue;
  1890. }
  1891. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  1892. // tripal_analysis_interpro modules store results in the analysisprop
  1893. // table which is probably not the best place, but we don't want to
  1894. // create a ton of fields for this.
  1895. if ($prop_table == 'analysisprop' and
  1896. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  1897. $term->dbxref_id->db_id->name == 'tripal')) {
  1898. continue;
  1899. }
  1900. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  1901. $field_name = substr($field_name, 0, 32);
  1902. $info[$field_name] = array(
  1903. 'field_name' => $field_name,
  1904. 'entity_type' => $entity_type,
  1905. 'bundle' => $bundle->name,
  1906. 'label' => ucwords(preg_replace('/_/', ' ', $term->name)),
  1907. 'description' => $term->definition,
  1908. 'required' => FALSE,
  1909. 'settings' => array(
  1910. 'auto_attach' => TRUE,
  1911. 'term_vocabulary' => $term->dbxref_id->db_id->name,
  1912. 'term_accession' => $term->dbxref_id->accession,
  1913. 'term_name' => $term->name,
  1914. 'base_table' => $table_name,
  1915. 'chado_table' => $prop_table,
  1916. 'chado_column' => $pkey,
  1917. ),
  1918. 'widget' => array(
  1919. 'type' => 'chado_linker__prop_widget',
  1920. 'settings' => array(
  1921. 'display_label' => 1,
  1922. ),
  1923. ),
  1924. 'display' => array(
  1925. 'default' => array(
  1926. 'label' => 'hidden',
  1927. 'type' => 'chado_linker__prop_formatter',
  1928. 'settings' => array(),
  1929. ),
  1930. ),
  1931. );
  1932. // Make some customizations to some fields
  1933. if ($term->name == 'Citation' and $term->cv_id->name == 'tripal_pub') {
  1934. $info[$field_name]['required'] = TRUE;
  1935. $info[$field_name]['description'] = t('All publications must have a unique citation.
  1936. Please enter the full citation for this publication. For PubMed style citations list
  1937. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  1938. the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
  1939. Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations
  1940. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>');
  1941. $info[$field_name]['settings']['rows'] = 3;
  1942. }
  1943. if ($term->name == 'Abstract' and $term->cv_id->name == 'tripal_pub') {
  1944. $info[$field_name]['settings']['rows'] = 5;
  1945. }
  1946. }
  1947. }
  1948. }
  1949. // CVTERMS
  1950. $term_table = $table_name . '_cvterm';
  1951. if (chado_table_exists($term_table)) {
  1952. $schema = chado_get_schema($term_table);
  1953. $pkey = $schema['primary key'][0];
  1954. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  1955. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  1956. $field_name = 'sio__annotation';
  1957. $info[$field_name] = array(
  1958. 'field_name' => $field_name,
  1959. 'entity_type' => $entity_type,
  1960. 'bundle' => $bundle->name,
  1961. 'label' => 'Annotations',
  1962. 'description' => 'Annotations that are associated with this record.',
  1963. 'required' => FALSE,
  1964. 'settings' => array(
  1965. 'auto_attach' => FALSE,
  1966. 'chado_table' => $term_table,
  1967. 'chado_column' => $pkey,
  1968. 'base_table' => $table_name,
  1969. ),
  1970. 'widget' => array(
  1971. 'type' => 'sio__annotation_widget',
  1972. 'settings' => array(
  1973. 'display_label' => 1,
  1974. ),
  1975. ),
  1976. 'display' => array(
  1977. 'default' => array(
  1978. 'label' => 'hidden',
  1979. 'type' => 'sio__annotation_formatter',
  1980. 'settings' => array(),
  1981. ),
  1982. ),
  1983. );
  1984. }
  1985. // PUBLICATIONS
  1986. $pub_table = $table_name . '_pub';
  1987. if (chado_table_exists($pub_table)) {
  1988. $field_name = 'schema__publication';
  1989. $schema = chado_get_schema($pub_table);
  1990. $pkey = $schema['primary key'][0];
  1991. $info[$field_name] = array(
  1992. 'field_name' => $field_name,
  1993. 'entity_type' => $entity_type,
  1994. 'bundle' => $bundle->name,
  1995. 'label' => 'Publication',
  1996. 'description' => 'This record has been referenced or is sourced from these publications.',
  1997. 'required' => FALSE,
  1998. 'settings' => array(
  1999. 'auto_attach' => FALSE,
  2000. 'chado_table' => $pub_table,
  2001. 'chado_column' => $pkey,
  2002. 'base_table' => $table_name,
  2003. ),
  2004. 'widget' => array(
  2005. 'type' => 'schema__publication_widget',
  2006. 'settings' => array(
  2007. 'display_label' => 1,
  2008. ),
  2009. ),
  2010. 'display' => array(
  2011. 'default' => array(
  2012. 'label' => 'hidden',
  2013. 'type' => 'schema__publication_formatter',
  2014. 'settings' => array(),
  2015. ),
  2016. ),
  2017. );
  2018. }
  2019. // PUBLICATIONS (in reverse)
  2020. // We want to be able to show all of the content that a publication links
  2021. // to. The sio__references field does that.
  2022. if ($table_name == 'pub') {
  2023. $field_name = 'sio__references';
  2024. $schema = chado_get_schema($table_name);
  2025. $pkey = $schema['primary key'][0];
  2026. $info[$field_name] = array(
  2027. 'field_name' => $field_name,
  2028. 'entity_type' => $entity_type,
  2029. 'bundle' => $bundle->name,
  2030. 'label' => 'References',
  2031. 'description' => 'Records that are referred to by the publication.',
  2032. 'required' => FALSE,
  2033. 'settings' => array(
  2034. 'auto_attach' => FALSE,
  2035. 'chado_table' => $table_name,
  2036. 'chado_column' => $pkey,
  2037. 'base_table' => $table_name,
  2038. ),
  2039. 'widget' => array(
  2040. 'type' => 'sio__references_widget',
  2041. 'settings' => array(
  2042. 'display_label' => 1,
  2043. ),
  2044. ),
  2045. 'display' => array(
  2046. 'default' => array(
  2047. 'label' => 'hidden',
  2048. 'type' => 'sio__references_formatter',
  2049. 'settings' => array(),
  2050. ),
  2051. ),
  2052. );
  2053. }
  2054. // RELATIONSHIPS
  2055. // If the linker table does not exists then we don't want to add attach.
  2056. $rel_table = $table_name . '_relationship';
  2057. if (chado_table_exists($rel_table)) {
  2058. $field_name = 'sbo__relationship';
  2059. $schema = chado_get_schema($rel_table);
  2060. $pkey = $schema['primary key'][0];
  2061. $info[$field_name] = array(
  2062. 'field_name' => $field_name,
  2063. 'entity_type' => $entity_type,
  2064. 'bundle' => $bundle->name,
  2065. 'label' => 'Relationship',
  2066. 'description' => 'Other records with relationships to this record.',
  2067. 'required' => FALSE,
  2068. 'settings' => array(
  2069. 'auto_attach' => FALSE,
  2070. 'chado_table' => $rel_table,
  2071. 'chado_column' => $pkey,
  2072. 'base_table' => $table_name,
  2073. ),
  2074. 'widget' => array(
  2075. 'type' => 'sbo__relationship_widget',
  2076. 'settings' => array(
  2077. 'display_label' => 1,
  2078. ),
  2079. ),
  2080. 'display' => array(
  2081. 'default' => array(
  2082. 'label' => 'hidden',
  2083. 'type' => 'sbo__relationship_formatter',
  2084. 'settings' => array(),
  2085. ),
  2086. ),
  2087. );
  2088. }
  2089. // SYNONYMS
  2090. $syn_table = $table_name . '_synonym';
  2091. if (chado_table_exists($syn_table)) {
  2092. $field_name = 'schema__alternate_name';
  2093. $schema = chado_get_schema($syn_table);
  2094. $pkey = $schema['primary key'][0];
  2095. $info[$field_name] = array(
  2096. 'field_name' => $field_name,
  2097. 'entity_type' => $entity_type,
  2098. 'bundle' => $bundle->name,
  2099. 'label' => 'Synonyms',
  2100. 'description' => 'Alternate names, aliases or synonyms for this record.',
  2101. 'required' => FALSE,
  2102. 'settings' => array(
  2103. 'auto_attach' => FALSE,
  2104. 'chado_table' => $syn_table,
  2105. 'chado_column' => $pkey,
  2106. 'base_table' => $table_name,
  2107. ),
  2108. 'widget' => array(
  2109. 'type' => 'schema__alternate_name_widget',
  2110. 'settings' => array(
  2111. 'display_label' => 1,
  2112. ),
  2113. ),
  2114. 'display' => array(
  2115. 'default' => array(
  2116. 'label' => 'hidden',
  2117. 'type' => 'schema__alternate_name_formatter',
  2118. 'settings' => array(),
  2119. ),
  2120. ),
  2121. );
  2122. }
  2123. }
  2124. /**
  2125. * Implements hook_bundle_create_user_field().
  2126. *
  2127. * A priviledged user has the ability to add new fields to the bundle. The
  2128. * chado_linker__prop and chado_linker__cvterm fields are allowed to be
  2129. * added dynamically by the user. But, Drupal doesn't know how to deal with
  2130. * it, so this function is called for any field attached to a TripalEntity
  2131. * bundle type. Any fields whose TripalField::$module argument is set to
  2132. * 'tripal_chado' and that can be added dynamically will result in a call
  2133. * to this function.
  2134. */
  2135. function tripal_chado_bundle_create_user_field($new_field, $bundle) {
  2136. // Get the table this bundle is mapped to.
  2137. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  2138. $vocab = $term->vocab;
  2139. $params = array(
  2140. 'vocabulary' => $vocab->vocabulary,
  2141. 'accession' => $term->accession,
  2142. );
  2143. $chado_table = $bundle->data_table;
  2144. $chado_type_table = $bundle->type_linker_table;
  2145. $chado_type_column = $bundle->type_column;
  2146. $chado_type_id = $bundle->type_id;
  2147. $chado_type_value = $bundle->type_value;
  2148. // We allow site admins to add new chado_linker__prop fields to an entity.
  2149. // This function will allow us to properly add them. But at this point we
  2150. // don't know the controlled vocabulary term. We'll have to use the
  2151. // defaults and let the user set it using the interface.
  2152. if ($new_field['type'] == 'chado_linker__prop') {
  2153. $table_name = $chado_table . 'prop';
  2154. if (chado_table_exists($table_name)) {
  2155. $schema = chado_get_schema($table_name);
  2156. $pkey = $schema['primary key'][0];
  2157. $field_name = $new_field['field_name'];
  2158. $field_type = 'chado_linker__prop';
  2159. // First add the field.
  2160. field_create_field(array(
  2161. 'field_name' => $field_name,
  2162. 'type' => $field_type,
  2163. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2164. 'locked' => FALSE,
  2165. 'storage' => array(
  2166. 'type' => 'field_chado_storage',
  2167. ),
  2168. ));
  2169. // Now add the instance
  2170. field_create_instance(array(
  2171. 'field_name' => $field_name,
  2172. 'entity_type' => 'TripalEntity',
  2173. 'bundle' => $bundle->name,
  2174. 'label' => $new_field['label'],
  2175. 'description' => '',
  2176. 'required' => FALSE,
  2177. 'settings' => array(
  2178. 'auto_attach' => TRUE,
  2179. 'base_table' => $chado_table,
  2180. 'chado_table' => $table_name,
  2181. 'chado_column' => $pkey,
  2182. 'term_vocabulary' => '',
  2183. 'term_accession' => '',
  2184. 'term_name' => ''
  2185. ),
  2186. 'widget' => array(
  2187. 'type' => 'chado_linker__prop_widget',
  2188. 'settings' => array(
  2189. 'display_label' => 1,
  2190. ),
  2191. ),
  2192. 'display' => array(
  2193. 'default' => array(
  2194. 'label' => 'inline',
  2195. 'type' => 'chado_linker__prop_formatter',
  2196. 'settings' => array(),
  2197. ),
  2198. ),
  2199. ));
  2200. }
  2201. else {
  2202. drupal_set_message('Cannot add a property field to this entity. Chado does not support properties for this data type.', 'error');
  2203. }
  2204. }
  2205. // We allow site admins to add new chado_linker__cvterm fields to an entity.
  2206. // This function will allow us to properly add them. But at this point we
  2207. // don't know the controlled vocabulary term. We'll have to use the
  2208. // defaults and let the user set it using the interface.
  2209. if ($new_field['type'] == 'chado_linker__cvterm') {
  2210. $table_name = $chado_table . '_cvterm';
  2211. if (chado_table_exists($table_name)) {
  2212. $schema = chado_get_schema($table_name);
  2213. $pkey = $schema['primary key'][0];
  2214. $field_name = $new_field['field_name'];
  2215. $field_type = 'chado_linker__cvterm';
  2216. // First add the field.
  2217. field_create_field(array(
  2218. 'field_name' => $field_name,
  2219. 'type' => $field_type,
  2220. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2221. 'locked' => FALSE,
  2222. 'storage' => array(
  2223. 'type' => 'field_chado_storage',
  2224. ),
  2225. 'settings' => array(
  2226. 'base_table' => $chado_table,
  2227. 'chado_table' => $table_name,
  2228. 'chado_column' => $pkey,
  2229. ),
  2230. ));
  2231. // Now add the instance
  2232. field_create_instance(array(
  2233. 'field_name' => $field_name,
  2234. 'entity_type' => 'TripalEntity',
  2235. 'bundle' => $bundle->name,
  2236. 'label' => $new_field['label'],
  2237. 'description' => '',
  2238. 'required' => FALSE,
  2239. 'settings' => array(
  2240. 'auto_attach' => TRUE,
  2241. ),
  2242. 'widget' => array(
  2243. 'type' => 'chado_linker__cvterm_widget',
  2244. 'settings' => array(
  2245. 'display_label' => 1,
  2246. ),
  2247. ),
  2248. 'display' => array(
  2249. 'default' => array(
  2250. 'label' => 'above',
  2251. 'type' => 'chado_linker__cvterm_formatter',
  2252. 'settings' => array(),
  2253. ),
  2254. ),
  2255. ));
  2256. }
  2257. else {
  2258. drupal_set_message('Cannot add a property field to this entity. Chado does not support annotations for this data type.', 'error');
  2259. }
  2260. }
  2261. }
  2262. /**
  2263. * Allows for altering of a field's instance setting form.
  2264. *
  2265. * This appears to be a Drupal hook but is actually a custom function created
  2266. * by this module. It is called by the tripal_form_alter() function of this
  2267. * module.
  2268. *
  2269. * Here we put additional form elements for any field, regardless if it is
  2270. * a tripalField or not.
  2271. *
  2272. * @param $form
  2273. * The form array. Alterations to the form can be made within this array.
  2274. * @param $form_state
  2275. * The form state array.
  2276. */
  2277. function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
  2278. global $language;
  2279. $field = $form['#field'];
  2280. $instance = $form['#instance'];
  2281. $base_table = array_key_exists('base_table', $instance['settings']) ? $instance['settings']['base_table'] : '';
  2282. $chado_table = array_key_exists('chado_table', $instance['settings']) ? $instance['settings']['chado_table'] : '';
  2283. $chado_column = array_key_exists('chado_column', $instance['settings']) ? $instance['settings']['chado_column'] : '';
  2284. if ($chado_table) {
  2285. // Construct a table for the vocabulary information.
  2286. $headers = array();
  2287. $rows = array();
  2288. $rows[] = array(
  2289. array(
  2290. 'data' => 'Base Table',
  2291. 'header' => TRUE,
  2292. 'width' => '20%',
  2293. ),
  2294. $base_table
  2295. );
  2296. $rows[] = array(
  2297. array(
  2298. 'data' => 'Record Table',
  2299. 'header' => TRUE,
  2300. 'width' => '20%',
  2301. ),
  2302. $chado_table
  2303. );
  2304. $rows[] = array(
  2305. array(
  2306. 'data' => 'ID Column',
  2307. 'header' => TRUE,
  2308. 'width' => '20%',
  2309. ),
  2310. $chado_column
  2311. );
  2312. $table = array(
  2313. 'header' => $headers,
  2314. 'rows' => $rows,
  2315. 'attributes' => array(
  2316. ),
  2317. 'sticky' => FALSE,
  2318. 'caption' => '',
  2319. 'colgroups' => array(),
  2320. 'empty' => '',
  2321. );
  2322. $form['chado_mapping'] = array(
  2323. '#type' => 'fieldset',
  2324. '#title' => 'Chado Mapping',
  2325. '#description' => t('This field maps to data in Chado to the following table:'),
  2326. );
  2327. $form['chado_mapping']['details'] = array(
  2328. '#type' => 'item',
  2329. '#markup' => theme_table($table),
  2330. );
  2331. }
  2332. }
  2333. /**
  2334. * Implements hook_form_FROM_ID_alter()
  2335. */
  2336. function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
  2337. global $language;
  2338. $bundle = $form['#bundle'];
  2339. $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
  2340. $term = reset($term);
  2341. $vocab = $term->vocab;
  2342. $params = array(
  2343. 'vocabulary' => $vocab->vocabulary,
  2344. 'accession' => $term->accession,
  2345. );
  2346. $chado_table = $bundle->data_table;
  2347. $chado_column = $bundle->type_column;
  2348. $chado_type_table = $bundle->type_linker_table;
  2349. $chado_type_id = $bundle->type_id;
  2350. $chado_type_value = $bundle->type_value;
  2351. // Construct a table for the vocabulary information.
  2352. $headers = array();
  2353. $rows = array();
  2354. $rows[] = array(
  2355. array(
  2356. 'data' => 'Chado Table',
  2357. 'header' => TRUE,
  2358. 'width' => '20%',
  2359. ),
  2360. $chado_table
  2361. );
  2362. if ($chado_column) {
  2363. $rows[] = array(
  2364. array(
  2365. 'data' => 'Type Column',
  2366. 'header' => TRUE,
  2367. 'width' => '20%',
  2368. ),
  2369. $chado_column
  2370. );
  2371. }
  2372. if ($chado_type_table) {
  2373. $rows[] = array(
  2374. array(
  2375. 'data' => 'Association Table',
  2376. 'header' => TRUE,
  2377. 'width' => '20%',
  2378. ),
  2379. $chado_type_table
  2380. );
  2381. }
  2382. if ($chado_type_table and $chado_type_id) {
  2383. $rows[] = array(
  2384. array(
  2385. 'data' => 'CVTerm Table ID',
  2386. 'header' => TRUE,
  2387. 'width' => '20%',
  2388. ),
  2389. $chado_type_id
  2390. );
  2391. }
  2392. if ($chado_type_value) {
  2393. $rows[] = array(
  2394. array(
  2395. 'data' => 'Property Value',
  2396. 'header' => TRUE,
  2397. 'width' => '20%',
  2398. ),
  2399. $chado_type_value
  2400. );
  2401. }
  2402. $table = array(
  2403. 'header' => $headers,
  2404. 'rows' => $rows,
  2405. 'attributes' => array(
  2406. ),
  2407. 'sticky' => FALSE,
  2408. 'caption' => '',
  2409. 'colgroups' => array(),
  2410. 'empty' => '',
  2411. );
  2412. $form['chado_mapping'] = array(
  2413. '#type' => 'item',
  2414. '#title' => 'Chado Mapping',
  2415. '#markup' => theme_table($table),
  2416. '#description' => t('This content type maps to the table in Chado
  2417. listed above. Chado allows multiple data types to be housed
  2418. in a single table. Therefore, the column that is used to
  2419. differentiate between data types is also listed above.'),
  2420. '#weight' => 0,
  2421. );
  2422. }
  2423. /**
  2424. * Implements hook_field_views_data_alter();
  2425. */
  2426. function tripal_chado_field_views_data_alter(&$result, $field, $module) {
  2427. // This module creates the data__image field for managing images on
  2428. // bio_data content types. But we want it to render correctly
  2429. // so we need to set some handlers.
  2430. if ($field['field_name'] == 'data__image') {
  2431. foreach ($result as $key => $fields) {
  2432. // It's not clear how to identify our bundle types, but they do have
  2433. // a double underscore in their name to separate the vocabulary from
  2434. // the accession, so we'll use that to find them.
  2435. if (preg_match('/__/', $key)) {
  2436. $result[$key]['data__image']['field']['handler'] = 'tripal_views_handler_field_image';
  2437. }
  2438. }
  2439. }
  2440. }