CoolCMS API

CustomerFormTrait

Add/edit form of a customer: `name`, the billing profile section (see {@see addBillingProfileFields()}) and a client multiplier of contacts.

The multiplier needs no naja round trips (client-multiplier.js); the server-side Multiplier only holds the structure and indexes. The mechanics come from PdfTemplateFormTrait.

Table of Contents

Methods

customerCompanyTypeIds()  : array<int, int>
Returns ids of user types that require company data (`name2`/`regNo`): the group `company` of the visibility matrix. The flags always come from the entities ({@see \App\UI\Admin\Invoicer\Presenters\CustomerPresenter::$userTypes}), never hardcoded by id, because new types may be added.
customerContactGroupClass()  : string
Returns the initial (server-side) `.d-none` class of a contact field group by the selected user type of the row (visibility matrix). Without a selected type (new row, legacy contact) everything is visible (safe default).
customerCountryOptions()  : array<string, string>
Returns the options of the contact country select: active countries, `CZ` and `SK` first; stored codes of contacts stay offered even when deactivated meanwhile.
customerVatTypeIds()  : array<int, int>
Returns ids of user types that require a VAT id (`vatId`/`vatInformations`): the group `vat` of the visibility matrix.
getCustomerContactSummary()  : string
Returns the summary on the right of a collapsed card header: the identification minimum of the contact.
getCustomerContactTitle()  : string
Returns the title of a collapsed contact card: `name`, or company/first name/last name when it is empty (the admin left it to be derived from the triple, see `addCustomerContactMultiplier()`).
hasCustomerContactErrors()  : bool
Tells whether the row has an error. A card with an error must be rendered expanded: the error message (typically a duplicate e-mail, {@see self::validateCustomerContactEmails()}) sits inside the body and would be invisible in a collapsed card.
createComponentEditForm()  : Form
addBillingProfileFields()  : void
Adds the billing profile section: optional overrides of the company settings.
addCustomerContactMultiplier()  : void
Contacts: client multiplier (see the trait docblock).
buildCustomerContacts()  : ArrayCollection<int, CustomerContact>
Builds the owned contacts collection from the multiplier (empty rows are skipped).
carryOverCompanyName()  : string|null
Returns `companyName` for carry-over: the form no longer sends it, so an existing contact keeps the stored value ({@see \App\UI\Admin\Invoicer\Presenters\CustomerPresenter::$editedCustomer}); a new row (no `contactId`) has no previous state, so `null`.
carryOverContactValue()  : string|null
Returns the stored country text of the contact (`country` / `dlvCountry`) for carry-over: the field is no longer in the form; a new row (no `contactId`) has no previous state, so `null`.
customerContactDefaults()  : array<int, array<string, mixed>>
customerContactEmailControls()  : array<string, array<int, BaseControl>>
Returns the multiplier e-mail controls by normalized value, so the error is reported on the right row: `buildCustomerContacts()` skips empty rows, so the collection index does not match the container index.
customerContactUserTypeId()  : int|null
Reads `userTypeId` of the row safely: the control may not exist and the value may arrive as a string.
customerContactValue()  : string
customerFormComponent()  : IComponent|null
Calls `getComponent()` through the `Container` type, bypassing the faulty vendor annotation of `getComponent()` on Contributte `BootstrapContainerTrait` (the real component-model signature has 2 arguments and a nullable return). Same workaround as `OrderFormTrait::formComponent()`.
customerTypeIdsWhere()  : array<int, int>
customerUserTypeOptions()  : array<int, string>
existingContactIdsForEmail()  : array<int, int>
Returns ids of contacts that already hold the address in the register (across all customers: the uniqueness is global).
normalizeContactEmail()  : string
prepareCurrencyOptions()  : array<int, string>
prepareInvoiceTypeOptions()  : array<int, string>
prepareLanguageOptions()  : array<int, string>
Returns the invoice language options (`id => name`) from the system language list, the same source as the multilingual form fields.
preparePaymentRegionOptions()  : array<int, string>
saveCustomerForm()  : bool
setCustomerFormDefaults()  : void
tr()  : string
Translates a key in the form domain to a ready string (for fields with `setTranslator(null)`).
translatedName()  : string
Entity name (with `translations`) in the current language, falling back to the first non-empty one.
validateCustomerContactEmails()  : bool
Checks uniqueness of contact e-mails before save. Covers both collisions the DB index rejects: two submitted rows with the same address and an address already held by a contact of someone else in the register. The comparison is case-insensitive, like the `utf8mb4_general_ci` index (`Franta@X.cz` == `franta@x.cz`).

