Tripal Plant PopGen Submit
tpps.api.inc File Reference

Go to the source code of this file.

Functions

 tpps_api_call ($type, $id=NULL, array $query=array())
 
 tpps_api_check_accession ($accession=NULL)
 
 tpps_api_compress_files ($accession=NULL)
 
 tpps_api_paths ()
 
 tpps_api_refresh_views ()
 

Detailed Description

Main file for the TPPS API.

This file includes the other TPPS API files, defines required paths that TPPS uses for its api, provides a function which can be used to call the API internally, and a function to verify that a provided accession number has a valid TPPS submission associated with it.

Definition in file tpps.api.inc.

Function Documentation

◆ tpps_api_call()

tpps_api_call (   $type,
  $id = NULL,
array  $query = array() 
)

Performs a TPPS API call.

This function will perform an internal call to the TPPS API. It constructs a TPPS API url, performs a get request, and decodes the resulting JSON object.

Parameters
string$typeThe base API path to be called.
string$idAn id to be passed to the base API path. (Optional)
array$queryAny additional query arguments to be passed to the API.
Returns
mixed The decoded JSON object returned by the API.

Definition at line 131 of file tpps.api.inc.

131  {
132  global $base_url;
133  $path = $base_url . "/tpps/api/$type";
134  if (!empty($id)) {
135  $path .= "/$id";
136  }
137  if (!empty($query)) {
138  $args = array();
139  foreach ($query as $key => $val) {
140  $args[] = "$key=$val";
141  }
142  $path .= "?" . implode("&", $args);
143  }
144  $response = file_get_contents($path);
145  return json_decode($response);
146 }

◆ tpps_api_check_accession()

tpps_api_check_accession (   $accession = NULL)

Verifies an existing TPPS accession number.

If the provided accession has a valid existing TPPS submission, return TRUE. Otherwise, return FALSE.

Parameters
string$accessionThe accession to be verified.
Returns
bool TRUE if there exists a valid TPPS submission, otherwise FALSE.

Definition at line 160 of file tpps.api.inc.

160  {
161  if (empty($accession)) {
162  return FALSE;
163  }
164 
165  return tpps_load_submission($accession) ? TRUE : FALSE;
166 }
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27

◆ tpps_api_compress_files()

tpps_api_compress_files (   $accession = NULL)

Creates and downloads a .zip file of all relevant files for the submission.

Parameters
string$accessionThe accession number of the submission with the associated files.

Definition at line 174 of file tpps.api.inc.

174  {
175  $state = tpps_load_submission($accession);
176  if (empty($state)) {
177  throw new Exception('Invalid state accession number');
178  }
179  ob_end_clean();
180  $zip_name = "{$accession}_files.zip";
181  if (!file_exists(drupal_realpath(TPPS_TEMP_ZIP))) {
182  mkdir(drupal_realpath(TPPS_TEMP_ZIP));
183  }
184  $zip_loc = drupal_realpath(TPPS_TEMP_ZIP) . '/' . $zip_name;
185 
186  $files = $state['files'];
187  foreach ($files as $fid) {
188  $file_str[] = str_replace(' ', '\\ ', drupal_realpath(file_load($fid)->uri));
189  }
190 
191  if (file_exists(drupal_realpath($zip_loc))) {
192  unlink($zip_loc);
193  }
194 
195  $file_str = implode(" ", $file_str);
196  $cmd = "zip -j $zip_loc $file_str";
197  exec($cmd);
198  drupal_add_http_header('Content-Type', 'application/zip');
199  drupal_add_http_header('Content-Disposition', 'attachment; filename="' . $zip_name . '"');
200  drupal_add_http_header('Content-length', filesize($zip_loc));
201  drupal_add_http_header('Pragma', "no-cache");
202  drupal_add_http_header('Expires', '0');
203 
204  readfile("$zip_loc");
205  exit;
206 }
const TPPS_TEMP_ZIP
Definition: tpps.module:17
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27

◆ tpps_api_paths()

tpps_api_paths ( )

Defines TPPS API paths.

