CoolCMS API

AdvertRenderer extends BaseComponent
in package
uses MultipliableTrait, ToggleRedrawTrait, FavouriteTrait, FollowTrait

FinalYes

Renders one advert in a list. Used via `{multicontrol}` from `AdvertListRenderer` (Multiplier, key = advertId), so each advert has its own isolated `advert` snippet and an AJAX toggle (favorite/follow) redraws only that item.

Table of Contents

Constants

DESC_LIMIT  : int = 150
Visible characters of the description a highlighted snippet may have. Must match `|truncate:150` in Style_1..3, otherwise the list would "bloat" on search.

Properties

$container  : Container
$routerDispatcher  : RouterDispatcher
$translator  : ITranslator
$appContext  : AppContext
$componentParameters  : array<string, mixed>
$currencyContext  : CurrencyContext|null
$deviceDetector  : DeviceDetector|null
$languageContext  : LanguageContext|null
$localizationContext  : LocalizationContext|null
$selectedStyle  : string|null
$settingContext  : SettingContext
$themeContext  : ThemeContext|null
$translatorDomain  : string|null
$advert  : Advert|null
$advertFollowerManager  : AdvertFollowerManager
$advertManager  : AdvertManager
$favouriteRedrawSnippets  : array<string|int, string>
Snippets / snippet areas redrawn after an AJAX toggle. Separate for favourite and follow — each action may refresh a different part.
$favouriteSessionSection  : string
$followRedrawSnippets  : array<string|int, string>
$headingTag  : string
$multiplierItemId  : string|int|null
$multiplierRenderMethod  : string|null
$multiplierUniqueKey  : string|null
$renderingDefault  : bool
Guard against the `renderDefault()` and `render()` delegation loop.
$session  : Session

Methods

__call()  : mixed
Dispatches `renderXyz()` to `render('Xyz', ...$args)`.
__construct()  : mixed
createComponent()  : IComponent|null
getAppContext()  : AppContext
getComponentParameter()  : mixed
Returns a component parameter, or null when it is not set.
getContainer()  : Container
getCurrencyContext()  : CurrencyContext|null
getFavouriteIds()  : array<string|int, int>
getLanguageContext()  : LanguageContext|null
getLocalizationContext()  : LocalizationContext|null
getMultiplierItemId()  : string|int|null
getMultiplierRenderMethod()  : string|null
Returns the render method of the multiplier.
getMultiplierUniqueKey()  : string|null
Returns the unique key of the multiplier.
getRouterDispatcher()  : RouterDispatcher
getSettingContext()  : SettingContext
getSettings()  : array<int, array<string, mixed>>
getThemeContext()  : ThemeContext|null
handleAddToFavourites()  : void
handleDelFromFavourites()  : void
handleFollow()  : void
handleUnfollow()  : void
hasServiceByType()  : bool
Returns whether the container has a service of the given type.
initFavourites()  : void
initializeAllContexts()  : void
injectDeviceDetector()  : void
isFollowing()  : bool
isInFavourites()  : bool
isInMultiplier()  : bool
Returns whether the component is rendered inside a multiplier.
loadAdvert()  : Advert|null
Loads an advert by ID and caches it into $this->advert. Also called from the signal handlers (Favourite/Follow), where there is no multiplier context and render() would otherwise not resolve the advert.
onCreate()  : void
render()  : void
setAdvert()  : self
setAppContext()  : $this
setComponentParameter()  : void
Sets a component parameter.
setCurrencyContext()  : $this
setFavouriteRedrawSnippets()  : self
setFollowRedrawSnippets()  : self
setHeadingTag()  : self
setLanguageContext()  : $this
setLocalizationContext()  : $this
setMultiplierContext()  : void
Sets the multiplier context; called automatically from `MultiControlMacros`.
setSettingContext()  : $this
setThemeContext()  : $this
setup()  : void
setupAppContext()  : void
typedComponent()  : T
Returns a subcomponent with a verified type.
frontPresenter()  : BasePresenter|null
Returns the front presenter the component is attached to (null outside the front end or when detached).
getTranslator()  : ITranslator
handleMultiplierSuccess()  : void
Handles a successful action in a multiplier (e.g. a form submit) and redraws the right snippet.
renderDefault()  : void
Aliases `render()` when no other render method is specified.
setTemplateFile()  : void
setTranslator()  : self
availableRenderStyles()  : array<int, string>
Returns styles derived from public `renderXxx()` methods, without `render()` and `renderDefault()`.
availableRenderStylesHint()  : string
Returns the message suffix listing styles; empty when the component has none.
createMultiplierComponent()  : Multiplier<string|int, IComponent>
Creates a multiplier for the component.
createNewComponentInstance()  : IComponent|null
Creates a new component instance without adding it to the presenter; used by the multiplier.
createStandardComponent()  : IComponent|null
Creates a standard component (not a multiplier).
finishToggle()  : void
Finishes a toggle signal: sets the style (so the default is not rendered after AJAX), redraws the given snippets of this component and flash messages.
firstRenderStyle()  : string|null
Returns the first available style, used as an example in the message.
getFavouriteSection()  : SessionSection
getFollowUserId()  : int|null
prepareTemplate()  : void
resolveAdvert()  : Advert|null
Advert resolution: 1) explicitly set, 2) already loaded in the parent AdvertListRenderer (no extra query), 3) loaded by the multiplier key (fallback for a standalone AJAX signal).
resolveHighlights()  : array<string, string>
Returns snippets for this advert. Same path as {@see resolveParameterOptions()}: the parent {@see AdvertListRenderer} holds the data and the item renderer fetches it via the multiplier. A standalone AJAX signal (favorite/follow) has no parent and returns an empty array, so the redrawn advert has no highlighting (and no error).
resolveIsHighlighted()  : bool
Returns whether the paid "Highlighting" is active (card tint via the class `highlighted`), via the parent like {@see resolveHighlights()}: the set is held by {@see AdvertListRenderer::isHighlighted()}; a standalone AJAX redraw of the item without a parent fails open to `false` (card without tint, no error).
resolveParameterOptions()  : array<string|int, object>
resolveStyleFromMultiplier()  : string|null
'style2' becomes 'Style_2'. After an AJAX signal the style comes primarily from `$selectedStyle` (passed by the signal); this is the multiplier-context fallback.

Constants

DESC_LIMIT

Visible characters of the description a highlighted snippet may have. Must match `|truncate:150` in Style_1..3, otherwise the list would "bloat" on search.

private int DESC_LIMIT = 150

Properties

$componentParameters

protected array<string, mixed> $componentParameters = []

component parameters set by setComponentParameter()

$translatorDomain

protected string|null $translatorDomain = 'front.bazaar.components.advertRenderer'

$favouriteRedrawSnippets

Snippets / snippet areas redrawn after an AJAX toggle. Separate for favourite and follow — each action may refresh a different part.

private array<string|int, string> $favouriteRedrawSnippets = ['advert']

Default = the whole card.

$favouriteSessionSection

private string $favouriteSessionSection = ''

$followRedrawSnippets

private array<string|int, string> $followRedrawSnippets = ['advert']

$renderingDefault

Guard against the `renderDefault()` and `render()` delegation loop.

private bool $renderingDefault = false

Methods

__call()

Dispatches `renderXyz()` to `render('Xyz', ...$args)`.

public __call(string $name, array<string|int, mixed> $args) : mixed

Called only when the component has no renderXyz() method of its own.

Parameters
$name : string
$args : array<string|int, mixed>

createComponent()

public createComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

getComponentParameter()

Returns a component parameter, or null when it is not set.

public getComponentParameter(string $name) : mixed
Parameters
$name : string

getContainer()

public getContainer() : Container
Return values
Container

