CoolCMS API

UserMapper extends Mapper
in package
uses SaveTrait

FinalYes

Base Api mapper over a Doctrine repository.

Every concrete mapper declares protected readonly XRepository $repository (a concrete subclass of OrmRepository); the base cannot declare it because PHP property types are invariant and a child could not narrow the type.

The repository returns the generic BaseEntity; narrowing to the service entity is done by the service.

Table of Contents

Properties

$em  : EntityManagerInterface
$repository  : UserRepository

Methods

__construct()  : mixed
anonymizeClaimedAccount()  : bool
See {@see UserRepository::anonymizeClaimedAccount()}.
assignReferralCode()  : void
See {@see UserRepository::assignReferralCode()}.
attachReferrer()  : void
See {@see UserRepository::attachReferrer()}.
beginTransaction()  : void
cancelAccountDeletion()  : bool
See {@see UserRepository::cancelAccountDeletion()}.
claimAccountDeletion()  : bool
See {@see UserRepository::claimAccountDeletion()}.
commit()  : void
countCreditedContentRewardsSince()  : int
See {@see UserRepository::countCreditedContentRewardsSince()}.
countCreditedReferralRewardsSince()  : int
See {@see UserRepository::countCreditedReferralRewardsSince()}.
creditPoints()  : void
See {@see UserRepository::creditPoints()} (the connection is passed in and joins the caller's transaction).
debitCreditsForPayment()  : CreditDebitOutcome
See {@see UserRepository::debitCreditsForPayment()}.
delete()  : Result
find()  : BaseEntity|null
findAll()  : array<string|int, mixed>
findBy()  : BaseEntity|null
findContact()  : array{email: ?string, phone: ?string}|null
See {@see UserRepository::findContact()}.
findEmailsByIds()  : array<int, string>
See {@see UserRepository::findEmailsByIds()}.
findRatingThreadIds()  : array<int, int>
See {@see UserRepository::findRatingThreadIds()}.
findReferralState()  : array{ip: ?string, referrerUserId: ?int, referrerIp: ?string, referrerActive: bool, referrerAffiliateDisabled: bool}|null
See {@see UserRepository::findReferralState()}.
findReferralStats()  : array{registered: int, activated: int, credits: int}
See {@see UserRepository::findReferralStats()}.
findReferrerByCode()  : array{userId: int, ip: ?string, affiliateDisabled: bool}|null
See {@see UserRepository::findReferrerByCode()}.
findRelatedIds()  : array<int, int>|null
Returns ids of target entities linked to the parent through the relation collection `$property`.
findUserTypeRequirements()  : array{companyData: bool, vatId: bool}|null
See {@see UserRepository::findUserTypeRequirements()}.
getTransactionLevel()  : int
grantContentReward()  : bool
See {@see UserRepository::grantContentReward()}.
grantReferralReward()  : bool
See {@see UserRepository::grantReferralReward()}.
hasContentReward()  : bool
See {@see UserRepository::hasContentReward()}.
holdsAccountDeletionClaim()  : bool
See {@see UserRepository::holdsAccountDeletionClaim()}.
isAnonymized()  : bool
Account deletion; see {@see UserRepository::isAnonymized()}.
isInTransaction()  : bool
isSignInAllowedNow()  : bool
See {@see UserRepository::isSignInAllowedNow()}.
markProfileCompleted()  : bool
See {@see UserRepository::markProfileCompleted()}.
rollback()  : void
save()  : Result
setupEntityManager()  : void
updateAllRelations()  : Result
Updates all relations of parent entity with given scalar values.
updateColumns()  : Result
Updates columns of the given rows and fully replaces to-many relations, all in one transaction.
updateRelations()  : Result
Updates existing relation entities in a join/relation table.
resolveRelations()  : void
bridgeScalarFkToAssociation()  : void
Fills a ManyToOne association from the value of the scalar foreign key that shares the same join column (typically `$menuId` and `menu`, `$pageId` and `page`). Does nothing when the association is not mapped in this entity variant or the scalar is missing or empty (null/0).
doUpdateRelations()  : Result
insertRelations()  : Result
Inserts relation entities into a join/relation table.
linkOwnedCollections()  : void
Links the owning side of owned collections (cascade persist OneToMany, for example translations): sets the back-reference to the parent (`mappedBy`) on every child so that Doctrine writes the FK on flush. Without it newly hydrated children would be saved with a null foreign key (or the insert would fail).
resolveFkIdentifierField()  : string|null
Finds the name of the identifier field of the target entity whose database column equals the join column of the back association (`mappedBy`), that is an identifier which is also a foreign key to the parent. Returns null when there is none.
rollBackOwnedLevel()  : Throwable|null
Rolls back the transaction levels opened by this mapper (level above the entry level), never foreign ones.
updateColumnsUnguarded()  : Result

Properties

$em

protected EntityManagerInterface $em

Methods

anonymizeClaimedAccount()

See {@see UserRepository::anonymizeClaimedAccount()}.

public anonymizeClaimedAccount(int $userId, string $claimNonce, array<string, scalar|DateTimeInterface|null> $values) : bool
Parameters
$userId : int
$claimNonce : string
$values : array<string, scalar|DateTimeInterface|null>
Return values
bool

assignReferralCode()

See {@see UserRepository::assignReferralCode()}.

public assignReferralCode(int $userId, string $suffix) : void
Parameters
$userId : int
$suffix : string

attachReferrer()

See {@see UserRepository::attachReferrer()}.

public attachReferrer(int $userId, int $referrerUserId, string $code) : void
Parameters
$userId : int
$referrerUserId : int
$code : string

cancelAccountDeletion()

See {@see UserRepository::cancelAccountDeletion()}.

public cancelAccountDeletion(int $userId, DateTimeInterface $requestedAt, string|null $nonce, DateTimeInterface $staleBefore) : bool
Parameters
$userId : int
$requestedAt : DateTimeInterface
$nonce : string|null
$staleBefore : DateTimeInterface
Return values
bool

claimAccountDeletion()

See {@see UserRepository::claimAccountDeletion()}.

public claimAccountDeletion(int $userId, DateTimeInterface $requestedAt, string|null $nonce, string $claimNonce, DateTimeInterface $now, DateTimeInterface $staleBefore) : bool
Parameters
$userId : int
$requestedAt : DateTimeInterface
$nonce : string|null
$claimNonce : string
$now : DateTimeInterface
$staleBefore : DateTimeInterface
Return values
bool

countCreditedContentRewardsSince()

See {@see UserRepository::countCreditedContentRewardsSince()}.

public countCreditedContentRewardsSince(int $userId, string $action, DateTimeInterface $since) : int
Parameters
$userId : int
$action : string
$since : DateTimeInterface
Return values
int

countCreditedReferralRewardsSince()

See {@see UserRepository::countCreditedReferralRewardsSince()}.

public countCreditedReferralRewardsSince(int $referrerUserId, DateTimeInterface $since) : int
Parameters
$referrerUserId : int
$since : DateTimeInterface
Return values
int

creditPoints()

See {@see UserRepository::creditPoints()} (the connection is passed in and joins the caller's transaction).

public creditPoints(Connection $conn, int $userId, int $points) : void
Parameters
$conn : Connection
$userId : int
$points : int

debitCreditsForPayment()

See {@see UserRepository::debitCreditsForPayment()}.

public debitCreditsForPayment(int $userId, int $paymentId, int $amount) : CreditDebitOutcome
Parameters
$userId : int
$paymentId : int
$amount : int
Return values
CreditDebitOutcome

find()

public find(int $id[, string|array<string|int, mixed> $includes = [] ]) : BaseEntity|null
Parameters
$id : int
$includes : string|array<string|int, mixed> = []
Return values
BaseEntity|null

findAll()

public findAll([array<string|int, mixed>|null $filters = [] ][, array<string|int, mixed>|null $orderBys = null ][, int|null $offset = null ][, int|null $limit = null ][, array<string|int, mixed>|null $columns = null ][, bool $computeTotalCount = false ][, string|array<string|int, mixed>|null $includes = [] ]) : array<string|int, mixed>
Parameters
$filters : array<string|int, mixed>|null = []
$orderBys : array<string|int, mixed>|null = null
$offset : int|null = null
$limit : int|null = null
$columns : array<string|int, mixed>|null = null
$computeTotalCount : bool = false
$includes : string|array<string|int, mixed>|null = []
Return values
array<string|int, mixed>

findBy()

public findBy([array<string|int, mixed>|null $filters = [] ][, string|array<string|int, mixed> $includes = [] ]) : BaseEntity|null
Parameters
$filters : array<string|int, mixed>|null = []
$includes : string|array<string|int, mixed> = []
Return values
BaseEntity|null

findContact()

See {@see UserRepository::findContact()}.

public findContact(int $userId) : array{email: ?string, phone: ?string}|null
Parameters
$userId : int
Return values
array{email: ?string, phone: ?string}|null

findEmailsByIds()

See {@see UserRepository::findEmailsByIds()}.

public findEmailsByIds(array<string|int, int> $userIds) : array<int, string>
Parameters
$userIds : array<string|int, int>
Return values
array<int, string>

findRatingThreadIds()

See {@see UserRepository::findRatingThreadIds()}.

public findRatingThreadIds(array<string|int, int> $userIds) : array<int, int>
Parameters
$userIds : array<string|int, int>
Return values
array<int, int>

findReferralState()

See {@see UserRepository::findReferralState()}.

public findReferralState(int $userId) : array{ip: ?string, referrerUserId: ?int, referrerIp: ?string, referrerActive: bool, referrerAffiliateDisabled: bool}|null
Parameters
$userId : int
Return values
array{ip: ?string, referrerUserId: ?int, referrerIp: ?string, referrerActive: bool, referrerAffiliateDisabled: bool}|null

findReferralStats()

See {@see UserRepository::findReferralStats()}.

public findReferralStats(int $userId) : array{registered: int, activated: int, credits: int}
Parameters
$userId : int
Return values
array{registered: int, activated: int, credits: int}

findReferrerByCode()

See {@see UserRepository::findReferrerByCode()}.

public findReferrerByCode(string $code) : array{userId: int, ip: ?string, affiliateDisabled: bool}|null
Parameters
$code : string
Return values
array{userId: int, ip: ?string, affiliateDisabled: bool}|null

findRelatedIds()

Returns ids of target entities linked to the parent through the relation collection `$property`.

public findRelatedIds(int $parentId, string $property, string $targetAssociation) : array<int, int>|null

For example ('assetRels', 'asset') returns the asset ids of a record gallery. Table and columns come from Doctrine metadata (same as self::updateAllRelations()).

Parameters
$parentId : int
$property : string
$targetAssociation : string
Return values
array<int, int>|null —

null when metadata or the database failed

findUserTypeRequirements()

See {@see UserRepository::findUserTypeRequirements()}.

public findUserTypeRequirements(int $userTypeId) : array{companyData: bool, vatId: bool}|null
Parameters
$userTypeId : int
Return values
array{companyData: bool, vatId: bool}|null

getTransactionLevel()

public getTransactionLevel() : int
Return values
int

grantContentReward()

See {@see UserRepository::grantContentReward()}.

public grantContentReward(int $userId, string $action, int $subjectId, int $credits, string|null $skipReason) : bool
Parameters
$userId : int
$action : string
$subjectId : int
$credits : int
$skipReason : string|null
Return values
bool

grantReferralReward()

See {@see UserRepository::grantReferralReward()}.

public grantReferralReward(int $recipientUserId, int $referredUserId, string $type, int $credits, string|null $skipReason) : bool
Parameters
$recipientUserId : int
$referredUserId : int
$type : string
$credits : int
$skipReason : string|null
Return values
bool

hasContentReward()

See {@see UserRepository::hasContentReward()}.

public hasContentReward(string $action, int $subjectId) : bool
Parameters
$action : string
$subjectId : int
Return values
bool

holdsAccountDeletionClaim()

See {@see UserRepository::holdsAccountDeletionClaim()}.

public holdsAccountDeletionClaim(int $userId, string $claimNonce) : bool
Parameters
$userId : int
$claimNonce : string
Return values
bool

isAnonymized()

Account deletion; see {@see UserRepository::isAnonymized()}.

public isAnonymized(int $userId) : bool
Parameters
$userId : int
Return values
bool

isSignInAllowedNow()

See {@see UserRepository::isSignInAllowedNow()}.

public isSignInAllowedNow(int $userId) : bool
Parameters
$userId : int
Return values
bool

markProfileCompleted()

See {@see UserRepository::markProfileCompleted()}.

public markProfileCompleted(int $userId, int $credits, string $action) : bool
Parameters
$userId : int
$credits : int
$action : string
Return values
bool

save()

public save(TEntity $entity[, array<int, string> $skipFields = [] ]) : Result
Parameters
$entity : TEntity
$skipFields : array<int, string> = []
Return values
Result

setupEntityManager()

public setupEntityManager(EntityManagerInterface $entityManager) : void
Parameters
$entityManager : EntityManagerInterface

updateAllRelations()

Updates all relations of parent entity with given scalar values.

public updateAllRelations(array<string|int, mixed> $parentEntityIds, string $property, array<string, mixed> $values) : Result

Sets values on every row matching the parent FK.

Parameters
$parentEntityIds : array<string|int, mixed>

Parent entity IDs (scalar or composite-id arrays)

$property : string
$values : array<string, mixed>

relation property name => value

Return values
Result

updateColumns()

Updates columns of the given rows and fully replaces to-many relations, all in one transaction.

public updateColumns(array<string|int, mixed> $entityIds, array<string, mixed> $values) : Result

A collection (one-to-many) is written as a full replace: delete of all parent rows plus per-row inserts. A failure halfway would leave the parent with part of its history or none (price snapshots of product sets), so a failed Result or an exception rolls everything back. A nested call inside a foreign transaction is handled by DBAL with a savepoint.

IMPORTANT: the mapper owns only the transaction level it opened itself. DBAL lowers the level in finally even after a failed commit or savepoint release, so a blind rollback in catch would throw NoActiveTransaction and hide the original error, or inside a foreign transaction it would roll back the caller's level. Rollback therefore runs only while the level is above the entry level; its own failure is logged and never replaces the primary error or Result (a failed Result with a failed rollback becomes DB_ERROR). An ambiguous commit is not retried.

Parameters
$entityIds : array<string|int, mixed>

ids or composite-id arrays ([prop => value])

$values : array<string, mixed>

property name => new value

Return values
Result

updateRelations()

Updates existing relation entities in a join/relation table.

public updateRelations(array<string|int, mixed> $parentEntityIds, string $property, array<string|int, object> $relationEntities) : Result
Parameters
$parentEntityIds : array<string|int, mixed>

Parent entity IDs (scalar or composite-id arrays)

$property : string

Association property name on parent entity

$relationEntities : array<string|int, object>

Relation entities with updated values

Return values
Result

resolveRelations()

protected resolveRelations(object $entity) : void
Parameters
$entity : object

bridgeScalarFkToAssociation()

Fills a ManyToOne association from the value of the scalar foreign key that shares the same join column (typically `$menuId` and `menu`, `$pageId` and `page`). Does nothing when the association is not mapped in this entity variant or the scalar is missing or empty (null/0).

private bridgeScalarFkToAssociation(object $entity, string $associationName) : void
Parameters
$entity : object
$associationName : string

doUpdateRelations()

private doUpdateRelations(array<string|int, mixed> $parentEntityIds, AssociationMapping $mapping, array<string|int, object> $relationEntities) : Result
Parameters
$parentEntityIds : array<string|int, mixed>

Parent entity IDs (scalar or composite-id arrays)

$mapping : AssociationMapping

OneToMany/ManyToMany association mapping

$relationEntities : array<string|int, object>

Relation entities with updated values

Return values
Result

insertRelations()

Inserts relation entities into a join/relation table.

private insertRelations(array<string|int, mixed> $parentEntityIds, AssociationMapping $mapping, array<int, object> $relationEntities) : Result
Parameters
$parentEntityIds : array<string|int, mixed>

Parent entity IDs (scalar or composite-id arrays)

$mapping : AssociationMapping

OneToMany/ManyToMany association mapping

$relationEntities : array<int, object>

relation entities (validated in updateColumnsUnguarded())

Return values
Result

linkOwnedCollections()

Links the owning side of owned collections (cascade persist OneToMany, for example translations): sets the back-reference to the parent (`mappedBy`) on every child so that Doctrine writes the FK on flush. Without it newly hydrated children would be saved with a null foreign key (or the insert would fail).

private linkOwnedCollections(object $entity) : void

For children whose identifier is itself a foreign key to the parent (typically translations: PK = page_id + language_id, where page_id is also the FK), the scalar identifier is filled from the parent id. Doctrine does not derive it from the association (it is not a derived identity through #[Id] on the association), so it would fail with EntityMissingAssignedId. Works for an existing parent (the id is known); a brand-new parent (the id appears only on flush) needs a two-phase write.

Parameters
$entity : object

resolveFkIdentifierField()

Finds the name of the identifier field of the target entity whose database column equals the join column of the back association (`mappedBy`), that is an identifier which is also a foreign key to the parent. Returns null when there is none.

private resolveFkIdentifierField(class-string $targetEntity, string $mappedBy) : string|null
Parameters
$targetEntity : class-string
$mappedBy : string
Return values
string|null

rollBackOwnedLevel()

Rolls back the transaction levels opened by this mapper (level above the entry level), never foreign ones.

private rollBackOwnedLevel(Connection $connection, int $entryLevel, Throwable|null $primary) : Throwable|null

Returns the rollback exception (logged together with $primary), or null on success.

Parameters
$connection : Connection
$entryLevel : int
$primary : Throwable|null
Return values
Throwable|null

updateColumnsUnguarded()

private updateColumnsUnguarded(array<string|int, mixed> $entityIds, array<string, mixed> $values) : Result
Parameters
$entityIds : array<string|int, mixed>

ids or composite-id arrays ([prop => value])

$values : array<string, mixed>

property name => new value

Return values
Result
On this page

Search results