|
@@ -1,11 +1,24 @@
|
|
|
<?php
|
|
|
class WeightReadingRepository extends BaseRepository implements IWeightReadingRepository {
|
|
|
- public static function GetAll($userId){
|
|
|
+ public function GetAll($userId){
|
|
|
$readings=array();
|
|
|
- self::SetupPDO();
|
|
|
$ids=self::$PDO->query("SELECT reading_id FROM weight_readings WHERE user_id=".(int)$userId)->fetchAll(PDO::FETCH_COLUMN);
|
|
|
foreach ($ids as $id)
|
|
|
$readings[]=new WeightReading($id);
|
|
|
return $readings;
|
|
|
}
|
|
|
+
|
|
|
+ public function GetReadingsInDateRange($userId, DateTime $from, DateTime $to){
|
|
|
+ $readings=array();
|
|
|
+ $prep=self::$PDO->prepare("SELECT reading_id FROM weight_readings WHERE user_id=:user_id AND (`timestamp`>=:from AND `timestamp`<=:to)");
|
|
|
+ $prep->execute(array(
|
|
|
+ ":user_id"=>$userId,
|
|
|
+ ":from"=>$from->format('Y-m-d 00:00:00'),
|
|
|
+ ":to"=>$to->format('Y-m-d 23:59:59')
|
|
|
+ ));
|
|
|
+ $results=$prep->fetchAll(PDO::FETCH_COLUMN);
|
|
|
+ foreach ($results as $id)
|
|
|
+ $readings[]=new WeightReading($id);
|
|
|
+ return $readings;
|
|
|
+ }
|
|
|
}
|