Commit c2a9e49f authored by Tino Goratsch's avatar Tino Goratsch

considerably reduced the amount of duplicated code in the users module

parent 8c8f2ff0
......@@ -75,32 +75,19 @@ class Account extends Core\Modules\FrontendController
$user = $this->auth->getUserInfo();
// Geschlecht
$lang_gender = [
$this->lang->t('users', 'gender_not_specified'),
$this->lang->t('users', 'gender_female'),
$this->lang->t('users', 'gender_male')
];
$this->view->assign('gender', $this->get('core.helpers.forms')->selectGenerator('gender', [1, 2, 3], $lang_gender, $user['gender']));
// Geburtstag
$datepickerParams = [
'constrainInput' => 'true',
'changeMonth' => 'true',
'changeYear' => 'true',
'yearRange' => "'-50:+0'"
];
$this->view->assign('birthday_datepicker', $this->get('core.helpers.date')->datepicker('birthday', $user['birthday'], 'Y-m-d', $datepickerParams, false, true));
// Kontaktangaben
$this->view->assign('contact', $this->get('users.helpers.forms')->fetchContactDetails(
$user['mail'],
$user['website'],
$user['icq'],
$user['skype']
));
$this->view->assign('countries', $this->get('users.helpers.forms')->generateWorldCountriesSelect($user['country']));
$this->view->assign(
$this->get('users.helpers.forms')->fetchUserProfileFormFields(
$user['birthday'],
$user['country'],
$user['gender']
)
);
$this->view->assign('form', array_merge($user, $this->request->getPost()->getAll()));
......@@ -119,31 +106,17 @@ class Account extends Core\Modules\FrontendController
$this->view->assign('language_override', $settings['language_override']);
$this->view->assign('entries_override', $settings['entries_override']);
// Sprache
$this->view->assign('languages', $this->lang->getLanguagePack($this->request->getPost()->get('language', $user['language'])));
// Einträge pro Seite
$this->view->assign('entries', $this->get('core.helpers.forms')->recordsPerPage((int)$user['entries']));
// Zeitzonen
$this->view->assign('time_zones', $this->get('core.helpers.date')->getTimeZones($user['time_zone']));
$lang_mailDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('mail_display', $this->get('core.helpers.forms')->checkboxGenerator('mail_display', [1, 0], $lang_mailDisplay, $user['mail_display']));
$lang_addressDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('address_display', $this->get('core.helpers.forms')->checkboxGenerator('address_display', [1, 0], $lang_addressDisplay, $user['address_display']));
$lang_countryDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('country_display', $this->get('core.helpers.forms')->checkboxGenerator('country_display', [1, 0], $lang_countryDisplay, $user['country_display']));
$lang_birthdayDisplay = [
$this->lang->t('users', 'birthday_hide'),
$this->lang->t('users', 'birthday_display_completely'),
$this->lang->t('users', 'birthday_hide_year')
];
$this->view->assign('birthday_display', $this->get('core.helpers.forms')->checkboxGenerator('birthday_display', [0, 1, 2], $lang_birthdayDisplay, $user['birthday_display']));
$this->view->assign(
$this->get('users.helpers.forms')->fetchUserSettingsFormFields(
(int)$user['entries'],
$user['language'],
$user['time_zone'],
$user['address_display'],
$user['birthday_display'],
$user['country_display'],
$user['mail_display']
)
);
$this->view->assign('form', array_merge($user, $this->request->getPost()->getAll()));
......
......@@ -81,59 +81,17 @@ class Index extends Core\Modules\AdminController
$systemSettings = $this->config->getSettings('system');
// Zugriffslevel holen
$this->view->assign('roles', $this->fetchUserRoles());
// Super User
$lang_superUser = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('super_user', $this->formsHelpers->checkboxGenerator('super_user', [1, 0], $lang_superUser, 0));
// Sprache
$this->view->assign('languages', $this->lang->getLanguagePack($this->request->getPost()->get('language', $systemSettings['lang'])));
// Einträge pro Seite
$this->view->assign('entries', $this->formsHelpers->recordsPerPage($systemSettings['entries']));
// Zeitzonen
$this->view->assign('time_zones', $this->get('core.helpers.date')->getTimeZones($systemSettings['date_time_zone']));
// Geschlecht
$lang_gender = [
$this->lang->t('users', 'gender_not_specified'),
$this->lang->t('users', 'gender_female'),
$this->lang->t('users', 'gender_male')
];
$this->view->assign('gender', $this->formsHelpers->selectGenerator('gender', [1, 2, 3], $lang_gender, ''));
// Geburtstag
$datepickerParams = [
'constrainInput' => 'true',
'changeMonth' => 'true',
'changeYear' => 'true',
'yearRange' => '\'-50:+0\''
];
$this->view->assign('birthday_datepicker', $this->get('core.helpers.date')->datepicker('birthday', '', 'Y-m-d', $datepickerParams, false, true));
// Kontaktangaben
$this->view->assign('super_user', $this->fetchIsSuperUser());
$this->view->assign('contact', $this->get('users.helpers.forms')->fetchContactDetails());
$this->view->assign('countries', $this->get('users.helpers.forms')->generateWorldCountriesSelect());
$lang_mailDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('mail_display', $this->formsHelpers->checkboxGenerator('mail_display', [1, 0], $lang_mailDisplay, 0));
$lang_addressDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('address_display', $this->formsHelpers->checkboxGenerator('address_display', [1, 0], $lang_addressDisplay, 0));
$lang_countryDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('country_display', $this->formsHelpers->checkboxGenerator('country_display', [1, 0], $lang_countryDisplay, 0));
$lang_birthdayDisplay = [
$this->lang->t('users', 'birthday_hide'),
$this->lang->t('users', 'birthday_display_completely'),
$this->lang->t('users', 'birthday_hide_year')
];
$this->view->assign('birthday_display', $this->formsHelpers->checkboxGenerator('birthday_display', [0, 1, 2], $lang_birthdayDisplay, 0));
$this->view->assign(
$this->get('users.helpers.forms')->fetchUserSettingsFormFields(
(int)$systemSettings['entries'],
$systemSettings['lang'],
$systemSettings['date_time_zone']
)
);
$this->view->assign($this->get('users.helpers.forms')->fetchUserProfileFormFields());
$defaults = [
'nickname' => '',
......@@ -204,60 +162,33 @@ class Index extends Core\Modules\AdminController
$this->_editPost($this->request->getPost()->getAll(), $id);
}
// Zugriffslevel holen
$userRoles = $this->acl->getUserRoleIds($id);
$this->view->assign('roles', $this->fetchUserRoles($userRoles));
// Super User
$langSuperUser = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('super_user', $this->formsHelpers->checkboxGenerator('super_user', [1, 0], $langSuperUser, $user['super_user']));
// Sprache
$this->view->assign('languages', $this->lang->getLanguagePack($this->request->getPost()->get('language', $user['language'])));
// Einträge pro Seite
$this->view->assign('entries', $this->formsHelpers->recordsPerPage((int)$user['entries']));
// Zeitzonen
$this->view->assign('time_zones', $this->get('core.helpers.date')->getTimeZones($user['time_zone']));
// Geschlecht
$lang_gender = [
$this->lang->t('users', 'gender_not_specified'),
$this->lang->t('users', 'gender_female'),
$this->lang->t('users', 'gender_male')
];
$this->view->assign('gender', $this->formsHelpers->selectGenerator('gender', [1, 2, 3], $lang_gender, $user['gender']));
// Geburtstag
$datepickerParams = ['constrainInput' => 'true', 'changeMonth' => 'true', 'changeYear' => 'true', 'yearRange' => '\'-50:+0\''];
$this->view->assign('birthday_datepicker', $this->get('core.helpers.date')->datepicker('birthday', $user['birthday'], 'Y-m-d', $datepickerParams, false, true));
// Kontaktangaben
$this->view->assign('super_user', $this->fetchIsSuperUser($user['super_user']));
$this->view->assign('contact', $this->get('users.helpers.forms')->fetchContactDetails(
$user['mail'],
$user['website'],
$user['icq'],
$user['skype']
));
$this->view->assign('countries', $this->get('users.helpers.forms')->generateWorldCountriesSelect($user['country']));
$lang_mailDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('mail_display', $this->formsHelpers->checkboxGenerator('mail_display', [1, 0], $lang_mailDisplay, $user['mail_display']));
$lang_addressDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('address_display', $this->formsHelpers->checkboxGenerator('address_display', [1, 0], $lang_addressDisplay, $user['address_display']));
$lang_countryDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
$this->view->assign('country_display', $this->formsHelpers->checkboxGenerator('country_display', [1, 0], $lang_countryDisplay, $user['country_display']));
$lang_birthdayDisplay = [
$this->lang->t('users', 'birthday_hide'),
$this->lang->t('users', 'birthday_display_completely'),
$this->lang->t('users', 'birthday_hide_year')
];
$this->view->assign('birthday_display', $this->formsHelpers->checkboxGenerator('birthday_display', [0, 1, 2], $lang_birthdayDisplay, $user['birthday_display']));
$this->view->assign(
$this->get('users.helpers.forms')->fetchUserSettingsFormFields(
(int)$user['entries'],
$user['language'],
$user['time_zone'],
$user['address_display'],
$user['birthday_display'],
$user['country_display'],
$user['mail_display']
)
);
$this->view->assign(
$this->get('users.helpers.forms')->fetchUserProfileFormFields(
$user['birthday'],
$user['country'],
$user['gender']
)
);
$this->view->assign('form', array_merge($user, $this->request->getPost()->getAll()));
......@@ -457,4 +388,15 @@ class Index extends Core\Modules\AdminController
}
return $roles;
}
/**
* @param int $value
*
* @return array
*/
protected function fetchIsSuperUser($value = 0)
{
$lang_superUser = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
return $this->formsHelpers->checkboxGenerator('super_user', [1, 0], $lang_superUser, $value);
}
}
......@@ -2,6 +2,7 @@
namespace ACP3\Modules\ACP3\Users\Helpers;
use ACP3\Core\Helpers\Country;
use ACP3\Core\Helpers\Date;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\Lang;
......@@ -19,6 +20,10 @@ class Forms
* @var \ACP3\Core\Http\RequestInterface
*/
protected $request;
/**
* @var \ACP3\Core\Helpers\Date
*/
protected $dateHelpers;
/**
* @var \ACP3\Core\Helpers\Forms
*/
......@@ -27,18 +32,22 @@ class Forms
/**
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Helpers\Date $dateHelpers
* @param \ACP3\Core\Helpers\Forms $formsHelpers
*/
public function __construct(
Lang $lang,
RequestInterface $request,
Date $dateHelpers,
\ACP3\Core\Helpers\Forms $formsHelpers
)
{
$this->lang = $lang;
$this->request = $request;
$this->dateHelpers = $dateHelpers;
$this->formsHelpers = $formsHelpers;
}
/**
* @param string $defaultMail
* @param string $defaultWebsite
......@@ -101,5 +110,120 @@ class Forms
return $countriesSelect;
}
public function fetchUserSettingsFormFields(
$entries,
$language,
$timeZone,
$displayAddress = 0,
$displayBirthday = 0,
$displayCountry = 0,
$displayMail = 0
)
{
return [
'entries' => $this->formsHelpers->recordsPerPage((int)$entries),
'languages' => $this->lang->getLanguagePack($this->request->getPost()->get('language', $language)),
'time_zones' => $this->dateHelpers->getTimeZones($timeZone),
'address_display' => $this->displayAddress($displayAddress),
'birthday_display' => $this->displayBirthday($displayBirthday),
'country_display' => $this->displayCountry($displayCountry),
'mail_display' => $this->displayMail($displayMail),
];
}
/**
* @param int $value
*
* @return array
*/
protected function displayAddress($value)
{
$lang_addressDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
return $this->formsHelpers->checkboxGenerator('address_display', [1, 0], $lang_addressDisplay, $value);
}
/**
* @param int $value
*
* @return array
*/
protected function displayBirthday($value)
{
$lang_birthdayDisplay = [
$this->lang->t('users', 'birthday_hide'),
$this->lang->t('users', 'birthday_display_completely'),
$this->lang->t('users', 'birthday_hide_year')
];
return $this->formsHelpers->checkboxGenerator('birthday_display', [0, 1, 2], $lang_birthdayDisplay, $value);
}
/**
* @param int $value
*
* @return array
*/
protected function displayCountry($value)
{
$lang_countryDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
return $this->formsHelpers->checkboxGenerator('country_display', [1, 0], $lang_countryDisplay, $value);
}
/**
* @param int $value
*
* @return array
*/
protected function displayMail($value)
{
$lang_mailDisplay = [$this->lang->t('system', 'yes'), $this->lang->t('system', 'no')];
return $this->formsHelpers->checkboxGenerator('mail_display', [1, 0], $lang_mailDisplay, $value);
}
/**
* @param string $birthday
* @param string $country
* @param int $gender
*
* @return array
*/
public function fetchUserProfileFormFields($birthday = '', $country = '', $gender = 1)
{
return [
'birthday_datepicker' => $this->fetchBirthdayDatepicker($birthday),
'countries' => $this->generateWorldCountriesSelect($country),
'gender' => $this->fetchGenderField($gender),
];
}
/**
* @param int $value
*
* @return array
*/
protected function fetchGenderField($value)
{
$lang_gender = [
$this->lang->t('users', 'gender_not_specified'),
$this->lang->t('users', 'gender_female'),
$this->lang->t('users', 'gender_male')
];
return $this->formsHelpers->selectGenerator('gender', [1, 2, 3], $lang_gender, $value);
}
/**
* @param string $value
*
* @return array
*/
protected function fetchBirthdayDatepicker($value)
{
$datepickerParams = [
'constrainInput' => 'true',
'changeMonth' => 'true',
'changeYear' => 'true',
'yearRange' => "'-50:+0'"
];
return $this->dateHelpers->datepicker('birthday', $value, 'Y-m-d', $datepickerParams, false, true);
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@ services:
users.helpers.forms:
class: ACP3\Modules\ACP3\Users\Helpers\Forms
arguments: [@core.lang, @core.request, @core.helpers.forms]
arguments: [@core.lang, @core.request, @core.helpers.date, @core.helpers.forms]
users.model:
class: %users.model.fqdn%
......
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