Back to FeaturedButton class

Method render

public string
render
(?int $value = null, ?int $row = null, array $options = [], mixed $featuredUp = null, mixed $featuredDown = null)
Render action button by item value.
Parameters
  • int|null $value Current value of this item.
  • int|null $row The row number of this item.
  • array $options The options to override group options.
  • string|\Joomla\CMS\Date\Date $featuredUp The date which item featured up.
  • string|\Joomla\CMS\Date\Date $featuredDown The date which item featured down.
Returns
  • string Rendered HTML.
Since
  • 4.0.0

Method render - Source code

/**
 * Render action button by item value.
 *
 * @param   integer|null  $value         Current value of this item.
 * @param   integer|null  $row           The row number of this item.
 * @param   array         $options       The options to override group options.
 * @param   string|Date   $featuredUp    The date which item featured up.
 * @param   string|Date   $featuredDown  The date which item featured down.
 *
 * @return  string  Rendered HTML.
 *
 * @since  4.0.0
 */
public function render(?int $value = null, ?int $row = null, array $options = [], $featuredUp = null, $featuredDown = null) : string
{
    if ($featuredUp || $featuredDown) {
        $bakState = $this->getState($value);
        $default = $this->getState($value) ?? $this->unknownState;
        $nowDate = Factory::getDate()->toUnix();
        $tz = Factory::getUser()->getTimezone();
        if (!is_null($featuredUp)) {
            $featuredUp = Factory::getDate($featuredUp, 'UTC')->setTimezone($tz);
        }
        if (!is_null($featuredDown)) {
            $featuredDown = Factory::getDate($featuredDown, 'UTC')->setTimezone($tz);
        }
        // Add tips and special titles
        // Create special titles for featured items
        if ($value === 1) {
            // Create tip text, only we have featured up or down settings
            $tips = [];
            if ($featuredUp) {
                $tips[] = Text::sprintf('JLIB_HTML_FEATURED_STARTED', HTMLHelper::_('date', $featuredUp, Text::_('DATE_FORMAT_LC5'), 'UTC'));
            }
            if ($featuredDown) {
                $tips[] = Text::sprintf('JLIB_HTML_FEATURED_FINISHED', HTMLHelper::_('date', $featuredDown, Text::_('DATE_FORMAT_LC5'), 'UTC'));
            }
            $tip = empty($tips) ? false : implode('<br>', $tips);
            $default['title'] = $tip;
            $options['tip_title'] = Text::_('JLIB_HTML_FEATURED_ITEM');
            if ($featuredUp && $nowDate < $featuredUp->toUnix()) {
                $options['tip_title'] = Text::_('JLIB_HTML_FEATURED_PENDING_ITEM');
                $default['icon'] = 'pending';
            }
            if ($featuredDown && $nowDate > $featuredDown->toUnix()) {
                $options['tip_title'] = Text::_('JLIB_HTML_FEATURED_EXPIRED_ITEM');
                $default['icon'] = 'expired';
            }
        }
        $this->states[$value] = $default;
        $html = parent::render($value, $row, $options);
        $this->states[$value] = $bakState;
        return $html;
    }
    return parent::render($value, $row, $options);
}