Tripal Plant PopGen Submit
tpps_ajax.php File Reference

Go to the source code of this file.

Functions

 tpps_attribute_autocomplete ($string)
 
 tpps_author_autocomplete ($string)
 
 tpps_autocomplete ($type, $string="")
 
 tpps_genotype_autocomplete ($string)
 
 tpps_genotype_marker_autocomplete ($string)
 
 tpps_journal_autocomplete ($string)
 
 tpps_ncbi_species_autocomplete ($string)
 
 tpps_no_header_callback (array $form, array &$form_state)
 
 tpps_organization_autocomplete ($string)
 
 tpps_phenotype_autocomplete ($string)
 
 tpps_phenotype_ontology_autocomplete ($string)
 
 tpps_project_accession_autocomplete ($string)
 
 tpps_project_title_autocomplete ($string)
 
 tpps_species_autocomplete ($string)
 
 tpps_structure_autocomplete ($string)
 
 tpps_units_autocomplete ($string)
 
 tpps_user_autocomplete ($string)
 

Detailed Description

Defines some ajax callback functions that TPPS uses often.

Definition in file tpps_ajax.php.

Function Documentation

◆ tpps_attribute_autocomplete()

tpps_attribute_autocomplete (   $string)

Phenotype attribute auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 290 of file tpps_ajax.php.

290  {
291  $matches = array();
292  $attributes = array();
293  $attr_results = chado_select_record('phenotype', array('distinct attr_id'), array());
294 
295  foreach ($attr_results as $result) {
296  $attributes[] = $result->attr_id;
297  }
298 
299  $results = chado_select_record('cvterm', array('name'), array(
300  'name' => array(
301  'data' => $string,
302  'op' => '~*',
303  ),
304  'cvterm_id' => $attributes,
305  ));
306 
307  foreach ($results as $row) {
308  $matches[$row->name] = check_plain($row->name);
309  }
310 
311  drupal_json_output($matches);
312 }

◆ tpps_author_autocomplete()

tpps_author_autocomplete (   $string)

Author auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 30 of file tpps_ajax.php.

30  {
31  $matches = array();
32 
33  $results = chado_select_record('contact', array('name'), array(
34  'name' => $string,
35  'type_id' => tpps_load_cvterm('person')->cvterm_id,
36  ), array(
37  'regex_columns' => array('name'),
38  ));
39 
40  foreach ($results as $row) {
41  $matches[$row->name] = check_plain($row->name);
42  }
43 
44  drupal_json_output($matches);
45 }
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)

◆ tpps_autocomplete()

tpps_autocomplete (   $type,
  $string = "" 
)

Call the correct autocomplete function based on the type provided.

Parameters
string$typeThe type of autocomplete function needed.
string$stringThe string to be autocompleted.

Definition at line 16 of file tpps_ajax.php.

16  {
17  $function = "tpps_{$type}_autocomplete";
18  if (function_exists($function)) {
19  $string = preg_replace('/\\\\/', '\\\\\\\\', $string);
20  $function($string);
21  }
22 }

◆ tpps_genotype_autocomplete()

tpps_genotype_autocomplete (   $string)

Genotype name auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 248 of file tpps_ajax.php.

248  {
249  $matches = array();
250 
251  $query = db_select('chado.tpps_search_genotype_name', 'g')
252  ->fields('g', array('name'))
253  ->condition('g.name', $string, '~*')
254  ->execute();
255 
256  while (($result = $query->fetchObject())) {
257  $matches[$result->name] = check_plain($result->name);
258  }
259 
260  drupal_json_output($matches);
261 }

◆ tpps_genotype_marker_autocomplete()

tpps_genotype_marker_autocomplete (   $string)

Genotype marker name auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 269 of file tpps_ajax.php.

269  {
270  $matches = array();
271 
272  $query = db_select('chado.tpps_search_genotype_marker', 'g')
273  ->fields('g', array('name'))
274  ->condition('g.name', $string, '~*')
275  ->execute();
276 
277  while (($result = $query->fetchObject())) {
278  $matches[$result->name] = check_plain($result->name);
279  }
280 
281  drupal_json_output($matches);
282 }

◆ tpps_journal_autocomplete()

