mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Added possibility to track who did a habit (this implements and closes #21)
This commit is contained in:
@@ -52,16 +52,23 @@ class HabitsService extends BaseService
|
||||
);
|
||||
}
|
||||
|
||||
public function TrackHabit(int $habitId, string $trackedTime)
|
||||
public function TrackHabit(int $habitId, string $trackedTime, $doneBy = GROCY_USER_ID)
|
||||
{
|
||||
if (!$this->HabitExists($habitId))
|
||||
{
|
||||
throw new \Exception('Habit does not exist');
|
||||
}
|
||||
|
||||
$userRow = $this->Database->users()->where('id = :1', $doneBy)->fetch();
|
||||
if ($userRow === null)
|
||||
{
|
||||
throw new \Exception('User does not exist');
|
||||
}
|
||||
|
||||
$logRow = $this->Database->habits_log()->createRow(array(
|
||||
'habit_id' => $habitId,
|
||||
'tracked_time' => $trackedTime
|
||||
'tracked_time' => $trackedTime,
|
||||
'done_by_user_id' => $doneBy
|
||||
));
|
||||
$logRow->save();
|
||||
|
||||
|
Reference in New Issue
Block a user