Skip to content

Commit 468e568

Browse files
NLG85ryahiaoui
authored andcommitted
FORMS-820 : publicdashboard returns now a list of formReponses
1 parent a9b3708 commit 468e568

File tree

2 files changed

+29
-58
lines changed

2 files changed

+29
-58
lines changed

src/java/fr/paris/lutece/plugins/forms/dashboard/PublicDashboardForms.java

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import fr.paris.lutece.plugins.forms.business.FormResponse;
1010
import fr.paris.lutece.plugins.forms.business.FormResponseHome;
1111
import fr.paris.lutece.plugins.forms.business.FormResponseStep;
12-
import fr.paris.lutece.plugins.genericattributes.business.Response;
1312
import fr.paris.lutece.portal.service.dashboard.IPublicDashboardComponent;
1413
import fr.paris.lutece.portal.service.i18n.I18nService;
1514
import fr.paris.lutece.portal.service.util.AppPropertiesService;
@@ -21,7 +20,7 @@ public class PublicDashboardForms implements IPublicDashboardComponent {
2120
public static final String DASHBOARD_PROPERTIES_QUESTION_PUBLISHED = "forms.publicdashboard.question.isPublished";
2221
private String strIdComponent = "forms.dashboardForms";
2322
private static final String TEMPLATE_DASHBOARD_FORMS = "/skin/plugins/forms/publicdashboard_form.html";
24-
private static final String MARK_DASHBOARD_FORMS = "forms_publicdashboard";
23+
private static final String MARK_LIST_FORMRESPONSE = "list_formsresponse";
2524

2625
@Override
2726
public String getComponentDescription( Locale local ) {
@@ -43,81 +42,49 @@ public String getDashboardTemplate()
4342
public Map<String, Object> getDashboardModel( String user_id, Map<String,String[]> additionalParameters )
4443
{
4544
Map<String, Object> model = new HashMap<String, Object>( );
46-
model.put( MARK_DASHBOARD_FORMS, searchDashboardFormsQuestionReponse( user_id, AppPropertiesService.getPropertyBoolean(DASHBOARD_PROPERTIES_FORMRESPONSE_PUBLISHED, true), AppPropertiesService.getPropertyBoolean(DASHBOARD_PROPERTIES_QUESTION_PUBLISHED, true) ) );
45+
model.put( MARK_LIST_FORMRESPONSE, searchDashboardFormReponsesFromUser( user_id, AppPropertiesService.getPropertyBoolean(DASHBOARD_PROPERTIES_FORMRESPONSE_PUBLISHED, true), AppPropertiesService.getPropertyBoolean(DASHBOARD_PROPERTIES_QUESTION_PUBLISHED, true) ) );
4746
return model;
4847
}
4948

5049
/**
51-
* Search all the responses from a user.
50+
* Search all the formResponse published from a user.
5251
* @param userId the userid
5352
* @param published_formresponse_only request only the formResponse published
5453
* @param published_questions_only request only the question published
55-
* @return
54+
* @return a list of form response from the user id and filtered by published formresponse
5655
*/
57-
private static Map<String, Map<String, String>> searchDashboardFormsQuestionReponse( String userId, boolean published_formresponse_only, boolean published_questions_only )
56+
private static List<FormResponse> searchDashboardFormReponsesFromUser( String userId, boolean published_formresponse_only, boolean published_questions_only )
5857
{
5958

60-
61-
Map<String, Map<String, String>> mapResponsesValuesByFormResponse = new HashMap<String, Map<String, String>>( );
6259
List<FormResponse> formResponseList = FormResponseHome.getFormResponseByGuid( userId );
63-
64-
for ( FormResponse formRep : formResponseList )
60+
//If the propertie published_formresponse_only is true, remove unpublished formReponse
61+
formResponseList.removeIf( f -> !f.isPublished( ) && published_formresponse_only );
62+
if (published_questions_only)
6563
{
66-
67-
getFormResponse(mapResponsesValuesByFormResponse, formRep, published_formresponse_only, published_questions_only);
64+
formResponseFilteredByQuestionsPublished(formResponseList);
6865
}
69-
70-
return mapResponsesValuesByFormResponse;
66+
return formResponseList;
7167

7268
}
7369

7470
/**
75-
* search all the formResponse from a user.
76-
* @param mapResponsesValuesByFormResponse the map filled with all the responses from a user
77-
* @param formRep The formResponses from a user
78-
* @param published_formresponse_only request only the formResponse published
79-
* @param published_questions_only request only the question published
71+
* remove the questionReponse not published.
72+
* @param formRep The formResponse from a user
8073
*/
81-
private static void getFormResponse( Map<String, Map<String, String>> mapResponsesValuesByFormResponse, FormResponse formRep, boolean published_formresponse_only, boolean published_questions_only )
74+
private static void formResponseFilteredByQuestionsPublished( List<FormResponse> lstFormRep )
8275
{
83-
//check if formResponse is published or if there is not control of the status of the formResponse
84-
if ( formRep.isPublished( ) || !published_formresponse_only )
76+
for ( FormResponse formRep : lstFormRep )
8577
{
86-
List<FormResponseStep> lstStep = formRep.getSteps( );
87-
Map<String, String> mapResponsesValues = new HashMap<String, String>( );
78+
List<FormResponseStep> lstStep = formRep.getSteps( );
8879
for ( FormResponseStep step : lstStep )
8980
{
9081
List<FormQuestionResponse> lstQr = step.getQuestions( );
91-
for ( FormQuestionResponse fqr : lstQr )
92-
{
93-
getResponse(mapResponsesValues, fqr, published_questions_only);
94-
}
95-
}
96-
97-
if ( !mapResponsesValues.isEmpty( ) )
98-
{
99-
mapResponsesValuesByFormResponse.put( String.valueOf( formRep.getId() ), mapResponsesValues );
100-
}
82+
lstQr.removeIf( f -> !f.getQuestion( ).isPublished( ) );
83+
step.setQuestions(lstQr);
84+
};
10185
}
86+
10287
}
10388

104-
/**
105-
* Search all the question response from a user.
106-
* @param mapResponsesValues the map filled with all the responses from a user
107-
* @param formQuestionResponse the QuestionResponse from the user
108-
* @param published_questions_only request only the question published
109-
*/
110-
private static void getResponse( Map<String, String> mapResponsesValues, FormQuestionResponse formQuestionResponse, boolean published_questions_only )
111-
{
112-
//check if question is published or if there is not control of the status of the question
113-
if ( formQuestionResponse.getQuestion( ).isPublished( ) || !published_questions_only )
114-
{
115-
List<Response> lstresp = formQuestionResponse.getEntryResponse( );
116-
for ( Response resp : lstresp )
117-
{
118-
mapResponsesValues.put( formQuestionResponse.getQuestion( ).getTitle( ), resp.getResponseValue( ) );
119-
}
120-
}
121-
}
12289

12390
}

webapp/WEB-INF/templates/skin/plugins/forms/publicdashboard_form.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ <h2>#i18n{forms.publicdashboard.title}</h2>
22
<div class="table-responsive">
33
<table class="table table-striped">
44
<tbody>
5-
<#list forms_publicdashboard?keys as keyForm>
6-
<#list forms_publicdashboard[keyForm]?keys as keyFormQuestionReponse>
7-
<tr>
8-
<td>${keyFormQuestionReponse}</td>
9-
<td>${forms_publicdashboard[keyForm][keyFormQuestionReponse]!}</td>
10-
</tr>
5+
<#list list_formsresponse as formRep>
6+
<#list formRep.steps as step>
7+
<#list step.questions as question>
8+
<tr>
9+
<td>${question.question.title!}</td>
10+
<#list question.entryResponse as response>
11+
<td>${response.responseValue!}</td>
12+
</#list>
13+
</tr>
14+
</#list>
1115
</#list>
1216
</#list>
1317
</tbody>

0 commit comments

Comments
 (0)