AdvertRenderer
extends BaseComponent
in package
uses
MultipliableTrait, ToggleRedrawTrait, FavouriteTrait
Renders one advert in a list. Used via {multicontrol} from AdvertListRenderer (Multiplier, key = advertId), so each advert has its own isolated 'advert' snippet — an AJAX toggle (favourite) redraws only that item.
Table of Contents
Constants
- DESC_LIMIT : int = 150
- How many visible characters of the description a highlighted snippet may have. Must match `|truncate:150` in Style_1..3, otherwise the list would "bloat" when searching.
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
- $advertManager : AdvertManager
- $favouriteRedrawSnippets : array<string|int, string>
- Snippets / snippet areas redrawn after an AJAX toggle.
- $favouriteSessionSection : 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
- hasServiceByType() : bool
- Returns whether the container has a service of the given type.
- initFavourites() : void
- initializeAllContexts() : void
- injectDeviceDetector() : void
- 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), 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
- 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
- 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>
- Snippets for this profile: the data is held by the parent {@see AdvertListRenderer} and the item renderer picks them up through the multiplier. The parent has no standalone AJAX signal, so the result is empty (a redrawn profile without highlighting, no error).
- resolveIsHighlighted() : bool
- Active paid "Highlighting" (card background through the class `highlighted`): the same path through the parent as {@see resolveHighlights()}; a standalone AJAX redraw without the parent falls back fail-open to `false`.
- resolveStyleFromMultiplier() : string|null
- 'style2' → '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
How many visible characters of the description a highlighted snippet may have. Must match `|truncate:150` in Style_1..3, otherwise the list would "bloat" when searching.
private
int
DESC_LIMIT
= 150
Properties
$container
public
Container
$container
Attributes
- #[Inject]
$routerDispatcher
public
RouterDispatcher
$routerDispatcher
$translator
public
ITranslator
$translator
Tags
$appContext
protected
AppContext
$appContext
$componentParameters
protected
array<string, mixed>
$componentParameters
= []
component parameters set by setComponentParameter()
$currencyContext
protected
CurrencyContext|null
$currencyContext
= NULL
$deviceDetector
protected
DeviceDetector|null
$deviceDetector
= NULL
$languageContext
protected
LanguageContext|null
$languageContext
= NULL
$localizationContext
protected
LocalizationContext|null
$localizationContext
= NULL
$selectedStyle
protected
string|null
$selectedStyle
= null
$settingContext
protected
SettingContext
$settingContext
$themeContext
protected
ThemeContext|null
$themeContext
= NULL
$translatorDomain
protected
string|null
$translatorDomain
= 'front.comcat.components.advertRenderer'
$advert
private
Advert|null
$advert
= null
$advertManager read-only
private
AdvertManager
$advertManager
$favouriteRedrawSnippets
Snippets / snippet areas redrawn after an AJAX toggle.
private
array<string|int, string>
$favouriteRedrawSnippets
= ['advert']
Default = the whole card.
$favouriteSessionSection
private
string
$favouriteSessionSection
= ''
$headingTag
private
string
$headingTag
= 'div'
$multiplierItemId
private
string|int|null
$multiplierItemId
= null
$multiplierRenderMethod
private
string|null
$multiplierRenderMethod
= null
$multiplierUniqueKey
private
string|null
$multiplierUniqueKey
= null
$renderingDefault
Guard against the `renderDefault()` and `render()` delegation loop.
private
bool
$renderingDefault
= false
$session read-only
private
Session
$session
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>
__construct()
public
__construct(AdvertManager $advertManager, Session $session) : mixed
Parameters
- $advertManager : AdvertManager
- $session : Session
createComponent()
public
createComponent(string $name) : IComponent|null
Parameters
- $name : string
Return values
IComponent|nullgetAppContext()
public
getAppContext() : AppContext
Return values
AppContextgetComponentParameter()
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
ContainergetCurrencyContext()
public
getCurrencyContext() : CurrencyContext|null
Return values
CurrencyContext|nullgetFavouriteIds()
public
getFavouriteIds() : array<string|int, int>
Return values
array<string|int, int>getLanguageContext()
public
getLanguageContext() : LanguageContext|null
Return values
LanguageContext|nullgetLocalizationContext()
public
getLocalizationContext() : LocalizationContext|null
Return values
LocalizationContext|nullgetMultiplierItemId()
public
getMultiplierItemId() : string|int|null
Return values
string|int|nullgetMultiplierRenderMethod()
Returns the render method of the multiplier.
public
getMultiplierRenderMethod() : string|null
Return values
string|nullgetMultiplierUniqueKey()
Returns the unique key of the multiplier.
public
getMultiplierUniqueKey() : string|null
Return values
string|nullgetRouterDispatcher()
public
getRouterDispatcher() : RouterDispatcher
Return values
RouterDispatchergetSettingContext()
public
getSettingContext() : SettingContext
Return values
SettingContextgetSettings()
public
getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>getThemeContext()
public
getThemeContext() : ThemeContext|null
Return values
ThemeContext|nullhandleAddToFavourites()
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'
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
Return values
boolinitFavourites()
public
initFavourites(string $sessionSection) : void
Parameters
- $sessionSection : string
initializeAllContexts()
public
initializeAllContexts() : void
injectDeviceDetector()
public
injectDeviceDetector(DeviceDetector $detector) : void
Parameters
- $detector : DeviceDetector
isInFavourites()
public
isInFavourites(int $advertId) : bool
Parameters
- $advertId : int
Return values
boolisInMultiplier()
Returns whether the component is rendered inside a multiplier.
public
isInMultiplier() : bool
Return values
boolloadAdvert()
Loads an advert by ID and caches it into $this->advert. Also called from the signal handlers (Favourite), 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|nullonCreate()
public
onCreate() : void
render()
public
render([string $style = 'Style1' ]) : void
Parameters
- $style : string = 'Style1'
setAdvert()
public
setAdvert(Advert $advert) : self
Parameters
- $advert : Advert
Return values
selfsetAppContext()
public
setAppContext(AppContext $appContext) : $this
Parameters
- $appContext : AppContext
Return values
$thissetComponentParameter()
Sets a component parameter.
public
setComponentParameter(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
setCurrencyContext()
public
setCurrencyContext(CurrencyContext|null $currencyContext) : $this
Parameters
- $currencyContext : CurrencyContext|null
Return values
$thissetFavouriteRedrawSnippets()
public
setFavouriteRedrawSnippets(string ...$snippets) : self
Parameters
- $snippets : string
Return values
selfsetHeadingTag()
public
setHeadingTag(string $headingTag) : self
Parameters
- $headingTag : string
Return values
selfsetLanguageContext()
public
setLanguageContext(LanguageContext|null $languageContext) : $this
Parameters
- $languageContext : LanguageContext|null
Return values
$thissetLocalizationContext()
public
setLocalizationContext(LocalizationContext|null $localizationContext) : $this
Parameters
- $localizationContext : LocalizationContext|null
Return values
$thissetMultiplierContext()
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
setSettingContext()
public
setSettingContext(SettingContext $settingContext) : $this
Parameters
- $settingContext : SettingContext
Return values
$thissetThemeContext()
public
setThemeContext(ThemeContext|null $themeContext) : $this
Parameters
- $themeContext : ThemeContext|null
Return values
$thissetup()
public
setup(BasePresenter|BasePresenter $presenter) : void
Parameters
- $presenter : BasePresenter|BasePresenter
setupAppContext()
public
setupAppContext(AppContext $appContext) : void
Parameters
- $appContext : AppContext
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
Return values
TfrontPresenter()
Returns the front presenter the component is attached to (null outside the front end or when detached).
protected
frontPresenter() : BasePresenter|null
Return values
BasePresenter|nullgetTranslator()
protected
getTranslator() : ITranslator
Return values
ITranslatorhandleMultiplierSuccess()
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
selfavailableRenderStyles()
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
stringcreateMultiplierComponent()
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|nullcreateStandardComponent()
Creates a standard component (not a multiplier).
private
createStandardComponent(string $name) : IComponent|null
Parameters
- $name : string
Return values
IComponent|nullfinishToggle()
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|nullgetFavouriteSection()
private
getFavouriteSection() : SessionSection
Return values
SessionSectionprepareTemplate()
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|nullresolveHighlights()
Snippets for this profile: the data is held by the parent {@see AdvertListRenderer} and the item renderer picks them up through the multiplier. The parent has no standalone AJAX signal, so the result is empty (a redrawn profile without highlighting, no error).
private
resolveHighlights(int|null $advertId) : array<string, string>
Parameters
- $advertId : int|null
Return values
array<string, string>resolveIsHighlighted()
Active paid "Highlighting" (card background through the class `highlighted`): the same path through the parent as {@see resolveHighlights()}; a standalone AJAX redraw without the parent falls back fail-open to `false`.
private
resolveIsHighlighted(int|null $advertId) : bool
Parameters
- $advertId : int|null
Return values
boolresolveStyleFromMultiplier()
'style2' → '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