Fill out mesurement type repo methods

This commit is contained in:
Starbeamrainbowlabs 2019-01-15 15:57:39 +00:00
parent cef578d7eb
commit dea95716ed
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 17 additions and 7 deletions

View file

@ -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.

View file

@ -61,6 +61,6 @@ class MariaDBMeasurementDataRepository implements IMeasurementDataRepository {
"datetime" => $datetime,
"reading_type" => $reading_type
]
);
)->fetchAll();
}
}

View file

@ -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();
}
}