tpps_journal_autocomplete (   $string)

Journal auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 118 of file tpps_ajax.php.

118  {
119  $matches = array();
120 
121  $results = chado_select_record('pub', array('series_name'), array(
122  'series_name' => $string,
123  ), array(
124  'regex_columns' => array('series_name'),
125  ));
126 
127  foreach ($results as $row) {
128  $matches[$row->series_name] = check_plain($row->series_name);
129  }
130 
131  drupal_json_output($matches);
132 }

◆ tpps_ncbi_species_autocomplete()

tpps_ncbi_species_autocomplete (   $string)

NCBI species auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 176 of file tpps_ajax.php.

176  {
177  $matches = array();
178 
179  $taxons = tpps_ncbi_get_taxon_id("$string*", TRUE);
180  $taxons = json_decode(json_encode($taxons))->Id;
181 
182  $fetch = new EFetch('taxonomy');
183  $fetch->addParam('id', implode(',', $taxons));
184  $response = $fetch->get()->xml();
185  $species = json_decode(json_encode($response))->Taxon;
186 
187  foreach ($species as $info) {
188  $name = $info->ScientificName;
189  if (!empty($name) and $info->Rank == 'species') {
190  $matches[$name] = "$name (autocomplete from NCBI)";
191  }
192  }
193  return $matches;
194 }
tpps_ncbi_get_taxon_id($organism, $list=FALSE)
Definition: ncbi_utils.inc:82

◆ tpps_no_header_callback()

tpps_no_header_callback ( array  $form,
array &  $form_state 
)

Indicate the managed_file element to be updated.

This function is called after a no_header element is changed, triggering an update of the managed_file element.

Parameters
array$formThe form that needs to be updated.
array$form_stateThe state of the form that needs to be updated.
Returns
array The element in the form to be updated.

Definition at line 417 of file tpps_ajax.php.

417  {
418 
419  $parents = $form_state['triggering_element']['#parents'];
420  array_pop($parents);
421 
422  $element = drupal_array_get_nested_value($form, $parents);
423  return $element;
424 }

◆ tpps_organization_autocomplete()

tpps_organization_autocomplete (   $string)

Organization auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 95 of file tpps_ajax.php.

95  {
96  $matches = array();
97 
98  $results = chado_select_record('contact', array('name'), array(
99  'name' => $string,
100  'type_id' => tpps_load_cvterm('organization')->cvterm_id,
101  ), array(
102  'regex_columns' => array('name'),
103  ));
104 
105  foreach ($results as $row) {
106  $matches[$row->name] = check_plain($row->name);
107  }
108 
109  drupal_json_output($matches);
110 }
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)

◆ tpps_phenotype_autocomplete()

tpps_phenotype_autocomplete (   $string)

Phenotype name auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 202 of file tpps_ajax.php.

202  {
203  $matches = array();
204 
205  $results = chado_select_record('phenotype', array('name'), array(
206  'name' => array(
207  'data' => $string,
208  'op' => '~*',
209  ),
210  ));
211 
212  foreach ($results as $row) {
213  $matches[$row->name] = check_plain($row->name);
214  }
215 
216  drupal_json_output($matches);
217 }

◆ tpps_phenotype_ontology_autocomplete()

tpps_phenotype_ontology_autocomplete (   $string)

Phenotype ontology name auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 225 of file tpps_ajax.php.

225  {
226  $matches = array();
227 
228  $query = db_select('chado.phenotype', 'p');
229  $query->join('chado.cvterm', 'cvt', 'cvt.cvterm_id = p.attr_id');
230  $query->join('chado.cv', 'cv', 'cv.cv_id = cvt.cv_id');
231  $query->fields('cv', array('name'));
232  $query->condition('cv.name', $string, '~*');
233  $query = $query->execute();
234 
235  while (($result = $query->fetchObject())) {
236  $matches[$result->name] = check_plain($result->name);
237  }
238 
239  drupal_json_output($matches);
240 }

◆ tpps_project_accession_autocomplete()

tpps_project_accession_autocomplete (   $string)

Project accession number auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 74 of file tpps_ajax.php.

