1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.quiz.modules.games.web;
35
36 import fr.paris.lutece.plugins.quiz.business.Answer;
37 import fr.paris.lutece.plugins.quiz.business.AnswerHome;
38 import fr.paris.lutece.plugins.quiz.business.QuestionGroupHome;
39 import fr.paris.lutece.plugins.quiz.business.Quiz;
40 import fr.paris.lutece.plugins.quiz.business.QuizHome;
41 import fr.paris.lutece.plugins.quiz.business.QuizQuestion;
42 import fr.paris.lutece.plugins.quiz.business.QuizQuestionHome;
43 import fr.paris.lutece.plugins.quiz.modules.games.business.QuizParticipant;
44 import fr.paris.lutece.plugins.quiz.modules.games.service.RandService;
45 import fr.paris.lutece.plugins.quiz.web.QuizJspBean;
46 import fr.paris.lutece.portal.service.admin.AdminUserService;
47 import fr.paris.lutece.portal.service.i18n.I18nService;
48 import fr.paris.lutece.portal.service.message.AdminMessage;
49 import fr.paris.lutece.portal.service.message.AdminMessageService;
50 import fr.paris.lutece.portal.service.spring.SpringContextService;
51 import fr.paris.lutece.portal.service.template.AppTemplateService;
52 import fr.paris.lutece.portal.service.util.AppPathService;
53 import fr.paris.lutece.portal.web.constants.Messages;
54 import fr.paris.lutece.util.ReferenceList;
55 import fr.paris.lutece.util.date.DateUtil;
56 import fr.paris.lutece.util.html.HtmlTemplate;
57 import fr.paris.lutece.util.url.UrlItem;
58
59 import java.util.Collection;
60 import java.util.Collections;
61 import java.util.HashMap;
62 import java.util.List;
63
64 import javax.servlet.http.HttpServletRequest;
65
66 import org.apache.commons.lang.StringUtils;
67
68
69
70
71
72
73 public class RandJspBean extends QuizJspBean
74 {
75 private static final long serialVersionUID = 8191245123673411012L;
76
77 private static final String PROPERTY_PAGE_TITLE_RAND_LIST = "module.quiz.games.rand_list.pageTitle";
78 private static final String PROPERTY_PAGE_TITLE_MANAGE_QUIZ = "quiz.manage_quiz.pageTitle";
79 private static final String PROPERTY_PAGE_TITLE_CREATE_QUIZ = "quiz.create_quiz.pageTitle";
80 private static final String PROPERTY_PAGE_TITLE_MODIFY_QUIZ = "quiz.modify_quiz.pageTitle";
81 private static final String PROPERTY_PAGE_TITLE_MANAGE_QUESTIONS = "quiz.manage_questions.pageTitle";
82 private static final String PROPERTY_PAGE_TITLE_CREATE_QUESTION = "quiz.create_question.pageTitle";
83 private static final String PROPERTY_PAGE_TITLE_CREATE_ANSWER = "quiz.create_answer.pageTitle";
84
85 private static final String PROPERTY_CONFIRM_DELETE_QUIZ = "quiz.remove_quiz.confirmRemoveQuiz";
86 private static final String PROPERTY_LABEL_NO = "portal.util.labelNo";
87 private static final String PROPERTY_LABEL_YES = "portal.util.labelYes";
88
89 private static final String MESSAGE_NB_WIN_NOT_A_NUMBER = "module.quiz.games.rand_list.message.nb_win.not_a_number";
90 private static final String MESSAGE_NB_WIN_MANDATORY = "module.quiz.games.rand_list.message.mandatory";
91 private static final String MESSAGE_NB_WIN_SUPERIOR_TO_NB_VALID_PARTICIPANT = "module.quiz.games.rand_list.message.nbWinSupToNbValid";
92 private static final String MESSAGE_CANNOT_DELETE_QUIZ = "quiz.message_quiz.cannotDeleteQuiz";
93
94 private static final String PARAMETER_QUIZ_ID = "quiz_id";
95 private static final String PARAMETER_NB_WIN = "nb_win";
96 private static final String PARAMETER_ASK_GENERATE = "ask_generate";
97 private static final String PARAMETER_QUIZ_NAME = "quiz_name";
98 private static final String PARAMETER_ACTIVE_CAPTCHA = "active_captcha";
99 private static final String PARAMETER_INTRODUCTION = "quiz_introduction";
100 private static final String PARAMETER_CONCLUSION = "quiz_conclusion";
101 private static final String PARAMETER_DATE_BEGIN_DISPONIBILITY = "date_begin_disponibility";
102 private static final String PARAMETER_DATE_END_DISPONIBILITY = "date_end_disponibility";
103 private static final String PARAMETER_QUIZ_STATUS = "quiz_status";
104 private static final String PARAMETER_ACTIVE_REQUIREMENT = "active_requirement";
105 private static final String PARAMETER_QUESTION_ID = "question_id";
106 private static final String PARAMETER_ANSWER_ID = "answer_id";
107 private static final String PARAMETER_QUESTION_LABEL = "question_label";
108 private static final String PARAMETER_EXPLAINATION = "explaination";
109
110 private static final String TEMPLATE_RAND_LIST = "admin/plugins/quiz/modules/games/rand_list.html";
111 private static final String TEMPLATE_MANAGE_QUIZ = "admin/plugins/quiz/modules/games/manage_quiz.html";
112 private static final String TEMPLATE_CREATE_QUIZ = "admin/plugins/quiz/modules/games/create_quiz.html";
113 private static final String TEMPLATE_MODIFY_QUIZ = "admin/plugins/quiz/modules/games/modify_quiz.html";
114 private static final String TEMPLATE_MANAGE_QUESTIONS = "admin/plugins/quiz/modules/games/manage_questions.html";
115 private static final String TEMPLATE_CREATE_QUESTION = "admin/plugins/quiz/modules/games/create_question.html";
116 private static final String TEMPLATE_MODIFY_QUESTION = "admin/plugins/quiz/modules/games/modify_question.html";
117 private static final String TEMPLATE_CREATE_ANSWER = "admin/plugins/quiz/modules/games/create_answer.html";
118 private static final String TEMPLATE_MODIFY_ANSWER = "admin/plugins/quiz/modules/games/modify_answer.html";
119
120
121 private static final String MARK_QUIZ = "quiz";
122 private static final String MARK_LIST_WIN_PARTICIPANT = "list_win_participant";
123 private static final String MARK_ERROR = "error";
124 private static final String MARK_QUIZ_LIST = "quiz_list";
125 private static final String MARK_WEBAPP_URL = "webapp_url";
126 private static final String MARK_LOCALE = "locale";
127 private static final String MARK_QUESTION = "question";
128 private static final String MARK_QUESTIONS_LIST = "questions_list";
129 private static final String MARK_ANSWER = "answer";
130 private static final String MARK_ANSWER_LIST = "answer_list";
131 private static final String MARK_YESNO_LIST = "yesno_list";
132
133 private static final String JSP_MANAGE_QUIZ = "jsp/admin/plugins/quiz/modules/games/ManageQuiz.jsp";
134 private static final String JSP_DO_REMOVE_QUIZ = "jsp/admin/plugins/quiz/modules/games/DoRemoveQuiz.jsp";
135
136 private static final String JSP_URL_MANAGE_QUIZ = "ManageQuiz.jsp";
137 private static final String JSP_URL_MANAGE_QUESTIONS = "ManageQuestions.jsp";
138 private static final String JSP_URL_MODIFY_QUESTION = "ModifyQuestion.jsp";
139
140 private final RandService _randService = SpringContextService.getContext( ).getBean( RandService.class );
141
142
143
144
145
146
147
148 @Override
149 public String getManageQuiz( HttpServletRequest request )
150 {
151 setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_QUIZ );
152
153 Collection<Quiz> listQuiz = QuizHome.findAll( getPlugin( ) );
154
155 HashMap<String, Object> model = new HashMap<String, Object>( );
156 model.put( MARK_QUIZ_LIST, listQuiz );
157
158 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_QUIZ, getLocale( ), model );
159
160 return getAdminPage( template.getHtml( ) );
161 }
162
163
164
165
166
167
168
169 @Override
170 public String getCreateQuiz( HttpServletRequest request )
171 {
172 setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_QUIZ );
173
174 HashMap<String, Object> model = new HashMap<String, Object>( );
175 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
176 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
177
178 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_QUIZ, getLocale( ), model );
179
180 return getAdminPage( template.getHtml( ) );
181 }
182
183
184
185
186
187
188
189 @Override
190 public String getModifyQuiz( HttpServletRequest request )
191 {
192 setPageTitleProperty( PROPERTY_PAGE_TITLE_MODIFY_QUIZ );
193
194 int nQuizId = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
195 Quiz quiz = QuizHome.findByPrimaryKey( nQuizId, getPlugin( ) );
196
197 HashMap<String, Object> model = new HashMap<String, Object>( );
198 model.put( MARK_QUIZ, quiz );
199 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
200 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
201
202 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_QUIZ, getLocale( ), model );
203
204 return getAdminPage( template.getHtml( ) );
205 }
206
207
208
209
210
211
212
213 @Override
214 public String doModifyQuiz( HttpServletRequest request )
215 {
216 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
217 String strIntroduction = request.getParameter( PARAMETER_INTRODUCTION );
218 String strConclusion = request.getParameter( PARAMETER_CONCLUSION );
219 String strDateBeginDisponibility = request.getParameter( PARAMETER_DATE_BEGIN_DISPONIBILITY );
220 java.util.Date tDateBeginDisponibility = null;
221 tDateBeginDisponibility = DateUtil.formatDate( strDateBeginDisponibility, getLocale( ) );
222
223 String strDateEndDisponibility = request.getParameter( PARAMETER_DATE_END_DISPONIBILITY );
224 java.util.Date tDateEndDisponibility = null;
225 tDateEndDisponibility = DateUtil.formatDate( strDateEndDisponibility, getLocale( ) );
226
227 int nCaptcha;
228 int nRequirement;
229
230 if ( request.getParameter( PARAMETER_ACTIVE_CAPTCHA ) == null )
231 {
232 nCaptcha = 0;
233 }
234 else
235 {
236 nCaptcha = Integer.parseInt( request.getParameter( PARAMETER_ACTIVE_CAPTCHA ) );
237 }
238
239 if ( request.getParameter( PARAMETER_ACTIVE_REQUIREMENT ) == null )
240 {
241 nRequirement = 0;
242 }
243 else
244 {
245 nRequirement = Integer.parseInt( request.getParameter( PARAMETER_ACTIVE_REQUIREMENT ) );
246 }
247
248 Quiz quiz = QuizHome.findByPrimaryKey( nIdQuiz, getPlugin( ) );
249
250
251 if ( request.getParameter( PARAMETER_QUIZ_NAME ).equals( "" ) )
252 {
253 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
254 }
255
256 quiz.setName( request.getParameter( PARAMETER_QUIZ_NAME ) );
257
258 if ( !( request.getParameter( PARAMETER_QUIZ_STATUS ) == null ) )
259 {
260 quiz.setStatus( 1 );
261 }
262 else
263 {
264 quiz.setStatus( 0 );
265 }
266
267 quiz.setIntroduction( strIntroduction );
268 quiz.setConclusion( strConclusion );
269 quiz.setActiveCaptcha( nCaptcha );
270 quiz.setActiveRequirement( nRequirement );
271 quiz.setDateBeginDisponibility( tDateBeginDisponibility );
272 quiz.setDateEndDisponibility( tDateEndDisponibility );
273
274 QuizHome.update( quiz, getPlugin( ) );
275
276
277 UrlItem url = new UrlItem( JSP_URL_MANAGE_QUIZ );
278
279 return url.getUrl( );
280 }
281
282
283
284
285
286
287
288 @Override
289 public String doDisplayQuiz( HttpServletRequest request )
290 {
291 int nQuizId = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
292 Quiz quiz = QuizHome.findByPrimaryKey( nQuizId, getPlugin( ) );
293
294 if ( quiz.isEnabled( ) )
295 {
296 quiz.setStatus( 0 );
297 }
298 else
299 {
300 quiz.setStatus( 1 );
301 }
302
303 QuizHome.update( quiz, getPlugin( ) );
304
305 UrlItem url = new UrlItem( JSP_URL_MANAGE_QUIZ );
306
307 return url.getUrl( );
308 }
309
310
311
312
313
314
315 public String getManageQuestions( HttpServletRequest request )
316 {
317 setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_QUESTIONS );
318
319 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
320 Quiz quiz = QuizHome.findByPrimaryKey( nIdQuiz, getPlugin( ) );
321
322 Collection<QuizQuestion> questionsList = QuizQuestionHome.findAll( nIdQuiz, getPlugin( ) );
323
324 HashMap<String, Object> model = new HashMap<String, Object>( );
325 model.put( MARK_QUIZ, quiz );
326 model.put( MARK_QUESTIONS_LIST, questionsList );
327
328 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_QUESTIONS, getLocale( ), model );
329
330 return getAdminPage( template.getHtml( ) );
331 }
332
333
334
335
336
337
338
339 public String getCreateQuizQuestion( HttpServletRequest request )
340 {
341 setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_QUESTION );
342
343 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
344 Quiz quiz = QuizHome.findByPrimaryKey( nIdQuiz, getPlugin( ) );
345
346 HashMap<String, Object> model = new HashMap<String, Object>( );
347 model.put( MARK_QUIZ, quiz );
348 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
349 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
350
351 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_QUESTION, getLocale( ), model );
352
353 return getAdminPage( template.getHtml( ) );
354 }
355
356
357
358
359
360
361
362 public String doCreateQuizQuestion( HttpServletRequest request )
363 {
364
365 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
366 String strQuestion = request.getParameter( PARAMETER_QUESTION_LABEL );
367 String strExplication = request.getParameter( PARAMETER_EXPLAINATION );
368
369
370 if ( StringUtils.isEmpty( strQuestion ) )
371 {
372 return AdminMessageService.getMessageUrl( request, "Vous n'avez pas remplis...", AdminMessage.TYPE_STOP );
373 }
374
375 QuizQuestion quizQuestion = new QuizQuestion( );
376 quizQuestion.setQuestionLabel( strQuestion );
377 quizQuestion.setIdQuiz( nIdQuiz );
378 quizQuestion.setExplaination( strExplication );
379 QuizQuestionHome.create( quizQuestion, getPlugin( ) );
380
381 QuizQuestion questionCreated = QuizQuestionHome.findLastQuestion( getPlugin( ) );
382
383
384 UrlItem url = new UrlItem( JSP_URL_MODIFY_QUESTION );
385 url.addParameter( PARAMETER_QUIZ_ID, questionCreated.getIdQuiz( ) );
386 url.addParameter( PARAMETER_QUESTION_ID, questionCreated.getIdQuestion( ) );
387
388 return url.getUrl( );
389 }
390
391
392
393
394
395
396
397 public String getModifyQuizQuestion( HttpServletRequest request )
398 {
399 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
400 int nIdQuestion = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
401 Quiz quiz = QuizHome.findByPrimaryKey( nIdQuiz, getPlugin( ) );
402 QuizQuestion quizQuestion = QuizQuestionHome.findByPrimaryKey( nIdQuestion, getPlugin( ) );
403 Collection<Answer> listAnswer = AnswerHome.getAnswersList( nIdQuestion, getPlugin( ) );
404
405 HashMap<String, Object> model = new HashMap<String, Object>( );
406 model.put( MARK_QUIZ, quiz );
407 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
408 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
409 model.put( MARK_QUESTION, quizQuestion );
410 model.put( MARK_ANSWER_LIST, listAnswer );
411
412 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_QUESTION, getLocale( ), model );
413
414 return getAdminPage( template.getHtml( ) );
415 }
416
417
418
419
420
421
422
423 public String doModifyQuizQuestion( HttpServletRequest request )
424 {
425 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
426 int nQuestionId = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
427 String strQuestion = request.getParameter( PARAMETER_QUESTION_LABEL );
428 String strExplaination = request.getParameter( PARAMETER_EXPLAINATION );
429
430
431 if ( StringUtils.isEmpty( strQuestion ) )
432 {
433 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
434 }
435
436 QuizQuestion quizQuestion = QuizQuestionHome.findByPrimaryKey( nQuestionId, getPlugin( ) );
437
438 quizQuestion.setQuestionLabel( strQuestion );
439 quizQuestion.setIdQuiz( nIdQuiz );
440 quizQuestion.setExplaination( strExplaination );
441 QuizQuestionHome.update( quizQuestion, getPlugin( ) );
442
443 UrlItem url = new UrlItem( JSP_URL_MANAGE_QUESTIONS );
444 url.addParameter( PARAMETER_QUIZ_ID, nIdQuiz );
445
446 return url.getUrl( );
447 }
448
449
450
451
452
453
454 public String getRandList( HttpServletRequest request )
455 {
456 setPageTitleProperty( PROPERTY_PAGE_TITLE_RAND_LIST );
457
458 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
459
460 Quiz quiz = QuizHome.findByPrimaryKey( nIdQuiz, getPlugin( ) );
461
462 HashMap<String, Object> model = new HashMap<String, Object>( );
463 model.put( MARK_QUIZ, quiz );
464
465
466 String askGenerate = request.getParameter( PARAMETER_ASK_GENERATE );
467 String nbWin = request.getParameter( PARAMETER_NB_WIN );
468 if ( StringUtils.isNotEmpty( askGenerate ) )
469 {
470
471 if ( StringUtils.isNotEmpty( nbWin ) )
472 {
473 Integer nNbWin = 0;
474 try
475 {
476 nNbWin = Integer.valueOf( nbWin );
477 }
478 catch ( NumberFormatException e )
479 {
480 model.put( MARK_ERROR,
481 I18nService.getLocalizedString( MESSAGE_NB_WIN_NOT_A_NUMBER, request.getLocale( ) ) );
482 }
483
484
485 List<QuizParticipant> listValidParticipant = this._randService.findAllValidByQuizId( nIdQuiz,
486 getPlugin( ) );
487
488
489 boolean nbWinValid = true;
490 if ( listValidParticipant != null && listValidParticipant.size( ) < nNbWin )
491 {
492 nbWinValid = false;
493 String[] args = new String[1];
494 args[0] = String.valueOf( listValidParticipant.size( ) );
495 model.put( MARK_ERROR, I18nService.getLocalizedString(
496 MESSAGE_NB_WIN_SUPERIOR_TO_NB_VALID_PARTICIPANT, args, request.getLocale( ) ) );
497 }
498 if ( nbWinValid )
499 {
500
501 if ( quiz.isEnabled( ) )
502 {
503 quiz.setStatus( 0 );
504 QuizHome.update( quiz, getPlugin( ) );
505 }
506
507 Collections.shuffle( listValidParticipant );
508
509
510
511 List<QuizParticipant> listWinParticipant = listValidParticipant.subList( 0, nNbWin );
512
513
514
515
516
517
518
519
520
521
522 model.put( MARK_LIST_WIN_PARTICIPANT, listWinParticipant );
523 }
524 }
525 else
526 {
527 model.put( MARK_ERROR, I18nService.getLocalizedString( MESSAGE_NB_WIN_MANDATORY, request.getLocale( ) ) );
528 }
529 }
530
531 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_RAND_LIST, getLocale( ), model );
532
533 return getAdminPage( template.getHtml( ) );
534 }
535
536
537
538
539
540
541
542 @Override
543 public String getRemoveQuiz( HttpServletRequest request )
544 {
545 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
546 Quiz quiz = QuizHome.findByPrimaryKey( nIdQuiz, getPlugin( ) );
547 String strAdminMessageUrl;
548 String strUrl;
549
550 if ( quiz.isEnabled( ) )
551 {
552 String strMessageKey = MESSAGE_CANNOT_DELETE_QUIZ;
553 strAdminMessageUrl = AdminMessageService.getMessageUrl( request, strMessageKey, JSP_MANAGE_QUIZ, "",
554 AdminMessage.TYPE_STOP );
555 }
556 else
557 {
558 strUrl = JSP_DO_REMOVE_QUIZ + "?" + PARAMETER_QUIZ_ID + "=" + nIdQuiz;
559
560 String strMessageKey = PROPERTY_CONFIRM_DELETE_QUIZ;
561 strAdminMessageUrl = AdminMessageService.getMessageUrl( request, strMessageKey, strUrl, "",
562 AdminMessage.TYPE_CONFIRMATION );
563 }
564
565 return strAdminMessageUrl;
566 }
567
568
569
570
571
572
573
574 @Override
575 public String doRemoveQuiz( HttpServletRequest request )
576 {
577 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
578 Quiz quiz = QuizHome.findByPrimaryKey( nIdQuiz, getPlugin( ) );
579 Collection<QuizQuestion> questions = QuizQuestionHome.findAll( nIdQuiz, getPlugin( ) );
580 quiz.setQuestions( questions );
581
582 QuestionGroupHome.removeByQuiz( nIdQuiz, getPlugin( ) );
583 QuizHome.remove( nIdQuiz, getPlugin( ) );
584 QuizQuestionHome.removeQuestionsByQuiz( nIdQuiz, getPlugin( ) );
585 this._randService.removeParticipantsByQuiz( nIdQuiz, getPlugin( ) );
586 AnswerHome.removeAnswersByQuestionList( questions, getPlugin( ) );
587
588
589 return getHomeUrl( request );
590 }
591
592
593
594
595
596
597 public String getCreateAnswer( HttpServletRequest request )
598 {
599 setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_ANSWER );
600
601 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
602 int nIdQuestion = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
603 Quiz quiz = QuizHome.findByPrimaryKey( nIdQuiz, getPlugin( ) );
604 QuizQuestion quizQuestion = QuizQuestionHome.findByPrimaryKey( nIdQuestion, getPlugin( ) );
605
606 HashMap<String, Object> model = new HashMap<String, Object>( );
607 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
608 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
609 model.put( MARK_QUIZ, quiz );
610 model.put( MARK_QUESTION, quizQuestion );
611 model.put( MARK_YESNO_LIST, getYesNoList( ) );
612
613 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_ANSWER, getLocale( ), model );
614
615 return getAdminPage( template.getHtml( ) );
616 }
617
618
619
620
621
622
623 public String getModifyAnswer( HttpServletRequest request )
624 {
625 int nIdQuiz = Integer.parseInt( request.getParameter( PARAMETER_QUIZ_ID ) );
626 Quiz quiz = QuizHome.findByPrimaryKey( nIdQuiz, getPlugin( ) );
627 int nIdQuestion = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
628 QuizQuestion question = QuizQuestionHome.findByPrimaryKey( nIdQuestion, getPlugin( ) );
629 int nIdAnswer = Integer.parseInt( request.getParameter( PARAMETER_ANSWER_ID ) );
630 Answer answer = AnswerHome.findByPrimaryKey( nIdAnswer, getPlugin( ) );
631
632 HashMap<String, Object> model = new HashMap<String, Object>( );
633 model.put( MARK_QUIZ, quiz );
634 model.put( MARK_QUESTION, question );
635 model.put( MARK_ANSWER, answer );
636 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
637 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
638 model.put( MARK_YESNO_LIST, getYesNoList( ) );
639
640 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_ANSWER, getLocale( ), model );
641
642 return getAdminPage( template.getHtml( ) );
643 }
644
645
646
647
648
649 private ReferenceList getYesNoList( )
650 {
651 ReferenceList list = new ReferenceList( );
652 list.addItem( 0, I18nService.getLocalizedString( PROPERTY_LABEL_NO, getLocale( ) ) );
653 list.addItem( 1, I18nService.getLocalizedString( PROPERTY_LABEL_YES, getLocale( ) ) );
654
655 return list;
656 }
657 }