Commit 060a9f29 authored by Tino Goratsch's avatar Tino Goratsch

refs #8

- added the foundation for retrieving the results per page on module basis
- removed the ability to customize the results per page on user basis
parent a61fcd1c
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
/**
* Created by PhpStorm.
* User: tinog
* Date: 07.11.2016
* Time: 01:28
*/
namespace ACP3\Core\Helpers;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Installer\Schema;
class ResultsPerPage
{
/**
* @var SettingsInterface
*/
private $settings;
/**
* @var array
*/
private $resultsPerPage = [];
/**
* ResultsPerPage constructor.
* @param SettingsInterface $settings
*/
public function __construct(SettingsInterface $settings)
{
$this->settings = $settings;
}
/**
* @param string $moduleName
* @return int
*/
public function getResultsPerPage($moduleName)
{
if (!isset($this->resultsPerPage[$moduleName])) {
$moduleName = $this->addResultsToCache($moduleName);
}
return (int)$this->resultsPerPage[$moduleName];
}
/**
* @param string $moduleName
* @return string
*/
protected function addResultsToCache($moduleName)
{
$moduleSettings = $this->settings->getSettings($moduleName);
if (!empty($moduleName['entries'])) {
$this->resultsPerPage[$moduleName] = $moduleSettings['entries'];
} else {
$moduleName = Schema::MODULE_NAME;
$this->getResultsPerPage($moduleName);
}
return $moduleName;
}
}
......@@ -55,6 +55,11 @@ services:
- '@core.router'
- '@core.helpers.toc'
core.helpers.results_per_page:
class: ACP3\Core\Helpers\ResultsPerPage
arguments:
- '@core.config'
core.helpers.sort:
class: ACP3\Core\Helpers\Sort
arguments:
......
......@@ -52,6 +52,9 @@ class Index extends Core\Controller\AbstractFrontendAction
$this->articleRepository = $articleRepository;
}
/**
* @return array
*/
public function execute()
{
$this->setCacheResponseCacheable($this->config->getSettings(Schema::MODULE_NAME)['cache_lifetime']);
......
......@@ -80,7 +80,6 @@ class Create extends AbstractFormAction
$this->view->assign(
$this->get('users.helpers.forms')->fetchUserSettingsFormFields(
(int)$systemSettings['entries'],
$systemSettings['lang'],
$systemSettings['date_time_zone']
)
......
......@@ -92,7 +92,6 @@ class Edit extends AbstractFormAction
$userRoles = $this->acl->getUserRoleIds($id);
$this->view->assign(
$this->get('users.helpers.forms')->fetchUserSettingsFormFields(
(int)$user['entries'],
$user['language'],
$user['time_zone'],
$user['address_display'],
......
......@@ -65,10 +65,6 @@ class Settings extends Core\Controller\AbstractAdminAction
'language_override',
$settings['language_override']
),
'entries' => $this->formsHelpers->yesNoCheckboxGenerator(
'entries_override',
$settings['entries_override']
),
'registration' => $this->formsHelpers->yesNoCheckboxGenerator(
'enable_registration',
$settings['enable_registration']
......@@ -90,7 +86,6 @@ class Settings extends Core\Controller\AbstractAdminAction
$data = [
'enable_registration' => $formData['enable_registration'],
'entries_override' => $formData['entries_override'],
'language_override' => $formData['language_override'],
'mail' => $formData['mail']
];
......
......@@ -70,7 +70,6 @@ class Settings extends AbstractAction
$this->view->assign(
$this->get('users.helpers.forms')->fetchUserSettingsFormFields(
(int)$user['entries'],
$user['language'],
$user['time_zone'],
$user['address_display'],
......@@ -82,7 +81,6 @@ class Settings extends AbstractAction
return [
'language_override' => $settings['language_override'],
'entries_override' => $settings['entries_override'],
'form' => array_merge($user, $this->request->getPost()->all()),
'form_token' => $this->formTokenHelper->renderFormToken()
];
......@@ -107,9 +105,6 @@ class Settings extends AbstractAction
if ($settings['language_override'] == 0) {
unset($formData['language']);
}
if ($settings['entries_override'] == 0) {
unset($formData['entries']);
}
$bool = $this->usersModel->save($formData, $this->user->getUserId());
......
......@@ -154,7 +154,6 @@ class Register extends Core\Controller\AbstractFrontendAction
'date_format_short' => $systemSettings['date_format_short'],
'time_zone' => $systemSettings['date_time_zone'],
'language' => $systemSettings['lang'],
'entries' => $systemSettings['entries'],
'registration_date' => $this->date->getCurrentDateTime(),
];
......
......@@ -100,18 +100,15 @@ class Forms
}
/**
* @param int $entries
* @param string $language
* @param string $timeZone
* @param int $displayAddress
* @param int $displayBirthday
* @param int $displayCountry
* @param int $displayMail
*
* @param int $displayAddress
* @param int $displayBirthday
* @param int $displayCountry
* @param int $displayMail
* @return array
*/
public function fetchUserSettingsFormFields(
$entries,
$language,
$timeZone,
$displayAddress = 0,
......@@ -120,7 +117,6 @@ class Forms
$displayMail = 0
) {
return [
'entries' => $this->formsHelpers->recordsPerPage((int)$entries),
'languages' => $this->translator->getLanguagePack($this->request->getPost()->get('language', $language)),
'time_zones' => $this->dateHelpers->getTimeZones($timeZone),
'address_display' => $this->displayAddress($displayAddress),
......
......@@ -95,6 +95,10 @@ class Migration extends Modules\Installer\AbstractMigration
],
45 => [
"ALTER TABLE `{pre}users` DROP COLUMN `draft`;"
],
46 => [
"ALTER TABLE `{pre}users` DROP COLUMN `entries`;",
"DELETE FROM `{pre}settings` WHERE `module_id` = {moduleId} AND `name` = 'entries_override';"
]
];
}
......
......@@ -33,7 +33,7 @@ class Schema implements Modules\Installer\SchemaInterface
*/
public function getSchemaVersion()
{
return 45;
return 46;
}
/**
......@@ -70,7 +70,6 @@ class Schema implements Modules\Installer\SchemaInterface
`date_format_short` VARCHAR(30) NOT NULL,
`time_zone` VARCHAR(100) NOT NULL,
`language` VARCHAR(10) NOT NULL,
`entries` TINYINT(2) UNSIGNED NOT NULL,
`registration_date` DATETIME NOT NULL,
PRIMARY KEY (`id`)
) {ENGINE} {CHARSET};"
......@@ -92,7 +91,6 @@ class Schema implements Modules\Installer\SchemaInterface
{
return [
'enable_registration' => 1,
'entries_override' => 1,
'language_override' => 1,
'mail' => ''
];
......
......@@ -95,10 +95,10 @@ class AuthenticationModel
->setUserId($userData['id'])
->setIsSuperUser($userData['super_user'])
->setLanguage($userData['language'])
->setEntriesPerPage($userData['entries']);
->setEntriesPerPage();
} else {
$this->userModel
->setEntriesPerPage('')
->setEntriesPerPage()
->setLanguage('');
}
}
......@@ -200,7 +200,6 @@ class AuthenticationModel
$this->sessionHandler->set(self::AUTH_NAME, [
'id' => $this->userModel->getUserId(),
'super_user' => $this->userModel->isSuperUser(),
'entries' => $this->userModel->getEntriesPerPage(),
'language' => $this->userModel->getLanguage()
]);
}
......
......@@ -171,19 +171,11 @@ class UserModel
}
/**
* @param int $entries
*
* @return $this
*/
public function setEntriesPerPage($entries)
public function setEntriesPerPage()
{
$userSettings = $this->config->getSettings(Users\Installer\Schema::MODULE_NAME);
$systemSettings = $this->config->getSettings(Schema::MODULE_NAME);
$this->entriesPerPage = (int)$systemSettings['entries'];
if ($userSettings['entries_override'] == 1 && $entries > 0) {
$this->entriesPerPage = (int)$entries;
}
$this->entriesPerPage = (int)$this->config->getSettings(Schema::MODULE_NAME)['entries'];
return $this;
}
......
......@@ -45,7 +45,6 @@ class UsersModel extends AbstractModel
'date_format_short' => ColumnTypes::COLUMN_TYPE_TEXT,
'time_zone' => ColumnTypes::COLUMN_TYPE_RAW,
'language' => ColumnTypes::COLUMN_TYPE_RAW,
'entries' => ColumnTypes::COLUMN_TYPE_INT,
'registration_date' => ColumnTypes::COLUMN_TYPE_DATETIME
];
}
......
......@@ -6,7 +6,7 @@
<li class="active"><a href="#tab-1" data-toggle="tab">{lang t="system|general"}</a></li>
<li><a href="#tab-2" data-toggle="tab">{lang t="users|contact"}</a></li>
<li><a href="#tab-3" data-toggle="tab">{lang t="users|address"}</a></li>
<li><a href="#tab-4" data-toggle="tab">{lang t="users|settings"}</a></li>
<li><a href="#tab-localization" data-toggle="tab">{lang t="users|localization"}</a></li>
<li><a href="#tab-5" data-toggle="tab">{lang t="users|privacy"}</a></li>
<li><a href="#tab-6" data-toggle="tab">{lang t="users|pwd"}</a></li>
</ul>
......@@ -31,7 +31,7 @@
{include file="asset:System/Partials/form_group.input_text.tpl" name="city" value=$form.city maxlength=80 label={lang t="users|address_city"}}
{include file="asset:System/Partials/form_group.select.tpl" options=$countries label={lang t="users|country"}}
</div>
<div id="tab-4" class="tab-pane fade">
<div id="tab-localization" class="tab-pane fade">
<div class="form-group">
<label for="language" class="col-sm-2 control-label required">{lang t="users|language"}</label>
......@@ -43,7 +43,6 @@
</select>
</div>
</div>
{include file="asset:System/Partials/form_group.select.tpl" options=$entries required=true label={lang t="system|records_per_page"}}
{include file="asset:System/Partials/form_group.input_text.tpl" name="date_format_long" value=$form.date_format_long required=true maxlength=20 label={lang t="system|date_format_long"} help={lang t="system|php_date_function"}}
{include file="asset:System/Partials/form_group.input_text.tpl" name="date_format_short" value=$form.date_format_short required=true maxlength=20 label={lang t="system|date_format_short"} help={lang t="system|php_date_function"}}
<div class="form-group">
......
......@@ -3,7 +3,6 @@
{block CONTENT_AJAX_FORM}
{include file="asset:System/Partials/form_group.input_email.tpl" name="mail" value=$form.mail required=true maxlength=120 label={lang t="system|email_address"}}
{include file="asset:System/Partials/form_group.button_group.tpl" options=$languages required=true label={lang t="users|allow_language_override"}}
{include file="asset:System/Partials/form_group.button_group.tpl" options=$entries required=true label={lang t="users|allow_entries_override"}}
{include file="asset:System/Partials/form_group.button_group.tpl" options=$registration required=true label={lang t="users|enable_registration"}}
{include file="asset:System/Partials/form_group.submit.tpl" form_token=$form_token back_url={uri args="acp/users"}}
{/block}
......@@ -3,12 +3,11 @@
{block CONTENT_AJAX_FORM}
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab-1" data-toggle="tab">{lang t="system|general"}</a></li>
<li><a href="#tab-2" data-toggle="tab">{lang t="system|date"}</a></li>
<li><a href="#tab-3" data-toggle="tab">{lang t="users|privacy"}</a></li>
<li class="active"><a href="#tab-localization" data-toggle="tab">{lang t="users|localization"}</a></li>
<li><a href="#tab-privacy" data-toggle="tab">{lang t="users|privacy"}</a></li>
</ul>
<div class="tab-content">
<div id="tab-1" class="tab-pane fade in active">
<div id="tab-localization" class="tab-pane fade in active">
<div class="form-group">
<label for="language" class="col-sm-2 control-label required">{lang t="users|language"}</label>
......@@ -20,9 +19,6 @@
</select>
</div>
</div>
{include file="asset:System/Partials/form_group.select.tpl" options=$entries required=true disabled=($entries_override == 0) label={lang t="system|records_per_page"}}
</div>
<div id="tab-2" class="tab-pane fade">
{include file="asset:System/Partials/form_group.input_text.tpl" name="date_format_long" value=$form.date_format_long required=true maxlength=20 label={lang t="system|date_format_long"} help={lang t="system|php_date_function"}}
{include file="asset:System/Partials/form_group.input_text.tpl" name="date_format_short" value=$form.date_format_short required=true maxlength=20 label={lang t="system|date_format_short"} help={lang t="system|php_date_function"}}
<div class="form-group">
......@@ -41,7 +37,7 @@
</div>
</div>
</div>
<div id="tab-3" class="tab-pane fade">
<div id="tab-privacy" class="tab-pane fade">
{include file="asset:System/Partials/form_group.button_group.tpl" options=$mail_display required=true label={lang t="users|display_mail"}}
{include file="asset:System/Partials/form_group.button_group.tpl" options=$address_display required=true label={lang t="users|display_address"}}
{include file="asset:System/Partials/form_group.button_group.tpl" options=$country_display required=true label={lang t="users|display_country"}}
......
......@@ -18,7 +18,6 @@
<item key="admin_index_settings">Einstellungen</item>
<item key="admin_user_undeletable">Der Administrator kann nicht gelöscht werden.</item>
<item key="allow_language_override">Benutzern erlauben, Sprache selber festzulegen</item>
<item key="allow_entries_override">Benutzern erlauben, angezeigte Datensätze pro Seite selber festzulegen</item>
<item key="birthday">Geburtstag</item>
<item key="birthday_hide">Geburtstag verstecken</item>
<item key="birthday_display_completely">Geburtstag vollständig anzeigen</item>
......@@ -62,6 +61,7 @@
<item key="invalid_birthday">Bitte geben Sie ein gültiges Geburtsdatum an.</item>
<item key="invalid_icq_number">Sie haben eine ungültige ICQ-Nummer eingegeben.</item>
<item key="language">Sprache</item>
<item key="localization">Lokalisierung</item>
<item key="log_in">Einloggen</item>
<item key="login">Login</item>
<item key="logout">Abmelden</item>
......@@ -93,7 +93,6 @@
<item key="select_birthday_display">Bitte geben Sie das Format Ihres Geburtstages in Ihrem öffentlichen Profil an.</item>
<item key="select_country_display">Bitte geben Sie an, ob Ihre Nation im öffentlichen Profil angezeigt werden soll oder nicht.</item>
<item key="select_enable_registration">Bitten wählen Sie aus, ob die Registrierung neuer Benutzer erlaubt werden soll oder nicht.</item>
<item key="select_entries_override">Bitte geben Sie an, ob es Benutzern gestattet sein soll, die angezeigten Datensätze pro Seite selber festzulegen.</item>
<item key="select_language">Bitte wählen Sie aus, in welcher Sprache Sie die Website angezeigt bekommen möchten.</item>
<item key="select_language_override">Bitte geben Sie an, ob es Benutzern gestattet sein soll, die Anzeigesprache selber festzulegen.</item>
<item key="select_mail_display">Bitte geben Sie an, ob Ihre E-Mail-Adresse im öffentlichen Profil angezeigt werden soll oder nicht.</item>
......
......@@ -18,7 +18,6 @@
<item key="admin_index_settings">Settings</item>
<item key="admin_user_undeletable">The administrator can't be deleted.</item>
<item key="allow_language_override">Allow users to override the default language</item>
<item key="allow_entries_override">Allow users to override the number of displayed resultsets per page</item>
<item key="birthday">Birthday</item>
<item key="birthday_hide">Hide birthday</item>
<item key="birthday_display_completely">Display birthday completely</item>
......@@ -62,6 +61,7 @@
<item key="invalid_birthday">Please type in a valid birthday.</item>
<item key="invalid_icq_number">Please type in a valid ICQ number.</item>
<item key="language">Language</item>
<item key="localization">Localization</item>
<item key="log_in">Log in</item>
<item key="login">Login</item>
<item key="logout">Logout</item>
......@@ -93,7 +93,6 @@
<item key="select_birthday_display">Please select the format of your birthday in which it should be displayed in your public profile.</item>
<item key="select_country_display">Please select whether you want to display your country in the public profile or not.</item>
<item key="select_enable_registration">Please select whether users should be allowed to register on this website.</item>
<item key="select_entries_override">Please select whether users should be allowed to override the number of displayed resultsets per page.</item>
<item key="select_language">Please select the language in which you want to see the website.</item>
<item key="select_language_override">Please select whether users should be allowed to override the default language.</item>
<item key="select_mail_display">Please select whether you want to display your E-mail address in the public profile or not.</item>
......
......@@ -51,14 +51,12 @@ class AdminSettingsFormValidationTest extends AbstractFormValidationTest
\ACP3\Core\Session\SessionHandlerInterface::XSRF_TOKEN_NAME => self::XSRF_FORM_TOKEN,
'mail' => '[email protected]',
'language_override' => 1,
'entries_override' => 1,
'enable_registration' => 1
],
[
\ACP3\Core\Session\SessionHandlerInterface::XSRF_TOKEN_NAME => self::XSRF_FORM_TOKEN,
'mail' => '[email protected]',
'language_override' => 0,
'entries_override' => 0,
'enable_registration' => 0
]
];
......@@ -74,7 +72,6 @@ class AdminSettingsFormValidationTest extends AbstractFormValidationTest
\ACP3\Core\Session\SessionHandlerInterface::XSRF_TOKEN_NAME => self::XSRF_FORM_TOKEN,
'mail' => 'baz',
'language_override' => 'foo',
'entries_override' => 'bar',
'enable_registration' => ''
],
];
......
......@@ -114,10 +114,9 @@ abstract class AbstractUserFormValidation extends Core\Validation\AbstractFormVa
/**
* @param array $formData
* @param int $languageOverride
* @param int $entriesOverride
* @param int $languageOverride
*/
protected function validateUserSettings(array $formData, $languageOverride = 1, $entriesOverride = 1)
protected function validateUserSettings(array $formData, $languageOverride = 1)
{
if ($languageOverride == 1) {
$this->validator->addConstraint(
......@@ -128,16 +127,6 @@ abstract class AbstractUserFormValidation extends Core\Validation\AbstractFormVa
'message' => $this->translator->t('users', 'select_language')
]);
}
if ($entriesOverride == 1) {
$this->validator->addConstraint(
Core\Validation\ValidationRules\IntegerValidationRule::class,
[
'data' => $formData,
'field' => 'entries',
'message' => $this->translator->t('system', 'select_records_per_page')
]);
}
$this->validator
->addConstraint(
Core\Validation\ValidationRules\NotEmptyValidationRule::class,
......
......@@ -33,8 +33,7 @@ class AccountSettingsFormValidation extends AbstractUserFormValidation
{
$this->validator->addConstraint(Core\Validation\ValidationRules\FormTokenValidationRule::class);
parent::validateUserSettings($formData, $this->settings['language_override'],
$this->settings['entries_override']);
$this->validateUserSettings($formData, $this->settings['language_override']);
$this->validator->validate();
}
......
......@@ -52,7 +52,7 @@ class AdminFormValidation extends AbstractUserFormValidation
]);
$this->validateAccountCoreData($formData, $this->userId);
$this->validateUserSettings($formData, 1, 1);
$this->validateUserSettings($formData, 1);
if (isset($formData['new_pwd'])) {
$this->validateNewPassword($formData, 'new_pwd', 'new_pwd_repeat');
......
......@@ -35,16 +35,6 @@ class AdminSettingsFormValidation extends AbstractFormValidation
'haystack' => [0, 1]
]
])
->addConstraint(
Core\Validation\ValidationRules\InArrayValidationRule::class,
[
'data' => $formData,
'field' => 'entries_override',
'message' => $this->translator->t('users', 'select_entries_override'),
'extra' => [
'haystack' => [0, 1]
]
])
->addConstraint(
Core\Validation\ValidationRules\InArrayValidationRule::class,
[
......
......@@ -178,7 +178,7 @@ class InstallModel
"INSERT INTO
`{pre}users`
VALUES
(1, 1, {$this->db->getConnection()->quote($formData["user_name"])}, '{$this->secure->generateSaltedPassword($salt, $formData["user_pwd"], 'sha512')}', '{$salt}', '', 0, '', '1', '', 0, '{$formData["mail"]}', 0, '', '', '', '', '', '', '', '', 0, 0, {$this->db->getConnection()->quote($formData["date_format_long"])}, {$this->db->getConnection()->quote($formData["date_format_short"])}, '{$formData["date_time_zone"]}', '{$this->translator->getLocale()}', '20', '{$currentDate}');",
(1, 1, {$this->db->getConnection()->quote($formData["user_name"])}, '{$this->secure->generateSaltedPassword($salt, $formData["user_pwd"], 'sha512')}', '{$salt}', '', 0, '', '1', '', 0, '{$formData["mail"]}', 0, '', '', '', '', '', '', '', '', 0, 0, {$this->db->getConnection()->quote($formData["date_format_long"])}, {$this->db->getConnection()->quote($formData["date_format_short"])}, '{$formData["date_time_zone"]}', '{$this->translator->getLocale()}', '{$currentDate}');",
"INSERT INTO `{pre}acl_user_roles` (`user_id`, `role_id`) VALUES (1, 4);"
];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment