mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +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)
|
||||
- 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
|
||||
- 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 `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
|
||||
|
@ -121,14 +121,12 @@ class GenericEntityApiController extends BaseApiController
|
||||
if ($this->IsValidExposedEntity($args['entity']) && !$this->IsEntityWithNoListing($args['entity']))
|
||||
{
|
||||
$userfields = $this->getUserfieldsService()->GetValues($args['entity'], $args['objectId']);
|
||||
|
||||
if (count($userfields) === 0)
|
||||
{
|
||||
$userfields = null;
|
||||
}
|
||||
|
||||
$object = $this->getDatabase()->{$args['entity']}($args['objectId']);
|
||||
|
||||
if ($object == null)
|
||||
{
|
||||
return $this->GenericErrorResponse($response, 'Object not found', 404);
|
||||
@ -146,33 +144,39 @@ class GenericEntityApiController extends BaseApiController
|
||||
|
||||
public function GetObjects(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$objects = $this->queryData($this->getDatabase()->{$args['entity']}(), $request->getQueryParams());
|
||||
$allUserfields = $this->getUserfieldsService()->GetAllValues($args['entity']);
|
||||
|
||||
foreach ($objects as $object)
|
||||
{
|
||||
$userfields = FindAllObjectsInArrayByPropertyValue($allUserfields, 'object_id', $object->id);
|
||||
$userfieldKeyValuePairs = null;
|
||||
|
||||
if (count($userfields) > 0)
|
||||
{
|
||||
foreach ($userfields as $userfield)
|
||||
{
|
||||
$userfieldKeyValuePairs[$userfield->name] = $userfield->value;
|
||||
}
|
||||
}
|
||||
|
||||
$object->userfields = $userfieldKeyValuePairs;
|
||||
}
|
||||
|
||||
if ($this->IsValidExposedEntity($args['entity']) && !$this->IsEntityWithNoListing($args['entity']))
|
||||
{
|
||||
return $this->ApiResponse($response, $objects);
|
||||
}
|
||||
else
|
||||
if (!$this->IsValidExposedEntity($args['entity']) || $this->IsEntityWithNoListing($args['entity']))
|
||||
{
|
||||
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
|
||||
}
|
||||
|
||||
$objects = $this->queryData($this->getDatabase()->{$args['entity']}(), $request->getQueryParams());
|
||||
$userfields = $this->getUserfieldsService()->GetFields($args['entity']);
|
||||
|
||||
if (count($userfields) > 0)
|
||||
{
|
||||
$allUserfieldValues = $this->getUserfieldsService()->GetAllValues($args['entity']);
|
||||
|
||||
foreach ($objects as $object)
|
||||
{
|
||||
$userfieldKeyValuePairs = null;
|
||||
foreach ($userfields as $userfield)
|
||||
{
|
||||
$value = FindObjectInArrayByPropertyValue($allUserfieldValues, 'object_id', $object->id);
|
||||
if ($value)
|
||||
{
|
||||
$userfieldKeyValuePairs[$userfield->name] = $value->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$userfieldKeyValuePairs[$userfield->name] = null;
|
||||
}
|
||||
}
|
||||
|
||||
$object->userfields = $userfieldKeyValuePairs;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->ApiResponse($response, $objects);
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
$userfields = $this->GetFields($entity);
|
||||
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');
|
||||
}
|
||||
|
||||
$userfields = $this->getDatabase()->userfield_values_resolved()->where('entity = :1 AND object_id = :2', $entity, $objectId)->orderBy('name', 'COLLATE NOCASE')->fetchAll();
|
||||
$userfieldKeyValuePairs = [];
|
||||
$userfields = $this->GetFields($entity);
|
||||
$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)
|
||||
{
|
||||
$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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user