2019-01-15 15:46:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace AirQuality\Repositories;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches device info from a MariaDB database.
|
|
|
|
*/
|
|
|
|
class MariaDBMeasurementTypeRepository implements IMeasurementTypeRepository {
|
|
|
|
public static $table_name = "reading_value_types";
|
|
|
|
|
|
|
|
public static $column_id = "id";
|
|
|
|
public static $column_friendly_text = "friendly_text";
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The database connection.
|
|
|
|
* @var \AirQuality\Database
|
|
|
|
*/
|
|
|
|
private $database;
|
|
|
|
|
|
|
|
function __construct(\AirQuality\Database $in_database) {
|
|
|
|
$this->database = $in_database;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-15 15:57:39 +00:00
|
|
|
public function is_valid_type(string $type_name) : boolean {
|
|
|
|
return !empty($this->database->query(
|
|
|
|
"SELECT $this->column_id FROM $this->table_name;",
|
|
|
|
[]
|
|
|
|
)->fetchColumn());
|
2019-01-15 15:46:24 +00:00
|
|
|
}
|
2019-01-15 15:57:39 +00:00
|
|
|
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();
|
2019-01-15 15:46:24 +00:00
|
|
|
// 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() {
|
2019-01-15 15:57:39 +00:00
|
|
|
return $this->database->query(
|
|
|
|
"SELECT * FROM $this->table_name"
|
|
|
|
)->fetchAll();
|
2019-01-15 15:46:24 +00:00
|
|
|
}
|
|
|
|
}
|