Go to the source code of this file.
Defines the data integrity checks for the third page of the form.
Definition in file page_3.php.
◆ 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 | $row | The item yielded by the TPPS file generator. |
array | $options | Additional options set when calling tpps_file_iterator(). |
Definition at line 142 of file page_3.php.
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'];
151 if (gettype($location_types) !==
'array') {
152 $location_types = array($location_types);
155 if (!empty($row[$id_name])) {
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;
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]]})";
169 if ($valid_combination) {
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]}\".");
◆ 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 | $row | The item yielded by the TPPS file generator. |
array | $options | Additional options set when calling tpps_file_iterator(). |
Definition at line 192 of file page_3.php.
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'];
200 if (!empty($row[$id_name])) {
203 if ($species_type ==
'separate') {
205 foreach ($species_options[$species_type] as $column) {
206 $species[] = $row[$species_columns[$column]];
208 $species = implode(
' ', $species);
211 $species = $row[$species_columns[current($species_options[$species_type])]];
214 for ($i = 1; $i <= $organisms[
'number']; $i++) {
215 if ($species == $organisms[$i][
'name']) {
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.");
◆ 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 | $form | The form that is being validated. |
array | $form_state | The state of the form that is being validated. |
Definition at line 16 of file page_3.php.
17 if ($form_state[
'submitted'] ==
'1') {
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.'));
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.");
34 $species_number = $form_state[
'stats'][
'species_count'];
35 $multi_file = !empty($form_state[
'values'][
'tree-accession'][
'check']);
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'];
41 if (empty($values[
'file'])) {
42 form_set_error(
"tree-accession][species-$i][file", t(
'Plant Accession file: field is required.'));
45 $required_groups = array(
49 'Location (latitude/longitude or country/state or population group)' => array(
50 'approx' => array(2, 3),
52 'pop_group' => array(12),
56 if (!empty($form_state[
'values'][
'skip_validation'])) {
57 unset($required_groups[
'Location (latitude/longitude or country/state or population group)']);
60 if (!$multi_file and $species_number > 1) {
61 $required_groups[
'Genus and Species'] = array(
62 'separate' => array(6, 7),
63 'combined' => array(10),
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.");
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."));
81 if (!form_get_errors() and empty($form_state[
'values'][
'skip_validation'])) {
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'],
93 if (!form_get_errors() and (!$multi_file and $species_number > 1)) {
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'],
101 'page_1_species' => $form_state[
'saved_values'][
TPPS_PAGE_1][
'organism'],
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";
tpps_file_validate_columns(array &$form_state, array $required_groups, array $file_element)
tpps_file_iterator($fid, $function, array &$options=array())