Go to the source code of this file.
Creates the Accession file form page and includes helper files.
Definition in file page_3.php.
◆ tpps_page_3_create_form()
tpps_page_3_create_form |
( |
array & |
$form, |
|
|
array & |
$form_state |
|
) |
| |
Creates the Accession file form page.
This function creates a single accession file field if the user has indicated that their study only includes one species. Otherwise, the user may choose to either upload a single accession file with every species type, or to upload multiple files sorted by species.
- Parameters
-
array | $form | The form to be populated. |
array | $form_state | The state of the form to be populated. |
Definition at line 24 of file page_3.php.
26 if (isset($form_state[
'saved_values'][
TPPS_PAGE_3])) {
33 if ($form_state[
'saved_values'][
TPPS_PAGE_2][
'study_type'] != 1) {
37 $form[
'existing_trees'] = array(
38 '#type' =>
'checkbox',
39 '#title' => t(
'These plants may have been studied in the past'),
40 '#description' => t(
'If this box is checked, TPPS will try to find plants with matching ids around the same location as the ones you are providing. If it finds them successfully, it will mark them as the same plant in the database.'),
44 $form[
'skip_validation'] = array(
45 '#type' =>
'checkbox',
46 '#title' => t(
'Skip location validation (ignore location information)'),
50 $form[
'tree-accession'] = array(
51 '#type' =>
'fieldset',
52 '#title' => t(
'Plant Accession Information'),
54 '#prefix' =>
'<div id="tpps_accession">',
55 '#suffix' =>
'</div>',
58 $species_number = $form_state[
'stats'][
'species_count'];
60 if ($species_number > 1) {
62 $form[
'tree-accession'][
'check'] = array(
63 '#type' =>
'checkbox',
64 '#title' => t(
'I would like to upload a separate plant accession file for each species.'),
66 'wrapper' =>
'tpps_accession',
67 'callback' =>
'tpps_accession_multi_file',
72 $file_description =
"Please upload a spreadsheet file containing plant population data. When your file is uploaded, you will be shown a table with your column header names, several drop-downs, and the first few rows of your file. You will be asked to define the data type for each column, using the drop-downs provided to you. If a column data type does not fit any of the options in the drop-down menu, you may omit that drop-down menu. Your file must contain columns with information about at least the Plant Identifier and the Location of the plant (either gps coordinates or country/state).";
73 $file_upload_location =
'public://' . variable_get(
'tpps_accession_files_dir',
'tpps_accession');
75 if ($form_state[
'saved_values'][
TPPS_PAGE_2][
'study_type'] ==
'4') {
76 $file_description .=
' Location columns should describe the location of the source plant for the Common Garden.';
79 if ($species_number > 1) {
80 $file_description .=
" If you are uploading a single file with multiple species, your file must also specify the genus and species of each plant.";
83 $image_path = drupal_get_path(
'module',
'tpps') .
'/images/';
84 $file_description .=
"Please find an example of an accession file below.<figure><img src=\"/{$image_path}accession_example.png\"><figcaption>Example Accession File</figcaption></figure>";
88 for ($i = 1; $i <= $species_number; $i++) {
89 $name = $form_state[
'saved_values'][
TPPS_PAGE_1][
'organism'][
"$i"][
'name'];
91 $column_options = array(
93 '1' =>
'Plant Identifier',
100 '12' =>
'Population Group',
101 '13' =>
'Clone Number',
104 $title = t(
"@name Accession File: *", array(
'@name' => $name)) .
"<br>$file_description";
105 if ($species_number > 1 and !$check) {
106 $title = t(
'Plant Accession File: *') .
"<br>$file_description";
107 $column_options[
'6'] =
'Genus';
108 $column_options[
'7'] =
'Species';
109 $column_options[
'10'] =
'Genus + Species';
112 if ($form_state[
'saved_values'][
TPPS_PAGE_2][
'study_type'] !=
'1') {
113 $column_options[
'11'] =
'Source Plant Identifier';
116 $form[
'tree-accession'][
"species-$i"] = array(
117 '#type' =>
'fieldset',
118 '#collapsible' => TRUE,
119 '#states' => ($i > 1) ? array(
121 ':input[name="tree-accession[check]"]' => array(
'checked' => TRUE),
126 $form[
'tree-accession'][
"species-$i"][
'file'] = array(
127 '#type' =>
'managed_file',
129 '#upload_location' => $file_upload_location,
130 '#upload_validators' => array(
131 'file_validate_extensions' => array(
'txt csv xlsx'),
133 '#field_prefix' =>
'<span style="width: 100%;display: block;text-align: right;padding-right: 2%;">Allowed file extensions: txt csv xlsx</span>',
134 '#suffix' =>
'<style>figure {}</style>',
136 '#default_value' => isset($values[
'tree-accession'][
"species-$i"][
'file'][
'empty']) ? $values[
'tree-accession'][
"species-$i"][
'file'][
'empty'] :
'NA',
139 '#description' => t(
'Please define which columns hold the required data: Plant Identifier and Location. If your plants are located based on a population group, you can provide the population group column and a mapping of population group to location below.'),
141 'no-header' => array(),
143 '#default_value' => isset($values[
'tree-accession'][
"species-$i"][
'file'][
'empty']) ? $values[
'tree-accession'][
"species-$i"][
'file'][
'empty'] :
'NA',
145 'columns-options' => array(
147 '#value' => $column_options,
151 $form[
'tree-accession'][
"species-$i"][
'coord-format'] = array(
153 '#title' => t(
'Coordinate Projection'),
158 'Other Coordinate Projection',
159 'My file does not use coordinates for plant locations',
161 '#states' => $form[
'tree-accession'][
"species-$i"][
'#states'] ?? NULL,
162 '#prefix' =>
"<div id=\"population-mapping-species-$i\">",
182 if (!empty($fid) and empty($skip)) {
183 $wrapper_id =
"{$fid}_map_wrapper";
184 $button_id =
"{$fid}_map_button";
185 $form[
'tree-accession'][
"species-$i"][
'coord-format'][
'#suffix'] =
"<div id=\"$wrapper_id\"></div>" 186 .
"<input id=\"$button_id\" type=\"button\" value=\"Click here to view plants on map!\" class=\"btn btn-primary map-button\"></input>";
194 $id_col = $lat_col = $long_col = NULL;
195 foreach ($cols as $key => $col) {
196 if ($key[0] !=
'#') {
197 if ((is_array($col) and $col[
'#value'] ==
'1') or (!is_array($col) and $col ==
'1')) {
200 if ((is_array($col) and $col[
'#value'] ==
'4') or (!is_array($col) and $col ==
'4')) {
203 if ((is_array($col) and $col[
'#value'] ==
'5') or (!is_array($col) and $col ==
'5')) {
211 'accession_files' => array(
213 'no_header' => $no_header,
215 'lat_col' => $lat_col,
216 'long_col' => $long_col,
225 'map_buttons' => array(
227 'wrapper' => $wrapper_id,
228 'button' => $button_id,
236 $form[
'tree-accession'][
"species-$i"][
'pop-group'] = array(
238 '#title' =>
'Population group mapping',
239 '#suffix' =>
'</div>',
243 $pop_group_show = FALSE;
248 foreach ($cols as $col_name => $data) {
249 if ($col_name[0] ==
'#') {
253 $fid = $form_state[
'saved_values'][
TPPS_PAGE_3][
'tree-accession'][
"species-$i"][
'file'] ?? NULL;
254 if (!empty($data[
'#value'])) {
255 $fid = $form_state[
'complete form'][
'tree-accession'][
"species-$i"][
'file'][
'#value'][
'fid'];
256 $val = $data[
'#value'];
268 $pop_group_show = TRUE;
269 $pop_col = $col_name;
277 if ($pop_group_show and !empty($fid) and ($file = file_load($fid))) {
278 $form[
'tree-accession'][
"species-$i"][
'pop-group'][
'#type'] =
'fieldset';
279 $pop_groups = array();
284 'pop_groups' => &$pop_groups,
287 foreach ($pop_groups as $pop_group) {
288 $form[
'tree-accession'][
"species-$i"][
'pop-group'][$pop_group] = array(
289 '#type' =>
'textfield',
290 '#title' =>
"Location for $name plants from group $pop_group:",
291 '#description' => t(
'The location for this population. This should be GPS coordinates if possbile, otherwise this can be the name of a location.'),
296 if ($found_lat and $found_lng) {
297 unset($form[
'tree-accession'][
"species-$i"][
'pop-group'][
'#suffix']);
298 $form[
'tree-accession'][
"species-$i"][
'exact_coords'] = array(
299 '#type' =>
'checkbox',
300 '#title' => t(
'The provided GPS coordinates are exact'),
301 '#default_value' => $form_state[
'saved_values'][TPPS_PAGE_3][
'tree-accession'][
"species-$i"][
'exact_coords'] ?? TRUE,
304 $form[
'tree-accession'][
"species-$i"][
'coord_precision'] = array(
305 '#type' =>
'textfield',
306 '#title' => t(
'Coordinates accuracy:'),
307 '#description' => t(
'The precision of the provided coordinates. For example, if a plant could be up to 10m awa from the provided coordinates, then the accuracy would be "10m".'),
308 '#suffix' =>
'</div>',
311 ":input[name=\"tree-accession[species-$i][exact_coords]\"]" => array(
'checked' => FALSE),
319 $map_api_key = variable_get(
'tpps_maps_api_key', NULL);
320 if (!empty($map_api_key)) {
321 $form[
'tree-accession'][
'#suffix'] .=
' 322 <script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"></script> 323 <script src="https://maps.googleapis.com/maps/api/js?key=' . $map_api_key .
'&callback=initMap" 324 async defer></script> 332 $form[
'Back'] = array(
334 '#value' => t(
'Back'),
335 '#prefix' =>
'<div class="input-description">* : Required Field</div>',
338 $form[
'Save'] = array(
340 '#value' => t(
'Save'),
343 $form[
'Next'] = array(
345 '#value' => t(
'Next'),
tpps_study_location(array &$form, array &$form_state)
tpps_file_iterator($fid, $function, array &$options=array())