74  {
75  $matches = array();
76 
77  $query = db_select('chado.plusgeno_view', 'p')
78  ->fields('p', array('accession'))
79  ->condition('accession', $string, '~*')
80  ->execute();
81 
82  while (($result = $query->fetchObject())) {
83  $matches[$result->accession] = check_plain($result->accession);
84  }
85 
86  drupal_json_output($matches);
87 }

◆ tpps_project_title_autocomplete()

tpps_project_title_autocomplete (   $string)

Project title auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 53 of file tpps_ajax.php.

53  {
54  $matches = array();
55 
56  $query = db_select('chado.plusgeno_view', 'p')
57  ->fields('p', array('title'))
58  ->condition('title', $string, '~*')
59  ->execute();
60 
61  while (($result = $query->fetchObject())) {
62  $matches[$result->title] = check_plain($result->title);
63  }
64 
65  drupal_json_output($matches);
66 }

◆ tpps_species_autocomplete()

tpps_species_autocomplete (   $string)

Species auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 140 of file tpps_ajax.php.

140  {
141  $matches = array();
142 
143  $parts = explode(" ", $string);
144  if (!isset($parts[1])) {
145  $parts[1] = ".";
146  }
147 
148  $results = chado_select_record('organism', array('genus', 'species'), array(
149  'genus' => array(
150  'data' => $parts[0],
151  'op' => '~*',
152  ),
153  'species' => array(
154  'data' => $parts[1],
155  'op' => '~*',
156  ),
157  ));
158 
159  foreach ($results as $row) {
160  $matches[$row->genus . " " . $row->species] = check_plain($row->genus . " " . $row->species);
161  }
162 
163  if (empty($matches)) {
164  $matches = tpps_ncbi_species_autocomplete($string);
165  }
166 
167  drupal_json_output($matches);
168 }
tpps_ncbi_species_autocomplete($string)
Definition: tpps_ajax.php:176

◆ tpps_structure_autocomplete()

tpps_structure_autocomplete (   $string)

Phenotype structure auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 344 of file tpps_ajax.php.

344  {
345  $matches = array();
346  $structures = array();
347  $struct_results = chado_select_record('phenotype', array('distinct observable_id'), array());
348 
349  foreach ($struct_results as $result) {
350  $structures[] = $result->observable_id;
351  }
352 
353  $results = chado_select_record('cvterm', array('name'), array(
354  'name' => array(
355  'data' => $string,
356  'op' => '~*',
357  ),
358  'cvterm_id' => $structures,
359  ));
360 
361  if (empty($results)) {
362  $results = chado_select_record('cvterm', array('name'), array(
363  'name' => array(
364  'data' => $string,
365  'op' => '~*',
366  ),
367  ));
368  }
369 
370  foreach ($results as $row) {
371  $matches[$row->name] = check_plain($row->name);
372  if (!empty($row->definition)) {
373  $matches[$row->name] = check_plain($row->name . ': ' . $row->definition);
374  }
375  }
376 
377  drupal_json_output($matches);
378 }

◆ tpps_units_autocomplete()

tpps_units_autocomplete (   $string)

Phenotype units auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 320 of file tpps_ajax.php.

320  {
321  $matches = array();
322 
323  $results = chado_select_record('phenotypeprop', array('value'), array(
324  'value' => array(
325  'data' => $string,
326  'op' => '~*',
327  ),
328  'type_id' => tpps_load_cvterm('unit')->cvterm_id,
329  ));
330 
331  foreach ($results as $row) {
332  $matches[$row->value] = check_plain($row->value);
333  }
334 
335  drupal_json_output($matches);
336 }
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)

◆ tpps_user_autocomplete()

tpps_user_autocomplete (   $string)

User account auto-complete matching.

Parameters
string$stringThe string the user has already entered into the text field.

Definition at line 386 of file tpps_ajax.php.

386  {
387  $matches = array();
388  $or = db_or()
389  ->condition('mail', $string, '~*')
390  ->condition('name', $string, '~*');
391  $result = db_select('users')
392  ->fields('users', array('uid', 'name'))
393  ->condition($or)
394  ->execute();
395  foreach ($result as $user) {
396  $user = user_load($user->uid);
397  $matches["$user->mail"] = check_plain($user->name);
398  }
399 
400  drupal_json_output($matches);
401 }