diff --git a/app/Models/IntegrationsModel.php b/app/Models/IntegrationsModel.php index 7b978df8e..3cfb0d36c 100644 --- a/app/Models/IntegrationsModel.php +++ b/app/Models/IntegrationsModel.php @@ -902,7 +902,7 @@ public function getLocalDevices($integration) $instance->user = new \stdClass(); } if (empty($instance->user->org_list)) { - $instance->user->org_list = $orgs; + $instance->user->org_list = implode(',', $orgs); } helper('security'); @@ -915,7 +915,6 @@ public function getLocalDevices($integration) } // Select by Group if ($integration->attributes->select_internal_type === 'group') { - $instance->user->org_list = implode(',', $orgs); $device_ids = $groupsModel->execute(intval($integration->attributes->select_internal_attribute), $instance->user); $dev_ids = array(); foreach ($device_ids as $device) { @@ -928,7 +927,7 @@ public function getLocalDevices($integration) } // Select by Query if ($integration->attributes->select_internal_type === 'query') { - $devices = $queriesModel->execute($integration->attributes->select_internal_value, ''); + $devices = $queriesModel->execute($integration->attributes->select_internal_attribute, $instance->user); $dev_ids = array(); foreach ($devices as $device) { if (!empty($device->attributes->{'devices.id'})) { @@ -1090,6 +1089,18 @@ public function includedRead(int $id = 0): array $devices = $this->db->query($sql)->getResult(); $include['devices'] = format_data($devices, 'devices'); } + + $sql = "SELECT `select_internal_type` FROM integrations WHERE id = ?"; + $data = array(intval($id)); + $type = $this->db->query($sql, [$id])->getResult()[0]->select_internal_type; + if ($type === 'query') { + $queries = model('App\Models\QueriesModel'); + $include['queries'] = $queries->listUser(); + } + if ($type === 'group') { + $groups = model('App\Models\GroupsModel'); + $include['groups'] = $groups->listUser(); + } return $include; } @@ -1367,6 +1378,16 @@ public function read(int $id = 0): array $query[0]->credentials = json_decode($query[0]->credentials); } } + if ($query[0]->select_internal_type === 'group') { + $sql = "SELECT `name` FROM groups WHERE `id` = ?"; + $data = array(intval($query[0]->select_internal_attribute)); + $query[0]->{'groups.name'} = $this->db->query($sql, $data)->getResult()[0]->name; + } + if ($query[0]->select_internal_type === 'query') { + $sql = "SELECT `name` FROM queries WHERE `id` = ?"; + $data = array(intval($query[0]->select_internal_attribute)); + $query[0]->{'queries.name'} = $this->db->query($sql, $data)->getResult()[0]->name; + } return format_data($query, 'integrations'); } diff --git a/app/Views/integrationsRead.php b/app/Views/integrationsRead.php index 64aff6b2b..9b5c8cd2a 100644 --- a/app/Views/integrationsRead.php +++ b/app/Views/integrationsRead.php @@ -142,25 +142,63 @@ - + + + +