diff --git a/logic/Repositories/ISensorRepository.php b/logic/Repositories/ISensorRepository.php new file mode 100644 index 0000000..b53c2e8 --- /dev/null +++ b/logic/Repositories/ISensorRepository.php @@ -0,0 +1,22 @@ +database = $in_database; + + $this->get_static = function($name) { return self::$$name; }; + $this->get_static_extra = function($class_name, $name) { + return $class_name::$$name; + }; + } + + + public function get_all_sensors() { + $s = $this->get_static; + + return $this->database->query( + "SELECT + {$s("table_name")}.{$s("col_id")} AS id, + {$s("table_name")}.{$s("col_type")} AS type, + {$s("table_name")}.{$s("col_description")} AS description, + FROM {$s("table_name")};", [ + + ] + )->fetchAll(); + } + + public function get_device_sensors(int $device_id) : array { + $s = $this->get_static; + + return $this->database->query( + "SELECT + {$s("table_name")}.{$s("col_id")} AS id, + {$s("table_name")}.{$s("col_type")} AS type, + {$s("table_name")}.{$s("col_description")} AS description, + FROM {$s("table_name")} + JOIN {$s("table_name_assoc")} ON + {$s("table_name_assoc")}.{$s("col_assoc_sensor_id")} + WHERE {$s("table_name_assoc")}.{$s("col_assoc_device_id")} = :device_id;", [ + "device_id" => $device_id + ] + )->fetchAll(); + } +}