Tripal Plant PopGen Submit
tpps_ajax.php
Go to the documentation of this file.
1 <?php
2 
16 function tpps_autocomplete($type, $string = "") {
17  $function = "tpps_{$type}_autocomplete";
18  if (function_exists($function)) {
19  $string = preg_replace('/\\\\/', '\\\\\\\\', $string);
20  $function($string);
21  }
22 }
23 
30 function tpps_author_autocomplete($string) {
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 }
46 
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 }
67 
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 }
88 
95 function tpps_organization_autocomplete($string) {
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 }
111 
118 function tpps_journal_autocomplete($string) {
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 }
133 
140 function tpps_species_autocomplete($string) {
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 }
169 
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 }
195 
202 function tpps_phenotype_autocomplete($string) {
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 }
218 
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 }
241 
248 function tpps_genotype_autocomplete($string) {
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 }
262 
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 }
283 
290 function tpps_attribute_autocomplete($string) {
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 }
313 
320 function tpps_units_autocomplete($string) {
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 }
337 
344 function tpps_structure_autocomplete($string) {
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 }
379 
386 function tpps_user_autocomplete($string) {
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 }
402 
417 function tpps_no_header_callback(array $form, array &$form_state) {
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_phenotype_ontology_autocomplete($string)
Definition: tpps_ajax.php:225
tpps_autocomplete($type, $string="")
Definition: tpps_ajax.php:16
tpps_units_autocomplete($string)
Definition: tpps_ajax.php:320
tpps_attribute_autocomplete($string)
Definition: tpps_ajax.php:290
tpps_journal_autocomplete($string)
Definition: tpps_ajax.php:118
tpps_ncbi_species_autocomplete($string)
Definition: tpps_ajax.php:176
tpps_author_autocomplete($string)
Definition: tpps_ajax.php:30
tpps_project_title_autocomplete($string)
Definition: tpps_ajax.php:53
tpps_ncbi_get_taxon_id($organism, $list=FALSE)
Definition: ncbi_utils.inc:82
tpps_no_header_callback(array $form, array &$form_state)
Definition: tpps_ajax.php:417
tpps_species_autocomplete($string)
Definition: tpps_ajax.php:140
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)
tpps_project_accession_autocomplete($string)
Definition: tpps_ajax.php:74
tpps_user_autocomplete($string)
Definition: tpps_ajax.php:386
tpps_structure_autocomplete($string)
Definition: tpps_ajax.php:344
tpps_genotype_autocomplete($string)
Definition: tpps_ajax.php:248
tpps_organization_autocomplete($string)
Definition: tpps_ajax.php:95
tpps_phenotype_autocomplete($string)
Definition: tpps_ajax.php:202
tpps_genotype_marker_autocomplete($string)
Definition: tpps_ajax.php:269