Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Chill-project
Chill-Report
Commits
ec700674
Commit
ec700674
authored
Jun 24, 2015
by
Julien Fastré
Browse files
add scope to form "new" report
[ci skip]
parent
a938ce50
Changes
3
Hide whitespace changes
Inline
Side-by-side
Controller/ReportController.php
View file @
ec700674
...
...
@@ -26,6 +26,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use
Chill\PersonBundle\Entity\Person
;
use
Chill\ReportBundle\Entity\Report
;
use
Chill\ReportBundle\Form\ReportType
;
use
Symfony\Component\Security\Core\Role\Role
;
/**
* Report controller.
...
...
@@ -194,15 +195,25 @@ class ReportController extends Controller
$em
=
$this
->
getDoctrine
()
->
getManager
();
$person
=
$em
->
getRepository
(
'ChillPersonBundle:Person'
)
->
find
(
$person_id
);
$cFGroup
=
$em
->
getRepository
(
'ChillCustomFieldsBundle:CustomFieldsGroup'
)
->
find
(
$cf_group_id
);
if
(
$person
===
NULL
)
{
throw
$this
->
createNotFoundException
(
"Person not found"
);
}
if
(
$cFGroup
===
NULL
){
throw
$this
->
createNotFoundException
(
"custom fields group not found"
);
}
$entity
=
new
Report
();
$entity
->
setUser
(
$this
->
get
(
'security.context'
)
->
getToken
()
->
getUser
());
$entity
->
setDate
(
new
\
DateTime
(
'now'
));
$cFGroup
=
$em
->
getRepository
(
'ChillCustomFieldsBundle:CustomFieldsGroup'
)
->
find
(
$cf_group_id
);
$entity
->
setCFGroup
(
$cFGroup
);
$form
=
$this
->
createCreateForm
(
$entity
,
$person
_id
,
$cFGroup
);
$form
=
$this
->
createCreateForm
(
$entity
,
$person
,
$cFGroup
);
return
$this
->
render
(
'ChillReportBundle:Report:new.html.twig'
,
array
(
'entity'
=>
$entity
,
...
...
@@ -280,13 +291,14 @@ class ReportController extends Controller
*/
private
function
createCreateForm
(
Report
$entity
,
Person
$person
,
$cFGroup
)
{
$form
=
$this
->
createForm
(
new
ReportType
()
,
$entity
,
array
(
$form
=
$this
->
createForm
(
'chill_reportbundle_report'
,
$entity
,
array
(
'action'
=>
$this
->
generateUrl
(
'report_create'
,
array
(
'person_id'
=>
$person
->
getId
(),
'cf_group_id'
=>
$cFGroup
->
getId
())),
'method'
=>
'POST'
,
'em'
=>
$this
->
getDoctrine
()
->
getManager
(),
'cFGroup'
=>
$cFGroup
,
'role'
=>
new
Role
(
'CHILL_REPORT_CREATE'
),
'center'
=>
$person
->
getCenter
()
));
return
$form
;
...
...
Form/ReportType.php
View file @
ec700674
...
...
@@ -21,52 +21,49 @@
namespace
Chill\ReportBundle\Form
;
use
Symfony\Component
\Form\AbstractType
;
use
Chill\MainBundle
\Form\
Type\
Abstract
HasScope
Type
;
use
Symfony\Component\Form\FormBuilderInterface
;
use
Symfony\Component\OptionsResolver\OptionsResolverInterface
;
use
Symfony\Component\OptionsResolver\OptionsResolver
;
use
Symfony\Component\Form\FormEvent
;
use
Symfony\Component\Form\FormEvents
;
class
ReportType
extends
AbstractType
{
class
ReportType
extends
Abstract
HasScope
Type
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public
function
buildForm
(
FormBuilderInterface
$builder
,
array
$options
)
{
$entityManager
=
$options
[
'em'
];
$builder
->
add
(
'user'
)
->
add
(
'date'
,
'date'
,
array
(
'required'
=>
true
,
'widget'
=>
'single_text'
,
'format'
=>
'dd-MM-yyyy'
))
->
add
(
'scope'
,
'scope'
)
->
add
(
'cFData'
,
'custom_field'
,
array
(
'attr'
=>
array
(
'class'
=>
'cf-fields'
),
'group'
=>
$options
[
'cFGroup'
]))
;
$this
->
appendScopeChoices
(
$builder
,
$options
);
}
/**
* @param OptionsResolverInterface $resolver
*/
public
function
setDefault
Options
(
OptionsResolver
Interface
$resolver
)
public
function
configure
Options
(
OptionsResolver
$resolver
)
{
parent
::
configureOptions
(
$resolver
);
$resolver
->
setDefaults
(
array
(
'data_class'
=>
'Chill\ReportBundle\Entity\Report'
));
$resolver
->
setRequired
(
array
(
'em'
,
'cFGroup'
,
'role'
,
'center'
));
$resolver
->
setAllowedTypes
(
array
(
'em'
=>
'Doctrine\Common\Persistence\ObjectManager'
,
'cFGroup'
=>
'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup'
,
'role'
=>
'Symfony\Component\Security\Core\Role\Role'
,
'center'
=>
'Chill\MainBundle\Entity\Center'
));
}
...
...
Resources/config/services.yml
View file @
ec700674
...
...
@@ -25,4 +25,13 @@ services:
arguments
:
-
"
@chill.main.security.authorization.helper"
tags
:
-
{
name
:
security.voter
}
\ No newline at end of file
-
{
name
:
security.voter
}
chill.report.form.report_type
:
class
:
Chill\ReportBundle\Form\ReportType
arguments
:
-
"
@chill.main.security.authorization.helper"
-
"
@security.token_storage"
-
"
@chill.main.helper.translatable_string"
tags
:
-
{
name
:
form.type
,
alias
:
chill_reportbundle_report
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment