# ivyforms/1.5/backend/src/Services/Confirmation/ConfirmationOrderService.php

The Innovative Form Builder – IvyForms, version 1.5. 74 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/1.5/code/backend/src/Services/Confirmation/ConfirmationOrderService.php
- Raw: https://pluginprobe.com/plugins/ivyforms/1.5/raw/backend/src/Services/Confirmation/ConfirmationOrderService.php
- Modified: 2026-07-15T16:27:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/1.5/code/backend/src/Services/Confirmation/ConfirmationOrderService.php#L10-L20`.

```php
<?php

namespace IvyForms\Services\Confirmation;

use IvyForms\Common\Exceptions\InvalidArgumentException;
use IvyForms\Repository\Confirmation\ConfirmationRepositoryInterface;
use IvyForms\Services\Translations\BackendStrings;

class ConfirmationOrderService
{
    private ConfirmationRepositoryInterface $confirmationRepository;

    public function __construct(ConfirmationRepositoryInterface $confirmationRepository)
    {
        $this->confirmationRepository = $confirmationRepository;
    }

    /**
     * @param int $formId
     * @param array<int, int> $orderedIds
     * @return void
     */
    public function applyOrder(int $formId, array $orderedIds): void
    {
        $this->confirmationRepository->updatePositions($formId, $orderedIds);

        if (!empty($orderedIds)) {
            $this->confirmationRepository->syncDefaultFlag($formId, (int) $orderedIds[0]);
        }
    }

    /**
     * @param int $formId
     * @param array<int, int> $orderedIds
     * @return void
     * @throws InvalidArgumentException
     */
    public function validateReorderIds(int $formId, array $orderedIds): void
    {
        if (empty($orderedIds)) {
            throw new InvalidArgumentException(
                BackendStrings::getExceptionStrings()['invalid_request_data']
            );
        }

        foreach ($orderedIds as $id) {
            if ((int) $id <= 0) {
                throw new InvalidArgumentException(
                    BackendStrings::getExceptionStrings()['invalid_request_data']
                );
            }
        }

        if (count($orderedIds) !== count(array_unique($orderedIds))) {
            throw new InvalidArgumentException(
                BackendStrings::getExceptionStrings()['invalid_request_data']
            );
        }

        $existing = $this->confirmationRepository->getAllById($formId);
        $existingIds = array_map(static fn ($confirmation) => $confirmation->getId(), $existing);
        sort($existingIds);

        $normalizedIds = array_map('intval', $orderedIds);
        sort($normalizedIds);

        if ($normalizedIds !== $existingIds) {
            throw new InvalidArgumentException(
                BackendStrings::getExceptionStrings()['invalid_request_data']
            );
        }
    }
}

```
