Skip to content

Commit

Permalink
Merge pull request #6057 from christianbeeznest/fixes-updates62
Browse files Browse the repository at this point in the history
User: Fix settings update, lang filter, profile form
  • Loading branch information
christianbeeznest authored Jan 29, 2025
2 parents 71af734 + b340fab commit f6452e7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/CoreBundle/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public function edit(Request $request, UserRepository $userRepository, Illustrat
}
}

if ($form->has('password')) {
$password = $form['password']->getData();
if ($password) {
$user->setPlainPassword($password);
}
}

$showTermsIfProfileCompleted = ('true' === $settingsManager->getSetting('show_terms_if_profile_completed'));
$user->setProfileCompleted($showTermsIfProfileCompleted);

Expand Down
13 changes: 12 additions & 1 deletion src/CoreBundle/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ public function getPlainPassword(): ?string
return $this->plainPassword;
}

public function setPlainPassword(string $password): self
public function setPlainPassword(?string $password): self
{
$this->plainPassword = $password;
// forces the object to look "dirty" to Doctrine. Avoids
Expand Down Expand Up @@ -2210,6 +2210,17 @@ public function setSurveyInvitations(Collection $surveyInvitations): self
return $this;
}

public function getLogin(): string
{
return $this->username;
}

public function setLogin(string $login): self
{
$this->username = $login;
return $this;
}

/**
* @return Collection<int, TrackELogin>
*/
Expand Down
32 changes: 18 additions & 14 deletions src/CoreBundle/Form/ProfileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
use Chamilo\CoreBundle\Repository\LanguageRepository;
use Chamilo\CoreBundle\Settings\SettingsManager;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Form\FormBuilderInterface;
Expand All @@ -23,20 +24,16 @@
*/
class ProfileType extends AbstractType
{
private LanguageRepository $languageRepository;

public function __construct(
LanguageRepository $languageRepository,
private readonly SettingsManager $settingsManager
) {
$this->languageRepository = $languageRepository;
}
private readonly LanguageRepository $languageRepository,
private readonly SettingsManager $settingsManager,
) {}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$changeableOptions = $this->settingsManager->getSetting('profile.changeable_options') ?? [];
$visibleOptions = $this->settingsManager->getSetting('profile.visible_options') ?? [];
$languages = array_flip($this->languageRepository->getAllAvailableToArray());
$changeableOptions = $this->settingsManager->getSetting('profile.changeable_options', true) ?? [];
$visibleOptions = $this->settingsManager->getSetting('profile.visible_options', true) ?? [];
$languages = array_flip($this->languageRepository->getAllAvailableToArray(true));

$fieldsMap = [
'name' => ['field' => 'firstname', 'type' => TextType::class, 'label' => 'Firstname'],
Expand All @@ -49,10 +46,16 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'mapped' => false,
],
'login' => ['field' => 'login', 'type' => TextType::class, 'label' => 'Login'],
'password' => ['field' => 'password', 'type' => TextType::class, 'label' => 'Password'],
'password' => [
'field' => 'password',
'type' => PasswordType::class,
'label' => 'Password',
'mapped' => false,
'required' => false,
],
'language' => [
'field' => 'locale',
'type' => LocaleType::class,
'type' => ChoiceType::class,
'label' => 'Language',
'choices' => $languages,
],
Expand All @@ -69,7 +72,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
array_merge(
[
'label' => $fieldConfig['label'],
'required' => false,
'required' => $fieldConfig['required'] ?? false,
'mapped' => $fieldConfig['mapped'] ?? true,
'attr' => !$isEditable ? ['readonly' => true] : [],
],
isset($fieldConfig['choices']) ? ['choices' => $fieldConfig['choices']] : []
Expand Down
10 changes: 8 additions & 2 deletions src/CoreBundle/Repository/LanguageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ public function getAllAvailable($excludeDefaultLocale = false): QueryBuilder
return $qb;
}

public function getAllAvailableToArray(): array
public function getAllAvailableToArray(bool $onlyActive = false): array
{
$languages = $this->getAllAvailable()->getQuery()->getResult();
$queryBuilder = $this->getAllAvailable();

if (!$onlyActive) {
$queryBuilder->resetDQLPart('where');
}

$languages = $queryBuilder->getQuery()->getResult();

$list = [];

Expand Down

0 comments on commit f6452e7

Please sign in to comment.