mirror of
https://github.com/grocy/grocy.git
synced 2025-04-30 10:05:45 +00:00
Return empty Userfields empty (closes #1412)
This commit is contained in:
parent
14cd6ca3bf
commit
7595d640f5
@ -83,6 +83,7 @@
|
|||||||
- Added a new API endpoint `/system/localization-strings` to get the localization strings (gettext JSON representation; in the by the user desired language)
|
- Added a new API endpoint `/system/localization-strings` to get the localization strings (gettext JSON representation; in the by the user desired language)
|
||||||
- The `GET /chores` endpoint now also returns the `next_execution_assigned_user` per chore (like the endpoint `GET /chores/{choreId}` already did for a single chore)
|
- The `GET /chores` endpoint now also returns the `next_execution_assigned_user` per chore (like the endpoint `GET /chores/{choreId}` already did for a single chore)
|
||||||
- The `GET /tasks` endpoint now also returns the assigned user and category object per task
|
- The `GET /tasks` endpoint now also returns the assigned user and category object per task
|
||||||
|
- Empty Userfields are now also returned (were previously omitted, endpoint `GET /objects/{entity}` and `GET /objects/{entity}/{objectId}`)
|
||||||
- Fixed that due soon products with `due_type` = "Expiration date" were missing in `due_products` of the `/stock/volatile` endpoint
|
- Fixed that due soon products with `due_type` = "Expiration date" were missing in `due_products` of the `/stock/volatile` endpoint
|
||||||
- Fixed that `PUT/DELETE /objects/{entity}/{objectId}` produced an internal server error when the given object id was invalid (now returns `400 Bad Request`)
|
- Fixed that `PUT/DELETE /objects/{entity}/{objectId}` produced an internal server error when the given object id was invalid (now returns `400 Bad Request`)
|
||||||
- Fixed that hyphens in filter values did not work
|
- Fixed that hyphens in filter values did not work
|
||||||
|
@ -121,14 +121,12 @@ class GenericEntityApiController extends BaseApiController
|
|||||||
if ($this->IsValidExposedEntity($args['entity']) && !$this->IsEntityWithNoListing($args['entity']))
|
if ($this->IsValidExposedEntity($args['entity']) && !$this->IsEntityWithNoListing($args['entity']))
|
||||||
{
|
{
|
||||||
$userfields = $this->getUserfieldsService()->GetValues($args['entity'], $args['objectId']);
|
$userfields = $this->getUserfieldsService()->GetValues($args['entity'], $args['objectId']);
|
||||||
|
|
||||||
if (count($userfields) === 0)
|
if (count($userfields) === 0)
|
||||||
{
|
{
|
||||||
$userfields = null;
|
$userfields = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = $this->getDatabase()->{$args['entity']}($args['objectId']);
|
$object = $this->getDatabase()->{$args['entity']}($args['objectId']);
|
||||||
|
|
||||||
if ($object == null)
|
if ($object == null)
|
||||||
{
|
{
|
||||||
return $this->GenericErrorResponse($response, 'Object not found', 404);
|
return $this->GenericErrorResponse($response, 'Object not found', 404);
|
||||||
@ -146,34 +144,40 @@ class GenericEntityApiController extends BaseApiController
|
|||||||
|
|
||||||
public function GetObjects(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
public function GetObjects(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||||
{
|
{
|
||||||
$objects = $this->queryData($this->getDatabase()->{$args['entity']}(), $request->getQueryParams());
|
if (!$this->IsValidExposedEntity($args['entity']) || $this->IsEntityWithNoListing($args['entity']))
|
||||||
$allUserfields = $this->getUserfieldsService()->GetAllValues($args['entity']);
|
|
||||||
|
|
||||||
foreach ($objects as $object)
|
|
||||||
{
|
{
|
||||||
$userfields = FindAllObjectsInArrayByPropertyValue($allUserfields, 'object_id', $object->id);
|
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
|
||||||
$userfieldKeyValuePairs = null;
|
}
|
||||||
|
|
||||||
|
$objects = $this->queryData($this->getDatabase()->{$args['entity']}(), $request->getQueryParams());
|
||||||
|
$userfields = $this->getUserfieldsService()->GetFields($args['entity']);
|
||||||
|
|
||||||
if (count($userfields) > 0)
|
if (count($userfields) > 0)
|
||||||
{
|
{
|
||||||
|
$allUserfieldValues = $this->getUserfieldsService()->GetAllValues($args['entity']);
|
||||||
|
|
||||||
|
foreach ($objects as $object)
|
||||||
|
{
|
||||||
|
$userfieldKeyValuePairs = null;
|
||||||
foreach ($userfields as $userfield)
|
foreach ($userfields as $userfield)
|
||||||
{
|
{
|
||||||
$userfieldKeyValuePairs[$userfield->name] = $userfield->value;
|
$value = FindObjectInArrayByPropertyValue($allUserfieldValues, 'object_id', $object->id);
|
||||||
|
if ($value)
|
||||||
|
{
|
||||||
|
$userfieldKeyValuePairs[$userfield->name] = $value->value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$userfieldKeyValuePairs[$userfield->name] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$object->userfields = $userfieldKeyValuePairs;
|
$object->userfields = $userfieldKeyValuePairs;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->IsValidExposedEntity($args['entity']) && !$this->IsEntityWithNoListing($args['entity']))
|
|
||||||
{
|
|
||||||
return $this->ApiResponse($response, $objects);
|
return $this->ApiResponse($response, $objects);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function GetUserfields(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
public function GetUserfields(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||||
{
|
{
|
||||||
|
@ -44,6 +44,7 @@ class UserfieldsService extends BaseService
|
|||||||
throw new \Exception('Entity does not exist or is not exposed');
|
throw new \Exception('Entity does not exist or is not exposed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$userfields = $this->GetFields($entity);
|
||||||
return $this->getDatabase()->userfield_values_resolved()->where('entity', $entity)->orderBy('name', 'COLLATE NOCASE')->fetchAll();
|
return $this->getDatabase()->userfield_values_resolved()->where('entity', $entity)->orderBy('name', 'COLLATE NOCASE')->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +89,21 @@ class UserfieldsService extends BaseService
|
|||||||
throw new \Exception('Entity does not exist or is not exposed');
|
throw new \Exception('Entity does not exist or is not exposed');
|
||||||
}
|
}
|
||||||
|
|
||||||
$userfields = $this->getDatabase()->userfield_values_resolved()->where('entity = :1 AND object_id = :2', $entity, $objectId)->orderBy('name', 'COLLATE NOCASE')->fetchAll();
|
$userfields = $this->GetFields($entity);
|
||||||
$userfieldKeyValuePairs = [];
|
$userfieldValues = $this->getDatabase()->userfield_values_resolved()->where('entity = :1 AND object_id = :2', $entity, $objectId)->orderBy('name', 'COLLATE NOCASE')->fetchAll();
|
||||||
|
|
||||||
|
$userfieldKeyValuePairs = [];
|
||||||
foreach ($userfields as $userfield)
|
foreach ($userfields as $userfield)
|
||||||
{
|
{
|
||||||
$userfieldKeyValuePairs[$userfield->name] = $userfield->value;
|
$value = FindObjectInArrayByPropertyValue($userfieldValues, 'name', $userfield->name);
|
||||||
|
if ($value)
|
||||||
|
{
|
||||||
|
$userfieldKeyValuePairs[$userfield->name] = $value->value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$userfieldKeyValuePairs[$userfield->name] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $userfieldKeyValuePairs;
|
return $userfieldKeyValuePairs;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user