. * */ namespace SP\Controller; use SP\Auth\Auth2FA; use SP\Language; use SP\Session; use SP\SessionUtil; use SP\Themes; use SP\UserPreferences; defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo')); /** * Class PreferencesC encargada de mostrar las preferencias de los usuarios * * @package SP\Controller */ class UsersPrefsC extends Controller implements ActionsInterface { /** * @var int */ private $_tabIndex = 0; /** * @var UserPreferences */ private $_userPrefs; /** * @var int */ private $_userId; /** * Constructor * * @param $template \SP\Template con instancia de plantilla */ public function __construct(\SP\Template $template = null) { parent::__construct($template); $this->view->assign('tabs', array()); $this->view->assign('sk', SessionUtil::getSessionKey(true)); $this->_userId = Session::getUserId(); $this->_userPrefs = UserPreferences::getPreferences($this->_userId); } /** * Obtener la pestaña de seguridad */ public function getSecurityTab() { $this->setAction(self::ACTION_USR_PREFERENCES_SECURITY); $this->view->addTemplate('security'); $twoFa = new Auth2FA($this->_userId, Session::getUserLogin()); if (!$this->_userPrefs->isUse2Fa()) { $this->view->assign('qrCode', $twoFa->getUserQRCode()); } $this->view->assign('userId', $this->_userId); $this->view->assign('chk2FAEnabled', $this->_userPrefs->isUse2Fa()); $this->view->append('tabs', array('title' => _('Seguridad'))); $this->view->assign('tabIndex', $this->getTabIndex(), 'security'); $this->view->assign('actionId', $this->getAction(), 'security'); } /** * Obtener la pestaña de preferencias */ public function getPreferencesTab() { $this->setAction(self::ACTION_USR_PREFERENCES_GENERAL); $this->view->addTemplate('preferences'); $this->view->assign('userId', $this->_userId); $this->view->assign('langsAvailable',Language::getAvailableLanguages()); $this->view->assign('currentLang', $this->_userPrefs->getLang()); $this->view->assign('themesAvailable', Themes::getThemesAvailable()); $this->view->assign('currentTheme', ($this->_userPrefs->getTheme()) ? $this->_userPrefs->getTheme() : \SP\Config::getValue('sitetheme')); $this->view->assign('chkAccountLink', ($this->_userPrefs->isAccountLink()) ? 'checked="checked"' : ''); $this->view->assign('resultsPerPage', ($this->_userPrefs->getResultsPerPage()) ? $this->_userPrefs->getResultsPerPage() : \SP\Config::getValue('account_count')); $this->view->assign('chkSortViews', ($this->_userPrefs->isSortViews()) ? 'checked="checked"' : ''); $this->view->assign('chkTopNavbar', ($this->_userPrefs->isTopNavbar()) ? 'checked="checked"' : ''); $this->view->assign('chkOptionalActions', ($this->_userPrefs->isOptionalActions()) ? 'checked="checked"' : ''); $this->view->append('tabs', array('title' => _('Preferencias'))); $this->view->assign('tabIndex', $this->getTabIndex(), 'preferences'); $this->view->assign('actionId', $this->getAction(), 'preferences'); } /** * Obtener el índice actual de las pestañas * * @return int */ private function getTabIndex(){ $index = $this->_tabIndex; $this->_tabIndex++; return $index; } }