TemperatureReadingRepository.php 897 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. class TemperatureReadingRepository extends BaseRepository implements ITemperatureReadingRepository {
  3. public function __construct() {
  4. parent::__construct();
  5. }
  6. public function GetAll() {
  7. $readings=array();
  8. $ids=self::$PDO->query("SELECT temperature_id FROM temperature_log")->fetchAll(PDO::FETCH_COLUMN);
  9. foreach ($ids as $id)
  10. $readings[]=new TemperatureReading($id);
  11. return $readings;
  12. }
  13. public function GetRange(DateTime $from, DateTime $to) {
  14. $readings=array();
  15. $prep=self::$PDO->prepare("SELECT temperature_id FROM temperature_log WHERE `timestamp`>=:from AND `timestamp`<=:to");
  16. $prep->execute(array(
  17. ":from"=>$from->format('Y-m-d H:i:s'),
  18. ":to"=>$to->format('Y-m-d H:i:s')
  19. ));
  20. $results=$prep->fetchAll(PDO::FETCH_COLUMN);
  21. foreach ($results as $id)
  22. $readings[]=new TemperatureReading($id);
  23. return $readings;
  24. }
  25. }