grocy/services/TasksService.php
fipwmaqzufheoxq92ebc 32a4f81f62
Filtering of API-Results (#985)
* Add FilteredApiResponse

* Use FilteredApiResponse for Generic-Entity-Search

* Use FilteredApiResponse for Recipe-Fullfillment

* Use FilteredApiResponse for GetUsers

* Use FilteredApiResponse for current Tasks

* Use FilteredApiResponse for ProductStockEntries & ProductStockLocations

* Use FilteredApiResponse for current chores

* Use FilteredApiResponse for batteries-current

* Fix missing highlighting of "< X days"

* Keep to use existing views

Co-authored-by: Bernd Bestel <bernd@berrnd.de>
2020-09-01 19:59:40 +02:00

51 lines
960 B
PHP

<?php
namespace Grocy\Services;
class TasksService extends BaseService
{
public function GetCurrent(): \LessQL\Result
{
return $this->getDatabase()->tasks_current();
}
public function MarkTaskAsCompleted($taskId, $doneTime)
{
if (!$this->TaskExists($taskId))
{
throw new \Exception('Task does not exist');
}
$taskRow = $this->getDatabase()->tasks()->where('id = :1', $taskId)->fetch();
$taskRow->update([
'done' => 1,
'done_timestamp' => $doneTime
]);
return true;
}
public function UndoTask($taskId)
{
if (!$this->TaskExists($taskId))
{
throw new \Exception('Task does not exist');
}
$taskRow = $this->getDatabase()->tasks()->where('id = :1', $taskId)->fetch();
$taskRow->update([
'done' => 0,
'done_timestamp' => null
]);
return true;
}
private function TaskExists($taskId)
{
$taskRow = $this->getDatabase()->tasks()->where('id = :1', $taskId)->fetch();
return $taskRow !== null;
}
}