1234567891011121314151617181920212223242526272829303132 |
- <?php
- class WeightReading extends DBObject {
- /**
- * @var IUserSettingsRepository
- */
- private $_userSettingsRepo;
- public static function CalculateBMI($weight, $height){
- if ($weight==0 || $height==0)
- return 0;
- return ($weight/$height)/$height;
- }
-
- public function __construct(IUserSettingsRepository $userSettingsRepo, $id=0) {
- parent::__construct("weight_readings", "reading_id", $id);
- $this->_userSettingsRepo=$userSettingsRepo;
- }
-
- public function GetParsedDate(){
- return date_parse($this->Timestamp);
- }
-
- public function Save(User $user=null) {
- if ($user==null)
- throw new Exception("Please specify user");
- $height=$this->_userSettingsRepo->GetSetting($user, "height")->GetValue;
- $this->Bmi=self::CalculateBMI($this->Weight, $height);
- $this->UserId=$user->UserId;
- parent::Save();
- }
- }
|