123456789101112131415161718192021222324252627282930 |
- <?php
- class TemperatureReadingRepository extends BaseRepository implements ITemperatureReadingRepository {
- public function __construct() {
- parent::__construct();
- }
- public function GetAll() {
- $readings=array();
- $ids=self::$PDO->query("SELECT temperature_id FROM temperature_log")->fetchAll(PDO::FETCH_COLUMN);
- foreach ($ids as $id)
- $readings[]=new TemperatureReading($id);
- return $readings;
- }
- public function GetRange(DateTime $from, DateTime $to) {
- $readings=array();
- $prep=self::$PDO->prepare("SELECT temperature_id FROM temperature_log WHERE `timestamp`>=:from AND `timestamp`<=:to");
- $prep->execute(array(
- ":from"=>$from->format('Y-m-d H:i:s'),
- ":to"=>$to->format('Y-m-d H:i:s')
- ));
- $results=$prep->fetchAll(PDO::FETCH_COLUMN);
- foreach ($results as $id)
- $readings[]=new TemperatureReading($id);
- return $readings;
- }
- }
|