mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-11-22 06:23:01 +00:00
Fill out mesurement type repo methods
This commit is contained in:
parent
cef578d7eb
commit
dea95716ed
3 changed files with 17 additions and 7 deletions
|
@ -8,14 +8,14 @@ interface IMeasurementTypeRepository {
|
|||
* @param string $type_name The name of the type to validate.
|
||||
* @return boolean Whether the specified type name is valid or not.
|
||||
*/
|
||||
public function is_valid_type(string $type_name);
|
||||
public function is_valid_type(string $type_name) : boolean;
|
||||
|
||||
/**
|
||||
* Gets the friendly name for the specified type name.
|
||||
* @param string $type_name The type name to get the friendly name for.
|
||||
* @return string The friendly name for the specified type name.
|
||||
*/
|
||||
public function get_friendly_name(string $type_name);
|
||||
public function get_friendly_name(string $type_name) : boolean;
|
||||
|
||||
/**
|
||||
* Returns all the currently known meeasurement types.
|
||||
|
|
|
@ -61,6 +61,6 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
|
|||
"datetime" => $datetime,
|
||||
"reading_type" => $reading_type
|
||||
]
|
||||
);
|
||||
)->fetchAll();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,15 +25,25 @@ class MariaDBMeasurementTypeRepository implements IMeasurementTypeRepository {
|
|||
|
||||
|
||||
|
||||
public function is_valid_type(string $type_name) {
|
||||
throw new Exception("Error: Not implemented yet :-\\");
|
||||
public function is_valid_type(string $type_name) : boolean {
|
||||
return !empty($this->database->query(
|
||||
"SELECT $this->column_id FROM $this->table_name;",
|
||||
[]
|
||||
)->fetchColumn());
|
||||
}
|
||||
public function get_friendly_name(string $type_name) {
|
||||
public function get_friendly_name(string $type_name) : string {
|
||||
return $this->database->query(
|
||||
"SELECT $this->column_friendly_text FROM $this->table_name WHERE $this->column_id = :type_name;", [
|
||||
"type_name" => $type_name
|
||||
]
|
||||
)->fetchColumn();
|
||||
// TODO: Cache results here? Maybe https://packagist.org/packages/thumbtack/querycache will be of some use
|
||||
throw new Exception("Error: Not implemented yet :-\\");
|
||||
}
|
||||
|
||||
public function get_all_types() {
|
||||
throw new Exception("Error: Not implemented yet :-\\");
|
||||
return $this->database->query(
|
||||
"SELECT * FROM $this->table_name"
|
||||
)->fetchAll();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue