Commit 90f1f402 authored by Jonathan Hunt's avatar Jonathan Hunt

#58 Avoid PHP warning if no pitch data entered.

parent 4a98e66a
......@@ -28,71 +28,74 @@ function climbnz_route_form_alter(&$form, &$form_state, $form_id) {
*/
function climbnz_route_node_presave($node) {
if ($node->type == 'route') {
// If first Pitch is not empty, or we have multiple Pitches.
if (!climbnz_pitch_field_is_empty($node->field_pitch[LANGUAGE_NONE][0], array()) ||
count($node->field_pitch[LANGUAGE_NONE]) > 1) {
$grades = array();
$length = 0;
$bolts = 0;
$natural_pro = 0;
$grade_ewbank_options = climbnz_pitch_grade_ewbank_options();
$grade_alpine_technical_options = climbnz_pitch_grade_alpine_technical_options();
$grade_alpine_commitment_options = climbnz_pitch_grade_alpine_commitment_options();
$grade_alpine_mtcook_options = climbnz_pitch_grade_alpine_mtcook_options();
$grade_aid_options = climbnz_pitch_grade_aid_options();
$grade_water_ice_options = climbnz_pitch_grade_water_ice_options();
$grade_mixed_options = climbnz_pitch_grade_mixed_options();
$grade_boulder_options = climbnz_pitch_grade_boulder_options();
foreach ($node->field_pitch[LANGUAGE_NONE] as $pitch) {
// Show aggregate value.
switch ($node->field_route_type[LANGUAGE_NONE][0]['value']) {
case 'alpine':
$route_grades = array(
!empty($pitch['grade_alpine_commitment']) ? $grade_alpine_commitment_options[$pitch['grade_alpine_commitment']] : NULL,
!empty($pitch['grade_alpine_technical']) ? $grade_alpine_technical_options[$pitch['grade_alpine_technical']] : NULL,
!empty($pitch['grade_alpine_mtcook']) ? $grade_alpine_mtcook_options[$pitch['grade_alpine_mtcook']] : NULL,
!empty($pitch['grade_ewbank']) ? $grade_ewbank_options[$pitch['grade_ewbank']] : NULL,
!empty($pitch['grade_aid']) ? $grade_aid_options[$pitch['grade_aid']] : NULL,
!empty($pitch['grade_water_ice']) ? $grade_water_ice_options[$pitch['grade_water_ice']] : NULL,
!empty($pitch['grade_mixed']) ? $grade_mixed_options[$pitch['grade_mixed']] : NULL,
);
$grades[] = trim(implode(' ', $route_grades));
break;
// Simply propagate Boulder grade.
case 'boulder':
$grades[] = !empty($pitch['grade_boulder']) ? $grade_boulder_options[$pitch['grade_boulder']] : NULL;
break;
case 'ice':
$route_grades = array(
!empty($pitch['grade_water_ice']) ? $grade_water_ice_options[$pitch['grade_water_ice']] : NULL,
!empty($pitch['grade_mixed']) ? $grade_mixed_options[$pitch['grade_mixed']] : NULL,
);
$grades[] = trim(implode(' ', $route_grades));
break;
// Show ewbank and aid, unless either is zero.
case 'rock':
$route_grades = array(
$pitch['grade_ewbank'] != 0 ? $grade_ewbank_options[$pitch['grade_ewbank']] : NULL,
!empty($pitch['grade_aid']) ? $grade_aid_options[$pitch['grade_aid']] : NULL,
);
$grades[] = trim(implode(' ', $route_grades));
break;
// Avoid PHP warning if no pitch data entered.
if (isset($node->field_pitch[LANGUAGE_NONE][0])) {
// If first Pitch is not empty, or we have multiple Pitches.
if (!climbnz_pitch_field_is_empty($node->field_pitch[LANGUAGE_NONE][0], array()) ||
count($node->field_pitch[LANGUAGE_NONE]) > 1) {
$grades = array();
$length = 0;
$bolts = 0;
$natural_pro = 0;
$grade_ewbank_options = climbnz_pitch_grade_ewbank_options();
$grade_alpine_technical_options = climbnz_pitch_grade_alpine_technical_options();
$grade_alpine_commitment_options = climbnz_pitch_grade_alpine_commitment_options();
$grade_alpine_mtcook_options = climbnz_pitch_grade_alpine_mtcook_options();
$grade_aid_options = climbnz_pitch_grade_aid_options();
$grade_water_ice_options = climbnz_pitch_grade_water_ice_options();
$grade_mixed_options = climbnz_pitch_grade_mixed_options();
$grade_boulder_options = climbnz_pitch_grade_boulder_options();
foreach ($node->field_pitch[LANGUAGE_NONE] as $pitch) {
// Show aggregate value.
switch ($node->field_route_type[LANGUAGE_NONE][0]['value']) {
case 'alpine':
$route_grades = array(
!empty($pitch['grade_alpine_commitment']) ? $grade_alpine_commitment_options[$pitch['grade_alpine_commitment']] : NULL,
!empty($pitch['grade_alpine_technical']) ? $grade_alpine_technical_options[$pitch['grade_alpine_technical']] : NULL,
!empty($pitch['grade_alpine_mtcook']) ? $grade_alpine_mtcook_options[$pitch['grade_alpine_mtcook']] : NULL,
!empty($pitch['grade_ewbank']) ? $grade_ewbank_options[$pitch['grade_ewbank']] : NULL,
!empty($pitch['grade_aid']) ? $grade_aid_options[$pitch['grade_aid']] : NULL,
!empty($pitch['grade_water_ice']) ? $grade_water_ice_options[$pitch['grade_water_ice']] : NULL,
!empty($pitch['grade_mixed']) ? $grade_mixed_options[$pitch['grade_mixed']] : NULL,
);
$grades[] = trim(implode(' ', $route_grades));
break;
// Simply propagate Boulder grade.
case 'boulder':
$grades[] = !empty($pitch['grade_boulder']) ? $grade_boulder_options[$pitch['grade_boulder']] : NULL;
break;
case 'ice':
$route_grades = array(
!empty($pitch['grade_water_ice']) ? $grade_water_ice_options[$pitch['grade_water_ice']] : NULL,
!empty($pitch['grade_mixed']) ? $grade_mixed_options[$pitch['grade_mixed']] : NULL,
);
$grades[] = trim(implode(' ', $route_grades));
break;
// Show ewbank and aid, unless either is zero.
case 'rock':
$route_grades = array(
$pitch['grade_ewbank'] != 0 ? $grade_ewbank_options[$pitch['grade_ewbank']] : NULL,
!empty($pitch['grade_aid']) ? $grade_aid_options[$pitch['grade_aid']] : NULL,
);
$grades[] = trim(implode(' ', $route_grades));
break;
}
$length += $pitch['length'];
$bolts += $pitch['bolts'];
$natural_pro += $pitch['trad'];
}
$length += $pitch['length'];
$bolts += $pitch['bolts'];
$natural_pro += $pitch['trad'];
$node->field_grade[LANGUAGE_NONE][0]['value'] = implode(',', $grades);
$node->field_length[LANGUAGE_NONE][0]['value'] = $length;
$node->field_bolts[LANGUAGE_NONE][0]['value'] = $bolts;
$node->field_natural_pro[LANGUAGE_NONE][0]['value'] = $natural_pro ? 1 : 0;
}
$node->field_grade[LANGUAGE_NONE][0]['value'] = implode(',', $grades);
$node->field_length[LANGUAGE_NONE][0]['value'] = $length;
$node->field_bolts[LANGUAGE_NONE][0]['value'] = $bolts;
$node->field_natural_pro[LANGUAGE_NONE][0]['value'] = $natural_pro ? 1 : 0;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment