CoolCMS API

AdvertExpirationTrait

Computes and extends the expiration of an advert (Api layer).

Shares the expiration calculation between inserting a new advert (prepareAdvertForAdd()) and extending an existing one (extendExpiration()).

Table of Contents

Methods

extendExpiration()  : Result
Extends the advert's expiration.
calculateExpirationDate()  : DateTime|null
Computes the new expiration date.
isExtensionPaymentRequired()  : bool
Whether a non-privileged caller extends a record that lies in a paid category.
resolveExpirationInterval()  : int
Returns the longest category expiration interval; falls back to the default setting (setting 6, key 'advert.expiration.days') when there are no categories or all have interval 0.

Methods

extendExpiration()

Extends the advert's expiration.

public extendExpiration(int $advertId[, bool $afterPayment = false ]) : Result

calculateExpirationDate() computes the new expiration from the current one and the intervals of the advert's categories.

Parameters
$advertId : int
$afterPayment : bool = false
Return values
Result

calculateExpirationDate()

Computes the new expiration date.

private calculateExpirationDate(DateTime|null $currentExpiration, array<int, object> $categories) : DateTime|null

The base is the current expiration when it is valid and in the future; if it is missing or already passed, today is used. The longest category expiration interval (resolveExpirationInterval()) is added to the base.

Returns null when no valid interval is available; the expiration cannot be determined and the caller keeps the original value or returns an error.

Parameters
$currentExpiration : DateTime|null
$categories : array<int, object>
Return values
DateTime|null

isExtensionPaymentRequired()

Whether a non-privileged caller extends a record that lies in a paid category.

private isExtensionPaymentRequired(Advert $advert) : bool
Parameters
$advert : Advert
Return values
bool

resolveExpirationInterval()

Returns the longest category expiration interval; falls back to the default setting (setting 6, key 'advert.expiration.days') when there are no categories or all have interval 0.

private resolveExpirationInterval(array<int, object> $categories) : int
Parameters
$categories : array<int, object>
Return values
int
On this page

Search results