Back to PhocacartDate class

Method getActiveDate

public static
getActiveDate
(mixed $from, mixed $to, mixed $returnText = 0)

Method getActiveDate - Source code

public static function getActiveDate($from, $to, $returnText = 0)
{
    $db = Factory::getDBO();
    $nullDate = $db->getNullDate();
    $now = Factory::getDate();
    $config = Factory::getConfig();
    $fromDate = Factory::getDate($from);
    $toDate = Factory::getDate($to);
    $tz = new DateTimeZone($config->get('offset'));
    $fromDate->setTimezone($tz);
    $toDate->setTimezone($tz);
    $status = 0;
    $text = '';
    if ($now->toUnix() <= $fromDate->toUnix()) {
        $status = 0;
        $text = '<span class="label label-warning badge bg-warning">' . Text::_('COM_PHOCACART_PENDING') . '</span>';
    } else {
        if ($now->toUnix() <= $toDate->toUnix() || $to == $nullDate) {
            $status = 1;
            $text = '<span class="label label-success badge bg-success">' . Text::_('COM_PHOCACART_ACTIVE') . '</span>';
        } else {
            if ($now->toUnix() > $toDate->toUnix()) {
                $status = 0;
                $text = '<span class="label label-important label-danger badge bg-danger">' . Text::_('COM_PHOCACART_EXPIRED') . '</span>';
            }
        }
    }
    if ($returnText == 1) {
        return $text;
    } else {
        return $status;
    }
    return false;
}