mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
user: current location edit form and page
This commit is contained in:
parent
32c7695d80
commit
5905038425
@ -18,6 +18,7 @@ use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Form\UserType;
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\MainBundle\Form\Type\ComposedGroupCenterType;
|
||||
use Chill\MainBundle\Form\UserCurrentLocationType;
|
||||
use Chill\MainBundle\Form\UserPasswordType;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
@ -87,7 +88,7 @@ class UserController extends CRUDController
|
||||
[
|
||||
'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($entity, $request)->createView(),
|
||||
'delete_groupcenter_form' => array_map(
|
||||
function(\Symfony\Component\Form\Form $form) {
|
||||
function (\Symfony\Component\Form\Form $form) {
|
||||
return $form->createView();
|
||||
},
|
||||
iterator_to_array($this->getDeleteLinkGroupCenterByUser($entity, $request), true)
|
||||
@ -145,11 +146,10 @@ class UserController extends CRUDController
|
||||
private function createEditPasswordForm(User $user)
|
||||
{
|
||||
return $this->createForm(UserPasswordType::class, null, array(
|
||||
'user' => $user
|
||||
))
|
||||
'user' => $user
|
||||
))
|
||||
->add('submit', SubmitType::class, array('label' => 'Change password'))
|
||||
->remove('actual_password')
|
||||
;
|
||||
->remove('actual_password');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,7 +167,7 @@ class UserController extends CRUDController
|
||||
}
|
||||
|
||||
$groupCenter = $em->getRepository('ChillMainBundle:GroupCenter')
|
||||
->find($gcid);
|
||||
->find($gcid);
|
||||
|
||||
if (!$groupCenter) {
|
||||
throw $this->createNotFoundException('Unable to find groupCenter entity');
|
||||
@ -184,10 +184,9 @@ class UserController extends CRUDController
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')
|
||||
->trans('The permissions where removed.'));
|
||||
->trans('The permissions where removed.'));
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_crud_admin_user_edit', array('id' => $uid)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -209,24 +208,26 @@ class UserController extends CRUDController
|
||||
|
||||
if ($form->isValid()) {
|
||||
$groupCenter = $this->getPersistedGroupCenter(
|
||||
$form[self::FORM_GROUP_CENTER_COMPOSED]->getData());
|
||||
$form[self::FORM_GROUP_CENTER_COMPOSED]->getData()
|
||||
);
|
||||
$user->addGroupCenter($groupCenter);
|
||||
|
||||
if ($this->validator->validate($user)->count() === 0) {
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')->trans('The '
|
||||
$this->addFlash('success', $this->get('translator')->trans('The '
|
||||
. 'permissions have been successfully added to the user'));
|
||||
|
||||
$returnPathParams = $request->query->has('returnPath') ?
|
||||
['returnPath' => $request->query->get('returnPath')] : [];
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_crud_admin_user_edit',
|
||||
\array_merge(['id' => $uid], $returnPathParams)));
|
||||
$returnPathParams = $request->query->has('returnPath') ?
|
||||
['returnPath' => $request->query->get('returnPath')] : [];
|
||||
|
||||
return $this->redirect($this->generateUrl(
|
||||
'chill_crud_admin_user_edit',
|
||||
\array_merge(['id' => $uid], $returnPathParams)
|
||||
));
|
||||
}
|
||||
|
||||
foreach($this->validator->validate($user) as $error) {
|
||||
foreach ($this->validator->validate($user) as $error) {
|
||||
$this->addFlash('error', $error->getMessage());
|
||||
}
|
||||
}
|
||||
@ -236,7 +237,7 @@ class UserController extends CRUDController
|
||||
'edit_form' => $this->createEditForm($user)->createView(),
|
||||
'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($user, $request)->createView(),
|
||||
'delete_groupcenter_form' => array_map(
|
||||
static fn(Form $form) => $form->createView(),
|
||||
static fn (Form $form) => $form->createView(),
|
||||
iterator_to_array($this->getDeleteLinkGroupCenterByUser($user, $request), true)
|
||||
)
|
||||
]);
|
||||
@ -247,10 +248,10 @@ class UserController extends CRUDController
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$groupCenterManaged = $em->getRepository('ChillMainBundle:GroupCenter')
|
||||
->findOneBy(array(
|
||||
'center' => $groupCenter->getCenter(),
|
||||
'permissionsGroup' => $groupCenter->getPermissionsGroup()
|
||||
));
|
||||
->findOneBy(array(
|
||||
'center' => $groupCenter->getCenter(),
|
||||
'permissionsGroup' => $groupCenter->getPermissionsGroup()
|
||||
));
|
||||
|
||||
if (!$groupCenterManaged) {
|
||||
$em->persist($groupCenter);
|
||||
@ -270,8 +271,10 @@ class UserController extends CRUDController
|
||||
$returnPathParams = $request->query->has('returnPath') ? ['returnPath' => $request->query->get('returnPath')] : [];
|
||||
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('admin_user_delete_groupcenter',
|
||||
array_merge($returnPathParams, ['uid' => $user->getId(), 'gcid' => $groupCenter->getId()])))
|
||||
->setAction($this->generateUrl(
|
||||
'admin_user_delete_groupcenter',
|
||||
array_merge($returnPathParams, ['uid' => $user->getId(), 'gcid' => $groupCenter->getId()])
|
||||
))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, array('label' => 'Delete'))
|
||||
->getForm();
|
||||
@ -285,8 +288,10 @@ class UserController extends CRUDController
|
||||
$returnPathParams = $request->query->has('returnPath') ? ['returnPath' => $request->query->get('returnPath')] : [];
|
||||
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('admin_user_add_groupcenter',
|
||||
array_merge($returnPathParams, ['uid' => $user->getId()])))
|
||||
->setAction($this->generateUrl(
|
||||
'admin_user_add_groupcenter',
|
||||
array_merge($returnPathParams, ['uid' => $user->getId()])
|
||||
))
|
||||
->setMethod('POST')
|
||||
->add(self::FORM_GROUP_CENTER_COMPOSED, ComposedGroupCenterType::class)
|
||||
->add('submit', SubmitType::class, array('label' => 'Add a new groupCenter'))
|
||||
@ -299,4 +304,45 @@ class UserController extends CRUDController
|
||||
yield $groupCenter->getId() => $this->createDeleteLinkGroupCenterForm($user, $groupCenter, $request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return \Symfony\Component\Form\Form
|
||||
*/
|
||||
private function createEditLocationForm()
|
||||
{
|
||||
return $this->createForm(UserCurrentLocationType::class)
|
||||
->add('submit', SubmitType::class, ['label' => 'Change current location']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to edit the user current location.
|
||||
*
|
||||
* @Route("/{_locale}/main/user/{id}/current-location/edit", name="chill_main_user_currentlocation_edit")
|
||||
*/
|
||||
public function editCurrentLocationAction(User $user, Request $request)
|
||||
{
|
||||
$editForm = $this->createEditLocationForm();
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
$currentLocation = $editForm->get('location')->getData();
|
||||
|
||||
$user->setCurrentLocation($currentLocation);
|
||||
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
$this->addFlash('success', $this->get('translator')->trans('Current location successfully updated'));
|
||||
|
||||
return $this->redirect(
|
||||
$request->query->has('returnPath') ? $request->query->get('returnPath') :
|
||||
$this->generateUrl('chill_main_homepage')
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render('@ChillMain/User/edit_current_location.html.twig', [
|
||||
'entity' => $user,
|
||||
'edit_form' => $editForm->createView()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
23
src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php
Normal file
23
src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
|
||||
class UserCurrentLocationType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('location', EntityType::class, [
|
||||
'class' => Location::class,
|
||||
'choice_label' => function (Location $entity) {
|
||||
return $entity->getName();
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
{% extends 'ChillMainBundle::layout.html.twig' %}
|
||||
|
||||
{% block title %}{{ 'Edit my current location'|trans }}{% endblock %}
|
||||
|
||||
{% block content -%}
|
||||
<h1>{{ 'Edit my current location'|trans }}</h1>
|
||||
|
||||
{{ form_start(edit_form) }}
|
||||
{{ form_row(edit_form.location) }}
|
||||
|
||||
<ul class="record_actions">
|
||||
<li class="cancel">
|
||||
<a href="{{ chill_return_path_or('chill_main_homepage') }}" class="btn btn-cancel">
|
||||
{{ 'Cancel'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ form_widget(edit_form.submit, { 'attr': { 'class': 'btn btn-edit' } } ) }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{{ form_end(edit_form) }}
|
||||
{% endblock %}
|
@ -176,6 +176,10 @@ Flags: Drapeaux
|
||||
# admin section for users jobs
|
||||
User jobs: Métiers
|
||||
|
||||
# user page for current location
|
||||
Edit my current location: Éditer ma localisation actuelle
|
||||
Change current location: Changer ma localisation actuelle
|
||||
Current location successfully updated: Localisation actuelle mise à jour
|
||||
|
||||
#admin section for circles (old: scopes)
|
||||
List circles: Cercles
|
||||
|
Loading…
x
Reference in New Issue
Block a user