|
@@ -1,28 +1,26 @@
|
|
|
<?php
|
|
|
ApplicationSettings::RegisterDefaultSetting("weight", "graph_history_duration", "1M");
|
|
|
|
|
|
-class Weight {
|
|
|
- public function Index(IWeightReadingRepository $repo) {
|
|
|
+class Weight extends Controller {
|
|
|
+ public function Index(IWeightReadingRepository $weightReadingRepo) {
|
|
|
$userId=Session::GetLoggedInUser()->UserId;
|
|
|
$dateTo=new DateTime();
|
|
|
$dateFrom=clone $dateTo;
|
|
|
$dateFrom->sub(new DateInterval("P".ApplicationSettings::GetSetting("weight", "graph_history_duration")));
|
|
|
- return new View("Weight/index.view",array("readings"=>$repo->GetReadingsInDateRange($userId,$dateFrom,$dateTo)));
|
|
|
+ return new View("Weight/index.view",array("readings"=>$weightReadingRepo->GetReadingsInDateRange($userId,$dateFrom,$dateTo)));
|
|
|
}
|
|
|
|
|
|
- public function Add($weight,$fat,$bmi){
|
|
|
- $reading=new WeightReading();
|
|
|
+ public function Add($weight, $fat, IUserSettingsRepository $userSettingsRepo){
|
|
|
+ $reading=new WeightReading($userSettingsRepo);
|
|
|
|
|
|
- foreach (func_get_args() as $arg)
|
|
|
+ foreach (array($weight,$fat) as $arg)
|
|
|
if ($arg=="" || $arg<=0)
|
|
|
return;
|
|
|
-
|
|
|
+
|
|
|
$reading->Weight=$weight;
|
|
|
$reading->Fat=$fat;
|
|
|
- $reading->Bmi=$bmi;
|
|
|
- $reading->UserId=Session::GetLoggedInUser()->UserId;
|
|
|
|
|
|
- $reading->Save();
|
|
|
+ $reading->Save(Session::GetLoggedInUser());
|
|
|
|
|
|
return '{"Weight":'.$reading->Weight.',"BMI":'.$reading->Bmi.',"Fat":'.$reading->Fat.'}';
|
|
|
}
|