Tripal Plant PopGen Submit
page_3_helper.php File Reference

Go to the source code of this file.

Functions

 tpps_accession_pop_groups ($row, array &$options)
 
 tpps_study_location (array &$form, array &$form_state)
 

Detailed Description

Define the helper functions for the Plant Accession page.

Definition in file page_3_helper.php.

Function Documentation

◆ tpps_accession_pop_groups()

tpps_accession_pop_groups (   $row,
array &  $options 
)

This function processes a single row of an accession file.

This function populates the pop_groups attribute of the options array with the names of all the selected population groups from an accession file. This function is meant to be used with tpps_file_iterator().

Parameters
mixed$rowThe item yielded by the TPPS file generator.
array$optionsAdditional options set when calling tpps_file_iterator().

Definition at line 154 of file page_3_helper.php.

154  {
155  $groups = &$options['pop_groups'];
156  $col = current($options['columns']);
157  if (array_search($row[$col], $groups) === FALSE) {
158  $groups[] = $row[$col];
159  }
160 }

◆ tpps_study_location()

tpps_study_location ( array &  $form,
array &  $form_state 
)

This function creates fields describing the study location.

Parameters
array$formThe form to be populated.
array$form_stateThe state of the form to be populated.
Returns
array The populated form.

Definition at line 19 of file page_3_helper.php.

19  {
20 
21  $form['study_location'] = array(
22  '#type' => 'fieldset',
23  '#title' => t('<div class="fieldset-title">Study Location:</div>'),
24  '#tree' => TRUE,
25  '#collapsible' => TRUE,
26  '#description' => t('This should be the location(s) of your common garden, plantation, etc.'),
27  '#prefix' => '<div id="common-garden-loc">',
28  '#suffix' => '</div>',
29  );
30 
31  $form['study_location']['type'] = array(
32  '#type' => 'select',
33  '#title' => t('Coordinate Projection: *'),
34  '#options' => array(
35  0 => t('- Select -'),
36  1 => t('WGS 84'),
37  3 => t('NAD 83'),
38  4 => t('ETRS 89'),
39  2 => t('Custom Location (brief description)'),
40  ),
41  '#ajax' => array(
42  'callback' => 'tpps_update_locations',
43  'wrapper' => 'common-garden-loc',
44  ),
45  '#attributes' => array(
46  'data-toggle' => array('tooltip'),
47  'data-placement' => array('right'),
48  'title' => array('Please select a Coordinate Projection, or select "Custom Location", to enter a custom study location'),
49  ),
50  );
51 
52  $type = tpps_get_ajax_value($form_state, array(
53  'study_location',
54  'type',
55  ), NULL);
56 
57  $field = array(
58  '#type' => 'textfield',
59  '#title' => 'Location !num: *',
60  );
61 
62  if ($type != 2) {
63  $field['#description'] = t('Accepted formats: <br>Degrees Minutes Seconds: 41° 48\' 27.7" N, 72° 15\' 14.4" W<br>Degrees Decimal Minutes: 41° 48.462\' N, 72° 15.24\' W<br>Decimal Degrees: 41.8077° N, 72.2540° W<br>');
64  }
65 
66  tpps_dynamic_list($form, $form_state, 'locations', $field, array(
67  'label' => 'Location',
68  'title' => 'Study Location(s):',
69  'parents' => array('study_location'),
70  'callback' => 'tpps_update_locations',
71  'default' => 1,
72  'wrapper' => 'common-garden-loc',
73  'substitute_fields' => array(
74  '#title',
75  ),
76  ));
77 
78  $form['study_location']['locations']['#states'] = array(
79  'invisible' => array(
80  ':input[name="study_location[type]"]' => array('value' => '0'),
81  ),
82  );
83 
84  if ($type != 2 and $type != 0) {
85  $form['study_location']['map-button'] = array(
86  '#type' => 'button',
87  '#title' => 'Click here to update map',
88  '#value' => 'Click here to update map',
89  '#button_type' => 'button',
90  '#name' => 'study_locations_map_button',
91  '#executes_submit_callback' => FALSE,
92  '#prefix' => '<div id="study_location_map">',
93  '#suffix' => '</div>',
94  '#ajax' => array(
95  'callback' => 'tpps_study_location_map_ajax',
96  'wrapper' => 'study_location_map',
97  ),
98  );
99  }
100 
101  $locs = tpps_get_ajax_value($form_state, array('study_location', 'locations'), NULL);
102 
103  if ($form_state['triggering_element']['#name'] == 'study_locations_map_button' and $type != 2 and !empty($locs) and !empty($locs['number'])) {
104  $coords = array();
105  $valid_coords = TRUE;
106  for ($i = 1; $i <= $locs['number']; $i++) {
107  if (empty($locs[$i])) {
108  $valid_coords = FALSE;
109  drupal_set_message(t('Location %num is required', array('%num' => $i)), 'error');
110  continue;
111  }
112  $raw_coord = $locs[$i];
113  $standard_coordinate = tpps_standard_coord($raw_coord);
114  if ($standard_coordinate) {
115  $parts = explode(',', $standard_coordinate);
116  $coords[] = array(
117  "Location $i",
118  $parts[0],
119  $parts[1],
120  );
121  continue;
122  }
123  $valid_coords = FALSE;
124  drupal_set_message(t('Location %num: Invalid coordinates', array('%num' => $i)), 'error');
125  }
126 
127  if (!empty($coords) and $valid_coords) {
128  $map_api_key = variable_get('tpps_maps_api_key', NULL);
129  $map_api_tools = "<script src=\"https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js\"></script><script src=\"https://maps.googleapis.com/maps/api/js?key=$map_api_key&callback=initMap\"
130  async defer></script>"
131  . "<div id=\"_map_wrapper\"></div>";
132  drupal_add_js(array('tpps' => array('tree_info' => $coords)), 'setting');
133  drupal_add_js(array('tpps' => array('study_locations' => TRUE)), 'setting');
134 
135  $form['study_location']['map-button']['#suffix'] = $map_api_tools;
136  }
137  }
138 
139  return $form;
140 }
tpps_standard_coord($raw_coordinate)
tpps_get_ajax_value(array &$state, array $parents, $default=NULL, $file_name="")
Definition: form_utils.inc:236
tpps_dynamic_list(array &$form, array &$form_state, $id, array $repeat, array $options=array())
Definition: form_utils.inc:29