protected function SensorDataController::getUniqueNamedValues in farmOS 2.x
Helper function to extract unique named values from the data payload.
Parameters
array $data: The submitted data.
Return value
array Array of unique names.
1 call to SensorDataController::getUniqueNamedValues()
- SensorDataController::handleAssetRequest in modules/
asset/ sensor/ src/ Controller/ SensorDataController.php - Helper function to handle the request once the asset has been loaded.
File
- modules/
asset/ sensor/ src/ Controller/ SensorDataController.php, line 186
Class
- SensorDataController
- Handles requests for basic data streams associated with a sensor.
Namespace
Drupal\farm_sensor\ControllerCode
protected function getUniqueNamedValues(array $data) : array {
// Start an array of names.
$names = [];
// If the data is an array of multiple data points, iterate over each and
// recursively process.
if (is_array(reset($data))) {
foreach ($data as $point) {
$names = array_unique(array_merge($names, $this
->getUniqueNamedValues($point)));
}
return $names;
}
// Iterate over the JSON properties to get each name.
foreach ($data as $key => $value) {
if ($key !== 'timestamp') {
$names[] = $key;
}
}
return array_unique($names);
}