Methods

customerCompanyTypeIds()

Returns ids of user types that require company data (`name2`/`regNo`): the group `company` of the visibility matrix. The flags always come from the entities ({@see \App\UI\Admin\Invoicer\Presenters\CustomerPresenter::$userTypes}), never hardcoded by id, because new types may be added.

public customerCompanyTypeIds() : array<int, int>
Return values
array<int, int>

customerContactGroupClass()

Returns the initial (server-side) `.d-none` class of a contact field group by the selected user type of the row (visibility matrix). Without a selected type (new row, legacy contact) everything is visible (safe default).

public customerContactGroupClass(Container $row, string $group) : string

Live switching on select change is done by contact-type-toggle.js; as with useDelivery, fields are never removed from the DOM, only hidden with .d-none, so a value is not lost.

Parameters
$row : Container
$group : string
Return values
string

customerCountryOptions()

Returns the options of the contact country select: active countries, `CZ` and `SK` first; stored codes of contacts stay offered even when deactivated meanwhile.

public customerCountryOptions() : array<string, string>
Return values
array<string, string>

customerVatTypeIds()

Returns ids of user types that require a VAT id (`vatId`/`vatInformations`): the group `vat` of the visibility matrix.

public customerVatTypeIds() : array<int, int>
Return values
array<int, int>

getCustomerContactSummary()

Returns the summary on the right of a collapsed card header: the identification minimum of the contact.

public getCustomerContactSummary(Container $row) : string
Parameters
$row : Container
Return values
string

getCustomerContactTitle()

Returns the title of a collapsed contact card: `name`, or company/first name/last name when it is empty (the admin left it to be derived from the triple, see `addCustomerContactMultiplier()`).

public getCustomerContactTitle(Container $row) : string

The server renders only the initial state; fold-summary.js rewrites it live while typing (same logic: group title, fallback title-alt), otherwise a collapsed card would show the old value until save.

Parameters
$row : Container
Return values
string

hasCustomerContactErrors()

Tells whether the row has an error. A card with an error must be rendered expanded: the error message (typically a duplicate e-mail, {@see self::validateCustomerContactEmails()}) sits inside the body and would be invisible in a collapsed card.

public hasCustomerContactErrors(Container $row) : bool
Parameters
$row : Container
Return values
bool

addBillingProfileFields()

Adds the billing profile section: optional overrides of the company settings.

private addBillingProfileFields(Form $form) : void

An empty field means invoicing takes the value from Company as before; the prompt/description says so in the UI. The same fields exist on the company (CompanyFormTrait::addBasicFields()).

Parameters
$form : Form

addCustomerContactMultiplier()

Contacts: client multiplier (see the trait docblock).

private addCustomerContactMultiplier(Form $form) : void
Parameters
$form : Form

buildCustomerContacts()

Builds the owned contacts collection from the multiplier (empty rows are skipped).

private buildCustomerContacts(ArrayHash<string|int, mixed> $values, Customer $customer) : ArrayCollection<int, CustomerContact>
Parameters
$values : ArrayHash<string|int, mixed>
$customer : Customer
Return values
ArrayCollection<int, CustomerContact>

carryOverCompanyName()

Returns `companyName` for carry-over: the form no longer sends it, so an existing contact keeps the stored value ({@see \App\UI\Admin\Invoicer\Presenters\CustomerPresenter::$editedCustomer}); a new row (no `contactId`) has no previous state, so `null`.

