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
1393a2b2
Commit
1393a2b2
authored
Feb 26, 2015
by
Julien Fastré
Browse files
add summary_fields in timeline
The tests and fixtures are adapted accordingly
parent
d0374961
Changes
5
Hide whitespace changes
Inline
Side-by-side
DataFixtures/ORM/LoadCustomFieldsGroup.php
View file @
1393a2b2
...
...
@@ -40,8 +40,13 @@ class LoadCustomFieldsGroup extends AbstractFixture implements OrderedFixtureInt
{
echo
"loading customFieldsGroup...
\n
"
;
$report
=
$this
->
createReport
(
$manager
,
array
(
'fr'
=>
'Situation de logement'
));
$this
->
addReference
(
'cf_group_report_logement'
,
$report
);
$report
=
$this
->
createReport
(
$manager
,
array
(
'fr'
=>
'Situation de logement'
),
[
'summary_fields'
=>
[
'has_logement'
,
'house-desc'
]]);
$this
->
addReference
(
'cf_group_report_logement'
,
$report
);
$report
=
$this
->
createReport
(
$manager
,
array
(
'fr'
=>
'Alphabétisme'
));
$this
->
addReference
(
'cf_group_report_education'
,
$report
);
...
...
@@ -65,13 +70,17 @@ class LoadCustomFieldsGroup extends AbstractFixture implements OrderedFixtureInt
* @param array $name
* @return CustomFieldsGroup
*/
private
function
createReport
(
ObjectManager
$manager
,
array
$name
)
private
function
createReport
(
ObjectManager
$manager
,
array
$name
,
array
$options
=
array
())
{
echo
$name
[
'fr'
]
.
"
\n
"
;
$cFGroup
=
(
new
CustomFieldsGroup
())
->
setName
(
$name
)
->
setEntity
(
'Chill\ReportBundle\Entity\Report'
);
->
setEntity
(
'Chill\ReportBundle\Entity\Report'
)
->
setOptions
(
$options
);
$manager
->
persist
(
$cFGroup
);
...
...
DependencyInjection/ChillReportExtension.php
View file @
1393a2b2
...
...
@@ -43,7 +43,19 @@ class ChillReportExtension extends Extension implements PrependExtensionInterfac
$container
->
prependExtensionConfig
(
'chill_custom_fields'
,
array
(
'customizables_entities'
=>
array
(
array
(
'class'
=>
'Chill\ReportBundle\Entity\Report'
,
'name'
=>
'ReportEntity'
)
array
(
'class'
=>
'Chill\ReportBundle\Entity\Report'
,
'name'
=>
'ReportEntity'
,
'options'
=>
array
(
'summary_fields'
=>
array
(
'form_type'
=>
'custom_fields_group_linked_custom_fields'
,
'form_options'
=>
[
'multiple'
=>
true
,
'expanded'
=>
false
]
)
))
)
)
);
...
...
Resources/views/Timeline/report_person_context.html.twig
View file @
1393a2b2
<div
class=
"report"
>
<span
class=
"statement"
>
{{
'%user% has filled a %report_label% report on %date%'
|
trans
(
{
'%user%'
:
user
,
'%report_label%'
:
report.CFGroup.name
|
localize_translatable_string
,
'%date%'
:
report.date
|
localizeddate
(
'long'
,
'none'
)
}
)
}}
</span>
<span
class=
"links"
><a
href=
"
{{
path
(
'report_view'
,
{
'person_id'
:
person.id
,
'report_id'
:
report.id
}
)
}}
"
>
{{
'View the report'
|
trans
}}
</a></span>
<div
class=
"statement"
>
<span
class=
"statement"
>
{{
'%user% has filled a %report_label% report on %date%'
|
trans
(
{
'%user%'
:
user
,
'%report_label%'
:
report.CFGroup.name
|
localize_translatable_string
,
'%date%'
:
report.date
|
localizeddate
(
'long'
,
'none'
)
}
)
}}
</span>
<span
class=
"links"
><a
href=
"
{{
path
(
'report_view'
,
{
'person_id'
:
person.id
,
'report_id'
:
report.id
}
)
}}
"
>
{{
'View the report'
|
trans
}}
</a></span>
</div>
{%
if
custom_fields_in_summary
|
length
>
0
%}
<div
class=
"summary"
>
{%
for
field
in
custom_fields_in_summary
%}
{%
if
field.type
==
'title'
%}
{{
chill_custom_field_widget
(
report.cFData
,
field
)
}}
{%
else
%}
<dt>
{{
chill_custom_field_label
(
field
)
}}
</dt>
<dd>
{{
chill_custom_field_widget
(
report.cFData
,
field
)
}}
</dd>
{%
endif
%}
{%
endfor
%}
</div>
{%
endif
%}
</div>
\ No newline at end of file
Tests/Timeline/TimelineProviderTest.php
View file @
1393a2b2
...
...
@@ -73,8 +73,9 @@ class TimelineProviderTest extends WebTestCase
->
findOneByUsername
(
'chill b_social'
))
->
setDate
(
new
\
DateTime
(
'2015-05-02'
))
->
setPerson
(
$this
->
person
)
->
setCFGroup
(
$this
->
getRandomCustomFieldsGroup
())
->
setCFData
(
array
());
->
setCFGroup
(
$this
->
getHousingCustomFieldsGroup
())
->
setCFData
([
'has_logement'
=>
'own_house'
,
'house-desc'
=>
'blah blah'
]);
static
::
$em
->
persist
(
$this
->
report
);
...
...
@@ -84,6 +85,9 @@ class TimelineProviderTest extends WebTestCase
}
/**
* Test that a report is shown in timeline
*/
public
function
testTimelineReport
()
{
$client
=
static
::
createClient
(
array
(),
...
...
@@ -99,16 +103,46 @@ class TimelineProviderTest extends WebTestCase
'the page contains the text "a publié un rapport"'
);
}
public
function
testTimelineReportWithSummaryField
()
{
//load the page
$client
=
static
::
createClient
(
array
(),
MainTestHelper
::
getAuthenticatedClientOptions
()
);
$crawler
=
$client
->
request
(
'GET'
,
'/fr/person/'
.
$this
->
person
->
getId
()
.
'/timeline'
);
//performs tests
$this
->
assertTrue
(
$client
->
getResponse
()
->
isSuccessful
(),
'The page timeline is loaded successfully'
);
$this
->
assertGreaterThan
(
0
,
$crawler
->
filter
(
'.report .summary'
)
->
count
(),
'the page contains a .report .summary element'
);
$this
->
assertContains
(
'blah blah'
,
$crawler
->
filter
(
'.report .summary'
)
->
text
(),
'the page contains the text "blah blah"'
);
$this
->
assertContains
(
'Propriétaire'
,
$crawler
->
filter
(
'.report .summary'
)
->
text
(),
'the page contains the mention "Propriétaire"'
);
}
/**
* get a random custom fields group
*
* @return \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
*/
private
function
get
Random
CustomFieldsGroup
()
private
function
get
Housing
CustomFieldsGroup
()
{
$groups
=
static
::
$em
->
getRepository
(
'ChillCustomFieldsBundle:CustomFieldsGroup'
)
->
findBy
(
array
(
'entity'
=>
'Chill\ReportBundle\Entity\Report'
));
->
findAll
();
foreach
(
$groups
as
$group
)
{
if
(
$group
->
getName
()[
'fr'
]
===
'Situation de logement'
)
{
return
$group
;
}
}
return
$groups
[
rand
(
0
,
count
(
$groups
)
-
1
)];
}
...
...
@@ -117,7 +151,7 @@ class TimelineProviderTest extends WebTestCase
public
function
tearDown
()
{
static
::
$em
->
remove
(
$this
->
person
);
static
::
$em
->
remove
(
$this
->
report
);
//
static::$em->remove($this->person);
//
static::$em->remove($this->report);
}
}
Timeline/TimelineReportProvider.php
View file @
1393a2b2
...
...
@@ -88,10 +88,27 @@ class TimelineReportProvider implements TimelineProviderInterface
*/
public
function
getEntityTemplate
(
$entity
,
$context
,
array
$args
)
{
$this
->
checkContext
(
$context
);
//gather all custom fields which should appears in summary
$customFieldsInSummary
=
array
();
if
(
array_key_exists
(
'summary_fields'
,
$entity
->
getCFGroup
()
->
getOptions
()))
{
foreach
(
$entity
->
getCFGroup
()
->
getCustomFields
()
as
$customField
)
{
if
(
in_array
(
$customField
->
getSlug
(),
$entity
->
getCFGroup
()
->
getOptions
()[
'summary_fields'
]))
{
$customFieldsInSummary
[]
=
$customField
;
}
}
}
return
array
(
'template'
=>
'ChillReportBundle:Timeline:report_person_context.html.twig'
,
'template_data'
=>
array
(
'report'
=>
$entity
,
'custom_fields_in_summary'
=>
$customFieldsInSummary
,
'person'
=>
$args
[
'person'
],
'user'
=>
$entity
->
getUser
()
)
...
...
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