Tripal Plant PopGen Submit
tpps.queries.api.inc File Reference

Go to the source code of this file.

Functions

 tpps_api_author_pid_query (array $authors)
 
 tpps_api_organism_pid_query (array $orgs)
 
 tpps_api_organization_pid_query (array $orgs)
 
 tpps_api_project_author_query (array $pids, $entities=FALSE)
 
 tpps_api_project_design_query (array $pids)
 
 tpps_api_project_genotype_query (array $pids, $entities=FALSE)
 
 tpps_api_project_organism_query (array $pids, $entities=FALSE)
 
 tpps_api_project_phenotype_query (array $pids, $entities=FALSE)
 
 tpps_api_project_publication_query (array $pids, $entities=FALSE)
 
 tpps_api_project_query (array $pids, $entities=FALSE)
 
 tpps_api_project_stats_query (array $states)
 
 tpps_api_project_stock_query (array $pids, $entities=FALSE)
 
 tpps_api_query_or (array $vals, array $fields, $override_op=NULL)
 
 tpps_api_record_entities ($label, array $record_ids)
 

Detailed Description

Defines queries for the TPPS API.

Most queries get information based on a list of project ids, but some can produce a list of project ids based on some conditions. Query functions with names like "tpps_api_*_pid_query" will produce a list of pids based on the provided conditions. For example, the function "tpps_api_author_pid_query" will return a list of pids with authors that match at least one of the provided names. Query functions with names like "tpps_api_project_*_query" will produce a list of ids or entities based on a list of pids. For example, the function "tpps_api_project_organism_query" will return a list of organism ids or, if the entities parameter is set to true, will return a list of organism entities associated with the provided pids.

Definition in file tpps.queries.api.inc.

Function Documentation

◆ tpps_api_author_pid_query()

tpps_api_author_pid_query ( array  $authors)

Returns array of project ids associated with provided authors.

Parameters
array$authorsAn array of author names.
Returns
array An array of associated project ids.

Definition at line 28 of file tpps.queries.api.inc.

28  {
29  $query = db_select('chado.pubauthor', 'pa');
30  $query->join('chado.project_pub', 'pp', 'pp.pub_id = pa.pub_id');
31  $query->fields('pp', array('project_id'));
32  $or = tpps_api_query_or($orgs, array(
33  'pa.givennames',
34  'pa.surname',
35  ));
36  $query->condition($or);
37  return $query->execute();
38 }
tpps_api_query_or(array $vals, array $fields, $override_op=NULL)

◆ tpps_api_organism_pid_query()

tpps_api_organism_pid_query ( array  $orgs)

Returns array of project ids associated with provided species.

Parameters
array$orgsAn array of species names.
Returns
array An array of associated project ids.

Definition at line 49 of file tpps.queries.api.inc.

49  {
50  $query = db_select('chado.organism', 'o');
51  $query->join('chado.project_organism', 'po', 'po.organism_id = o.organism_id');
52  $query->fields('po', array('project_id'));
53  $or = tpps_api_query_or($orgs, array(
54  'o.genus',
55  'o.species',
56  ));
57  $query->condition($or);
58  return $query->execute();
59 }
tpps_api_query_or(array $vals, array $fields, $override_op=NULL)

◆ tpps_api_organization_pid_query()

tpps_api_organization_pid_query ( array  $orgs)

Returns array of project ids associated with provided organizations.

Parameters
array$orgsAn array of organization names.
Returns
array An array of associated project ids.

Definition at line 70 of file tpps.queries.api.inc.

70  {
71  $query = db_select('chado.contact', 'c');
72  $query->join('chado.contact_relationship', 'cr', 'c.contact_id = cr.object_id');
73  $query->join('chado.project_contact', 'pc', 'pc.contact_id = cr.subject_id');
74  $query->fields('pc', array('project_id'));
75  $or = tpps_api_query_or($orgs, array(
76  'c.name',
77  ));
78  $and = db_and()
79  ->condition('c.type_id', tpps_load_cvterm('organization')->cvterm_id)
80  ->condition($or);
81  $query->condition($and);
82  return $query->execute();
83 }
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)
tpps_api_query_or(array $vals, array $fields, $override_op=NULL)

◆ tpps_api_project_author_query()

tpps_api_project_author_query ( array  $pids,
  $entities = FALSE 
)

Returns array of authors associated with provided project ids.

This function currently does not support returning Tripal Entities.

Parameters
array$pidsAn array of project ids.
bool$entities(Placeholder) Whether or not to return entities.
Returns
array An array of pubauthor table record ids.

Definition at line 146 of file tpps.queries.api.inc.

