# ivyforms/0.1.2/backend/src/Repository/Confirmation/ConfirmationRepository.php

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

- Page: https://pluginprobe.com/plugins/ivyforms/0.1.2/code/backend/src/Repository/Confirmation/ConfirmationRepository.php
- Raw: https://pluginprobe.com/plugins/ivyforms/0.1.2/raw/backend/src/Repository/Confirmation/ConfirmationRepository.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/Repository/Confirmation/ConfirmationRepository.php#L10-L20`.

```php
<?php

namespace IvyForms\Repository\Confirmation;

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

use IvyForms\Common\Exceptions\QueryExecutionException;
use IvyForms\Entity\Confirmation\Confirmation;
use IvyForms\Factory\Confirmation\ConfirmationFactory;
use IvyForms\Repository\AbstractRepository;
use IvyForms\Repository\Confirmation\ConfirmationRepositoryInterface;

class ConfirmationRepository extends AbstractRepository implements ConfirmationRepositoryInterface
{
    public const FACTORY = ConfirmationFactory::class;

    /**
     * Add confirmation to the database
     *
     * @param Confirmation $entity
     *
     * @return int
     *
     * @throws QueryExecutionException
     */
    public function add($entity): int
    {
        $data = $entity->toArray();

        $result = $this->wpdb->insert(
            $this->table,
            [
                'formId'    => (int) $data['formId'],
                'type'      => $data['type'],
                'status'    => (int) $data['status'],
                'showForm'  => (int) $data['showForm'],
                'message'   => $data['message'],
                'url'       => $data['url'],
                'page'      => $data['page'],
            ],
            ['%d', '%s', '%d', '%d', '%s', '%s', '%s']
        );

        if ($result === false) {
            throw new QueryExecutionException('Unable to add data in ' . __CLASS__);
        }

        return $this->wpdb->insert_id;
    }

    /**
     * Update confirmation in the database
     *
     * @param int $id
     * @param Confirmation $entity
     *
     * @return bool
     *
     * @throws QueryExecutionException
     */
    public function update(int $id, $entity): bool
    {
        $data = $entity->toArray();

        $result = $this->wpdb->update(
            $this->table,
            [
                'formId'    => (int) $data['formId'],
                'type'      => $data['type'],
                'status'    => (int) $data['status'],
                'showForm'  => (int) $data['showForm'],
                'message'   => $data['message'],
                'url'       => $data['url'],
                'page'      => $data['page'],
            ],
            ['id' => $id],
            ['%d', '%s', '%d', '%d', '%s', '%s', '%s'],
            ['%d']
        );

        if ($result === false) {
            throw new QueryExecutionException('Unable to save data in ' . __CLASS__);
        }

        return $result;
    }

    /**
     * Get all confirmations by form ID.
     *
     * @param int $id
     *
     * @return array<Confirmation>
     */
    public function getAllById(int $id): array
    {
        $rows = $this->wpdb->get_results(
            $this->wpdb->prepare(
                $this->selectQuery() . " WHERE $this->table.formId = %d",
                $id
            ),
            ARRAY_A
        );

        if (empty($rows)) {
            return [];
        }

        return array_map(function ($row) {
            return call_user_func([static::FACTORY, 'create'], $row);
        }, $rows);
    }
}

```
