|
@@ -1,8 +1,8 @@
|
|
|
<?php
|
|
|
ApplicationSettings::RegisterDefaultSetting("weight", "graph_history_duration", "1M");
|
|
|
|
|
|
-class Weight extends Controller {
|
|
|
- public function Index(IWeightReadingRepository $weightReadingRepo, IUserSettingsRepository $userSettingRepo) {
|
|
|
+class Weight extends Controller {
|
|
|
+ private function GetUserReadings(IWeightReadingRepository $weightReadingRepo, IUserSettingsRepository $userSettingRepo){
|
|
|
$user=Session::GetLoggedInUser();
|
|
|
$graphDuration=ApplicationSettings::GetSetting("weight", "graph_history_duration");
|
|
|
$userDurationSetting=$userSettingRepo->GetSetting($user, "weight_graph_duration")->Value;
|
|
@@ -12,7 +12,15 @@ class Weight extends Controller {
|
|
|
$dateTo=new DateTime();
|
|
|
$dateFrom=clone $dateTo;
|
|
|
$dateFrom->sub(new DateInterval("P".$graphDuration));
|
|
|
- return new View("Weight/index.view",array("readings"=>$weightReadingRepo->GetReadingsInDateRange($user->UserId,$dateFrom,$dateTo)));
|
|
|
+ return $weightReadingRepo->GetReadingsInDateRange($user->UserId,$dateFrom,$dateTo);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function Index(IWeightReadingRepository $weightReadingRepo, IUserSettingsRepository $userSettingRepo) {
|
|
|
+ return new View("Weight/index.view",array("readings"=>$this->GetUserReadings($weightReadingRepo, $userSettingRepo)));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function GetReadings(IWeightReadingRepository $weightReadingRepo, IUserSettingsRepository $userSettingRepo) {
|
|
|
+ return json_encode($this->GetUserReadings($weightReadingRepo, $userSettingRepo));
|
|
|
}
|
|
|
|
|
|
public function Add($weight, $fat, IUserSettingsRepository $userSettingsRepo){
|
|
@@ -24,10 +32,12 @@ class Weight extends Controller {
|
|
|
|
|
|
$reading->Weight=$weight;
|
|
|
$reading->Fat=$fat;
|
|
|
-
|
|
|
$reading->Save(Session::GetLoggedInUser());
|
|
|
|
|
|
- //return '{"Weight":'.$reading->Weight.',"BMI":'.$reading->Bmi.',"Fat":'.$reading->Fat.'}';
|
|
|
return json_encode($reading);
|
|
|
}
|
|
|
+
|
|
|
+ public function Delete($id,IWeightReadingRepository $weightReadingRepo){
|
|
|
+ $weightReadingRepo->Delete($id);
|
|
|
+ }
|
|
|
}
|