array(self::DAY, 'days', 'day', ' ', ', '), self::HOUR => array(self::HOUR, 'hrs', 'hr', '', ''), self::MIN => array(0, 'mins', 'min', '', ''), self::SEC => array(0, 'secs', 'sec', '', ''), ); /** * * base url of the application * * @var string */ protected $_baseUrl; /** * * date timestamp * * @var int */ protected $_date; /** * * class constructor */ public function __construct() { $this->_baseUrl = Front::getInstance()->getRequest()->getBaseUrl(); } /** * * main method, will only store the date in the helper * * @param string|int $date * * @return string */ public function countdown($date) { if (!is_numeric($date)) { $date = strtotime($date); } $this->_date = $date; return $this; } /** * * display the time left w/o javascript component * * @param int $secs minimum number of seconds to display * * @return string */ public function timeLeft($secs = self::MIN) { $translate = $this->getTranslate(); if (!$this->_date) { return $translate->_('n/a'); } $output = null; $original = $countdown = $this->_date - time(); if ($countdown > 0) { foreach ($this->_intervals as $seconds => $data) { $left = floor($countdown / $seconds); $countdown -= ($left * $seconds); list($min, $plural, $singular, $separator, $suffix) = $data; if ($original >= $min && $seconds >= $secs) { $output .= ' ' . $left . $separator . (($left > 1) ? $translate->_($plural) : $translate->_($singular)) . $suffix; } } } else { $output = '' . $translate->_('Closed') . ''; } return $output; } /** * * display the time elapsed w/o javascript component * * @param int $secs minimum time interval to display (by key) * * @return string */ public function timeElapsed($secs = self::MIN) { $translate = $this->getTranslate(); $original = $elapsed = time() - $this->_date; if ($original <= 0 || $this->_date <= 0) { return $translate->_('n/a'); } $output = null; foreach ($this->_intervals as $seconds => $data) { $left = floor($elapsed / $seconds); $elapsed -= ($left * $seconds); list($min, $plural, $singular, $separator, $suffix) = $data; if ($original >= $min && $seconds >= $secs) { $output .= $left . $separator . (($left > 1) ? $translate->_($plural) : $translate->_($singular)) . $suffix; } } return $output; } public function display() { $translate = $this->getTranslate(); if (!$this->_date) { return $translate->_('n/a'); } $this->_generateJavascript(); $countdown = $this->_date . '000'; // workaround for 32 bit systems return ''; } protected function _generateJavascript() { $translate = $this->getTranslate(); /** @var \Cube\View\Helper\Script $scriptHelper */ $scriptHelper = $this->getView()->getHelper('script'); $scriptHelper->addBodyCode('') ->addBodyCode(""); } }