Skip to content

Commit

Permalink
[Update] Add multi sort for images
Browse files Browse the repository at this point in the history
  • Loading branch information
zoglo committed Aug 4, 2022
1 parent 8bb7247 commit 1137ffa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Controller/Api/RoutingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function propertyLinks(?int $id = null): JsonResponse
*
* @Route("/images/{id}", defaults={"id" = null}, name="property_image")
*/
public function propertyImages(?int $id = null): JsonResponse
public function propertyImages(/*mixed*/ $id = null): JsonResponse
{
$request = $this->requestStack->getCurrentRequest();
$parameters = $request->query->all();
Expand All @@ -189,6 +189,12 @@ public function propertyImages(?int $id = null): JsonResponse

case PropstackController::METHOD_EDIT:
// Edit

if('sort' === $id)
{
return $objImages->sortImages($parameters);
}

return $objImages->edit($id, $parameters);

case PropstackController::METHOD_DELETE:
Expand Down
10 changes: 10 additions & 0 deletions src/Controller/Options/UnitImageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@

final class UnitImageOptions extends Options
{
const MODE_EDIT_SORT = 1001;

protected function configure(): void
{
$this->set(Options::MODE_CREATE, $this->getCreateEditFields());
$this->set(Options::MODE_EDIT, $this->getCreateEditFields());

$this->set(Options::MODE_QUERY, [
'property_id'
]);

$this->set(self::MODE_EDIT_SORT, [
'item'
]);
}

public function getCreateEditFields(): array
Expand Down
22 changes: 22 additions & 0 deletions src/Controller/Unit/UnitImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,26 @@ public function delete($id)

return $this->getResponse();
}

/**
* Sort unit images
*/
public function sortImages(array $parameters)
{
// Add sort attribute to route
$this->addRoutePath('sort');

foreach ((new UnitImageOptions(Options::MODE_QUERY))->validate($parameters) as $key => $value)
{
$this->addRouteQuery($key, $value);
}

$this->call(
(new UnitImageOptions(UnitImageOptions::MODE_EDIT_SORT))
->validate($parameters),
self::METHOD_EDIT
);

return $this->getResponse();
}
}

0 comments on commit 1137ffa

Please sign in to comment.