CoolCMS API

PdfVariantMatrixTrait

Api operation that saves the whole PDF variant matrix of one payment region atomically.

The operation is one database transaction: delete the cells of this region for the affected invoice types, insert the new matrix, commit or roll back. The caller sends the whole matrix in one call and gets a single Result. It touches only rows of the given paymentRegionId, so the full-replace of the whole collection is not needed (a cell of another region left out by mistake would be deleted by orphanRemoval).

The seams are separated so the logic can be tested without a database, DI or network (PdfVariantMatrixAtomicityTest).

Tags
phpstan-type

PdfVariantCell array{invoiceTypeId: int, productTypeId: int, buyerVatType: int, sellerUseVat: int, pdfTemplateVariantId: int|null}

Table of Contents

Methods

savePdfVariantMatrix()  : Result
Saves the whole matrix of one payment region in one transaction.
deletePdfVariantCells()  : void
Deletes the cells of the given region for the given invoice types; other regions must stay untouched. Failure is reported by an exception.
inPdfVariantMatrixTransaction()  : Result
Wraps the operation in a transaction. The implementation must roll back on a failed `Result` as well as on an exception, and must not open its own transaction when one is already running.
insertPdfVariantCell()  : void
Inserts one matrix cell. Failure is reported by an exception, which the transaction turns into a rollback of the whole matrix.

Methods

savePdfVariantMatrix()

Saves the whole matrix of one payment region in one transaction.

public savePdfVariantMatrix(int $paymentRegionId, array<int|string, mixed> $cells) : Result
Parameters
$paymentRegionId : int
$cells : array<int|string, mixed>

matrix cells; each {invoiceTypeId, productTypeId, buyerVatType, sellerUseVat, pdfTemplateVariantId}. The matrix is dense: an empty cell is sent with pdfTemplateVariantId = null.

Return values
Result

deletePdfVariantCells()

Deletes the cells of the given region for the given invoice types; other regions must stay untouched. Failure is reported by an exception.

protected abstract deletePdfVariantCells(int $paymentRegionId, array<int, int> $invoiceTypeIds) : void
Parameters
$paymentRegionId : int
$invoiceTypeIds : array<int, int>

inPdfVariantMatrixTransaction()

Wraps the operation in a transaction. The implementation must roll back on a failed `Result` as well as on an exception, and must not open its own transaction when one is already running.

protected abstract inPdfVariantMatrixTransaction(callable(): Result $work) : Result
Parameters
$work : callable(): Result
Return values
Result

insertPdfVariantCell()

Inserts one matrix cell. Failure is reported by an exception, which the transaction turns into a rollback of the whole matrix.

protected abstract insertPdfVariantCell(int $paymentRegionId, array{invoiceTypeId: int, productTypeId: int, buyerVatType: int, sellerUseVat: int, pdfTemplateVariantId: int|null} $cell) : void
Parameters
$paymentRegionId : int
$cell : array{invoiceTypeId: int, productTypeId: int, buyerVatType: int, sellerUseVat: int, pdfTemplateVariantId: int|null}
On this page

Search results