Tripal Plant PopGen Submit
page_3.php File Reference

Go to the source code of this file.

Functions

 tpps_accession_valid_locations ($row, array &$options)
 
 tpps_accession_valid_species ($row, array &$options)
 
 tpps_page_3_validate_form (array &$form, array &$form_state)
 

Detailed Description

Defines the data integrity checks for the third page of the form.

Definition in file page_3.php.

Function Documentation

◆ tpps_accession_valid_locations()

tpps_accession_valid_locations (   $row,
array &  $options 
)

This function processes a single row of a plant accession file.

This function validates that the accession file has valid/complete location information for each plant. 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 142 of file page_3.php.

142  {
143  $id_name = $options['id_col'];
144  $empty = $options['empty'];
145  $location_options = $options['loc_options'];
146  $location_columns = $options['loc_cols'];
147  $location_types = $location_columns['#type'] ?? array();
148  $org_num = $options['org_num'];
149  $reason = "";
150 
151  if (gettype($location_types) !== 'array') {
152  $location_types = array($location_types);
153  }
154 
155  if (!empty($row[$id_name])) {
156  $valid_row = FALSE;
157  foreach ($location_types as $type) {
158  $valid_combination = TRUE;
159  foreach ($location_options[$type] as $column) {
160  if (empty($row[$location_columns[$column]]) or $row[$location_columns[$column]] == $empty) {
161  $valid_combination = FALSE;
162  $reason = "missing";
163  }
164  elseif ($type == 'gps' and abs($row[$location_columns[$column]]) > 180) {
165  $valid_combination = FALSE;
166  $reason = "invalid (invalid coordinate value: {$row[$location_columns[$column]]})";
167  }
168  }
169  if ($valid_combination) {
170  $valid_row = TRUE;
171  break;
172  }
173  }
174  if (!$valid_row) {
175  form_set_error("tree-accession-species-$org_num-file-{$row[$id_name]}", "Plant Accession file: Some location information is $reason for plant \"{$row[$id_name]}\".");
176  }
177  }
178 }

◆ tpps_accession_valid_species()

tpps_accession_valid_species (   $row,
array &  $options 
)

This function processes a single row of a plant accession file.

This function validates that the accession file has valid/complete species information for each plant. 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 192 of file page_3.php.

192  {
193  $id_name = $options['id_col'];
194  $species_options = $options['species_options'];
195  $species_columns = $options['species_cols'];
196  $species_type = $species_columns['#type'];
197  $org_num = $options['org_num'];
198  $organisms = $options['page_1_species'];
199 
200  if (!empty($row[$id_name])) {
201  $valid_row = FALSE;
202 
203  if ($species_type == 'separate') {
204  $species = array();
205  foreach ($species_options[$species_type] as $column) {
206  $species[] = $row[$species_columns[$column]];
207  }
208  $species = implode(' ', $species);
209  }
210  else {
211  $species = $row[$species_columns[current($species_options[$species_type])]];
212  }
213 
214  for ($i = 1; $i <= $organisms['number']; $i++) {
215  if ($species == $organisms[$i]['name']) {
216  $valid_row = TRUE;
217  break;
218  }
219  }
220 
221  if (!$valid_row) {
222  form_set_error("tree-accession-species-$org_num-file-{$row[$id_name]}", "Plant Accession file: Some species information is invalid for plant \"{$row[$id_name]}\". The species name, \"$species\", does not match any species name supplied on the Author and Species information page. Please correct the file or add the correct species name.");
223  }
224  }
225 }

◆ tpps_page_3_validate_form()

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

Defines the data integrity checks for the third page of the form.

Parameters
array$formThe form that is being validated.
array$form_stateThe state of the form that is being validated.

Definition at line 16 of file page_3.php.

