mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
improve activity form
- create as a service with required depedencies (required for scope) - add scope - fix date show - adapt controller accordingly
This commit is contained in:
parent
86b24f58ac
commit
be78c25091
@ -27,6 +27,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\ActivityBundle\Form\ActivityType;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
/**
|
||||
* Activity controller.
|
||||
@ -59,6 +61,12 @@ class ActivityController extends Controller
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||
|
||||
/**if ($person === NULL) {
|
||||
throw $this->createNotFoundException('person not found');
|
||||
}*/
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
|
||||
$entity = new Activity();
|
||||
$form = $this->createCreateForm($entity, $person);
|
||||
$form->handleRequest($request);
|
||||
@ -85,12 +93,16 @@ class ActivityController extends Controller
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createCreateForm(Activity $entity, $person)
|
||||
private function createCreateForm(Activity $entity, Person $person)
|
||||
{
|
||||
$form = $this->createForm(new ActivityType(), $entity, array(
|
||||
'action' => $this->generateUrl('chill_activity_activity_create', ['person_id' => $person->getId()]),
|
||||
'method' => 'POST',
|
||||
));
|
||||
$form = $this->createForm('chill_activitybundle_activity', $entity,
|
||||
array(
|
||||
'action' => $this->generateUrl('chill_activity_activity_create', ['person_id' => $person->getId()]),
|
||||
'method' => 'POST',
|
||||
'center' => $person->getCenter(),
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE')
|
||||
)
|
||||
);
|
||||
|
||||
$form->add('submit', 'submit', array('label' => 'Create'));
|
||||
|
||||
|
@ -99,7 +99,7 @@ class Activity
|
||||
*
|
||||
* @return Activity
|
||||
*/
|
||||
public function setUserr(User $user)
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
|
@ -4,10 +4,57 @@ namespace Chill\ActivityBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\AppendScopeChoiceTypeTrait;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
class ActivityType extends AbstractType
|
||||
{
|
||||
|
||||
use AppendScopeChoiceTypeTrait;
|
||||
|
||||
/**
|
||||
* the user running this form
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ObjectManager
|
||||
*/
|
||||
protected $om;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
public function __construct(TokenStorageInterface $tokenStorage,
|
||||
AuthorizationHelper $authorizationHelper, ObjectManager $om,
|
||||
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->om = $om;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
@ -15,26 +62,46 @@ class ActivityType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('date')
|
||||
->add('date', 'date', array(
|
||||
'required' => true,
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy')
|
||||
)
|
||||
->add('durationTime')
|
||||
->add('remark')
|
||||
->add('attendee')
|
||||
->add('remark', 'textarea', array(
|
||||
'required' => false,
|
||||
'empty_data' => ''
|
||||
))
|
||||
->add('attendee', 'choice', array(
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => array(
|
||||
true => 'present',
|
||||
false => 'not present'
|
||||
)
|
||||
))
|
||||
->add('user')
|
||||
//->add('scope')
|
||||
//->add('reason')
|
||||
//->add('type')
|
||||
//->add('person')
|
||||
;
|
||||
|
||||
$this->appendScopeChoices($builder, $options['role'],
|
||||
$options['center'], $this->user, $this->authorizationHelper,
|
||||
$this->translatableStringHelper, $this->om);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolverInterface $resolver
|
||||
*/
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\ActivityBundle\Entity\Activity'
|
||||
));
|
||||
|
||||
$this->appendScopeChoicesOptions($resolver);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,17 @@
|
||||
services:
|
||||
chill.activity.form.type.translatableactivityreasoncategory:
|
||||
chill.activity.form.type.translatableactivityreasoncategory:
|
||||
class: Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategory
|
||||
arguments:
|
||||
- "@request_stack"
|
||||
tags:
|
||||
- { name: form.type, alias: translatable_activity_reason_category }
|
||||
- { name: form.type, alias: translatable_activity_reason_category }
|
||||
|
||||
chill.activity.form.type.activity:
|
||||
class: Chill\ActivityBundle\Form\ActivityType
|
||||
arguments:
|
||||
- "@security.token_storage"
|
||||
- "@chill.main.security.authorization.helper"
|
||||
- "@doctrine.orm.entity_manager"
|
||||
- "@chill.main.helper.translatable_string"
|
||||
tags:
|
||||
- { name: form.type, alias: chill_activitybundle_activity }
|
Loading…
x
Reference in New Issue
Block a user