CoolCMS API

ContentCreditRewardTrait

Credits for published content, the content module's half: finds which of the saved records are published now and hands them to {@see UserManager::rewardPublishedContent()}, which pays at most once per record.

Shared by adverts (Bazaar), company profiles (Comcat) and discussion posts (Discussion). A record gets published along several paths (insert with automatic approval, admin approval in the form or the grid toggle, author confirmation by the e-mail link, payment of a paid category), so the host calls this after each of them:

  • completedSave() → self::rewardPublishedContentIds(),
  • updateColumns() → self::rewardPublishedContentAfterUpdate() (grid toggles and the confirmation by key go through it),
  • payment activation → self::rewardPublishedContentIds() from the payment item manager.

The state is read by a scalar query over the host's own table, not through the Api read path: no UoW::clear() in the middle of a caller's save or payment flow.

Fail-open: nothing here may break the save, the moderation or the payment.

Table of Contents

Constants

CONTENT_REWARD_VISIBILITY_PROPERTIES  : array<string|int, mixed> = ['approvedAt', 'confirmedAt', 'banned', 'paid',...
Entity properties whose change can publish a record; other `updateColumns()` calls are ignored.

Methods

rewardPublishedContentIds()  : void
Rewards the authors of those given records that are published now.
contentRewardAction()  : string
Action key of the host ({@see UserManager::CONTENT_REWARD_ACTIONS}).
contentRewardCandidatesSql()  : string
SELECT over the host's table returning `id`, `user_id` and `inserted_at` of the published records with an author, limited by `IN (?)` to the given ids.
contentRewardConnection()  : Connection
contentRewardUserManager()  : UserManager|null
Null only in unit tests that build the host without it; nothing is rewarded then.
rewardPublishedContentAfterUpdate()  : void
`updateColumns()` hook: rewards only when the write succeeded and touched a column that can publish the record (view counters and similar writes cost nothing).

Constants

CONTENT_REWARD_VISIBILITY_PROPERTIES

Entity properties whose change can publish a record; other `updateColumns()` calls are ignored.

private array<string|int, mixed> CONTENT_REWARD_VISIBILITY_PROPERTIES = ['approvedAt', 'confirmedAt', 'banned', 'paid', 'deleted', 'deactivated', 'sold']

Methods

rewardPublishedContentIds()

Rewards the authors of those given records that are published now.

public rewardPublishedContentIds(array<string|int, mixed> $ids) : void
Parameters
$ids : array<string|int, mixed>

contentRewardAction()

Action key of the host ({@see UserManager::CONTENT_REWARD_ACTIONS}).

protected abstract contentRewardAction() : string
Return values
string

contentRewardCandidatesSql()

SELECT over the host's table returning `id`, `user_id` and `inserted_at` of the published records with an author, limited by `IN (?)` to the given ids.

protected abstract contentRewardCandidatesSql() : string
Return values
string

contentRewardConnection()

protected abstract contentRewardConnection() : Connection
Return values
Connection

rewardPublishedContentAfterUpdate()

`updateColumns()` hook: rewards only when the write succeeded and touched a column that can publish the record (view counters and similar writes cost nothing).

protected rewardPublishedContentAfterUpdate(int|array<string|int, mixed> $entityId, array<string, mixed> $values, Result $result) : void
Parameters
$entityId : int|array<string|int, mixed>
$values : array<string, mixed>
$result : Result
On this page

Search results