tripal_chado.fields.inc 80 KB

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