Tripal Plant PopGen Submit
page_4.php File Reference

Go to the source code of this file.

Functions

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

Detailed Description

Creates GxPxE Data form page and includes helper files.

Definition in file page_4.php.

Function Documentation

◆ tpps_page_4_create_form()

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

Creates the GxPxE Data form page.

This function creates the genotype, phenotype, and environmental fieldsets based on the data type selection made on page 2. It will then call all necessary helper functions.

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

Definition at line 23 of file page_4.php.

23  {
24  if (isset($form_state['saved_values'][TPPS_PAGE_4])) {
25  $values = $form_state['saved_values'][TPPS_PAGE_4];
26  }
27  else {
28  $values = array();
29  }
30 
31  $form['#tree'] = TRUE;
32 
33  $organism_number = $form_state['saved_values'][TPPS_PAGE_1]['organism']['number'];
34  $data_type = $form_state['saved_values'][TPPS_PAGE_2]['data_type'];
35  for ($i = 1; $i <= $organism_number; $i++) {
36 
37  $name = $form_state['saved_values'][TPPS_PAGE_1]['organism']["$i"]['name'];
38 
39  $form["organism-$i"] = array(
40  '#type' => 'fieldset',
41  '#title' => "<div class=\"fieldset-title\">$name:</div>",
42  '#tree' => TRUE,
43  '#collapsible' => TRUE,
44  );
45 
46  if (preg_match('/P/', $data_type)) {
47  if ($i > 1) {
48  $form["organism-$i"]['phenotype-repeat-check'] = array(
49  '#type' => 'checkbox',
50  '#title' => "Phenotype information for $name is the same as phenotype information for {$form_state['saved_values'][TPPS_PAGE_1]['organism'][$i - 1]['name']}.",
51  '#default_value' => isset($values["organism-$i"]['phenotype-repeat-check']) ? $values["organism-$i"]['phenotype-repeat-check'] : 1,
52  );
53  }
54 
55  $form["organism-$i"]['phenotype'] = tpps_phenotype($form, $form_state, $values, "organism-$i");
56 
57  if ($i > 1) {
58  $form["organism-$i"]['phenotype']['#states'] = array(
59  'invisible' => array(
60  ":input[name=\"organism-$i\[phenotype-repeat-check]\"]" => array('checked' => TRUE),
61  ),
62  );
63  }
64 
65  $normal_check = tpps_get_ajax_value($form_state, array(
66  "organism-$i",
67  'phenotype',
68  'normal-check',
69  ), TRUE);
70  if (!empty($normal_check)) {
71  $image_path = drupal_get_path('module', 'tpps') . '/images/';
72  $form["organism-$i"]['phenotype']['format'] = array(
73  '#type' => 'radios',
74  '#title' => t('Phenotype file format: *'),
75  '#options' => array(
76  'Type 1',
77  'Type 2',
78  ),
79  '#ajax' => array(
80  'callback' => 'tpps_phenotype_file_format_callback',
81  'wrapper' => "edit-organism-$i-phenotype-file-ajax-wrapper",
82  ),
83  '#default_value' => (isset($form_state['saved_values'][TPPS_PAGE_4]["organism-$i"]['phenotype']['format'])) ? $form_state['saved_values'][TPPS_PAGE_4]["organism-$i"]['phenotype']['format'] : 0,
84  '#description' => t('Please select a file format type from the listed options. Below please see examples of each format type.'),
85  '#states' => array(
86  'invisible' => array(
87  ":input[name=\"organism-{$i}[phenotype][phenotypes-meta][number]\"]" => array('value' => '0'),
88  ":input[name=\"organism-{$i}[phenotype][check]\"]" => array('checked' => FALSE),
89  ),
90  ),
91  );
92 
93  $form["organism-$i"]['phenotype']['format'][0]['#prefix'] = "<figure><img src=\"/{$image_path}phenotype_format_1.png\"><figcaption>";
94  $form["organism-$i"]['phenotype']['format'][0]['#suffix'] = "</figcaption></figure>";
95  $form["organism-$i"]['phenotype']['format'][1]['#prefix'] = "<figure><img src=\"/{$image_path}phenotype_format_2.png\"><figcaption>";
96  $form["organism-$i"]['phenotype']['format'][1]['#suffix'] = "</figcaption></figure>";
97 
98  $form["organism-$i"]['phenotype']['file'] = array(
99  '#type' => 'managed_file',
100  '#title' => t('Phenotype file: Please upload a file containing columns for Plant Identifier, Phenotype Data: *'),
101  '#upload_location' => 'public://' . variable_get('tpps_phenotype_files_dir', 'tpps_phenotype'),
102  '#upload_validators' => array(
103  'file_validate_extensions' => array('csv tsv xlsx'),
104  ),
105  '#tree' => TRUE,
106  '#states' => array(
107  'invisible' => array(
108  ":input[name=\"organism-{$i}[phenotype][phenotypes-meta][number]\"]" => array('value' => '0'),
109  ":input[name=\"organism-{$i}[phenotype][check]\"]" => array('checked' => FALSE),
110  ),
111  ),
112  );
113 
114  $form["organism-$i"]['phenotype']['file']['empty'] = array(
115  '#default_value' => isset($values["organism-$i"]['phenotype']['file']['empty']) ? $values["organism-$i"]['phenotype']['file']['empty'] : 'NA',
116  );
117 
118  $form["organism-$i"]['phenotype']['file']['columns'] = array(
119  '#description' => t('Please define which columns hold the required data: Plant Identifier, Phenotype name, and Value(s)'),
120  );
121 
122 
123  $format = tpps_get_ajax_value($form_state, array(
124  "organism-$i",
125  'phenotype',
126  'format',
127  ), 0);
128 
129  if ($format == 0) {
130  $column_options = array(
131  'Phenotype Data',
132  'Plant Identifier',
133  'Timepoint',
134  'Clone Number',
135  'N/A',
136  );
137  }
138  else {
139  $column_options = array(
140  'N/A',
141  'Plant Identifier',
142  'Phenotype Name/Identifier',
143  'Value(s)',
144  'Timepoint',
145  'Clone Number',
146  );
147  $form["organism-$i"]['phenotype']['file']['#title'] = t('Phenotype file: Please upload a file containing columns for Plant Identifier, Phenotype Name, and value for all of your phenotypic data: *');
148  }
149 
150  $form["organism-$i"]['phenotype']['file']['columns-options'] = array(
151  '#type' => 'hidden',
152  '#value' => $column_options,
153  );
154 
155  $form["organism-$i"]['phenotype']['file']['no-header'] = array();
156  }
157  }
158 
159  if (preg_match('/G/', $data_type)) {
160  if ($i > 1) {
161  $form["organism-$i"]['genotype-repeat-check'] = array(
162  '#type' => 'checkbox',
163  '#title' => "Genotype information for $name is the same as genotype information for {$form_state['saved_values'][TPPS_PAGE_1]['organism'][$i - 1]['name']}.",
164  '#default_value' => isset($values["organism-$i"]['genotype-repeat-check']) ? $values["organism-$i"]['genotype-repeat-check'] : 1,
165  );
166  }
167 
168  $form["organism-$i"]['genotype'] = tpps_genotype($form, $form_state, $values, "organism-$i");
169 
170  if ($i > 1) {
171  $form["organism-$i"]['genotype']['#states'] = array(
172  'invisible' => array(
173  ":input[name=\"organism-$i\[genotype-repeat-check]\"]" => array('checked' => TRUE),
174  ),
175  );
176  }
177 
178  }
179 
180  if (preg_match('/E/', $data_type)) {
181  if ($i > 1) {
182  $form["organism-$i"]['environment-repeat-check'] = array(
183  '#type' => 'checkbox',
184  '#title' => "Environmental information for $name is the same as environmental information for {$form_state['saved_values'][TPPS_PAGE_1]['organism'][$i - 1]['name']}.",
185  '#default_value' => isset($values["organism-$i"]['environment-repeat-check']) ? $values["organism-$i"]['environment-repeat-check'] : 1,
186  );
187  }
188 
189  $form["organism-$i"]['environment'] = tpps_environment($form, $form_state, "organism-$i");
190 
191  if ($i > 1) {
192  $form["organism-$i"]['environment']['#states'] = array(
193  'invisible' => array(
194  ":input[name=\"organism-$i\[environment-repeat-check]\"]" => array('checked' => TRUE),
195  ),
196  );
197  }
198  }
199  }
200 
201  $form['Back'] = array(
202  '#type' => 'submit',
203  '#value' => t('Back'),
204  '#prefix' => '<div class="input-description">* : Required Field</div>',
205  );
206 
207  $form['Save'] = array(
208  '#type' => 'submit',
209  '#value' => t('Save'),
210  );
211 
212  $form['submit'] = array(
213  '#type' => 'submit',
214  '#value' => t('Review Information and Submit'),
215  );
216 
217  if (preg_match('/G/', $data_type)) {
218  $pre_valid_states = array();
219  for ($i = 1; $i <= $organism_number; $i++) {
220  $pre_valid_states["input[name=\"organism-{$i}[genotype][files][file-type][VCF]\"]"] = array('checked' => FALSE);
221  }
222  $form['pre_validate'] = array(
223  '#type' => 'button',
224  '#value' => t('Pre-validate my VCF files'),
225  '#states' => array(
226  'invisible' => $pre_valid_states,
227  ),
228  '#suffix' => '<div>Sometimes large VCF files can cause problems during the validation step. If your VCF file is very large, you can click the "Pre-validate my VCF files" button to validate your VCF file in the background, before clicking "Review Information and Submit".</div>',
229  );
230 
231  $form['Back']['#prefix'] .= "<div id=\"pre-validate-message\"></div>";
232  }
233 }
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_genotype(array &$form, array &$form_state, array $values, $id)
tpps_get_ajax_value(array &$state, array $parents, $default=NULL, $file_name="")
Definition: form_utils.inc:236
tpps_environment(array &$form, array &$form_state, $id)
tpps_phenotype(array &$form, array &$form_state, array $values, $id)
const TPPS_PAGE_4
Definition: tpps.module:15
const TPPS_PAGE_2
Definition: tpps.module:13