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

Go to the source code of this file.

Functions

 tpps_api_submission_info ()
 
 tpps_api_submission_query ()
 
 tpps_api_submission_std_query (array &$conditions)
 

Detailed Description

Defines TPPS API functions for submission-related operations.

Definition in file tpps.submission.api.inc.

Function Documentation

◆ tpps_api_submission_info()

tpps_api_submission_info ( )

Returns information about submissions based on provided accessions.

This function will return data and possibly Tripal Entities for TPPS submissions based on provided accessions and data requests. Possible data that can be retrieved using this function includes: project publication author organism design stock phenotype genotype stats By default, the function will simply return the database ids of the associated data, but if the entities parameter is provided and set to true, the function will instead return Tripal Entites of associated data if possible. Data options that currently support Tripal Entities include: project publication organism stock genotype For example, to retrieve the database ids of the authors and species associated with a TPPS submission, you could call submission_info?accessions=TGDR001&data=author,organism If you instead want to return the Tripal Entities for the species, call submission_info?accessions=TGDR001&data=author,organism&entities=TRUE The returned information is sorted by data type, and if entities are both requested and valid, then the information for that data type will be indexed by Tripal Entity id.

Returns
array An array of information about the specified TPPS Submissions.

Definition at line 171 of file tpps.submission.api.inc.

171  {
172  $params = drupal_get_query_parameters();
173  if (empty($params['accessions'])) {
174  return NULL;
175  }
176 
177  if (empty($params['data'])) {
178  return NULL;
179  }
180 
181  $entities = FALSE;
182  if (array_key_exists('entities', $params)) {
183  $entities = $params['entities'];
184  }
185 
186  $accessions = explode(',', $params['accessions']);
187  $states = tpps_load_submission_multiple(array('accession' => $accessions));
188  $pids = array();
189  foreach ($states as $state) {
190  $pids[] = $state['ids']['project_id'];
191  }
192  $data_types = explode(',', $params['data']);
193  $results = array();
194  foreach ($data_types as $type) {
195  $function_name = "tpps_api_project_{$type}_query";
196  if ($type == 'project') {
197  $function_name = "tpps_api_project_query";
198  }
199 
200  if ($type == 'stats') {
201  $results[$type] = $function_name($states);
202  continue;
203  }
204 
205  if (!function_exists($function_name)) {
206  return NULL;
207  }
208 
209  $results[$type] = $function_name($pids, $entities);
210  }
211 
212  return $results;
213 }
tpps_load_submission_multiple(array $conditions=array(), $state=TRUE)
Definition: submissions.inc:85

◆ tpps_api_submission_query()

tpps_api_submission_query ( )

Returns information about TPPS submissions satisfying provided conditions.

This function first calls the tpps_api_submission_std_query function with the provided conditions, then filters the list of submissions using the various tpps_api_*_pid_query functions if there are remaining unused conditions. The supported standard query conditions include: accession number tpps_submission table record id submission uid submisison status submission dbxref_id submission state Supported additional query conditions include: author organism organization The default database comparison operator is '~*', but different operators can be specified using square brackets. For example, calling submission?organization=University would produce a condition like WHERE name ~* 'University' but calling submission?organization=University[LIKE] would produce a condition like WHERE name LIKE 'University'

Returns
array An array of information about submissions that satisfy the conditions.

Definition at line 38 of file tpps.submission.api.inc.

38  {
39  $conditions = drupal_get_query_parameters();
40 
41  $submissions = tpps_api_submission_std_query($conditions);
42  if (!empty($conditions)) {
43  foreach ($conditions as $key => $val) {
44  $pids = array();
45  $vals = explode(',', $val);
46  $function_name = "tpps_api_{$key}_pid_query";
47 
48  if (!function_exists($function_name)) {
49  return array();
50  }
51 
52  $query = $function_name($vals);
53  while (($result = $query->fetchObject())) {
54  $pids[] = $result->project_id;
55  }
56 
57  if (empty($pids)) {
58  return array();
59  }
60 
61  foreach ($submissions as $num => $state) {
62  if (array_search($state['ids']['project_id'], $pids) === FALSE) {
63  unset($submissions[$num]);
64  }
65  }
66  }
67  }
68 
69  $results = array();
70  foreach ($submissions as $submission) {
71  $results[] = array(
72  'accession' => $submission['accession'],
73  'data' => $submission['saved_values'],
74  'dbxref_id' => $submission['dbxref_id'],
75  'file_info' => $submission['file_info'] ?? NULL,
76  'file_rank' => $submission['file_rank'] ?? NULL,
77  'ids' => $submission['ids'] ?? NULL,
78  'job_id' => $submission['job_id'] ?? NULL,
79  'stage' => $submission['stage'],
80  'stats' => $submission['stats'] ?? NULL,
81  'status' => $submission['status'],
82  'submitting_uid' => $submission['submitting_uid'] ?? NULL,
83  'tpps_type' => $submission['tpps_type'] ?? NULL,
84  );
85  }
86 
87  return $results;
88 }
tpps_api_submission_std_query(array &$conditions)

◆ tpps_api_submission_std_query()

tpps_api_submission_std_query ( array &  $conditions)

Performs the initial TPPS submission standard query.

This function filters submissions by conditions that match columns in the tpps_submission table. These columns include: tpps_submission_id accession uid status dbxref_id submission_state The function will also unset items in the conditions array that have already been used, so that the tpps_api_submission_query function knows whether to perform additional query filtering. If no conditions in the conditions array match the columns of the tpps_submission table, this function will simply return all TPPS submissions found in the table.

Parameters
array$conditionsThe conditions to filter the submission query by.
Returns
array An array of submissions that satisfy the provided conditions.

Definition at line 114 of file tpps.submission.api.inc.

114  {
115  $args = array();
116  $valid_args = tpps_table_columns('tpps_submission');
117  foreach ($conditions as $key => $val) {
118  if (array_search($key, $valid_args)) {
119  $args[$key] = explode(',', $val);
120  unset($conditions[$key]);
121  }
122  }
123 
124  $states = tpps_load_submission_multiple($args);
125  $results = array();
126  foreach ($states as $state) {
127  if (!isset($state['ids']['project_id'])) {
128  continue;
129  }
130  $results[$state['ids']['project_id']] = $state;
131  }
132  return $results;
133 }
tpps_load_submission_multiple(array $conditions=array(), $state=TRUE)
Definition: submissions.inc:85
tpps_table_columns($table)