<?php
class Weight {
	public function Index($params) {
		return new View("Weight/index.view",array("readings"=>WeightReading::GetAll(Session::GetLoggedInUser()->UserId)));
	}
	
	public function Add($params){
		$reading=new WeightReading();
		
		foreach ($params as $param)
			if ($param=="" || $param<=0)
				return;
		
		$reading->Weight=$params['weight'];
		$reading->Fat=$params['fat'];
		$reading->Bmi=$params['bmi'];
		$reading->UserId=Session::GetLoggedInUser()->UserId;
		
		$reading->Save();
		
		return '{"Weight":'.$reading->Weight.',"BMI":'.$reading->Bmi.',"Fat":'.$reading->Fat.'}';
	}
}
