api: Add ability to return all device info for get_devices_by_group() (#5971)

* Changed GetDevicesFromGroup to output all columns if  is defined in url
This commit is contained in:
gilrim
2017-02-22 10:37:40 +01:00
committed by Neil Lathwood
parent 8d528124a9
commit 1c9cbc42f5
4 changed files with 16 additions and 6 deletions

View File

@@ -188,11 +188,16 @@ function QueryDevicesFromGroup($group_id)
* Get an array of all the device ids belonging to this group_id
* @param $group_id
* @param bool $nested Return an array of arrays containing 'device_id'. (for API compatibility)
* @param bool $full Return all fields from devices_id
* @return array
*/
function GetDevicesFromGroup($group_id, $nested = false)
function GetDevicesFromGroup($group_id, $nested = false, $full = false)
{
$query = 'SELECT `device_id` FROM `device_group_device` WHERE `device_group_id`=?';
if ($full) {
$query = 'SELECT `device_groups`.`name`, `devices`.* FROM `device_groups` INNER JOIN `device_group_device` ON `device_groups`.`id` = `device_group_device`.`device_group_id` INNER JOIN `devices` ON `device_group_device`.`device_id` = `devices`.`device_id` WHERE `device_groups`.`id`=?';
} else {
$query = 'SELECT `device_id` FROM `device_group_device` WHERE `device_group_id`=?';
}
if ($nested) {
return dbFetchRows($query, array($group_id));
} else {