From 5c98acd36c495dc4b50d3f03dfd1dbc7ce5950cf Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 7 Aug 2013 10:53:44 +0200 Subject: [PATCH] Framework: Add doctrings to DateFormat view helper refs #4424 --- application/views/helpers/DateFormat.php | 83 +++++++++++++++++++--- application/views/helpers/FormDateTime.php | 6 +- 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/application/views/helpers/DateFormat.php b/application/views/helpers/DateFormat.php index 3a77bc791..d8dcf399a 100644 --- a/application/views/helpers/DateFormat.php +++ b/application/views/helpers/DateFormat.php @@ -1,62 +1,125 @@ request = Icinga::app()->getFrontController()->getRequest(); + } + + /** + * Helper entry point + * + * @return self + */ public function dateFormat() { 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) { $dt = new DateTime($timestamp, $this->getTimeZone()); 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()); 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) { $dt = new DateTime($timestamp, $this->getTimeZone()); return $dt->format($this->getDateTimeFormat()); } - private function getRequest() - { - // TODO(el/WIP): Set via constructor - return Icinga::app()->getFrontController()->getRequest(); - } - + /** + * Retrieve the current user's timezone + * + * @return DateTimeZone + */ 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() { - return $this->getRequest()->getUser()->getPreferences()->get( + return $this->request->getUser()->getPreferences()->get( 'dateFormat', IcingaConfig::app()->global->get('dateFormat', 'Y-m-d') ); } + /** + * Retrieve the current user's time format string + * + * @return string + */ public function getTimeFormat() { - return $this->getRequest()->getUser()->getPreferences()->get( + return $this->request->getUser()->getPreferences()->get( 'timeFormat', IcingaConfig::app()->global->get('timeFormat', 'H:i:s') ); } + /** + * Retrieve the current user's datetime format string + * + * @return string + */ public function getDateTimeFormat() { return $this->getDateFormat() . ' ' . $this->getTimeFormat(); } } + +// @codingStandardsIgnoreStop diff --git a/application/views/helpers/FormDateTime.php b/application/views/helpers/FormDateTime.php index 5d8618238..eabf29863 100644 --- a/application/views/helpers/FormDateTime.php +++ b/application/views/helpers/FormDateTime.php @@ -36,9 +36,9 @@ class Zend_View_Helper_FormDateTime extends Zend_View_Helper_FormElement /** * Generate a 'datetime' element * - * @param string $name The element name - * @param int $value The default timestamp - * @param array $attribs Attributes for the element tag + * @param string $name The element name + * @param int $value The default timestamp + * @param array $attribs Attributes for the element tag * * @return string The element XHTML */