tripal_chado.field_storage.inc 23 KB

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