From 054d5de1e7ffea0b71c6e93c50f28f0b2c421e56 Mon Sep 17 00:00:00 2001 From: Gregor Gawol <gawol@ub.uni-leipzig.de> Date: Thu, 20 Feb 2020 15:30:39 +0100 Subject: [PATCH] refs #16787 [fid_bbi] * set full_access to requested for certain user group * set fid_bbi based input filter * remove deleted flag * if empty values set empty string * set condition --- module/fid_bbi/config/user-create-form.php | 3 ++ .../InputFilter/UserCreateFormInputFilter.php | 47 +++++++++++++++++++ .../templates/myresearch/profile.phtml | 10 ++-- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 module/fid_bbi/src/fid_bbi/InputFilter/UserCreateFormInputFilter.php diff --git a/module/fid_bbi/config/user-create-form.php b/module/fid_bbi/config/user-create-form.php index 6b88279f12a..e5aaf1e6c52 100644 --- a/module/fid_bbi/config/user-create-form.php +++ b/module/fid_bbi/config/user-create-form.php @@ -21,6 +21,8 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 */ +use fid_bbi\InputFilter\UserCreateFormInputFilter; + return [ 'elements' => [ 'firstname' => [ @@ -46,6 +48,7 @@ return [ ], ], 'input_filter' => [ + 'type' => UserCreateFormInputFilter::class, 'firstname' => [ 'required' => false, ], diff --git a/module/fid_bbi/src/fid_bbi/InputFilter/UserCreateFormInputFilter.php b/module/fid_bbi/src/fid_bbi/InputFilter/UserCreateFormInputFilter.php new file mode 100644 index 00000000000..f2df5bb00ca --- /dev/null +++ b/module/fid_bbi/src/fid_bbi/InputFilter/UserCreateFormInputFilter.php @@ -0,0 +1,47 @@ +<?php +/** + * Copyright (C) 2020 Leipzig University Library + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> + * @author Gregor Gawol <gawol@ub.uni-leipzig.de> + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + */ + +namespace fid_bbi\InputFilter; + +use fid\InputFilter\UserCreateFormInputFilter as BaseInputFilter; + +class UserCreateFormInputFilter extends BaseInputFilter +{ + public function getValues() + { + $values = parent::getValues(); + $permissions = $this->getPermissions($values) + $values['permissions']; + return compact('permissions') + $values; + } + + protected function getPermissions($values): array + { + $permissions = []; + switch ($values['job_title']) { + case '0': + $permissions['full_access'] = 'requested'; + } + + return $permissions; + } +} diff --git a/themes/fid_bbi/templates/myresearch/profile.phtml b/themes/fid_bbi/templates/myresearch/profile.phtml index 9442c7b3672..a9598b4dd88 100644 --- a/themes/fid_bbi/templates/myresearch/profile.phtml +++ b/themes/fid_bbi/templates/myresearch/profile.phtml @@ -18,8 +18,10 @@ if (is_array($profile)) { $this->translate('fid::label_salutation_' . $profile['user']->getSalutation()) : ''; $profile['academic_title'] = !empty($profile['user']->getAcademicTitle()) ? $profile['user']->getAcademicTitle() : ''; - $profile['home_library'] = $profile['libs'][$profile['user']->getHomeLibrary()]->getLabel(); - $profile['college'] = $profile['user']->getCollege(); + $profile['home_library'] = !empty($profile['user']->getHomeLibrary()) ? + $profile['libs'][$profile['user']->getHomeLibrary()]->getLabel() : ''; + $profile['college'] = !empty($profile['user']->getCollege()) ? + $profile['user']->getCollege() : ''; } ?> @@ -35,9 +37,9 @@ if (is_array($profile)) { $profile, array_merge( [ - $this->transEsc('fid::label_username') => 'email', - $this->transEsc('fid::label_home_library') => 'home_library' + $this->transEsc('fid::label_username') => 'email' ], + $profile['academic_title'] ? [$this->transEsc('fid::label_home_library') => 'home_library'] : [], $profile['academic_title'] ? [$this->transEsc('fid::label_academic_title') => 'academic_title'] : [], $profile['salutation'] ? [$this->transEsc('fid::label_salutation') => 'salutation'] : [], $profile['firstname'] ? [$this->transEsc('fid::label_firstname') => 'firstname'] : [], -- GitLab