16  {
17  if ($form_state['submitted'] == '1') {
18  unset($form_state['file_info'][TPPS_PAGE_3]);
19 
20  if (!empty($form_state['values']['study_location'])) {
21  if (!$form_state['values']['study_location']['type']) {
22  form_set_error('study_location][type', t('Location Format: field is required.'));
23  }
24  else {
25  $locs = $form_state['values']['study_location']['locations'];
26  for ($i = 1; $i <= $locs['number']; $i++) {
27  if (empty($locs[$i])) {
28  form_set_error("study_location][locations][$i", "Location $i: field is required.");
29  }
30  }
31  }
32  }
33 
34  $species_number = $form_state['stats']['species_count'];
35  $multi_file = !empty($form_state['values']['tree-accession']['check']);
36 
37  for ($i = 1; $i <= $species_number; $i++) {
38  $values = &$form_state['values']['tree-accession']["species-$i"];
39  $file_element = $form['tree-accession']["species-$i"]['file'];
40 
41  if (empty($values['file'])) {
42  form_set_error("tree-accession][species-$i][file", t('Plant Accession file: field is required.'));
43  }
44  else {
45  $required_groups = array(
46  'Tree Id' => array(
47  'id' => array(1),
48  ),
49  'Location (latitude/longitude or country/state or population group)' => array(
50  'approx' => array(2, 3),
51  'gps' => array(4, 5),
52  'pop_group' => array(12),
53  ),
54  );
55 
56  if (!empty($form_state['values']['skip_validation'])) {
57  unset($required_groups['Location (latitude/longitude or country/state or population group)']);
58  }
59 
60  if (!$multi_file and $species_number > 1) {
61  $required_groups['Genus and Species'] = array(
62  'separate' => array(6, 7),
63  'combined' => array(10),
64  );
65  }
66 
67  $groups = tpps_file_validate_columns($form_state, $required_groups, $file_element);
68 
69  if (gettype($values['pop-group']) === 'array') {
70  foreach ($values['pop-group'] as $pop_name => $location) {
71  if (empty($location)) {
72  form_set_error("tree-accession][species-$i][pop-group][$pop_name", "Population Group $pop_name Location: field is required.");
73  }
74  }
75  }
76 
77  if (isset($values['exact_coords']) and !$values['exact_coords'] and empty($values['coord_precision'])) {
78  form_set_error("tree-accession][species-$i][coord_precision", t("Coordinates accuracy: field is required."));
79  }
80 
81  if (!form_get_errors() and empty($form_state['values']['skip_validation'])) {
82  $options = array(
83  'no_header' => !empty($values['file-no-header']),
84  'loc_options' => $required_groups['Location (latitude/longitude or country/state or population group)'],
85  'id_col' => $groups['Tree Id']['1'],
86  'loc_cols' => $groups['Location (latitude/longitude or country/state or population group)'],
87  'empty' => $values['file-empty'],
88  'org_num' => $i,
89  );
90  tpps_file_iterator($values['file'], 'tpps_accession_valid_locations', $options);
91  }
92 
93  if (!form_get_errors() and (!$multi_file and $species_number > 1)) {
94  $options = array(
95  'no_header' => !empty($values['file-no-header']),
96  'species_options' => $required_groups['Genus and Species'],
97  'id_col' => $groups['Tree Id']['1'],
98  'species_cols' => $groups['Genus and Species'],
99  'empty' => $values['file-empty'],
100  'org_num' => $i,
101  'page_1_species' => $form_state['saved_values'][TPPS_PAGE_1]['organism'],
102  );
103  tpps_file_iterator($values['file'], 'tpps_accession_valid_species', $options);
104  }
105 
106  tpps_preserve_valid_file($form_state, $values['file'], $i, "Plant_Accession");
107  }
108 
109  if (!$multi_file) {
110  break;
111  }
112  }
113 
114  if (form_get_errors()) {
115  $form_state['rebuild'] = TRUE;
116  $new_form = drupal_rebuild_form('tpps_main', $form_state, $form);
117  for ($i = 1; $i <= $species_number; $i++) {
118  $form['tree-accession']["species-$i"]['file']['upload'] = $new_form['tree-accession']["species-$i"]['file']['upload'];
119  $form['tree-accession']["species-$i"]['file']['columns'] = $new_form['tree-accession']["species-$i"]['file']['columns'];
120  $form['tree-accession']["species-$i"]['file']['upload']['#id'] = "edit-tree-accession-species-$i-file-upload";
121  $form['tree-accession']["species-$i"]['file']['columns']['#id'] = "edit-tree-accession-species-$i-file-columns";
122  if (!$multi_file) {
123  break;
124  }
125  }
126  }
127  }
128 }
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_preserve_valid_file(array &$form_state, $fid, $org_num=NULL, $prefix=NULL)
Definition: form_utils.inc:328
tpps_file_validate_columns(array &$form_state, array $required_groups, array $file_element)
Definition: file_utils.inc:442
const TPPS_PAGE_3
Definition: tpps.module:14
tpps_file_iterator($fid, $function, array &$options=array())