tripal_chado.field_storage.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. <?php
  2. /**
  3. * Implements hook_field_storage_info().
  4. */
  5. function tripal_chado_field_storage_info() {
  6. return array(
  7. 'field_chado_storage' => array(
  8. 'label' => t('Chado'),
  9. 'description' => t('Stores fields in the local Chado database.'),
  10. 'settings' => array(),
  11. // The logo_url key is supported by Tripal. It's not a Drupal key. It's
  12. // used for adding a logo or picture for the data store to help make it
  13. // more easily recognized on the field_ui_field_overview_form. Ideally
  14. // the URL should point to a relative path on the local Drupal site.
  15. 'logo_url' => url(drupal_get_path('module', 'tripal') . '/theme/images/250px-ChadoLogo.png'),
  16. ),
  17. );
  18. }
  19. /**
  20. * Implements hook_field_storage_write().
  21. */
  22. function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
  23. // Get the bundle and the term for this entity.
  24. $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle));
  25. $term = entity_load('TripalTerm', array('id' => $entity->term_id));
  26. $term = reset($term);
  27. // Convert the Tripal term entity into the appropriate record in Chado.
  28. $dbxref = tripal_get_dbxref(array('accession' => $term->accession, 'db_id' => array('name' => $term->vocab->vocabulary)));
  29. $cvterm = tripal_get_cvterm(array('dbxref_id' => $dbxref->dbxref_id));
  30. // Get the base table, type field and record_id from the entity.
  31. $base_table = $entity->chado_table;
  32. $type_field = $entity->chado_column;
  33. $record = $entity->chado_record;
  34. $record_id = $entity->chado_record_id;
  35. $base_schema = chado_get_schema($base_table);
  36. $base_pkey = $base_schema['primary key'][0];
  37. // Convert the fields into a key/value list of fields and their values.
  38. $field_vals = tripal_chado_field_storage_write_merge_fields($fields, $entity_type, $entity);
  39. // First, write the record for the base table. If we have a record id then
  40. // this is an update and we need to set the primary key. If not, then this
  41. // is an insert and we need to set the type_id if the table supports it.
  42. $values = $field_vals[$base_table];
  43. if ($record_id) {
  44. $values[$base_pkey] = $record_id;
  45. }
  46. elseif ($type_field) {
  47. $values[$type_field] = $cvterm->cvterm_id;
  48. }
  49. $base_record_id = tripal_chado_field_storage_write_table($base_table, $values);
  50. // If this is an insert then add the chado_entity record.
  51. if ($op == FIELD_STORAGE_INSERT) {
  52. // Add a record to the chado_entity table so that the data for the
  53. // fields can be pulled from Chado when loaded the next time.
  54. $record = array(
  55. 'entity_id' => $entity->id,
  56. 'record_id' => $base_record_id,
  57. 'data_table' => $base_table,
  58. 'type_table' => $base_table,
  59. 'field' => $type_field,
  60. );
  61. $success = drupal_write_record('chado_entity', $record);
  62. if (!$success) {
  63. drupal_set_message('Unable to insert new Chado entity.', 'error');
  64. }
  65. }
  66. // Now that we have handled the base table, we need to handle linking tables.
  67. foreach ($field_vals as $table_name => $details) {
  68. // Skip the base table as we've already dealt with it.
  69. if ($table_name == $base_table) {
  70. continue;
  71. }
  72. foreach ($details as $delta => $values) {
  73. $record_id = tripal_chado_field_storage_write_table($table_name, $values);
  74. }
  75. }
  76. }
  77. /**
  78. * Write (inserts/updates/deletes) values for a Chado table.
  79. *
  80. * The $values array is of the same format used by chado_insert_record() and
  81. * chado_update_record(). However, both of those methods will use any nested
  82. * arrays (i.e. representing foreign keys) to select an appropriate record ID
  83. * that can be substituted as the value. Here, the nested arrays are
  84. * either inserted or updated as well, but the choice is determined if the
  85. * primary key value is present. If present an update occurs, if not present
  86. * then an insert occurs.
  87. *
  88. * This function is recursive and nested arrays from the lowest point of the
  89. * "tree" are dealt with first.
  90. *
  91. * @param $table_name
  92. * The name of the table on which the insertion/update is performed.
  93. * @param $values
  94. * The values array for the insertion.
  95. *
  96. * @throws Exception
  97. *
  98. * @return
  99. * The unique record ID.
  100. */
  101. function tripal_chado_field_storage_write_table($table_name, $values) {
  102. $schema = chado_get_schema($table_name);
  103. $fkeys = $schema['foreign keys'];
  104. $pkey = $schema['primary key'][0];
  105. // Fields with a cardinality greater than 1 will often submit an
  106. // empty form. We want to remove these empty submissions. We can detect
  107. // them if all of the fields are empty.
  108. $num_empty = 0;
  109. foreach ($values as $column => $value) {
  110. if (!$value) {
  111. $num_empty++;
  112. }
  113. }
  114. if ($num_empty == count(array_keys($values))) {
  115. return '';
  116. }
  117. // If the primary key column has a value but all other values are empty then
  118. // this is a delete.
  119. if (array_key_exists($pkey, $values) and $values[$pkey]) {
  120. $num_vals = 0;
  121. foreach ($values as $value) {
  122. if ($value) {
  123. $num_vals++;
  124. }
  125. }
  126. if ($num_vals == 1) {
  127. $new_vals[$pkey] = $values[$pkey];
  128. if (!chado_delete_record($table_name, $new_vals)) {
  129. throw new Exception('Could not delete record from table: "' . $table_name . '".');
  130. }
  131. return '';
  132. }
  133. }
  134. // If the primary key column does not have a value then this is an insert.
  135. if (!array_key_exists($pkey, $values) or !$values[$pkey] or !isset($values[$pkey])) {
  136. // Before inserting, we want to make sure the record does not
  137. // already exist. Using the unique constraint check for a matching record.
  138. $options = array('is_duplicate' => TRUE);
  139. $is_duplicate = chado_select_record($table_name, array('*'), $values, $options);
  140. if($is_duplicate) {
  141. $record = chado_select_record($table_name, array('*'), $values);
  142. return $record[0]->$pkey;
  143. }
  144. // Insert the values array as a new record in the table but remove the
  145. // pkey as it should be set.
  146. $new_vals = $values;
  147. unset($new_vals[$pkey]);
  148. $record = chado_insert_record($table_name, $new_vals);
  149. if ($record === FALSE) {
  150. throw new Exception('Could not insert Chado record into table: "' . $table_name . '".');
  151. }
  152. return $record[$pkey];
  153. }
  154. // If we've made it to this point then this is an update.
  155. // TODO: what if the unique constraint matches another record? That is
  156. // not being tested for here.
  157. $match[$pkey] = $values[$pkey];
  158. if (!chado_update_record($table_name, $match, $values)) {
  159. drupal_set_message("Could not update Chado record in table: $table_name.", 'error');
  160. }
  161. return $values[$pkey];
  162. }
  163. /**
  164. * Implements hook_field_storage_load().
  165. *
  166. * Responsible for loading the fields from the Chado database and adding
  167. * their values to the entity.
  168. */
  169. function tripal_chado_field_storage_load($entity_type, $entities, $age,
  170. $fields, $options) {
  171. $load_current = $age == FIELD_LOAD_CURRENT;
  172. global $language;
  173. $langcode = $language->language;
  174. foreach ($entities as $id => $entity) {
  175. if (property_exists($entity, 'chado_table')) {
  176. // Get the base table and record id for the fields of this entity.
  177. $base_table = $entity->chado_table;
  178. $type_field = $entity->chado_column;
  179. $record_id = $entity->chado_record_id;
  180. }
  181. else {
  182. // Get the base table and record id for the fields of this entity.
  183. $details = db_select('chado_entity', 'ce')
  184. ->fields('ce')
  185. ->condition('entity_id', $entity->id)
  186. ->execute()
  187. ->fetchObject();
  188. if (!$details) {
  189. // TODO: what to do if record is missing!
  190. }
  191. // Get some values needed for loading the values from Chado.
  192. $base_table = isset($details->data_table) ? $details->data_table : '';
  193. $type_field = isset($details->field) ? $details->field : '';
  194. $record_id = isset($details->record_id) ? $details->record_id : '';
  195. }
  196. // Get this table's schema.
  197. $schema = chado_get_schema($base_table);
  198. $pkey_field = $schema['primary key'][0];
  199. // Get the base record if one exists
  200. $columns = array('*');
  201. $match = array($pkey_field => $record_id);
  202. $record = chado_generate_var($base_table, $match);
  203. $entity->chado_record = $record;
  204. // For now, expand all 'text' fields.
  205. // TODO: we want to be a bit smarter and allow the user to configure this
  206. // for now we'll expand.
  207. if (isset($schema['fields'])) {
  208. foreach ($schema['fields'] as $field_name => $details) {
  209. if ($schema['fields'][$field_name]['type'] == 'text') {
  210. $record = chado_expand_var($record, 'field', $base_table . '.' . $field_name);
  211. }
  212. }
  213. }
  214. // Iterate through the entity's fields so we can get the column names
  215. // that need to be selected from each of the tables represented.
  216. $tables = array();
  217. foreach ($fields as $field_id => $ids) {
  218. // By the time this hook runs, the relevant field definitions have been
  219. // populated and cached in FieldInfo, so calling field_info_field_by_id()
  220. // on each field individually is more efficient than loading all fields in
  221. // memory upfront with field_info_field_by_ids().
  222. $field = field_info_field_by_id($field_id);
  223. $field_name = $field['field_name'];
  224. $field_type = $field['type'];
  225. $field_module = $field['module'];
  226. // Skip fields that don't map to a Chado table (e.g. kvproperty_adder).
  227. if (!array_key_exists('settings', $field) or !array_key_exists('chado_table', $field['settings'])) {
  228. continue;
  229. }
  230. // Get the Chado table and column for this field.
  231. $field_table = $field['settings']['chado_table'];
  232. $field_column = $field['settings']['chado_column'];
  233. // There are only two types of fields: 1) fields that represent a single
  234. // column of the base table, or 2) fields that represent a linked record
  235. // in a many-to-one relationship with the base table.
  236. // Type 1: fields from base tables.
  237. if ($field_table == $base_table) {
  238. // Set an empty value by default, and if there is a record, then update.
  239. $entity->{$field_name}['und'][0]['value'] = '';
  240. if ($record and property_exists($record, $field_column)) {
  241. // If the field column is an object then it's a FK to another table.
  242. // and because $record object is created by the chado_generate_var()
  243. // function we must go one more level deeper to get the value
  244. if (is_object($record->$field_column)) {
  245. $entity->{$field_name}['und'][0]['chado-' . $field_table . '__' . $field_column] = $record->$field_column->$field_column;
  246. }
  247. else {
  248. // For non FK fields we'll make the field value be the same
  249. // as the column value.
  250. $entity->{$field_name}['und'][0]['value'] = $record->$field_column;
  251. $entity->{$field_name}['und'][0]['chado-' . $field_table . '__' . $field_column] = $record->$field_column;
  252. }
  253. }
  254. // Allow the creating module to alter the value if desired. The
  255. // module should do this if the field has any other form elements
  256. // that need populationg besides the value which was set above.
  257. tripal_load_include_field_class($field_type);
  258. if (class_exists($field_type) and is_subclass_of($field_type, 'TripalField')) {
  259. $tfield = new $field_type($field);
  260. $tfield->load($entity, array('record' => $record));
  261. }
  262. }
  263. // Type 2: fields for linked records. These fields will have any number
  264. // of form elements that might need populating so we'll offload the
  265. // loading of these fields to the field itself.
  266. if ($field_table != $base_table) {
  267. // Set an empty value by default, and let the hook function update it.
  268. $entity->{$field_name}['und'][0]['value'] = '';
  269. tripal_load_include_field_class($field_type);
  270. if (class_exists($field_type) && method_exists($field_type, 'load')) {
  271. $tfield = new $field_type($field);
  272. $tfield->load($entity, array('record' => $record));
  273. }
  274. }
  275. } // end: foreach ($fields as $field_id => $ids) {
  276. } // end: foreach ($entities as $id => $entity) {
  277. }
  278. /**
  279. * Merges the values of all fields into a single array keyed by table name.
  280. */
  281. function tripal_chado_field_storage_write_merge_fields($fields, $entity_type, $entity) {
  282. $all_fields = array();
  283. $base_fields = array();
  284. // Iterate through all of the fields and organize them into a
  285. // new fields array keyed by the table name
  286. foreach ($fields as $field_id => $ids) {
  287. // Get the field name and information about it.
  288. $field = field_info_field_by_id($field_id);
  289. $field_name = $field['field_name'];
  290. // Some fields (e.g. chado_linker_cvterm_adder) don't add data to
  291. // Chado so they don't have a table, but they are still attached to the
  292. // entity. Just skip these.
  293. if (!array_key_exists('chado_table', $field['settings'])) {
  294. continue;
  295. }
  296. $chado_table = $field['settings']['chado_table'];
  297. $chado_column = $field['settings']['chado_column'];
  298. $base_table = $field['settings']['base_table'];
  299. // Iterate through the field's items. Fields with cardinality ($delta) > 1
  300. // are multi-valued.
  301. $items = field_get_items($entity_type, $entity, $field_name);
  302. $temp = array();
  303. foreach ($items as $delta => $item) {
  304. // A field may have multiple items. The field can use items
  305. // indexed with "chado-" to represent values that should map directly
  306. // to chado tables and fields.
  307. foreach ($item as $item_name => $value) {
  308. $matches = array();
  309. if (preg_match('/^chado-(.*?)__(.*?)$/', $item_name, $matches)) {
  310. $table_name = $matches[1];
  311. $column_name = $matches[2];
  312. // If this field belongs to the base table then we just add
  313. // those values in... there's no delta.
  314. if ($table_name == $base_table) {
  315. $base_fields[$table_name][$column_name] = $value;
  316. }
  317. else {
  318. $temp[$table_name][$delta][$column_name] = $value;
  319. }
  320. }
  321. }
  322. // If there is no value set for the field using the
  323. // chado-[table_name]__[field name] naming schema then check if a 'value'
  324. // item is present and if so use that for the table column value.
  325. if ((!array_key_exists($chado_table, $temp) or
  326. !array_key_exists($delta, $temp[$chado_table]) or
  327. !array_key_exists($chado_column, $temp[$chado_table][$delta])) and
  328. array_key_exists('value', $items[$delta]) and
  329. !is_array($items[$delta]['value'])) {
  330. // If this field belongs to the base table then we just add
  331. // those values in... there's no delta.
  332. if ($base_table == $chado_table) {
  333. $base_fields[$chado_table][$chado_column] = $items[$delta]['value'];
  334. }
  335. else {
  336. $temp[$chado_table][$delta][$chado_column] = $items[$delta]['value'];
  337. }
  338. }
  339. }
  340. // Now merge the records for this field with the $new_fields array
  341. foreach ($temp as $table_name => $details) {
  342. foreach ($details as $delta => $list) {
  343. $all_fields[$table_name][] = $list;
  344. }
  345. }
  346. }
  347. $all_fields = array_merge($base_fields, $all_fields);
  348. return $all_fields;
  349. }
  350. /**
  351. * Recurses through a field's items breaking it into a nested array.
  352. */
  353. function tripal_chado_field_storage_expand_field($item_name, $value) {
  354. $matches = array();
  355. if (preg_match('/^(.*?)--(.*?)$/', $item_name, $matches)) {
  356. $parent_item_name = $matches[1];
  357. $sub_item_name = $matches[2];
  358. $sub_item = tripal_chado_field_storage_expand_field($sub_item_name, $value);
  359. return array($parent_item_name => $sub_item);
  360. }
  361. else {
  362. return array($item_name => $value);
  363. }
  364. }
  365. /**
  366. * Implements hook_field_storage_query().
  367. */
  368. function tripal_chado_field_storage_query($query) {
  369. //print_r($query->fieldConditions);
  370. // The conditions and order bys are reorganized into a filters array for the
  371. // chado_select_record function()
  372. $filters = array();
  373. // Iterate through all the conditions and add to the filters array
  374. // a chado_select_record compatible set of filters.
  375. foreach ($query->fieldConditions as $index => $condition) {
  376. $field = $condition['field'];
  377. // Skip conditions that don't belong to this storage type.
  378. if ($field['storage']['type'] != 'field_chado_storage') {
  379. continue;
  380. }
  381. $column = $condition['column'];
  382. $value = $condition['value'];
  383. $field_type = $field['type'];
  384. $field_module = $field['module'];
  385. $settings = $field['settings'];
  386. $chado_table = $settings['chado_table'];
  387. $chado_column = $settings['chado_column'];
  388. // Set the value for this field search.
  389. $subfields = explode('.', $column);
  390. //print_r($subfields);
  391. if (count($subfields) > 1) {
  392. // Get the term for this field's column and replace the field_name with
  393. // the term. We need to do this for the recursive function to work.
  394. // We must lowercase the term and underscore it because that's how we
  395. // can support case-insensitivity and lack of spacing such as for
  396. // web services.
  397. $subfield1 = tripal_get_chado_semweb_term($chado_table, $chado_column, array('return_object' => TRUE));
  398. $subfields[0] = strtolower(preg_replace('/ /', '_', $subfield1->name));
  399. $value = tripal_chado_field_storage_recurse_subfilters($chado_table, $subfields, $value);
  400. $value = array_shift($value);
  401. }
  402. else {
  403. $value = $condition['value'];
  404. }
  405. // Use the appropriate operator.
  406. $operator = $condition['operator'] ? $condition['operator'] : '=';
  407. switch ($operator) {
  408. case '=':
  409. $filters[$chado_table][$chado_column] = $value;
  410. break;
  411. case '>':
  412. case '>=':
  413. case '<':
  414. case '<=':
  415. $filters[$chado_table][$chado_column] = array(
  416. 'op' => $operator,
  417. 'data' => $value,
  418. );
  419. break;
  420. case '<>':
  421. $filters[$chado_table][$chado_column] = array(
  422. 'op' => '<>',
  423. 'data' => $value,
  424. );
  425. break;
  426. case 'CONTAINS':
  427. $filters[$chado_table][$chado_column] = array(
  428. 'op' => 'LIKE',
  429. 'data' => '%' . $value . '%',
  430. );
  431. break;
  432. case 'NOT':
  433. $filters[$chado_table][$chado_column] = array(
  434. 'op' => 'NOT LIKE',
  435. 'data' => '%' . $value . '%',
  436. );
  437. break;
  438. case 'STARTS WITH':
  439. $filters[$chado_table][$chado_column] = array(
  440. 'op' => 'LIKE',
  441. 'data' => $value . '%',
  442. );
  443. break;
  444. case 'NOT STARTS':
  445. $filters[$chado_table][$chado_column] = array(
  446. 'op' => 'NOT LIKE',
  447. 'data' => $value . '%',
  448. );
  449. break;
  450. case 'ENDS WITH':
  451. $filters[$chado_table][$chado_column] = array(
  452. 'op' => 'LIKE',
  453. 'data' => '%' . $value,
  454. );
  455. break;
  456. case 'NOT ENDS':
  457. $filters[$chado_table][$chado_column] = array(
  458. 'op' => 'NOT LIKE',
  459. 'data' => '%' . $value,
  460. );
  461. break;
  462. default:
  463. // unrecognized operation.
  464. break;
  465. }
  466. }
  467. // Now get the list for sorting.
  468. foreach ($query->order as $index => $sort) {
  469. $field = $sort['specifier']['field'];
  470. // Skip sorts that don't belong to this storage type.
  471. if ($field['storage']['type'] != 'field_chado_storage') {
  472. continue;
  473. }
  474. $direction = $sort['direction'];
  475. $field_type = $field['type'];
  476. $field_module = $field['module'];
  477. $settings = $field['settings'];
  478. $chado_table = $settings['chado_table'];
  479. $chado_column = $settings['chado_column'];
  480. $sorting[$chado_table][$chado_column] = $direction;
  481. }
  482. // Iterate through the filters and perform the query
  483. $entity_ids = array();
  484. foreach ($filters as $chado_table => $values) {
  485. //print_r($chado_table);
  486. //print_r($values);
  487. // First get the matching record IDs from the Chado table.
  488. $schema = chado_get_schema($chado_table);
  489. $pkey = $schema['primary key'][0];
  490. $results = chado_select_record($chado_table, array($pkey), $values);
  491. $record_ids = array();
  492. foreach ($results as $result) {
  493. $record_ids[] = $result->$pkey;
  494. }
  495. // Next look for matching IDs in the chado_entity table.
  496. $filter_ids = array();
  497. if (count($record_ids) > 0) {
  498. $select = db_select('chado_entity', 'CE');
  499. $select->join('tripal_entity', 'TE', 'TE.id = CE.entity_id');
  500. $select->fields('CE', array('entity_id'));
  501. $select->fields('TE', array('bundle'));
  502. $select->condition('record_id', $record_ids);
  503. // If a bundle is specified then make sure we match on the bundle.
  504. if (array_key_exists('bundle', $query->entityConditions)) {
  505. $select->condition('bundle', $query->entityConditions['bundle']);
  506. }
  507. $results = $select->execute();
  508. while ($result = $results->fetchObject()) {
  509. $entity_ids[] = array($result->entity_id, 0, $result->bundle);
  510. }
  511. }
  512. }
  513. $result = array(
  514. 'TripalEntity' => array()
  515. );
  516. foreach ($entity_ids as $ids) {
  517. $result['TripalEntity'][$ids[0]] = entity_create_stub_entity('TripalEntity', $ids);
  518. }
  519. return $result;
  520. }
  521. /**
  522. *
  523. * @param $subfields
  524. * @param $value
  525. */
  526. function tripal_chado_field_storage_recurse_subfilters($chado_table, $subfields, $value) {
  527. $sub_value = array();
  528. // Get the subvalue for this iteration
  529. $subfield = array_shift($subfields);
  530. // Get the cvterms mapped to this table.
  531. $columns = db_select('chado_semweb', 'CS')
  532. ->fields('CS', array('chado_column', 'cvterm_id'))
  533. ->condition('chado_table', $chado_table)
  534. ->execute();
  535. // Iterate through the columns and find the one with cvterm that matches
  536. // the subfield name.
  537. $chado_column = '';
  538. while($column = $columns->fetchObject()) {
  539. $cvterm_id = $column->cvterm_id;
  540. $cvterm = tripal_get_cvterm(array('cvterm_id' => $cvterm_id));
  541. // Convert the term name to lower-case and replace spaces with underscores
  542. // so we can perform case insensitive comparisions and ingore spacing.
  543. $term_name = strtolower(preg_replace('/ /', '_', $cvterm->name));
  544. if ($subfield == $term_name) {
  545. $chado_column = $column->chado_column;
  546. }
  547. }
  548. // If we have more subfields then this should be a foreign key and we should
  549. // recurse.
  550. if (count($subfields) > 0) {
  551. // Get the foreign keys for this Chado table.
  552. $schema = chado_get_schema($chado_table);
  553. $fkeys = $schema['foreign keys'];
  554. // Iterate through the FKs to find the one that matches this Chado field.
  555. foreach ($fkeys as $fk_table => $details) {
  556. foreach ($details['columns'] as $lkey => $rkey) {
  557. if ($lkey == $chado_column) {
  558. $sub_value = tripal_chado_field_storage_recurse_subfilters($fk_table, $subfields, $value);
  559. return array($chado_column => $sub_value);
  560. }
  561. }
  562. }
  563. }
  564. return array($chado_column => $value);
  565. }