getFavouriteIds()

public getFavouriteIds() : array<string|int, int>
Return values
array<string|int, int>

getMultiplierItemId()

public getMultiplierItemId() : string|int|null
Return values
string|int|null

getMultiplierRenderMethod()

Returns the render method of the multiplier.

public getMultiplierRenderMethod() : string|null
Return values
string|null

getMultiplierUniqueKey()

Returns the unique key of the multiplier.

public getMultiplierUniqueKey() : string|null
Return values
string|null

getSettings()

public getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

handleAddToFavourites()

public handleAddToFavourites(int $advertId[, string $style = 'Style_1' ]) : void
Parameters
$advertId : int
$style : string = 'Style_1'

handleDelFromFavourites()

public handleDelFromFavourites(int $advertId[, string $style = 'Style_1' ]) : void
Parameters
$advertId : int
$style : string = 'Style_1'

handleFollow()

public handleFollow(int $advertId[, string $style = 'Style_1' ]) : void
Parameters
$advertId : int
$style : string = 'Style_1'

handleUnfollow()

public handleUnfollow(int $advertId[, string $style = 'Style_1' ]) : void
Parameters
$advertId : int
$style : string = 'Style_1'

hasServiceByType()

Returns whether the container has a service of the given type.

public hasServiceByType(string $className) : bool

The name is composed dynamically (module plus component), so class_exists() runs first, and a true result guarantees a valid type.

Parameters
$className : string
Tags
phpstan-assert-if-true

class-string $className

Return values
bool

initFavourites()

public initFavourites(string $sessionSection) : void
Parameters
$sessionSection : string

isFollowing()

public isFollowing(int $advertId) : bool
Parameters
$advertId : int
Return values
bool

isInFavourites()

public isInFavourites(int $advertId) : bool
Parameters
$advertId : int
Return values
bool

isInMultiplier()

Returns whether the component is rendered inside a multiplier.

public isInMultiplier() : bool
Return values
bool

loadAdvert()

Loads an advert by ID and caches it into $this->advert. Also called from the signal handlers (Favourite/Follow), where there is no multiplier context and render() would otherwise not resolve the advert.

public loadAdvert(int $advertId) : Advert|null
Parameters
$advertId : int
Return values
Advert|null

render()

public render([string $style = 'Style1' ]) : void
Parameters
$style : string = 'Style1'

setComponentParameter()

Sets a component parameter.

