diff options
-rw-r--r-- | core/Date.php | 26 | ||||
-rw-r--r-- | core/Updates/2.15.1-b1.php | 32 | ||||
-rw-r--r-- | core/Version.php | 2 | ||||
-rw-r--r-- | lang/en.json | 3 | ||||
-rw-r--r-- | plugins/LanguagesManager/API.php | 39 | ||||
-rw-r--r-- | plugins/LanguagesManager/LanguagesManager.php | 13 | ||||
-rw-r--r-- | plugins/LanguagesManager/Model.php | 31 | ||||
-rw-r--r-- | plugins/UsersManager/Controller.php | 3 | ||||
-rw-r--r-- | plugins/UsersManager/javascripts/usersSettings.js | 1 | ||||
-rw-r--r-- | plugins/UsersManager/templates/userSettings.twig | 8 |
10 files changed, 157 insertions, 1 deletions
diff --git a/core/Date.php b/core/Date.php index bac8ce7db2..eac218eb9e 100644 --- a/core/Date.php +++ b/core/Date.php @@ -11,6 +11,7 @@ namespace Piwik; use Exception; use Piwik\Container\StaticContainer; +use Piwik\Plugins\LanguagesManager\Model as LanguagesManagerModel; /** * Utility class that wraps date/time related PHP functions. Using this class can @@ -627,6 +628,31 @@ class Date $template = $translator->translate($template); } + if (strpos($template, '{time}') !== false) { + + static $use12HourClock = null; + + if (is_null($use12HourClock)) { + + $model = new LanguagesManagerModel(); + + $use12HourClock = $model->uses12HourClock(Piwik::getCurrentUserLogin()); + } + + $timeFormat = 'Intl_Format_Time_24'; + + if ($use12HourClock) { + $timeFormat = 'Intl_Format_Time_12'; + + } + + $translator = StaticContainer::get('Piwik\Translation\Translator'); + $replacement = $translator->translate($timeFormat); + + $template = str_replace('{time}', $replacement, $template); + } + + $tokens = self::parseFormat($template); $out = ''; diff --git a/core/Updates/2.15.1-b1.php b/core/Updates/2.15.1-b1.php new file mode 100644 index 0000000000..c2c0fcadbd --- /dev/null +++ b/core/Updates/2.15.1-b1.php @@ -0,0 +1,32 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\Updates; + +use Piwik\Common; +use Piwik\Updater; +use Piwik\Updates; + + +class Updates_2_15_1_b1 extends Updates +{ + public function getMigrationQueries(Updater $updater) + { + $updateSql = array( + 'ALTER TABLE `' . Common::prefixTable('user_language') + . '` ADD COLUMN `use_12_hour_clock` TINYINT(1) NOT NULL DEFAULT 0 AFTER `language`' => array(1060) + ); + return $updateSql; + } + + public function doUpdate(Updater $updater) + { + $updater->executeMigrationQueries(__FILE__, $this->getMigrationQueries($updater)); + } +} diff --git a/core/Version.php b/core/Version.php index ee5bad9caa..77b3d42f1c 100644 --- a/core/Version.php +++ b/core/Version.php @@ -20,7 +20,7 @@ final class Version * The current Piwik version. * @var string */ - const VERSION = '2.15.0'; + const VERSION = '2.15.1-b1'; public function isStableVersion($version) { diff --git a/lang/en.json b/lang/en.json index b70d71e53a..f235a6fa77 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1,5 +1,7 @@ { "General": { + "12HourClock": "12-hour clock", + "24HourClock": "24-hour clock", "AbandonedCarts": "Abandoned Carts", "AboutPiwikX": "About Piwik %s", "Action": "Action", @@ -348,6 +350,7 @@ "TagCloud": "Tag Cloud", "Tax": "Tax", "TimeAgo": "%s ago", + "TimeFormat": "Time format", "TimeOnPage": "Time on page", "Total": "Total", "TotalRatioTooltip": "This is %1$s of all %2$s %3$s.", diff --git a/plugins/LanguagesManager/API.php b/plugins/LanguagesManager/API.php index dc252abbda..9d75f62c2f 100644 --- a/plugins/LanguagesManager/API.php +++ b/plugins/LanguagesManager/API.php @@ -275,6 +275,45 @@ class API extends \Piwik\Plugin\API return true; } + /** + * Returns whether the user uses 12 hour clock + * + * @param string $login + * @return string + */ + public function uses12HourClockForUser($login) + { + if ($login == 'anonymous') { + return false; + } + + Piwik::checkUserHasSuperUserAccessOrIsTheUser($login); + + $lang = $this->getModel()->uses12HourClock($login); + + return $lang; + } + + /** + * Returns whether the user uses 12 hour clock + * + * @param string $login + * @param bool $use12HourClock + * @return string + */ + public function set12HourClockForUser($login, $use12HourClock) + { + if ($login == 'anonymous') { + return false; + } + + Piwik::checkUserHasSuperUserAccessOrIsTheUser($login); + + $lang = $this->getModel()->set12HourClock($login, $use12HourClock); + + return $lang; + } + private function loadAvailableLanguages() { if (!is_null($this->availableLanguageNames)) { diff --git a/plugins/LanguagesManager/LanguagesManager.php b/plugins/LanguagesManager/LanguagesManager.php index 012de9cd50..70444c15c8 100644 --- a/plugins/LanguagesManager/LanguagesManager.php +++ b/plugins/LanguagesManager/LanguagesManager.php @@ -138,6 +138,19 @@ class LanguagesManager extends \Piwik\Plugin } /** + * @return boolean + */ + public static function uses12HourClockForCurrentUser() + { + try { + $currentUser = Piwik::getCurrentUserLogin(); + return API::getInstance()->uses12HourClockForUser($currentUser); + } catch (Exception $e) { + return false; + } + } + + /** * @return string Two letters language code, eg. "fr" */ public static function getLanguageCodeForCurrentUser() diff --git a/plugins/LanguagesManager/Model.php b/plugins/LanguagesManager/Model.php index e40452c134..fad84238cd 100644 --- a/plugins/LanguagesManager/Model.php +++ b/plugins/LanguagesManager/Model.php @@ -57,10 +57,41 @@ class Model return true; } + /** + * Returns whether the given user has choosen to use 12 hour clock + * + * @param $userLogin + * @return bool + * @throws \Exception + */ + public function uses12HourClock($userLogin) + { + return (bool) Db::fetchOne('SELECT use_12_hour_clock FROM ' . $this->table . + ' WHERE login = ? ', array($userLogin)); + } + + /** + * Sets whether the given user wants to use 12 hout clock + * + * @param string $login + * @param string $use12HourClock + * @return bool + */ + public function set12HourClock($login, $use12HourClock) + { + $query = 'INSERT INTO ' . $this->table . + ' (login, use_12_hour_clock) VALUES (?,?) ON DUPLICATE KEY UPDATE use_12_hour_clock=?'; + $bind = array($login, $use12HourClock, $use12HourClock); + Db::query($query, $bind); + + return true; + } + public static function install() { $userLanguage = "login VARCHAR( 100 ) NOT NULL , language VARCHAR( 10 ) NOT NULL , + use_12_hour_clock TINYINT(1) NOT NULL DEFAULT 0 , PRIMARY KEY ( login )"; DbHelper::createTable(self::$rawPrefix, $userLanguage); } diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php index 105d795036..3b0755199f 100644 --- a/plugins/UsersManager/Controller.php +++ b/plugins/UsersManager/Controller.php @@ -259,6 +259,7 @@ class Controller extends ControllerAdmin $view->languages = APILanguagesManager::getInstance()->getAvailableLanguageNames(); $view->currentLanguageCode = LanguagesManager::getLanguageCodeForCurrentUser(); + $view->currentTimeformat = LanguagesManager::uses12HourClockForCurrentUser(); $view->ignoreCookieSet = IgnoreCookie::isIgnoreCookieFound(); $view->piwikHost = Url::getCurrentHost(); $this->setBasicVariablesView($view); @@ -379,12 +380,14 @@ class Controller extends ControllerAdmin $defaultReport = Common::getRequestVar('defaultReport'); $defaultDate = Common::getRequestVar('defaultDate'); $language = Common::getRequestVar('language'); + $timeFormat = Common::getRequestVar('timeformat'); $userLogin = Piwik::getCurrentUserLogin(); $this->processPasswordChange($userLogin); LanguagesManager::setLanguageForSession($language); APILanguagesManager::getInstance()->setLanguageForUser($userLogin, $language); + APILanguagesManager::getInstance()->set12HourClockForUser($userLogin, $timeFormat); APIUsersManager::getInstance()->setUserPreference($userLogin, APIUsersManager::PREFERENCE_DEFAULT_REPORT, diff --git a/plugins/UsersManager/javascripts/usersSettings.js b/plugins/UsersManager/javascripts/usersSettings.js index a72bb4db96..c6c909ea6b 100644 --- a/plugins/UsersManager/javascripts/usersSettings.js +++ b/plugins/UsersManager/javascripts/usersSettings.js @@ -38,6 +38,7 @@ function sendUserSettingsAJAX() { postParams.defaultReport = defaultReport; postParams.defaultDate = defaultDate; postParams.language = $('#userSettingsTable #language').val(); + postParams.timeformat = $('#userSettingsTable #timeformat').val(); var ajaxHandler = new ajaxHelper(); ajaxHandler.addParams({ diff --git a/plugins/UsersManager/templates/userSettings.twig b/plugins/UsersManager/templates/userSettings.twig index 57e04dff85..1478368858 100644 --- a/plugins/UsersManager/templates/userSettings.twig +++ b/plugins/UsersManager/templates/userSettings.twig @@ -45,6 +45,14 @@ </div> <div class="form-group"> + <label for="timeformat">{{ 'General_TimeFormat'|translate }}</label> + <select name="timeformat" id="timeformat"> + <option value="1" {% if currentTimeformat == 1 %}selected="selected"{% endif %} title="{{ 'General_12HourClock'|translate }}">{{ 'General_12HourClock'|translate }}</option> + <option value="0" {% if currentTimeformat == 0 %}selected="selected"{% endif %} title="{{ 'General_24HourClock'|translate }}">{{ 'General_24HourClock'|translate }}</option> + </select> + </div> + + <div class="form-group"> <label>{{ 'UsersManager_ReportToLoadByDefault'|translate }}</label> <label class="radio"> <input id="defaultReportRadioAll" type="radio" value="MultiSites" |