PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/common/user/PreferencesPresenter.class.php

https://gitlab.com/prenaud76/tuleap
PHP | 391 lines | 274 code | 87 blank | 30 comment | 0 complexity | 8e2be832198bb401b83a5182552aa355 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-2.0, GPL-3.0
  1. <?php
  2. /**
  3. * Copyright (c) Enalean, 2014. All rights reserved
  4. *
  5. * This file is a part of Tuleap.
  6. *
  7. * Tuleap is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tuleap is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tuleap. If not, see <http://www.gnu.org/licenses/
  19. */
  20. class User_PreferencesPresenter {
  21. /** @var PFUser */
  22. private $user;
  23. public $can_change_real_name;
  24. private $can_change_email;
  25. private $can_change_password;
  26. private $extra_user_info;
  27. /** @var array */
  28. private $user_access;
  29. /** string */
  30. private $third_party_html;
  31. private $ssh_keys_extra_html;
  32. public $csrf_input_html;
  33. /** @var array */
  34. public $tracker_formats;
  35. /** @var array */
  36. public $all_themes;
  37. /** @var array */
  38. public $languages_html;
  39. /** @var array */
  40. public $user_helper_preferences;
  41. /** @var array */
  42. public $plugins_prefs;
  43. /** @var array */
  44. public $all_csv_separator;
  45. /** @var array */
  46. public $all_csv_dateformat;
  47. public function __construct(
  48. PFUser $user,
  49. $can_change_real_name,
  50. $can_change_email,
  51. $can_change_password,
  52. array $extra_user_info,
  53. array $user_access,
  54. $ssh_keys_extra_html,
  55. $third_party_html,
  56. $csrf_input_html,
  57. array $tracker_formats,
  58. array $all_themes,
  59. array $languages_html,
  60. array $user_helper_preferences,
  61. array $plugins_prefs,
  62. array $all_csv_separator,
  63. array $all_csv_dateformat
  64. ) {
  65. $this->user = $user;
  66. $this->can_change_real_name = $can_change_real_name;
  67. $this->can_change_email = $can_change_email;
  68. $this->can_change_password = $can_change_password;
  69. $this->extra_user_info = $extra_user_info;
  70. $this->user_access = $user_access;
  71. $this->ssh_keys_extra_html = $ssh_keys_extra_html;
  72. $this->third_party_html = $third_party_html;
  73. $this->csrf_input_html = $csrf_input_html;
  74. $this->tracker_formats = $tracker_formats;
  75. $this->all_themes = $all_themes;
  76. $this->languages_html = $languages_html;
  77. $this->user_helper_preferences = $user_helper_preferences;
  78. $this->plugins_prefs = $plugins_prefs;
  79. $this->all_csv_separator = $all_csv_separator;
  80. $this->all_csv_dateformat = $all_csv_dateformat;
  81. }
  82. public function has_avatar() {
  83. return ForgeConfig::get('sys_enable_avatars');
  84. }
  85. public function avatar() {
  86. return $this->user->fetchHtmlAvatar();
  87. }
  88. public function change_real_name() {
  89. return $GLOBALS['Language']->getText('account_options', 'change_real_name');
  90. }
  91. public function real_name() {
  92. return $this->user->getRealName();
  93. }
  94. public function user_username() {
  95. return $this->user->getUnixName();
  96. }
  97. public function welcome_user() {
  98. return $GLOBALS['Language']->getText('account_options', 'welcome') . ' ' . $this->user->getRealName();
  99. }
  100. public function user_id_label() {
  101. return $GLOBALS['Language']->getText('account_options', 'user_id');
  102. }
  103. public function user_id_value() {
  104. return $this->user->getId();
  105. }
  106. public function user_email_label() {
  107. return $GLOBALS['Language']->getText('account_options', 'email_address');
  108. }
  109. public function user_email_value() {
  110. return $this->user->getEmail();
  111. }
  112. public function can_change_email() {
  113. return $this->can_change_email;
  114. }
  115. public function change_email() {
  116. return $GLOBALS['Language']->getText('account_options', 'change_email_address');
  117. }
  118. public function can_change_password() {
  119. return $this->can_change_password;
  120. }
  121. public function change_password() {
  122. return $GLOBALS['Language']->getText('account_options', 'change_password');
  123. }
  124. public function member_since_label() {
  125. return $GLOBALS['Language']->getText('account_options', 'member_since');
  126. }
  127. public function member_since_value() {
  128. return format_date($GLOBALS['Language']->getText('system', 'datefmt'), $this->user->getAddDate());
  129. }
  130. public function timezone_label() {
  131. return $GLOBALS['Language']->getText('account_options', 'timezone');
  132. }
  133. public function timezone_value() {
  134. return $this->user->getTimezone();
  135. }
  136. public function change_timezone() {
  137. return $GLOBALS['Language']->getText('account_options', 'change_timezone');
  138. }
  139. public function extra_user_info() {
  140. return $this->extra_user_info;
  141. }
  142. public function shell_account_title() {
  143. return $GLOBALS['Language']->getText('account_options', 'shell_account_title');
  144. }
  145. public function ssh_keys_count_label() {
  146. return $GLOBALS['Language']->getText('account_options', 'shell_shared_keys');
  147. }
  148. public function ssh_keys_count() {
  149. return count($this->user->getAuthorizedKeysArray());
  150. }
  151. public function ssh_keys_label() {
  152. return 'Key';
  153. }
  154. public function ssh_keys_list() {
  155. $keys = array();
  156. foreach ($this->user->getAuthorizedKeysArray() as $ssh_key_number => $ssh_key_value) {
  157. $keys[] = array(
  158. 'ssh_key_ellipsis_value' => substr($ssh_key_value, 0, 40).'...'.substr($ssh_key_value, -40),
  159. 'ssh_key_value' => $ssh_key_value,
  160. 'ssh_key_number' => $ssh_key_number
  161. );
  162. }
  163. return $keys;
  164. }
  165. public function ssh_keys_extra_html() {
  166. return $this->ssh_keys_extra_html;
  167. }
  168. public function authentication_attempts_title() {
  169. return $GLOBALS['Language']->getText('account_options', 'auth_attempt_title');
  170. }
  171. public function last_successful_login_label() {
  172. return $GLOBALS['Language']->getText('account_options', 'auth_attempt_last_success');
  173. }
  174. public function last_successful_login_value() {
  175. return format_date($GLOBALS['Language']->getText('system', 'datefmt'), $this->user_access['last_auth_success']);
  176. }
  177. public function last_login_failure_label() {
  178. return $GLOBALS['Language']->getText('account_options', 'auth_attempt_last_failure');
  179. }
  180. public function last_login_failure_value() {
  181. return format_date($GLOBALS['Language']->getText('system', 'datefmt'), $this->user_access['last_auth_failure']);
  182. }
  183. public function number_login_failure_label() {
  184. return $GLOBALS['Language']->getText('account_options', 'auth_attempt_nb_failure');
  185. }
  186. public function number_login_failure_value() {
  187. return $this->user_access['nb_auth_failure'];
  188. }
  189. public function previous_successful_login_label() {
  190. return $GLOBALS['Language']->getText('account_options', 'auth_attempt_prev_success');
  191. }
  192. public function previous_successful_login_value() {
  193. return format_date($GLOBALS['Language']->getText('system', 'datefmt'), $this->user_access['prev_auth_success']);
  194. }
  195. public function third_party_applications_title() {
  196. return 'Third party applications';
  197. }
  198. public function third_party_applications_content() {
  199. return $this->third_party_html;
  200. }
  201. public function user_legal() {
  202. ob_start();
  203. include $GLOBALS['Language']->getContent('account/user_legal');
  204. return ob_get_clean();
  205. }
  206. public function add_ssh_key_button() {
  207. return $GLOBALS['Language']->getText('account_options', 'shell_add_keys');
  208. }
  209. public function delete_ssh_key_button() {
  210. return $GLOBALS['Language']->getText('account_options', 'shell_delete_ssh_keys');
  211. }
  212. public function has_ssh_key() {
  213. return $this->ssh_keys_count() > 0;
  214. }
  215. /* PREFERENCES */
  216. public function preference_title() {
  217. return $GLOBALS['Language']->getText('account_options', 'preferences');
  218. }
  219. public function email_settings() {
  220. return $GLOBALS['Language']->getText('account_preferences', 'email_settings');
  221. }
  222. public function user_has_mail_site_updates() {
  223. return $this->user->getMailSiteUpdates();
  224. }
  225. public function user_has_sticky_login() {
  226. return $this->user->getStickyLogin();
  227. }
  228. public function user_has_mail_va() {
  229. return $this->user->getMailVA();
  230. }
  231. public function site_update_label() {
  232. return $GLOBALS['Language']->getText('account_register', 'siteupdate');
  233. }
  234. public function community_mail_label() {
  235. return $GLOBALS['Language']->getText('account_register', 'communitymail');
  236. }
  237. public function tracker_mail_format_label() {
  238. return $GLOBALS['Language']->getText('account_preferences','tracker_mail_format');
  239. }
  240. public function tracker_mail_format_select_name() {
  241. return Codendi_Mail_Interface::PREF_FORMAT;
  242. }
  243. public function session_label() {
  244. return $GLOBALS['Language']->getText('account_preferences', 'session');
  245. }
  246. public function remember_me() {
  247. return $GLOBALS['Language']->getText('account_options', 'remember_me', $GLOBALS['sys_name']);
  248. }
  249. public function lab_features_title() {
  250. return $GLOBALS['Language']->getText('account_preferences', 'lab_features_title', array($GLOBALS['sys_name']));
  251. }
  252. public function lab_features_description() {
  253. return $GLOBALS['Language']->getText('account_preferences', 'lab_features_description', array($GLOBALS['sys_name']));
  254. }
  255. public function user_uses_lab_features() {
  256. return $this->user->useLabFeatures();
  257. }
  258. public function lab_features_checkbox_label() {
  259. return $GLOBALS['Language']->getText('account_preferences', 'lab_features_cblabel', $GLOBALS['sys_name']);
  260. }
  261. public function lab_features_default_image() {
  262. return $GLOBALS['HTML']->getImage('lab_features_default.png');
  263. }
  264. public function appearance_title() {
  265. return $GLOBALS['Language']->getText('account_preferences', 'appearance');
  266. }
  267. public function theme_label() {
  268. return $GLOBALS['Language']->getText('account_options', 'theme');
  269. }
  270. public function default_theme() {
  271. return $GLOBALS['Language']->getText('global', 'default');
  272. }
  273. public function theme_variant_label() {
  274. return $GLOBALS['Language']->getText('account_options', 'theme_variant');
  275. }
  276. public function language_label() {
  277. return $GLOBALS['Language']->getText('account_options', 'language');
  278. }
  279. public function username_display_label() {
  280. return $GLOBALS['Language']->getText('account_options', 'username_display');
  281. }
  282. public function import_export_title() {
  283. return $GLOBALS['Language']->getText('account_preferences', 'import_export');
  284. }
  285. public function csv_separator_label() {
  286. return $GLOBALS['Language']->getText('account_options', 'csv_separator');
  287. }
  288. public function csv_dateformat_label() {
  289. return $GLOBALS['Language']->getText('account_preferences', 'csv_dateformat');
  290. }
  291. public function preference_save_button() {
  292. return $GLOBALS['Language']->getText('account_preferences', 'save_preferences');
  293. }
  294. /* MODAL */
  295. public function add_keys_modal_title() {
  296. return $GLOBALS['Language']->getText('account_editsshkeys', 'add_keys_title');
  297. }
  298. public function btn_close_label() {
  299. return $GLOBALS['Language']->getText('global', 'btn_close');
  300. }
  301. public function btn_save_keys_label() {
  302. return $GLOBALS['Language']->getText('account_editsshkeys', 'btn_save_keys');
  303. }
  304. }