public setComponentParameter(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed

setFavouriteRedrawSnippets()

public setFavouriteRedrawSnippets(string ...$snippets) : self
Parameters
$snippets : string
Return values
self

setFollowRedrawSnippets()

public setFollowRedrawSnippets(string ...$snippets) : self
Parameters
$snippets : string
Return values
self

setHeadingTag()

public setHeadingTag(string $headingTag) : self
Parameters
$headingTag : string
Return values
self

setMultiplierContext()

Sets the multiplier context; called automatically from `MultiControlMacros`.

public setMultiplierContext(string $uniqueKey, string $renderMethod) : void

It is the only writer of the properties above; the component parameters are copies for templates.

Parameters
$uniqueKey : string
$renderMethod : string

typedComponent()

Returns a subcomponent with a verified type.

public typedComponent(string $name, T> $type) : T

Use it instead of an inline @var above $this['x'] (which does not narrow the type) and instead of the generic IComponent that $this['x'] returns. See Form::typedComponent().

Parameters
$name : string
$type : T>
Tags
template
Return values
T

frontPresenter()

Returns the front presenter the component is attached to (null outside the front end or when detached).

protected frontPresenter() : BasePresenter|null
Return values
BasePresenter|null

getTranslator()

protected getTranslator() : ITranslator
Return values
ITranslator

handleMultiplierSuccess()

Handles a successful action in a multiplier (e.g. a form submit) and redraws the right snippet.

protected handleMultiplierSuccess() : void

renderDefault()

Aliases `render()` when no other render method is specified.

protected renderDefault() : void

IMPORTANT: the guard prevents an endless loop. A component whose render() delegates by MultiplierRenderStyleTrait::getRenderStyle() (default 'default') builds the method name renderDefault and lands on this alias, which calls render() again. Without the guard that exhausts memory and, in production mode, the page ends half-rendered with no readable trace. The guard turns it into an exception that says what to add to the template. Components with a real renderDefault() are unaffected.

setTemplateFile()

protected setTemplateFile(string $dir, string $filename) : void
Parameters
$dir : string
$filename : string

setTranslator()

protected setTranslator(ITranslator $translator) : self
Parameters
$translator : ITranslator
Return values
self

availableRenderStyles()

Returns styles derived from public `renderXxx()` methods, without `render()` and `renderDefault()`.

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

availableRenderStylesHint()

Returns the message suffix listing styles; empty when the component has none.

private availableRenderStylesHint() : string
Return values
string

createMultiplierComponent()

Creates a multiplier for the component.

private createMultiplierComponent(string $name) : Multiplier<string|int, IComponent>
Parameters
$name : string
Return values
Multiplier<string|int, IComponent>

createNewComponentInstance()

Creates a new component instance without adding it to the presenter; used by the multiplier.

private createNewComponentInstance(string $baseName[, int|string|null $uniqueKey = null ]) : IComponent|null
Parameters
$baseName : string
$uniqueKey : int|string|null = null
Return values
IComponent|null

createStandardComponent()

Creates a standard component (not a multiplier).

private createStandardComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

finishToggle()

Finishes a toggle signal: sets the style (so the default is not rendered after AJAX), redraws the given snippets of this component and flash messages.

private finishToggle(string $style[, array<string|int, string> $snippets = ['advert'] ]) : void
Parameters
$style : string
$snippets : array<string|int, string> = ['advert']

snippet / snippet-area names to redraw

firstRenderStyle()

Returns the first available style, used as an example in the message.

private firstRenderStyle() : string|null
Return values
string|null

getFavouriteSection()

private getFavouriteSection() : SessionSection
Return values
SessionSection

getFollowUserId()

private getFollowUserId() : int|null
Return values
int|null

prepareTemplate()

private prepareTemplate(Advert $advert, string $style) : void
Parameters
$advert : Advert
$style : string

resolveAdvert()

Advert resolution: 1) explicitly set, 2) already loaded in the parent AdvertListRenderer (no extra query), 3) loaded by the multiplier key (fallback for a standalone AJAX signal).

private resolveAdvert() : Advert|null
Return values
Advert|null

resolveHighlights()

Returns snippets for this advert. Same path as {@see resolveParameterOptions()}: the parent {@see AdvertListRenderer} holds the data and the item renderer fetches it via the multiplier. A standalone AJAX signal (favorite/follow) has no parent and returns an empty array, so the redrawn advert has no highlighting (and no error).

private resolveHighlights(int|null $advertId) : array<string, string>
Parameters
$advertId : int|null
Return values
array<string, string>

resolveIsHighlighted()

Returns whether the paid "Highlighting" is active (card tint via the class `highlighted`), via the parent like {@see resolveHighlights()}: the set is held by {@see AdvertListRenderer::isHighlighted()}; a standalone AJAX redraw of the item without a parent fails open to `false` (card without tint, no error).

private resolveIsHighlighted(int|null $advertId) : bool
Parameters
$advertId : int|null
Return values
bool

resolveParameterOptions()

private resolveParameterOptions() : array<string|int, object>
Return values
array<string|int, object>

resolveStyleFromMultiplier()

'style2' becomes 'Style_2'. After an AJAX signal the style comes primarily from `$selectedStyle` (passed by the signal); this is the multiplier-context fallback.

private resolveStyleFromMultiplier() : string|null
Return values
string|null
On this page

Search results