mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Applied PHP formatting rules
This commit is contained in:
@@ -4,12 +4,6 @@ namespace Grocy\Services;
|
||||
|
||||
class BatteriesService extends BaseService
|
||||
{
|
||||
public function GetCurrent()
|
||||
{
|
||||
$sql = 'SELECT * from batteries_current';
|
||||
return $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||
}
|
||||
|
||||
public function GetBatteryDetails(int $batteryId)
|
||||
{
|
||||
if (!$this->BatteryExists($batteryId))
|
||||
@@ -22,12 +16,18 @@ class BatteriesService extends BaseService
|
||||
$batteryLastChargedTime = $this->getDatabase()->battery_charge_cycles()->where('battery_id = :1 AND undone = 0', $batteryId)->max('tracked_time');
|
||||
$nextChargeTime = $this->getDatabase()->batteries_current()->where('battery_id', $batteryId)->min('next_estimated_charge_time');
|
||||
|
||||
return array(
|
||||
return [
|
||||
'battery' => $battery,
|
||||
'last_charged' => $batteryLastChargedTime,
|
||||
'charge_cycles_count' => $batteryChargeCyclesCount,
|
||||
'next_estimated_charge_time' => $nextChargeTime
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public function GetCurrent()
|
||||
{
|
||||
$sql = 'SELECT * from batteries_current';
|
||||
return $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||
}
|
||||
|
||||
public function TrackChargeCycle(int $batteryId, string $trackedTime)
|
||||
@@ -37,33 +37,35 @@ class BatteriesService extends BaseService
|
||||
throw new \Exception('Battery does not exist');
|
||||
}
|
||||
|
||||
$logRow = $this->getDatabase()->battery_charge_cycles()->createRow(array(
|
||||
$logRow = $this->getDatabase()->battery_charge_cycles()->createRow([
|
||||
'battery_id' => $batteryId,
|
||||
'tracked_time' => $trackedTime
|
||||
));
|
||||
]);
|
||||
$logRow->save();
|
||||
|
||||
return $this->getDatabase()->lastInsertId();
|
||||
}
|
||||
|
||||
public function UndoChargeCycle($chargeCycleId)
|
||||
{
|
||||
$logRow = $this->getDatabase()->battery_charge_cycles()->where('id = :1 AND undone = 0', $chargeCycleId)->fetch();
|
||||
|
||||
if ($logRow == null)
|
||||
{
|
||||
throw new \Exception('Charge cycle does not exist or was already undone');
|
||||
}
|
||||
|
||||
// Update log entry
|
||||
$logRow->update([
|
||||
'undone' => 1,
|
||||
'undone_timestamp' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
private function BatteryExists($batteryId)
|
||||
{
|
||||
$batteryRow = $this->getDatabase()->batteries()->where('id = :1', $batteryId)->fetch();
|
||||
return $batteryRow !== null;
|
||||
}
|
||||
|
||||
public function UndoChargeCycle($chargeCycleId)
|
||||
{
|
||||
$logRow = $this->getDatabase()->battery_charge_cycles()->where('id = :1 AND undone = 0', $chargeCycleId)->fetch();
|
||||
if ($logRow == null)
|
||||
{
|
||||
throw new \Exception('Charge cycle does not exist or was already undone');
|
||||
}
|
||||
|
||||
// Update log entry
|
||||
$logRow->update(array(
|
||||
'undone' => 1,
|
||||
'undone_timestamp' => date('Y-m-d H:i:s')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user