mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 06:14:23 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
167a147f52
@ -12,6 +12,7 @@ use Symfony\Component\Form\Extension\Core\Type\FormType;
|
|||||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event controller.
|
* Event controller.
|
||||||
*
|
*
|
||||||
@ -66,9 +67,9 @@ class EventController extends Controller
|
|||||||
*/
|
*/
|
||||||
private function createCreateForm(Event $entity)
|
private function createCreateForm(Event $entity)
|
||||||
{
|
{
|
||||||
$form = $this->createForm(new EventType(), $entity, array(
|
$form = $this->createForm(EventType::class, $entity, array(
|
||||||
'action' => $this->generateUrl('event_create'),
|
'action' => $this->generateUrl('event_create'),
|
||||||
'method' => 'POST',
|
'method' => 'POST'
|
||||||
));
|
));
|
||||||
|
|
||||||
$form->add('submit', 'submit', array('label' => 'Create'));
|
$form->add('submit', 'submit', array('label' => 'Create'));
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
namespace Chill\EventBundle\Entity;
|
namespace Chill\EventBundle\Entity;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\HasScopeInterface;
|
|
||||||
use Chill\MainBundle\Entity\HasCenterInterface;
|
use Chill\MainBundle\Entity\HasCenterInterface;
|
||||||
|
use Chill\MainBundle\Entity\HasScopeInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event
|
* Event
|
||||||
*/
|
*/
|
||||||
class Event implements HasScopeInterface, HasCenterInterface
|
class Event implements HasCenterInterface, HasScopeInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var integer
|
* @var integer
|
||||||
@ -123,7 +123,7 @@ class Event implements HasScopeInterface, HasCenterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return EventType
|
* @return EventType
|
||||||
*/
|
*/
|
||||||
public function getType()
|
public function getType()
|
||||||
@ -132,7 +132,7 @@ class Event implements HasScopeInterface, HasCenterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param \Chill\EventBundle\Entity\EventType $type
|
* @param \Chill\EventBundle\Entity\EventType $type
|
||||||
* @return \Chill\EventBundle\Entity\Event
|
* @return \Chill\EventBundle\Entity\Event
|
||||||
*/
|
*/
|
||||||
@ -143,7 +143,7 @@ class Event implements HasScopeInterface, HasCenterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return \Chill\MainBundle\Entity\Center
|
* @return \Chill\MainBundle\Entity\Center
|
||||||
*/
|
*/
|
||||||
public function getCenter()
|
public function getCenter()
|
||||||
@ -152,7 +152,7 @@ class Event implements HasScopeInterface, HasCenterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return \Chill\MainBundle\Entity\Scope
|
* @return \Chill\MainBundle\Entity\Scope
|
||||||
*/
|
*/
|
||||||
public function getCircle()
|
public function getCircle()
|
||||||
@ -161,7 +161,7 @@ class Event implements HasScopeInterface, HasCenterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param \Chill\MainBundle\Entity\Scope $circle
|
* @param \Chill\MainBundle\Entity\Scope $circle
|
||||||
* @return \Chill\EventBundle\Entity\Event
|
* @return \Chill\EventBundle\Entity\Event
|
||||||
*/
|
*/
|
||||||
@ -172,7 +172,7 @@ class Event implements HasScopeInterface, HasCenterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* @return \Chill\MainBundle\Entity\Scope
|
* @return \Chill\MainBundle\Entity\Scope
|
||||||
*/
|
*/
|
||||||
|
@ -6,15 +6,66 @@ use Symfony\Component\Form\AbstractType;
|
|||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||||
use Chill\EventBundle\Form\Type\TranslatableEventType;
|
use Chill\EventBundle\Form\Type\TranslatableEventType;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Chill\MainBundle\Entity\Center;
|
||||||
|
use Chill\MainBundle\Entity\Scope;
|
||||||
|
|
||||||
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
|
|
||||||
class EventType extends AbstractType
|
class EventType extends AbstractType
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var the user running this form */
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
/** @var AuthorizationHelper */
|
||||||
|
protected $authorizationHelper;
|
||||||
|
|
||||||
|
/** @var TranslatableStringHelper */
|
||||||
|
protected $translatableStringHelper;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
TokenStorageInterface $tokenStorage,
|
||||||
|
AuthorizationHelper $authorizationHelper,
|
||||||
|
TranslatableStringHelper $translatableStringHelper
|
||||||
|
) {
|
||||||
|
if (!$tokenStorage->getToken()->getUser() instanceof User) {
|
||||||
|
throw new \RuntimeException("you should have a valid user");
|
||||||
|
}
|
||||||
|
$this->user = $tokenStorage->getToken()->getUser();
|
||||||
|
$this->authorizationHelper = $authorizationHelper;
|
||||||
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param FormBuilderInterface $builder
|
* @param FormBuilderInterface $builder
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*/
|
*/
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
|
$userReachableCenters = $this->authorizationHelper
|
||||||
|
->getReachableCenters($this->user, new Role('CHILL_EVENT_CREATE'));
|
||||||
|
|
||||||
|
$userReachableCirclesByCircleId = array();
|
||||||
|
$userReachableCentersByCircleId = array();
|
||||||
|
|
||||||
|
foreach ($userReachableCenters as $center) {
|
||||||
|
foreach ($this->authorizationHelper
|
||||||
|
->getReachableCircles($this->user, new Role('CHILL_EVENT_CREATE'), $center) as $circle) {
|
||||||
|
if (array_key_exists($circle->getId(), $userReachableCirclesByCircleId)) {
|
||||||
|
array_push($userReachableCentersByCircleId[$circle->getId()], $center);
|
||||||
|
} else {
|
||||||
|
$userReachableCirclesByCircleId[$circle->getId()] = $circle;
|
||||||
|
$userReachableCentersByCircleId[$circle->getId()] = array($center);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('label')
|
->add('label')
|
||||||
->add(
|
->add(
|
||||||
@ -26,9 +77,36 @@ class EventType extends AbstractType
|
|||||||
'format' => 'dd-MM-yyyy'
|
'format' => 'dd-MM-yyyy'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
->add('center')
|
->add('center', EntityType::class, array(
|
||||||
|
'class' => Center::class,
|
||||||
|
'choices' => $userReachableCenters,
|
||||||
|
'choice_attr' => function (Center $center) {
|
||||||
|
return array(
|
||||||
|
'data-link-category' => $center->getId()
|
||||||
|
);
|
||||||
|
},
|
||||||
|
))
|
||||||
|
->add('circle', EntityType::class, array(
|
||||||
|
'class' => Scope::class,
|
||||||
|
'choices' => array_values($userReachableCirclesByCircleId),
|
||||||
|
'choice_label' => function ($circle) {
|
||||||
|
$helper = $this->translatableStringHelper;
|
||||||
|
return $helper->localize($circle->getName());
|
||||||
|
},
|
||||||
|
'choice_attr' => function ($circle) use ($userReachableCentersByCircleId) {
|
||||||
|
$centersId = "";
|
||||||
|
foreach ($userReachableCentersByCircleId[$circle->getId()] as $center) {
|
||||||
|
print $center;
|
||||||
|
$centersId = $centersId.($center->getId()).',';
|
||||||
|
}
|
||||||
|
$centersId = trim($centersId, ',');
|
||||||
|
return array(
|
||||||
|
'data-link-categories' => $centersId,
|
||||||
|
|
||||||
|
);
|
||||||
|
},
|
||||||
|
))
|
||||||
->add('type', TranslatableEventType::class)
|
->add('type', TranslatableEventType::class)
|
||||||
//->add('circle')
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
services:
|
services:
|
||||||
chill_event.form.event_type_type:
|
chill.event.form.type.translatable_event_type:
|
||||||
class: Chill\EventBundle\Form\Type\TranslatableEventType
|
class: Chill\EventBundle\Form\Type\TranslatableEventType
|
||||||
arguments:
|
arguments:
|
||||||
- "@chill.main.helper.translatable_string"
|
- "@chill.main.helper.translatable_string"
|
||||||
tags:
|
tags:
|
||||||
- { name: form.type }
|
- { name: form.type }
|
||||||
|
|
||||||
|
chill.event.form.event_type_test:
|
||||||
|
class: Chill\EventBundle\Form\EventType
|
||||||
|
arguments:
|
||||||
|
- "@security.token_storage"
|
||||||
|
- "@chill.main.security.authorization.helper"
|
||||||
|
- "@chill.main.helper.translatable_string"
|
||||||
|
tags:
|
||||||
|
- { name: form.type }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user