146  {
147  $query = db_select('chado.project_pub', 'pp');
148  $query->join('chado.pubauthor', 'pa', 'pa.pub_id = pp.pub_id');
149  $query->fields('pa', array('pubauthor_id'));
150  $or = tpps_api_query_or($pids, array(
151  'pp.project_id',
152  ), '=');
153  $query->condition($or);
154  $query = $query->execute();
155  return $query->fetchCol();
156 }
tpps_api_query_or(array $vals, array $fields, $override_op=NULL)

◆ tpps_api_project_design_query()

tpps_api_project_design_query ( array  $pids)

Returns array of design information associated with provided project ids.

This function does not support returning Tripal Entities.

Parameters
array$pidsAn array of project ids.
Returns
array An array of study design information.

Definition at line 198 of file tpps.queries.api.inc.

198  {
199  $query = db_select('chado.projectprop', 'pp');
200  $query->join('chado.cvterm', 'c', 'c.cvterm_id = pp.type_id');
201  $query->fields('c', array('name'))
202  ->fields('pp', array('value'));
203  $or = tpps_api_query_or($pids, array(
204  'pp.project_id',
205  ), '=');
206  $query->condition($or);
207  $query = $query->execute();
208 
209  $results = array();
210  while (($result = $query->fetchObject())) {
211  $results[$result->name][] = $result->value;
212  }
213 
214  return $results;
215 }
tpps_api_query_or(array $vals, array $fields, $override_op=NULL)

◆ tpps_api_project_genotype_query()

tpps_api_project_genotype_query ( array  $pids,
  $entities = FALSE 
)

Returns array of genotypes associated with provided project ids.

Parameters
array$pidsAn array of project ids.
bool$entitiesWhether or not to return entities.
Returns
array An array of genotype ids or entities.

Definition at line 284 of file tpps.queries.api.inc.

284  {
285  $query = db_select('chado.project_stock', 'ps');
286  $query->join('chado.stock_genotype', 'sg', 'sg.stock_id = ps.stock_id');
287  $or = tpps_api_query_or($pids, array(
288  'ps.project_id',
289  ), '=');
290  $query->fields('sg', array('genotype_id'))
291  ->condition($or);
292  $query = $query->execute();
293 
294  $results = $query->fetchCol();
295 
296  if (!$entities) {
297  return $results;
298  }
299  return tpps_api_record_entities('Genotype', $results);
300 }
tpps_api_record_entities($label, array $record_ids)
tpps_api_query_or(array $vals, array $fields, $override_op=NULL)

◆ tpps_api_project_organism_query()

tpps_api_project_organism_query ( array  $pids,
  $entities = FALSE 
)

Returns array of species associated with provided project ids.

Parameters
array$pidsAn array of project ids.
bool$entitiesWhether or not to return entities.
Returns
array An array of organism ids or entities.

Definition at line 169 of file tpps.queries.api.inc.

169  {
170  $query = db_select('chado.project_organism', 'po')
171  ->fields('po', array('organism_id'));
172  $or = tpps_api_query_or($pids, array(
173  'po.project_id',
174  ), '=');
175  $query->condition($or);
176  $query = $query->execute();
177 
178  $results = $query->fetchCol();
179 
180  if (!$entities) {
181  return $results;
182  }
183 
184  return tpps_api_record_entities('Organism', $results);
185 }
tpps_api_record_entities($label, array $record_ids)
tpps_api_query_or(array $vals, array $fields, $override_op=NULL)

◆ tpps_api_project_phenotype_query()

tpps_api_project_phenotype_query ( array  $pids,
  $entities = FALSE 
)

Returns array of phenotype ids associated with provided project ids.

This function currently does not support returning Tripal Entities.

Parameters
array$pidsAn array of project ids.
bool$entities(Placeholder) Whether or not to return entities.
Returns
array An array of study design information.

Definition at line 259 of file tpps.queries.api.inc.

259  {
260  $query = db_select('chado.project_stock', 'ps');
261  $query->join('chado.stock_phenotype', 'sp', 'sp.stock_id = ps.stock_id');
262  $or = tpps_api_query_or($pids, array(
263  'ps.project_id',
264  ), '=');
265  $query->fields('sp', array('phenotype_id'))
266  ->condition($or);
267  $query = $query->execute();
268 
269  $results = $query->fetchCol();
270  return $results;
271 }
tpps_api_query_or(array $vals, array $fields, $override_op=NULL)

◆ tpps_api_project_publication_query()

tpps_api_project_publication_query ( array  $pids,
  $entities = FALSE 
)

Returns array of publications associated with provided project ids.

Parameters
array$pidsAn array of project ids.
bool$entitiesWhether or not to return entities.
Returns
array An array of publication ids or entities.

Definition at line 115 of file tpps.queries.api.inc.

