2019-04-28 14:18:11 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* part-db version 0.1
|
|
|
|
* Copyright (C) 2005 Christoph Lechner
|
|
|
|
* http://www.cl-projects.de/
|
|
|
|
*
|
|
|
|
* part-db version 0.2+
|
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
|
|
|
* http://code.google.com/p/part-db/
|
|
|
|
*
|
|
|
|
* Part-DB Version 0.4+
|
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer
|
|
|
|
* https://github.com/jbtronics
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Form;
|
|
|
|
|
|
|
|
|
2019-08-12 18:04:53 +02:00
|
|
|
use App\Entity\UserSystem\Group;
|
|
|
|
use App\Entity\Base\NamedDBElement;
|
|
|
|
use App\Entity\Base\StructuralDBElement;
|
2019-09-10 17:12:56 +02:00
|
|
|
use App\Form\Permissions\PermissionsType;
|
|
|
|
use App\Form\Permissions\PermissionType;
|
2019-09-19 12:12:12 +02:00
|
|
|
use App\Form\Type\CurrencyEntityType;
|
2019-08-13 23:04:06 +02:00
|
|
|
use App\Form\Type\StructuralEntityType;
|
2019-04-28 14:18:11 +02:00
|
|
|
use FOS\CKEditorBundle\Form\Type\CKEditorType;
|
|
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
|
|
use Symfony\Component\Form\AbstractType;
|
2019-09-19 12:35:28 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
2019-09-19 12:12:12 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
2019-09-24 18:28:35 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
2019-09-19 12:12:12 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
|
2019-09-19 12:35:28 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
2019-04-28 14:18:11 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ResetType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
2019-09-19 12:12:12 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
|
2019-04-28 14:18:11 +02:00
|
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
2019-09-24 18:28:35 +02:00
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
2019-04-28 14:18:11 +02:00
|
|
|
use Symfony\Component\Security\Core\Security;
|
2019-09-19 12:35:28 +02:00
|
|
|
use Symfony\Component\Validator\Constraints\Length;
|
2019-09-04 15:53:18 +02:00
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
2019-04-28 14:18:11 +02:00
|
|
|
|
|
|
|
class UserAdminForm extends AbstractType
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $security;
|
2019-09-04 15:53:18 +02:00
|
|
|
protected $trans;
|
2019-04-28 14:18:11 +02:00
|
|
|
|
2019-09-04 15:53:18 +02:00
|
|
|
public function __construct(Security $security, TranslatorInterface $trans)
|
2019-04-28 14:18:11 +02:00
|
|
|
{
|
|
|
|
$this->security = $security;
|
2019-09-04 15:53:18 +02:00
|
|
|
$this->trans = $trans;
|
2019-04-28 14:18:11 +02:00
|
|
|
}
|
|
|
|
|
2019-09-24 18:28:35 +02:00
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
|
|
{
|
|
|
|
parent::configureOptions($resolver); // TODO: Change the autogenerated stub
|
|
|
|
$resolver->setRequired('attachment_class');
|
|
|
|
}
|
2019-04-28 14:18:11 +02:00
|
|
|
|
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
|
|
{
|
|
|
|
/** @var StructuralDBElement $entity */
|
|
|
|
$entity = $options['data'];
|
|
|
|
$is_new = $entity->getID() === null;
|
|
|
|
|
|
|
|
$builder
|
2019-09-04 15:53:18 +02:00
|
|
|
->add('name', TextType::class, [
|
|
|
|
'empty_data' => '',
|
|
|
|
'label' => $this->trans->trans('user.username.label'),
|
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.username.placeholder')],
|
|
|
|
'disabled' => !$this->security->isGranted('edit_username', $entity),
|
|
|
|
])
|
|
|
|
|
|
|
|
->add('group', StructuralEntityType::class, [
|
|
|
|
'class' => Group::class,
|
|
|
|
'required' => false,
|
|
|
|
'label' => $this->trans->trans('group.label'),
|
|
|
|
'disable_not_selectable' => true,
|
2019-04-28 14:18:11 +02:00
|
|
|
'disabled' => !$this->security->isGranted('change_group', $entity), ])
|
|
|
|
|
2019-09-04 15:53:18 +02:00
|
|
|
->add('first_name', TextType::class, [
|
|
|
|
'empty_data' => '',
|
|
|
|
'label' => $this->trans->trans('user.firstName.label'),
|
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.firstName.placeholder')], 'required' => false,
|
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity),
|
|
|
|
])
|
|
|
|
|
|
|
|
->add('last_name', TextType::class, [
|
|
|
|
'empty_data' => '',
|
|
|
|
'label' => $this->trans->trans('user.lastName.label'),
|
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.lastName.placeholder')],
|
|
|
|
'required' => false,
|
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity),
|
|
|
|
])
|
|
|
|
|
|
|
|
->add('email', TextType::class, [
|
|
|
|
'empty_data' => '',
|
|
|
|
'label' => $this->trans->trans('user.email.label'),
|
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.email.placeholder')],
|
|
|
|
'required' => false,
|
2019-04-28 14:18:11 +02:00
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity), ])
|
|
|
|
|
|
|
|
|
2019-09-04 15:53:18 +02:00
|
|
|
->add('department', TextType::class, [
|
|
|
|
'empty_data' => '',
|
|
|
|
'label' => $this->trans->trans('user.department.label'),
|
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.department.placeholder')],
|
|
|
|
'required' => false,
|
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity),
|
|
|
|
])
|
2019-04-28 14:18:11 +02:00
|
|
|
|
2019-09-19 12:12:12 +02:00
|
|
|
//Config section
|
|
|
|
->add('language', LanguageType::class, [
|
|
|
|
'required' => false,
|
|
|
|
'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
|
|
|
|
'placeholder' => $this->trans->trans('user_settings.language.placeholder'),
|
|
|
|
'label' => $this->trans->trans('user.language_select'),
|
|
|
|
'preferred_choices' => ['en', 'de'],
|
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity)
|
|
|
|
])
|
|
|
|
->add('timezone', TimezoneType::class, [
|
|
|
|
'required' => false,
|
|
|
|
'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
|
|
|
|
'placeholder' => $this->trans->trans('user_settings.timezone.placeholder'),
|
|
|
|
'label' => $this->trans->trans('user.timezone.label'),
|
|
|
|
'preferred_choices' => ['Europe/Berlin'],
|
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity)
|
|
|
|
])
|
|
|
|
->add('theme', ChoiceType::class, [
|
|
|
|
'required' => false,
|
|
|
|
'placeholder' => $this->trans->trans('user_settings.theme.placeholder'),
|
|
|
|
'label' => $this->trans->trans('user.theme.label'),
|
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity)
|
|
|
|
])
|
|
|
|
->add('currency', CurrencyEntityType::class, [
|
|
|
|
'required' => false,
|
|
|
|
'label' => $this->trans->trans('user.currency.label'),
|
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity)
|
|
|
|
])
|
|
|
|
|
2019-09-19 12:35:28 +02:00
|
|
|
->add('new_password', RepeatedType::class, [
|
|
|
|
'type' => PasswordType::class,
|
|
|
|
'first_options' => ['label' => $this->trans->trans('user.settings.pw_new.label')],
|
|
|
|
'second_options' => ['label' => $this->trans->trans('user.settings.pw_confirm.label')],
|
|
|
|
'invalid_message' => 'password_must_match',
|
|
|
|
'required' => false,
|
|
|
|
'mapped' => false,
|
|
|
|
'constraints' => [new Length([
|
|
|
|
'min' => 6,
|
|
|
|
'max' => 128,
|
|
|
|
])]
|
|
|
|
])
|
|
|
|
|
|
|
|
->add('need_pw_change', CheckboxType::class, [
|
|
|
|
'required' => false,
|
|
|
|
'label_attr' => ['class' => 'checkbox-custom'],
|
|
|
|
'label' => $this->trans->trans('user.edit.needs_pw_change')
|
|
|
|
])
|
|
|
|
|
2019-09-19 12:12:12 +02:00
|
|
|
//Permission section
|
2019-09-10 17:12:56 +02:00
|
|
|
->add('permissions', PermissionsType::class, [
|
|
|
|
'mapped' => false,
|
|
|
|
'data' => $builder->getData(),
|
2019-09-11 17:00:03 +02:00
|
|
|
'disabled' => !$this->security->isGranted('edit_permissions', $entity)
|
2019-09-10 17:12:56 +02:00
|
|
|
])
|
2019-04-28 14:18:11 +02:00
|
|
|
;
|
|
|
|
/*->add('comment', CKEditorType::class, ['required' => false,
|
|
|
|
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
|
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); */
|
|
|
|
|
|
|
|
$this->additionalFormElements($builder, $options, $entity);
|
|
|
|
|
2019-09-24 18:28:35 +02:00
|
|
|
//Attachment section
|
|
|
|
$builder->add('attachments', CollectionType::class, [
|
|
|
|
'entry_type' => AttachmentFormType::class,
|
|
|
|
'allow_add' => true,
|
|
|
|
'allow_delete' => true,
|
|
|
|
'label' => false,
|
|
|
|
'entry_options' => [
|
|
|
|
'data_class' => $options['attachment_class'],
|
|
|
|
],
|
2019-09-24 18:41:53 +02:00
|
|
|
'by_reference' => false,
|
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
|
2019-09-24 18:28:35 +02:00
|
|
|
]);
|
|
|
|
|
2019-04-28 14:18:11 +02:00
|
|
|
//Buttons
|
2019-09-04 15:53:18 +02:00
|
|
|
$builder->add('save', SubmitType::class, [
|
|
|
|
'label' => $is_new ? $this->trans->trans('user.create') : $this->trans->trans('user.edit.save'),
|
|
|
|
'attr' => ['class' => $is_new ? 'btn-success' : '']
|
|
|
|
])
|
|
|
|
->add('reset', ResetType::class, [
|
|
|
|
'label' => $this->trans->trans('entity.edit.reset')
|
|
|
|
]);
|
2019-04-28 14:18:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
|
|
|
|
{
|
|
|
|
//Empty for Base
|
|
|
|
}
|
|
|
|
}
|