123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- function chado_get_record_entity_by_bundle(TripalBundle $bundle, $record_id) {
- if (!$bundle) {
- throw new Exception('Please provide a TripalBundle object.');
- };
- if (!$record_id) {
- throw new Exception('Please provide an integer record ID.');
- };
- if (!is_numeric($record_id)) {
- throw new Exception('Please provide an integer record ID. The value provided was "' . $record_id . '"');
- }
- $chado_entity_table = chado_get_bundle_entity_table($bundle);
- return db_select($chado_entity_table, 'CE')
- ->fields('CE', array('entity_id'))
- ->condition('CE.record_id', $record_id)
- ->execute()
- ->fetchField();
- }
- function chado_get_record_entity_by_table($data_table, $record_id) {
-
- if (!$data_table) {
- throw new Exception('Please provide the $data_table argument.');
- };
- if (!$record_id) {
- throw new Exception('Please provide an integer record ID.');
- };
- if (!is_numeric($record_id)) {
- throw new Exception('Please provide an integer record ID. The value provided was "' . $record_id . '"');
- }
-
- $bundles = db_select('chado_bundle', 'CB')
- ->fields('CB', array('bundle_id'))
- ->condition('CB.data_table', $data_table)
- ->execute();
-
- while ($bundle_id = $bundles->fetchField()) {
- $entity_id = db_select('chado_bio_data_' . $bundle_id , 'CBD')
- ->fields('CBD', array('entity_id'))
- ->condition('record_id', $record_id)
- ->execute()
- ->fetchField();
- if ($entity_id) {
- return $entity_id;
- }
- }
- return NULL;
- }
- function chado_get_bundle_entity_table($bundle) {
- if (!$bundle) {
- return '';
- }
- return 'chado_' . $bundle->name;
- }
|