$type) { $parsedTypes[$orderNum] = $type['type']; } return $parsedTypes; } //check if dubdevice exist //Add History to be set in Creation public static function create($deviceId, $type, $unit) { $record = array( 'device_id' => $deviceId, 'type' => $type, 'unit' => $unit, ); try { Db::add('subdevices', $record); } catch (PDOException $error) { echo $error->getMessage(); die(); } } public static function edit($subDeviceId, $values) { $record = []; foreach ($values as $key => $value) { $record[$key] = $value; } try { Db::edit('subdevices', $record, 'WHERE subdevice_id = ?', array ($subDeviceId)); } catch (PDOException $error) { echo $error->getMessage(); die(); } } public static function remove($subDeviceId) { RecordManager::cleanSubdeviceRecords($subDeviceId); return Db::loadAll("DELETE FROM subdevices WHERE subdevice_id = ?", array($subDeviceId)); } public static function getSubdevicesByRoomIds($roomIds = NULL) { if (empty($roomIds)) return NULL; //TODO: @Patrik Check line 89 $rows = Db::loadAll(" SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.device_id, COALESCE(sd.icon, d.icon) AS icon, COALESCE(sd.name, d.name) AS name, sd.type, sd.unit, r.value, r.time FROM subdevices sd JOIN devices d ON sd.device_id = d.device_id JOIN records r ON r.subdevice_id = sd.subdevice_id WHERE d.room_id IN (" . str_repeat("?,", count($roomIds) - 1) . "?) /*AND value != '999'*/ AND r.record_id IN ( SELECT MAX(record_id) FROM records GROUP BY subdevice_id ) GROUP BY subdevice_id ORDER BY d.name DESC ", $roomIds); $ret = []; foreach ($rows as $row) { $ret[$row['room_id']][] = $row; } return $ret; } public static function getSubdeviceDetailById($subDeviceId){ if (empty($subDeviceId)) return NULL; $rows = Db::loadOne("SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.type, sd.device_id FROM subdevices sd JOIN devices d ON sd.device_id = d.device_id WHERE sd.subdevice_id = ? ", [$subDeviceId]); return $rows; } }