Back to JGrid class

Method published

public static string
published
(mixed $value, mixed $i, mixed $prefix = '', mixed $enabled = true, mixed $checkbox = 'cb', mixed $publishUp = null, mixed $publishDown = null, mixed $formId = null)
Returns a published state on a grid
Parameters
  • int $value The state value.
  • int $i The row index
  • string|array $prefix An optional task prefix or an array of options
  • bool $enabled An optional setting for access control on the action.
  • string $checkbox An optional prefix for checkboxes.
  • string $publishUp An optional start publishing date.
  • string $publishDown An optional finish publishing date.
  • string $formId An optional form selector.
Returns
  • string The HTML markup
Since
  • 1.6
-
  • \Joomla\CMS\HTML\Helpers\JHtmlJGrid::state()
Class: JGrid
Project: Joomla

Method published - Source code

/**
 * Returns a published state on a grid
 *
 * @param   integer       $value        The state value.
 * @param   integer       $i            The row index
 * @param   string|array  $prefix       An optional task prefix or an array of options
 * @param   boolean       $enabled      An optional setting for access control on the action.
 * @param   string        $checkbox     An optional prefix for checkboxes.
 * @param   string        $publishUp    An optional start publishing date.
 * @param   string        $publishDown  An optional finish publishing date.
 * @param   string        $formId       An optional form selector.
 *
 * @return  string  The HTML markup
 *
 * @see     JHtmlJGrid::state()
 * @since   1.6
 */
public static function published($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $publishUp = null, $publishDown = null, $formId = null)
{
    if (is_array($prefix)) {
        $options = $prefix;
        $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
        $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
        $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
    }
    $states = array(1 => array('unpublish', 'JPUBLISHED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JPUBLISHED', true, 'publish', 'publish'), 0 => array('publish', 'JUNPUBLISHED', 'JLIB_HTML_PUBLISH_ITEM', 'JUNPUBLISHED', true, 'unpublish', 'unpublish'), 2 => array('unpublish', 'JARCHIVED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JARCHIVED', true, 'archive', 'archive'), -2 => array('publish', 'JTRASHED', 'JLIB_HTML_PUBLISH_ITEM', 'JTRASHED', true, 'trash', 'trash'));
    // Special state for dates
    if ($publishUp || $publishDown) {
        $nullDate = Factory::getDbo()->getNullDate();
        $nowDate = Factory::getDate()->toUnix();
        $tz = Factory::getUser()->getTimezone();
        $publishUp = $publishUp !== null && $publishUp !== $nullDate ? Factory::getDate($publishUp, 'UTC')->setTimezone($tz) : false;
        $publishDown = $publishDown !== null && $publishDown !== $nullDate ? Factory::getDate($publishDown, 'UTC')->setTimezone($tz) : false;
        // Create tip text, only we have publish up or down settings
        $tips = array();
        if ($publishUp) {
            $tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_START', HTMLHelper::_('date', $publishUp, Text::_('DATE_FORMAT_LC5'), 'UTC'));
        }
        if ($publishDown) {
            $tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_FINISHED', HTMLHelper::_('date', $publishDown, Text::_('DATE_FORMAT_LC5'), 'UTC'));
        }
        $tip = empty($tips) ? false : implode('<br>', $tips);
        // Add tips and special titles
        foreach ($states as $key => $state) {
            // Create special titles for published items
            if ($key == 1) {
                $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_ITEM';
                if ($publishUp > $nullDate && $nowDate < $publishUp->toUnix()) {
                    $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_PENDING_ITEM';
                    $states[$key][5] = $states[$key][6] = 'pending';
                }
                if ($publishDown > $nullDate && $nowDate > $publishDown->toUnix()) {
                    $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_EXPIRED_ITEM';
                    $states[$key][5] = $states[$key][6] = 'expired';
                }
            }
            // Add tips to titles
            if ($tip) {
                $states[$key][1] = Text::_($states[$key][1]);
                $states[$key][2] = Text::_($states[$key][2]) . '<br>' . $tip;
                $states[$key][3] = Text::_($states[$key][3]) . '<br>' . $tip;
                $states[$key][4] = true;
            }
        }
        return static::state($states, $value, $i, array('prefix' => $prefix, 'translate' => !$tip), $enabled, true, $checkbox, $formId);
    }
    return static::state($states, $value, $i, $prefix, $enabled, true, $checkbox, $formId);
}