mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
parent
da7f619804
commit
5c98acd36c
@ -1,62 +1,125 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// @codingStandardsIgnoreStart
|
||||||
|
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
use \DateTime;
|
use \DateTime;
|
||||||
use \DateTimeZone;
|
use \DateTimeZone;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Application\Config as IcingaConfig;
|
use Icinga\Application\Config as IcingaConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to format date and time
|
||||||
|
*/
|
||||||
class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
|
class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current request
|
||||||
|
* @var Zend_Controller_Request_Abstract
|
||||||
|
*/
|
||||||
|
private $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* Retrieve current request
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->request = Icinga::app()->getFrontController()->getRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper entry point
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
public function dateFormat()
|
public function dateFormat()
|
||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format date according to current user's format
|
||||||
|
*
|
||||||
|
* @param int $timestamp A unix timestamp
|
||||||
|
* @return string The formatted date string
|
||||||
|
*/
|
||||||
public function formatDate($timestamp)
|
public function formatDate($timestamp)
|
||||||
{
|
{
|
||||||
$dt = new DateTime($timestamp, $this->getTimeZone());
|
$dt = new DateTime($timestamp, $this->getTimeZone());
|
||||||
return $dt->format($this->getDateFormat());
|
return $dt->format($this->getDateFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function timeFormat($timestamp)
|
/**
|
||||||
|
* Format time according to current user's format
|
||||||
|
*
|
||||||
|
* @param int $timestamp A unix timestamp
|
||||||
|
* @return string The formatted time string
|
||||||
|
*/
|
||||||
|
public function formatTime($timestamp)
|
||||||
{
|
{
|
||||||
$dt = new DateTime($timestamp, $this->getTimeZone());
|
$dt = new DateTime($timestamp, $this->getTimeZone());
|
||||||
return $dt->format($this->getTimeFormat());
|
return $dt->format($this->getTimeFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format datetime according to current user's format
|
||||||
|
*
|
||||||
|
* @param int $timestamp A unix timestamp
|
||||||
|
* @return string The formatted datetime string
|
||||||
|
*/
|
||||||
public function formatDateTime($timestamp)
|
public function formatDateTime($timestamp)
|
||||||
{
|
{
|
||||||
$dt = new DateTime($timestamp, $this->getTimeZone());
|
$dt = new DateTime($timestamp, $this->getTimeZone());
|
||||||
return $dt->format($this->getDateTimeFormat());
|
return $dt->format($this->getDateTimeFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRequest()
|
/**
|
||||||
{
|
* Retrieve the current user's timezone
|
||||||
// TODO(el/WIP): Set via constructor
|
*
|
||||||
return Icinga::app()->getFrontController()->getRequest();
|
* @return DateTimeZone
|
||||||
}
|
*/
|
||||||
|
|
||||||
private function getTimeZone()
|
private function getTimeZone()
|
||||||
{
|
{
|
||||||
return new DateTimeZone($this->getRequest()->getUser()->getTimeZone());
|
return new DateTimeZone($this->request->getUser()->getTimeZone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the current user's date format string
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getDateFormat()
|
public function getDateFormat()
|
||||||
{
|
{
|
||||||
return $this->getRequest()->getUser()->getPreferences()->get(
|
return $this->request->getUser()->getPreferences()->get(
|
||||||
'dateFormat', IcingaConfig::app()->global->get('dateFormat', 'Y-m-d')
|
'dateFormat', IcingaConfig::app()->global->get('dateFormat', 'Y-m-d')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the current user's time format string
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getTimeFormat()
|
public function getTimeFormat()
|
||||||
{
|
{
|
||||||
return $this->getRequest()->getUser()->getPreferences()->get(
|
return $this->request->getUser()->getPreferences()->get(
|
||||||
'timeFormat', IcingaConfig::app()->global->get('timeFormat', 'H:i:s')
|
'timeFormat', IcingaConfig::app()->global->get('timeFormat', 'H:i:s')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the current user's datetime format string
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getDateTimeFormat()
|
public function getDateTimeFormat()
|
||||||
{
|
{
|
||||||
return $this->getDateFormat() . ' ' . $this->getTimeFormat();
|
return $this->getDateFormat() . ' ' . $this->getTimeFormat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @codingStandardsIgnoreStop
|
||||||
|
@ -36,9 +36,9 @@ class Zend_View_Helper_FormDateTime extends Zend_View_Helper_FormElement
|
|||||||
/**
|
/**
|
||||||
* Generate a 'datetime' element
|
* Generate a 'datetime' element
|
||||||
*
|
*
|
||||||
* @param string $name The element name
|
* @param string $name The element name
|
||||||
* @param int $value The default timestamp
|
* @param int $value The default timestamp
|
||||||
* @param array $attribs Attributes for the element tag
|
* @param array $attribs Attributes for the element tag
|
||||||
*
|
*
|
||||||
* @return string The element XHTML
|
* @return string The element XHTML
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user