9
9
import fr .paris .lutece .plugins .forms .business .FormResponse ;
10
10
import fr .paris .lutece .plugins .forms .business .FormResponseHome ;
11
11
import fr .paris .lutece .plugins .forms .business .FormResponseStep ;
12
- import fr .paris .lutece .plugins .genericattributes .business .Response ;
13
12
import fr .paris .lutece .portal .service .dashboard .IPublicDashboardComponent ;
14
13
import fr .paris .lutece .portal .service .i18n .I18nService ;
15
14
import fr .paris .lutece .portal .service .util .AppPropertiesService ;
@@ -21,7 +20,7 @@ public class PublicDashboardForms implements IPublicDashboardComponent {
21
20
public static final String DASHBOARD_PROPERTIES_QUESTION_PUBLISHED = "forms.publicdashboard.question.isPublished" ;
22
21
private String strIdComponent = "forms.dashboardForms" ;
23
22
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 " ;
25
24
26
25
@ Override
27
26
public String getComponentDescription ( Locale local ) {
@@ -43,81 +42,49 @@ public String getDashboardTemplate()
43
42
public Map <String , Object > getDashboardModel ( String user_id , Map <String ,String []> additionalParameters )
44
43
{
45
44
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 ) ) );
47
46
return model ;
48
47
}
49
48
50
49
/**
51
- * Search all the responses from a user.
50
+ * Search all the formResponse published from a user.
52
51
* @param userId the userid
53
52
* @param published_formresponse_only request only the formResponse published
54
53
* @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
56
55
*/
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 )
58
57
{
59
58
60
-
61
- Map <String , Map <String , String >> mapResponsesValuesByFormResponse = new HashMap <String , Map <String , String >>( );
62
59
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 )
65
63
{
66
-
67
- getFormResponse (mapResponsesValuesByFormResponse , formRep , published_formresponse_only , published_questions_only );
64
+ formResponseFilteredByQuestionsPublished (formResponseList );
68
65
}
69
-
70
- return mapResponsesValuesByFormResponse ;
66
+ return formResponseList ;
71
67
72
68
}
73
69
74
70
/**
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
80
73
*/
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 )
82
75
{
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 )
85
77
{
86
- List <FormResponseStep > lstStep = formRep .getSteps ( );
87
- Map <String , String > mapResponsesValues = new HashMap <String , String >( );
78
+ List <FormResponseStep > lstStep = formRep .getSteps ( );
88
79
for ( FormResponseStep step : lstStep )
89
80
{
90
81
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
+ };
101
85
}
86
+
102
87
}
103
88
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
- }
122
89
123
90
}
0 commit comments