private carryOverCompanyName(int|null $contactId) : string|null
Parameters
$contactId : int|null
Return values
string|null

carryOverContactValue()

Returns the stored country text of the contact (`country` / `dlvCountry`) for carry-over: the field is no longer in the form; a new row (no `contactId`) has no previous state, so `null`.

private carryOverContactValue(int|null $contactId, string $property) : string|null
Parameters
$contactId : int|null
$property : string
Return values
string|null

customerContactDefaults()

private customerContactDefaults() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

customerContactEmailControls()

Returns the multiplier e-mail controls by normalized value, so the error is reported on the right row: `buildCustomerContacts()` skips empty rows, so the collection index does not match the container index.

private customerContactEmailControls(Form|null $form) : array<string, array<int, BaseControl>>
Parameters
$form : Form|null
Return values
array<string, array<int, BaseControl>>

customerContactUserTypeId()

Reads `userTypeId` of the row safely: the control may not exist and the value may arrive as a string.

private customerContactUserTypeId(Container $row) : int|null
Parameters
$row : Container
Return values
int|null

customerContactValue()

private customerContactValue(Container $row, string $name) : string
Parameters
$row : Container
$name : string
Return values
string

customerFormComponent()

Calls `getComponent()` through the `Container` type, bypassing the faulty vendor annotation of `getComponent()` on Contributte `BootstrapContainerTrait` (the real component-model signature has 2 arguments and a nullable return). Same workaround as `OrderFormTrait::formComponent()`.

private customerFormComponent(Container $container, string $name) : IComponent|null
Parameters
$container : Container
$name : string
Return values
IComponent|null

customerTypeIdsWhere()

private customerTypeIdsWhere(callable(UserType): bool $predicate) : array<int, int>
Parameters
$predicate : callable(UserType): bool
Return values
array<int, int>

customerUserTypeOptions()

private customerUserTypeOptions() : array<int, string>
Return values
array<int, string>

existingContactIdsForEmail()

Returns ids of contacts that already hold the address in the register (across all customers: the uniqueness is global).

private existingContactIdsForEmail(string $email) : array<int, int>
Parameters
$email : string
Return values
array<int, int>

normalizeContactEmail()

private normalizeContactEmail(string|null $email) : string
Parameters
$email : string|null
Return values
string

prepareCurrencyOptions()

private prepareCurrencyOptions() : array<int, string>
Return values
array<int, string>

prepareInvoiceTypeOptions()

private prepareInvoiceTypeOptions() : array<int, string>
Return values
array<int, string>

prepareLanguageOptions()

Returns the invoice language options (`id => name`) from the system language list, the same source as the multilingual form fields.

private prepareLanguageOptions() : array<int, string>
Return values
array<int, string>

preparePaymentRegionOptions()

private preparePaymentRegionOptions() : array<int, string>
Return values
array<int, string>

saveCustomerForm()

private saveCustomerForm(ArrayHash<string|int, mixed> $values[, Form|null $form = null ]) : bool
Parameters
$values : ArrayHash<string|int, mixed>
$form : Form|null = null
Return values
bool

tr()

Translates a key in the form domain to a ready string (for fields with `setTranslator(null)`).

private tr(string $key) : string
Parameters
$key : string
Return values
string

translatedName()

Entity name (with `translations`) in the current language, falling back to the first non-empty one.

private translatedName(object $entity) : string
Parameters
$entity : object
Return values
string

validateCustomerContactEmails()

Checks uniqueness of contact e-mails before save. Covers both collisions the DB index rejects: two submitted rows with the same address and an address already held by a contact of someone else in the register. The comparison is case-insensitive, like the `utf8mb4_general_ci` index (`Franta@X.cz` == `franta@x.cz`).

private validateCustomerContactEmails(ArrayCollection<int, CustomerContact> $contacts, Form|null $form) : bool
Parameters
$contacts : ArrayCollection<int, CustomerContact>
$form : Form|null
Return values
bool —

false on conflict; the error is reported on the specific e-mail controls

On this page

Search results