This function is called from the tpps_menu() function and returns the menu items that TPPS will use for its API. All API paths start with tpps/api/ and return their data as JSON objects. The api paths include: check_accession/<accession number>=""> submission/<accession number>=""> submissions?<arguments> submission_info?<arguments> Details about each of the paths can be found in the inline documentation of this function, as well as the documentation for each of the functions the API calls.

Returns
array An array of menu items.

Definition at line 33 of file tpps.api.inc.

33  {
34  $items = array();
35 
36  // tpps/api/refresh_views calls tpps_api_refresh_views which will
37  // update the tpps specific views used in particular for details pages
38  $items['tpps/api/refresh_views'] = array(
39  'title' => 'TPPS Refresh Views',
40  'page callback' => 'tpps_api_refresh_views',
41  'page arguments' => array(),
42  'access arguments' => array('access content'),
43  'delivery callback' => 'drupal_json_output',
44  'type' => MENU_CALLBACK,
45  );
46 
47  // tpps/api/check_accession calls tpps_api_check_accession on a provided
48  // accession number. It will return TRUE for accessions with a valid
49  // TPPS submission and FALSE for all other accessions.
50  $items['tpps/api/check_accession/%'] = array(
51  'title' => 'TPPS Check Accession',
52  'page callback' => 'tpps_api_check_accession',
53  'page arguments' => array(3),
54  'access callback' => 'tpps_access',
55  'access arguments' => array('access content'),
56  'delivery callback' => 'drupal_json_output',
57  'type' => MENU_CALLBACK,
58  );
59 
60  // tpps/api/submission calls tpps_load_submission on a provided accession.
61  // If a valid TPPS submission exists for the accession, it will return the
62  // form_state of the submission.
63  $items['tpps/api/submission/%'] = array(
64  'title' => 'TPPS Raw Submissions',
65  'page callback' => 'tpps_load_submission',
66  'page arguments' => array(3),
67  'access callback' => 'tpps_access',
68  'access arguments' => array('access content'),
69  'delivery callback' => 'drupal_json_output',
70  'type' => MENU_CALLBACK,
71  );
72 
73  // tpps/api/submissions calls tpps_api_submission_query. If no query
74  // conditions are provided, it will return information about all of the
75  // existing valid TPPS submissions. Otherwise, it will filter the submissions
76  // based on the provided conditions. Please see the tpps_api_submission_query
77  // function for more details.
78  $items['tpps/api/submissions'] = array(
79  'title' => 'TPPS Submissions Query',
80  'page callback' => 'tpps_api_submission_query',
81  'page arguments' => array(),
82  'access callback' => 'tpps_access',
83  'access arguments' => array('access content'),
84  'delivery callback' => 'drupal_json_output',
85  'type' => MENU_CALLBACK,
86  );
87 
88  // tpps/api/submission_info calls tpps_api_submission_info. It will return
89  // data on multiple TPPS submissions based on accessions provided in the
90  // API query. The data returned can be specified using the data query
91  // argument. Please see the tpps_api_submission_info function for more
92  // details.
93  $items['tpps/api/submission_info'] = array(
94  'title' => 'TPPS Submission Data',
95  'page callback' => 'tpps_api_submission_info',
96  'page arguments' => array(),
97  'access callback' => 'tpps_access',
98  'access arguments' => array('access content'),
99  'delivery callback' => 'drupal_json_output',
100  'type' => MENU_CALLBACK,
101  );
102 
103  $items['tpps/api/files/%'] = array(
104  'title' => 'TPPS Submission Files Download',
105  'page callback' => 'tpps_api_compress_files',
106  'page arguments' => array(3),
107  'access callback' => 'tpps_access',
108  'access arguments' => array('access tpps details'),
109  'type' => MENU_NORMAL_ITEM,
110  );
111 
112  return $items;
113 }

◆ tpps_api_refresh_views()

tpps_api_refresh_views ( )

Definition at line 209 of file tpps.api.inc.

209  {
210  db_query('refresh materialized view chado.tpps_search_genotype_name;');
211  db_query('refresh materialized view chado.tpps_search_genotype_marker;');
212  return TRUE;
213 }