function farm_area_calculate_area_multiple in farmOS 7
Calculate the area of multiple farm areas.
Parameters
array $area_ids: An array of area IDs.
$format: Boolean indicating whether or not the returned value should be formatted based on the unit of measurement
Return value
string Returns the calculated are of the areas as a string, in meters squared by default. If $format is TRUE it will be converted and formatted using farm_area_format_calculated_area().
See also
farm_area_format_calculated_area()
1 call to farm_area_calculate_area_multiple()
- farm_area_calculate_area_type in modules/
farm/ farm_area/ farm_area.module - Calculate the area of all areas of a particular type.
File
- modules/
farm/ farm_area/ farm_area.module, line 381
Code
function farm_area_calculate_area_multiple($area_ids, $format = FALSE) {
// If there are no area IDs, bail.
if (empty($area_ids)) {
return '';
}
// Set BCMath scale.
farm_map_set_bcscale();
// Add up the total area.
$total_area = '';
foreach ($area_ids as $area_id) {
$area_area = farm_area_calculate_area($area_id);
if (function_exists('bcadd')) {
$total_area = bcadd($total_area, $area_area);
}
else {
if (empty($total_area)) {
$total_area = 0;
}
$total_area += floatval($area_area);
}
}
// Reset BCMath scale.
farm_map_reset_bcscale();
// Return the area as a string (optionally formatted using the default
// system of measure).
if (!empty($format)) {
return farm_area_format_calculated_area($total_area);
}
return $total_area;
}