2018-04-11 19:49:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Grocy\Controllers;
|
|
|
|
|
2018-09-22 13:26:58 +02:00
|
|
|
use \Grocy\Services\ChoresService;
|
2018-04-11 19:49:35 +02:00
|
|
|
|
2018-09-22 13:26:58 +02:00
|
|
|
class ChoresApiController extends BaseApiController
|
2018-04-11 19:49:35 +02:00
|
|
|
{
|
|
|
|
public function __construct(\Slim\Container $container)
|
|
|
|
{
|
|
|
|
parent::__construct($container);
|
2018-09-22 13:26:58 +02:00
|
|
|
$this->ChoresService = new ChoresService();
|
2018-04-11 19:49:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-22 13:26:58 +02:00
|
|
|
protected $ChoresService;
|
2018-04-11 19:49:35 +02:00
|
|
|
|
2018-09-22 13:26:58 +02:00
|
|
|
public function TrackChoreExecution(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
2018-04-11 19:49:35 +02:00
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
$requestBody = $request->getParsedBody();
|
2018-07-24 20:45:14 +02:00
|
|
|
|
2018-04-22 14:25:08 +02:00
|
|
|
try
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
$trackedTime = date('Y-m-d H:i:s');
|
2019-07-06 13:32:40 +02:00
|
|
|
if (array_key_exists('tracked_time', $requestBody) && (IsIsoDateTime($requestBody['tracked_time']) || IsIsoDate($requestBody['tracked_time'])))
|
2019-01-19 14:51:51 +01:00
|
|
|
{
|
|
|
|
$trackedTime = $requestBody['tracked_time'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$doneBy = GROCY_USER_ID;
|
|
|
|
if (array_key_exists('done_by', $requestBody) && !empty($requestBody['done_by']))
|
|
|
|
{
|
|
|
|
$doneBy = $requestBody['done_by'];
|
|
|
|
}
|
|
|
|
|
2018-10-27 17:26:00 +02:00
|
|
|
$choreExecutionId = $this->ChoresService->TrackChore($args['choreId'], $trackedTime, $doneBy);
|
2019-03-05 17:51:50 +01:00
|
|
|
return $this->ApiResponse($this->Database->chores_log($choreExecutionId));
|
2018-04-22 14:25:08 +02:00
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
2018-04-22 14:25:08 +02:00
|
|
|
}
|
2018-04-11 19:49:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-22 13:26:58 +02:00
|
|
|
public function ChoreDetails(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
2018-04-11 19:49:35 +02:00
|
|
|
{
|
2018-04-22 14:25:08 +02:00
|
|
|
try
|
|
|
|
{
|
2018-09-22 13:26:58 +02:00
|
|
|
return $this->ApiResponse($this->ChoresService->GetChoreDetails($args['choreId']));
|
2018-04-22 14:25:08 +02:00
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
2018-04-22 14:25:08 +02:00
|
|
|
}
|
2018-04-11 19:49:35 +02:00
|
|
|
}
|
2018-08-04 15:44:58 +02:00
|
|
|
|
|
|
|
public function Current(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
|
|
|
{
|
2018-09-22 13:26:58 +02:00
|
|
|
return $this->ApiResponse($this->ChoresService->GetCurrent());
|
2018-08-04 15:44:58 +02:00
|
|
|
}
|
2018-10-27 10:55:30 +02:00
|
|
|
|
|
|
|
public function UndoChoreExecution(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$this->ApiResponse($this->ChoresService->UndoChoreExecution($args['executionId']));
|
2019-01-19 14:51:51 +01:00
|
|
|
return $this->EmptyApiResponse($response);
|
2018-10-27 10:55:30 +02:00
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
2018-10-27 10:55:30 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-11 19:49:35 +02:00
|
|
|
}
|