# ivyforms/0.1.2/backend/src/Services/Confirmation/ConfirmationService.php

The Innovative Form Builder – IvyForms, version 0.1.2. 89 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.1.2/code/backend/src/Services/Confirmation/ConfirmationService.php
- Raw: https://pluginprobe.com/plugins/ivyforms/0.1.2/raw/backend/src/Services/Confirmation/ConfirmationService.php
- Modified: 2025-06-12T10:29:14+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/0.1.2/code/backend/src/Services/Confirmation/ConfirmationService.php#L10-L20`.

```php
<?php

namespace IvyForms\Services\Confirmation;

// phpcs:disable PSR1.Files.SideEffects
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

use IvyForms\Common\Exceptions\NotFoundException;
use IvyForms\Entity\Confirmation\Confirmation;
use IvyForms\Repository\Confirmation\ConfirmationRepositoryInterface;

class ConfirmationService
{
    private ConfirmationRepositoryInterface $confirmationRepository;

    // Constructor injection for the ConfirmationRepository via PHP-DI
    public function __construct(ConfirmationRepositoryInterface $confirmationRepository)
    {
        $this->confirmationRepository = $confirmationRepository;
    }

    /**
     * Create a new confirmation.
     *
     * @param Confirmation $confirmationData
     *
     * @return int Confirmation ID
     */
    public function createConfirmation(Confirmation $confirmationData): int
    {
        // Create confirmation via repository and return new confirmation ID
        return $this->confirmationRepository->add($confirmationData);
    }

    /**
     * Update an existing confirmation.
     *
     * @param int $confirmationId
     * @param Confirmation $confirmationData
     *
     * @return bool
     */
    public function updateConfirmation(int $confirmationId, Confirmation $confirmationData): bool
    {
        return $this->confirmationRepository->update($confirmationId, $confirmationData);
    }

    /**
     * Get confirmations by form ID.
     *
     * @param int $id
     *
     * @return mixed[]|null
     *
     * @throws NotFoundException If no confirmations are found
     */
    public function getConfirmationsById(int $id): ?array
    {
        $confirmation = $this->confirmationRepository->getAllById($id);

        if (!$confirmation) {
            throw new NotFoundException('Confirmation not found.');
        }

        return $confirmation;
    }
    /**
     * Get a specific form by its ID.
     *
     * @param int $id
     *
     * @return object ConfirmationEntity
     *
     * @throws NotFoundException If the confirmation is not found
     */
    public function getConfirmationById(int $id): object
    {
        $confirmation = $this->confirmationRepository->getById($id);

        if (!$confirmation) {
            throw new NotFoundException('Confirmation not found.');
        }

        return $confirmation;
    }
}

```
