Refresh also habit/battery statistics on changes on overview pages (references #26)

This commit is contained in:
Bernd Bestel
2018-08-04 15:44:58 +02:00
parent ca3f28b615
commit e830805443
13 changed files with 214 additions and 86 deletions

View File

@@ -10,28 +10,6 @@ class BatteriesService extends BaseService
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
}
public function GetNextChargeTime(int $batteryId)
{
if (!$this->BatteryExists($batteryId))
{
throw new \Exception('Battery does not exist');
}
$battery = $this->Database->batteries($batteryId);
$batteryLastLogRow = $this->DatabaseService->ExecuteDbQuery("SELECT * from batteries_current WHERE battery_id = $batteryId LIMIT 1")->fetch(\PDO::FETCH_OBJ);
if ($battery->charge_interval_days > 0)
{
return date('Y-m-d H:i:s', strtotime('+' . $battery->charge_interval_days . ' day', strtotime($batteryLastLogRow->last_tracked_time)));
}
else
{
return date('2999-12-31 23:59:59');
}
return null;
}
public function GetBatteryDetails(int $batteryId)
{
if (!$this->BatteryExists($batteryId))

View File

@@ -7,33 +7,12 @@ class HabitsService extends BaseService
const HABIT_TYPE_MANUALLY = 'manually';
const HABIT_TYPE_DYNAMIC_REGULAR = 'dynamic-regular';
public function GetCurrentHabits()
public function GetCurrent()
{
$sql = 'SELECT * from habits_current';
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
}
public function GetNextHabitTime(int $habitId)
{
if (!$this->HabitExists($habitId))
{
throw new \Exception('Habit does not exist');
}
$habit = $this->Database->habits($habitId);
$habitLastLogRow = $this->DatabaseService->ExecuteDbQuery("SELECT * from habits_current WHERE habit_id = $habitId LIMIT 1")->fetch(\PDO::FETCH_OBJ);
switch($habit->period_type)
{
case self::HABIT_TYPE_MANUALLY:
return date('2999-12-31 23:59:59');
case self::HABIT_TYPE_DYNAMIC_REGULAR:
return date('Y-m-d H:i:s', strtotime('+' . $habit->period_days . ' day', strtotime($habitLastLogRow->last_tracked_time)));
}
return null;
}
public function GetHabitDetails(int $habitId)
{
if (!$this->HabitExists($habitId))