115  {
116  $query = db_select('chado.project_pub', 'pp')
117  ->fields('pp', array('pub_id'));
118  $or = tpps_api_query_or($pids, array(
119  'pp.project_id',
120  ), '=');
121  $query->condition($or);
122  $query = $query->execute();
123 
124  $results = $query->fetchCol();
125 
126  if (!$entities) {
127  return $results;
128  }
129 
130  return tpps_api_record_entities('Publication', $results);
131 }
tpps_api_record_entities($label, array $record_ids)
tpps_api_query_or(array $vals, array $fields, $override_op=NULL)

◆ tpps_api_project_query()

tpps_api_project_query ( array  $pids,
  $entities = FALSE 
)

Returns array of projects associated with provided project ids.

Parameters
array$pidsAn array of project ids.
bool$entitiesWhether or not to return entities.
Returns
array An array of project ids or entities.

Definition at line 96 of file tpps.queries.api.inc.

96  {
97  if (!$entities) {
98  return $pids;
99  }
100 
101  return tpps_api_record_entities('Project', $pids);
102 }
tpps_api_record_entities($label, array $record_ids)

◆ tpps_api_project_stats_query()

tpps_api_project_stats_query ( array  $states)

Returns array of submission statistics based on provided submission states.

This function does not support returning Tripal Entities.

Parameters
array$statesAn array of TPPS submission states.
Returns
array An array of TPPS submission statistics.

Definition at line 313 of file tpps.queries.api.inc.

313  {
314  $results = array();
315  foreach ($states as $state) {
316  $results[] = $state['stats'];
317  }
318  return $results;
319 }

◆ tpps_api_project_stock_query()

tpps_api_project_stock_query ( array  $pids,
  $entities = FALSE 
)

Returns array of stocks associated with provided project ids.

Parameters
array$pidsAn array of project ids.
bool$entitiesWhether or not to return entities.
Returns
array An array of stock ids or entities.

Definition at line 228 of file tpps.queries.api.inc.

228  {
229  $query = db_select('chado.project_stock', 'p')
230  ->fields('p', array('stock_id'));
231  $or = tpps_api_query_or($pids, array(
232  'p.project_id',
233  ), '=');
234  $query->condition($or);
235  $query = $query->execute();
236 
237  $results = $query->fetchCol();
238 
239  if (!$entities) {
240  return $results;
241  }
242 
243  return tpps_api_record_entities('Stock', $results);
244 }
tpps_api_record_entities($label, array $record_ids)
tpps_api_query_or(array $vals, array $fields, $override_op=NULL)

◆ tpps_api_query_or()

tpps_api_query_or ( array  $vals,
array  $fields,
  $override_op = NULL 
)

Constructs a db_or() condition object for use with other TPPS API functions.

The default comparison operator is '~*', but this can be overriden by either specifying a different argument in square brackets following the value being compared, or by specifying a condition-wide operator in the override_op function parameter.

Parameters
array$valsThe values being compared in this condition.
array$fieldsThe columns that the values should be compared against.
string$override_opThe condition-wide overriding operator.
Returns
object The constructed db_or() condition object.

Definition at line 339 of file tpps.queries.api.inc.

339  {
340  $or = db_or();
341  foreach ($vals as $val) {
342  $op = '~*';
343  if (preg_match('/^(.*)\[(.+)\]$/', $val, $matches)) {
344  $val = $matches[1];
345  $op = $matches[2];
346  }
347  $op = !empty($override_op) ? $override_op : $op;
348  foreach ($fields as $field) {
349  $or->condition($field, $val, $op);
350  }
351  }
352  return $or;
353 }

◆ tpps_api_record_entities()

tpps_api_record_entities (   $label,
array  $record_ids 
)

Loads and returns entities that refer to the provided record ids.

This function takes a Tripal Entity label and an array of record ids and attempts to load the associated Tripal Entities. It will also attach fields that are not automatically attached by the Tripal Entity loader.

Parameters
string$labelThe label of the Tripal Entity type.
array$record_idsThe array of database record ids referred to by the Tripal Entities.
Returns
array An array of associated Tripal Entities.

Definition at line 370 of file tpps.queries.api.inc.

370  {
371  $bundle = tripal_load_bundle_entity(array('label' => $label));
372  $details = @tripal_get_bundle_details($bundle->name);
373 
374  $entity_ids = array();
375  foreach ($record_ids as $id) {
376  $entity_ids[] = chado_get_record_entity_by_bundle($bundle, $id);
377  }
378 
379  $field_ids = array();
380  if (!empty($details['fields'])) {
381  foreach ($details['fields'] as $field) {
382  $field_ids[] = field_info_field($field['name'])['id'];
383  }
384  }
385 
386  return tripal_load_entity('TripalEntity', $entity_ids, FALSE, $field_ids);
387 }