fix chores service

This commit is contained in:
zebardy 2019-11-23 20:47:42 +00:00
parent 5b214dbf27
commit 90c00680fa

View File

@ -29,7 +29,7 @@ class ChoresService extends BaseService
public function GetCurrent()
{
$sql = 'SELECT * from chores_current';
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
return $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
}
public function GetChoreDetails(int $choreId)
@ -42,12 +42,12 @@ class ChoresService extends BaseService
$usersService = new UsersService();
$users = $usersService->GetUsersAsDto();
$chore = $this->Database->chores($choreId);
$choreTrackedCount = $this->Database->chores_log()->where('chore_id = :1 AND undone = 0', $choreId)->count();
$choreLastTrackedTime = $this->Database->chores_log()->where('chore_id = :1 AND undone = 0', $choreId)->max('tracked_time');
$nextExecutionTime = $this->Database->chores_current()->where('chore_id', $choreId)->min('next_estimated_execution_time');
$lastChoreLogRow = $this->Database->chores_log()->where('chore_id = :1 AND tracked_time = :2 AND undone = 0', $choreId, $choreLastTrackedTime)->fetch();
$chore = $this->getDatabase()->chores($choreId);
$choreTrackedCount = $this->getDatabase()->chores_log()->where('chore_id = :1 AND undone = 0', $choreId)->count();
$choreLastTrackedTime = $this->getDatabase()->chores_log()->where('chore_id = :1 AND undone = 0', $choreId)->max('tracked_time');
$nextExecutionTime = $this->getDatabase()->chores_current()->where('chore_id', $choreId)->min('next_estimated_execution_time');
$lastChoreLogRow = $this->getDatabase()->chores_log()->where('chore_id = :1 AND tracked_time = :2 AND undone = 0', $choreId, $choreLastTrackedTime)->fetch();
$lastDoneByUser = null;
if ($lastChoreLogRow !== null && !empty($lastChoreLogRow))
{
@ -77,25 +77,25 @@ class ChoresService extends BaseService
throw new \Exception('Chore does not exist');
}
$userRow = $this->Database->users()->where('id = :1', $doneBy)->fetch();
$userRow = $this->getDatabase()->users()->where('id = :1', $doneBy)->fetch();
if ($userRow === null)
{
throw new \Exception('User does not exist');
}
$chore = $this->Database->chores($choreId);
$chore = $this->getDatabase()->chores($choreId);
if ($chore->track_date_only == 1)
{
$trackedTime = substr($trackedTime, 0, 10) . ' 00:00:00';
}
$logRow = $this->Database->chores_log()->createRow(array(
$logRow = $this->getDatabase()->chores_log()->createRow(array(
'chore_id' => $choreId,
'tracked_time' => $trackedTime,
'done_by_user_id' => $doneBy
));
$logRow->save();
$lastInsertId = $this->Database->lastInsertId();
$lastInsertId = $this->getDatabase()->lastInsertId();
$this->CalculateNextExecutionAssignment($choreId);
@ -109,13 +109,13 @@ class ChoresService extends BaseService
private function ChoreExists($choreId)
{
$choreRow = $this->Database->chores()->where('id = :1', $choreId)->fetch();
$choreRow = $this->getDatabase()->chores()->where('id = :1', $choreId)->fetch();
return $choreRow !== null;
}
public function UndoChoreExecution($executionId)
{
$logRow = $this->Database->chores_log()->where('id = :1 AND undone = 0', $executionId)->fetch();
$logRow = $this->getDatabase()->chores_log()->where('id = :1 AND undone = 0', $executionId)->fetch();
if ($logRow == null)
{
throw new \Exception('Execution does not exist or was already undone');
@ -135,11 +135,11 @@ class ChoresService extends BaseService
throw new \Exception('Chore does not exist');
}
$chore = $this->Database->chores($choreId);
$choreLastTrackedTime = $this->Database->chores_log()->where('chore_id = :1 AND undone = 0', $choreId)->max('tracked_time');
$lastChoreLogRow = $this->Database->chores_log()->where('chore_id = :1 AND tracked_time = :2 AND undone = 0', $choreId, $choreLastTrackedTime)->fetch();
$chore = $this->getDatabase()->chores($choreId);
$choreLastTrackedTime = $this->getDatabase()->chores_log()->where('chore_id = :1 AND undone = 0', $choreId)->max('tracked_time');
$lastChoreLogRow = $this->getDatabase()->chores_log()->where('chore_id = :1 AND tracked_time = :2 AND undone = 0', $choreId, $choreLastTrackedTime)->fetch();
$lastDoneByUserId = $lastChoreLogRow->done_by_user_id;
$usersService = new UsersService();
$users = $usersService->GetUsersAsDto();
$assignedUsers = array();
@ -198,7 +198,7 @@ class ChoresService extends BaseService
}
else if ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST)
{
$row = $this->Database->chores_execution_users_statistics()->where('chore_id = :1', $choreId)->orderBy('execution_count')->limit(1)->fetch();
$row = $this->getDatabase()->chores_execution_users_statistics()->where('chore_id = :1', $choreId)->orderBy('execution_count')->limit(1)->fetch();
if ($row != null)
{
$nextExecutionUserId = $row->user_id;