This repository was archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfarm_grazing.plan.dashboard.inc
More file actions
287 lines (257 loc) · 12.4 KB
/
farm_grazing.plan.dashboard.inc
File metadata and controls
287 lines (257 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
/**
* @file
* Grazing dashboard form.
*/
/**
* Management concerns form callback.
*/
function farm_grazing_plan_dashboard_form($form, &$form_state, $plan_obj) {
$plan = $plan_obj->id;
$wrapper = entity_metadata_wrapper('farm_plan', $plan);
$grazing_growing_season = $wrapper->field_grazing_growing_season->value();
$farm_grazing_factors = $wrapper->field_farm_grazing_factors->value();
$days_bulk_feeding = $wrapper->field_days_bulk_feeding->value();
$days_of_drought_reserve = $wrapper->field_days_of_drought_reserve->value();
$expected_rotations = $wrapper->field_expected_rotations->value();
$start_ts = $wrapper->field_farm_date_range->value->value();
$end_ts = $wrapper->field_farm_date_range->value2->value();
$expected_days_non_growth = floor(($end_ts - $start_ts) / 3600 / 24);
$form['plan'] = array(
'#type' => 'value',
'#value' => $plan,
);
if (!$grazing_growing_season) {
$form['non_growing'] = array(
'#type' => 'value',
'#value' => !$grazing_growing_season,
);
}
$form['spacer_1'] = array(
'#prefix' => '<br><p>',
'#markup' => t('Click the sections below to open/close them.'),
'#suffix' => '</p><br>',
'#weight' => 101,
);
// Add introductory text.
$form['introduction'] = array(
'#type' => 'fieldset',
'#title' => t('Getting Started'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 105,
);
// get the path to the herds rotations we use below
$current_path = base_path() . current_path();
$rotation_url = trim($current_path, "#") . '/herds/rotations';
$animal_types_url = base_path() . 'admin/config/farm/grazing_animal_types';
$form['introduction']['text'] = array(
'#type' => 'markup',
'#markup' => '<p>' . t('Welcome to the Holistic Grazing Planning Application.') . '</p>' .
'<h4>' . t('For the First Time') . '</h4>' .
'<p>' . t('To get started, you need to:') .
'<ul>' .
'<li>' . t('Define your ranch\'s paddocks. This is done on the "Areas" tab at the top of the page. This needs to be done once initially and anytime you decide to change the layout of paddocks on the ranch.') . '</li>' .
'<li>' . t('Review and add Animal types ') .
'<a href="' . $animal_types_url . '">' . t('HERE') . '</a>' . t(' that you will be working with.') . '</li>' .
'</ul>' .
'</p>' .
'<h4>' . t('Making a Plan') . '</h4>' .
'<p>' . t('This is the "active" plan you are working with. The planning process follows the order of the tabs from left to right and top to bottom. You can revisit any tab as needed to review or change your inputs. Most of the tabs are focused on collecting data needed to build your plan. Planning the paddock rotations is done on ') . '<a href="' . $rotation_url . '">' . t('Herds/Rotations') . '</a>' . t(' tab.') . '</p>' .
'<p>' . t('The Plan tab will bring you back here and the Settings tab allows you edit information about the plan.') . '</p>' .
'<p>' . t('Next Steps: Simple open the "Management Concerns" section below and enter data there and then work your way across the Paddocks and Herds tabs both have sub-menu steps that you should work left to right.') . '</p>',
);
$form['concerns'] = array(
'#type' => 'fieldset',
'#title' => t('Management Concerns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 110,
);
$form['concerns']['section_1']['text'] = array(
// '<h2>Management concerns</h2>' .
'#markup' =>
'<p>' . t('In this section, think about various factors that influence your calendar for the plan. Consider:') . '</p>' .
'<ul>' .
'<li>' . t('Livestock events like birthing, breeding, weaning, etc and when these are planned.') .
'<li>' . t('Management events such as vacations, family or community events that need to be planned around.') .
'<li>' . t('Other specific events like hunting seasons, parasites, or flooding that might influence the sequence of paddock moves.') .
'<li>' . t('Enter these concerns below. You will want to add to this and review it as you are doing your planning and planning the herd rotations.') .
'</ul>',
);
$form['concerns']['section_2']['factors'] = array(
'#title' => t('Planning factors'),
'#type' => 'textarea',
'#description' => t('Enter your planning factors here'),
'#default_value' => $farm_grazing_factors['value'],
);
$form['concerns']['factors_format'] = array(
'#type' => 'value',
'#value' => $farm_grazing_factors['format'],
);
if (!$grazing_growing_season) {
$form['concerns']['non_growing'] = array(
'#type' => 'fieldset',
'#title' => t('Non-growing plan variables'),
'#description' => t('Enter the follow parameters for the non-growing season plan.'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['concerns']['non_growing']['days_bulk_feeding'] = array(
'#type' => 'textfield',
'#title' => t('Days of bulk feeding'),
'#default_value' => $days_bulk_feeding,
'#required' => TRUE,
);
$form['concerns']['non_growing']['days_of_drought_reserve'] = array(
'#type' => 'textfield',
'#title' => t('Days of drought reserve required'),
'#default_value' => $days_of_drought_reserve,
'#required' => TRUE,
);
$form['concerns']['non_growing']['expected_days_non_growth'] = array(
'#type' => 'textfield',
'#title' => t('Expected days of non-growth'),
'#default_value' => $expected_days_non_growth,
'#disabled' => TRUE,
);
$form['concerns']['non_growing']['expected_rotations'] = array(
'#type' => 'textfield',
'#title' => t('Number of planned rotations through paddocks'),
'#default_value' => $expected_rotations,
'#required' => TRUE,
);
}
$form['concerns']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Changes'),
'#submit' => array('farm_grazing_plan_dashboard_form_submit'),
'#validate' => array('farm_grazing_plan_dashboard_form_validate'),
);
// Add "Implement the plan" content.
$form['implement'] = array(
'#type' => 'fieldset',
'#title' => t('Implementing the plan'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 120,
);
$form['implement']['content'] = array(
'#type' => 'markup',
'#markup' => '<h4>' . t('Recheck your plan') . '</h4>' .
'<p>' . t('Review your plan regularly, print out reports, check that the plan is on track and make adjustments as needed.') . '</p>' .
'<h4>' . t('Monitor Your Paddocks') . '</h4>' .
'<p>' . t('Monitor the growth and recovery of your paddocks. Also assess the quality of the paddock you are moving the herd to and record it as a monitor event here. All the paddock moves in the active plans are shown on the ') . l(t('Dashboard Task List'), '/') . t(' and you can check them off when they are completed, but you should also make observations about the paddock you are moving out of and into.') . '</p>' .
'<ul>' .
'<li><a href="' . current_path() . '/herds">' . t('Herds Tab for detailed movement records') . '</a></li>' .
'<ul>' .
'<li>' . t('Select a herd to move') . '</li>' .
'<li>' . t('Click Add activity') . '</li>' .
'<li>' . t('Click Movements') . '</li>' .
'<li>' . t('Select paddock for "Movement to"') . '</li>' .
'<li>' . t('Click "Save Log"') . '</li>' .
'</ul>' .
'<li><a href="' . base_path() . 'farm/area">' . t('Observations on paddock leaving') . '</a></li>' .
'<ul><ul>' .
'<li>' . t('Select paddock you are making an observation of') . '</li>' .
'<li>' . t('Click "Add Observation"') . '</li>' .
'<li>' . t('Use "General" for errors or general text comments') . '</li>'
.
'<li>' . t('Use "Quantity"->"Add another item" to add quantity observations') . '</li>' .
'</ul></ul>' .
'<ul>' .
'<li>' . t('Residual feed left on the paddock') . '</li>' .
'<li>' . t('The current growth rate on the paddock') . '</li>' .
'<li>' . t('Was a serious error made on the paddock') . '</li>' .
'<li>' . t('Soil moisture') . '</li>' .
'</ul>' .
'<li><a href="' . base_path() . 'farm/area">' . t('Observations on paddock entering') . '</a></li>' .
'<ul><ul>' .
'<li>' . t('Select paddock you are making an observation of') . '</li>' .
'<li>' . t('Click "Add Observation"') . '</li>' .
'<li>' . t('Use "General" for errors or general text comments') . '</li>' .
'<li>' . t('Use "Quantity"->"Add another item" to add quantity observations') . '</li>' .
'</ul></ul>' .
'<ul>' .
'<li>' . t('Quality of paddock') . '</li>' .
'<li>' . t('Estimate of feed on paddock') . '</li>' .
'<li>' . t('Soil moisture') . '</li>' .
'</ul>' .
'</ul>' .
'<h4>' . t('How to Replan if Needed') . '</h4>' .
'<p>' . t('You can make changes to your plan at any time. Actual events obviously can not be changed, but you can replan future events. There are two approaches to replanning.') . '<ol>' .
'<li>' . t('is to just update the current plan for minor changes') . '</li>' .
'<li>' . t('another is to create a new plan, for major changes, based on the remaining days and abandon the old plan for now.') . '</li>' .
'<p>' . t('The advantage to making a new plan is that you can keep the original plan around for archival purposes and look at it in the future to re-assess assumptions or conditions that changed and forced the replan. On the new plan, you might need to sell stock to reduce the requirements for intake if you are in a drought or had a fire that burnt through some padocks or add more paddocks that you had not planned to use in the original plan. If you only need to make minor changes then use your existing plan, otherwise start a new plan.') . '</p>',
);
return $form;
}
/**
* theme_farm_grazing_plan_dashboard_form
*
* theme handler for farm_grazing_plan_dashboard_form
*/
function theme_farm_grazing_plan_dashboard_form($variables) {
$form = &$variables['form'];
$plan = $form['plan']['#value'];
// $growing_season = $form['growing_season']['#value'];.
$output = drupal_render($form['plan']);
$output .= drupal_render($form['spacer_1']);
$output .= drupal_render($form['introduction']);
$output .= drupal_render($form['section_1']['text']);
$output .= drupal_render($form['section_2']['factors']);
$output .= drupal_render($form['factors_format']);
if (array_key_exists('non_growing', $form)) {
$output .= drupal_render($form['non_growing']);
}
$output .= drupal_render_children($form);
return $output;
}
/**
* farm_grazing_plan_dashboard_form_validate
*
* validate handler for farm_grazing_plan_dashboard_form
*/
function farm_grazing_plan_dashboard_form_validate($form, &$form_state) {
// Load the plan object into an EntityMetadataWrapper.
$wrapper = entity_metadata_wrapper('farm_plan', $form_state['values']['plan']);
// Only perform the following validation if this is a non-growing season.
if (!empty($wrapper->field_grazing_growing_season->value())) {
return;
}
if (!is_numeric($form_state['values']['days_bulk_feeding']) or
$form_state['values']['days_bulk_feeding'] < 0) {
form_set_error('days_bulk_feeding', t('Days bulk feeding must be numeric >= 0'));
}
if (!is_numeric($form_state['values']['days_of_drought_reserve']) or
$form_state['values']['days_of_drought_reserve'] < 0) {
form_set_error('days_of_drought_reserve', t('Days of drought reserve required must be numeric >= 0'));
}
if (!is_numeric($form_state['values']['expected_rotations']) or
$form_state['values']['expected_rotations'] < 0) {
form_set_error('expected_rotations', t('Number of planned rotations must be numeric >= 0'));
}
}
/**
* farm_grazing_plan_dashboard_form_submit
*
* submit handler for farm_grazing_plan_dashboard_form
*/
function farm_grazing_plan_dashboard_form_submit($form, &$form_state) {
$wrapper = entity_metadata_wrapper('farm_plan', $form_state['values']['plan']);
if (isset($form_state['values']['factors'])) {
$wrapper->field_farm_grazing_factors->set(array(
'value' => $form_state['values']['factors'],
));
}
if (isset($form_state['values']['days_bulk_feeding'])) {
$wrapper->field_days_bulk_feeding->set($form_state['values']['days_bulk_feeding']);
}
if (isset($form_state['values']['days_of_drought_reserve'])) {
$wrapper->field_days_of_drought_reserve->set($form_state['values']['days_of_drought_reserve']);
}
if (isset($form_state['values']['expected_rotations'])) {
$wrapper->field_expected_rotations->set($form_state['values']['expected_rotations']);
}
$wrapper->save();
}