1 /*
2 * Copyright (c) 2002-2014, Mairie de Paris
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice
10 * and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice
13 * and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * License 1.0
33 */
34 package fr.paris.lutece.plugins.quiz.business;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.portal.service.spring.SpringContextService;
38
39 import java.util.Collection;
40
41
42 /**
43 * This class provides instances management methods (create, find, ...) for
44 * QuizQuestion objects
45 */
46 public final class QuizQuestionHome
47 {
48 private static IQuizQuestionDAO _dao = SpringContextService.getBean( "quiz.questionDAO" );
49
50 /**
51 * Private constructor - this class need not be instantiated
52 */
53 private QuizQuestionHome( )
54 {
55 }
56
57 /**
58 * Creation of an instance of an article QuizQuestion
59 *
60 * @param quizQuestion An instance of the QuizQuestion which contains the
61 * informations to store
62 * @param plugin the plugin
63 * @return The instance of the QuizQuestion which has been created
64 */
65 public static QuizQuestion create( QuizQuestion quizQuestion, Plugin plugin )
66 {
67 _dao.insert( quizQuestion, plugin );
68
69 return quizQuestion;
70 }
71
72 /**
73 * Updates of the QuizQuestion instance specified in parameter
74 *
75 * @param question An instance of the QuizQuestion which contains the
76 * informations to store
77 * @param plugin the plugin
78 * @return The instance of the QuizQuestion which has been updated.
79 */
80 public static QuizQuestion update( QuizQuestion question, Plugin plugin )
81 {
82 _dao.store( question, plugin );
83
84 return question;
85 }
86
87 /**
88 * Deletes the QuizQuestion instance whose identifier is specified in
89 * parameter
90 *
91 * @param nIdQuestion The identifier of the article QuizQuestion to delete
92 * in the database
93 * @param plugin the plugin
94 */
95 public static void remove( int nIdQuestion, Plugin plugin )
96 {
97 _dao.delete( nIdQuestion, plugin );
98 }
99
100 /**
101 * Deletes the QuizQuestion instance whose identifier is specified in
102 * parameter
103 *
104 * @param nQuiz The identifier of the article QuizQuestion to delete in the
105 * database
106 * @param plugin the plugin
107 */
108 public static void removeQuestionsByQuiz( int nQuiz, Plugin plugin )
109 {
110 _dao.deleteQuestionsByQuiz( nQuiz, plugin );
111 }
112
113 /**
114 * Returns an instance of the article QuizQuestion whose identifier is
115 * specified in parameter
116 *
117 * @param nKey The primary key of the article to find in the database
118 * @param plugin the plugin
119 * @return An instance of the QuizQuestion which corresponds to the key
120 */
121 public static QuizQuestion findByPrimaryKey( int nKey, Plugin plugin )
122 {
123 return _dao.load( nKey, plugin );
124 }
125
126 /**
127 * Returns QuizQuestion list
128 *
129 * @param plugin the plugin
130 * @param nIdQuiz The identifier of the article Quiz to find it in the
131 * database
132 * @return the list of the QuizQuestion of the database in form of a
133 * QuizQuestion Collection object
134 */
135 public static Collection<QuizQuestion> findAll( int nIdQuiz, Plugin plugin )
136 {
137 return _dao.selectQuestionsList( nIdQuiz, plugin );
138 }
139
140 /**
141 * Gets a list of questions for a group
142 * @param nIdQuiz The Quiz id
143 * @param nIdGroup The group id
144 * @param plugin The plugin
145 * @return The list
146 */
147 public static Collection<Integer> findIdQuestionsByGroup( int nIdQuiz, int nIdGroup, Plugin plugin )
148 {
149 return _dao.getVerifyQuestionsByGroup( nIdQuiz, nIdGroup, plugin );
150 }
151
152 /**
153 * Gets a list of questions for a group
154 * @param nIdQuiz The Quiz id
155 * @param nIdGroup The group id
156 * @param plugin The plugin
157 * @return The list
158 */
159 public static Collection<QuizQuestion> findQuestionsByGroup( int nIdQuiz, int nIdGroup, Plugin plugin )
160 {
161 return _dao.selectQuestionsByGroup( nIdQuiz, nIdGroup, plugin );
162 }
163
164 /**
165 * Deletes the QuizQuestions instance by Group
166 *
167 * @param nIdQuiz The identifier of the article Quiz to delete in the
168 * database
169 * @param nIdGroup the id of the group
170 * @param plugin the plugin
171 */
172 public static void removeQuestionsByGroup( int nIdQuiz, int nIdGroup, Plugin plugin )
173 {
174 _dao.deleteQuestionsByGroup( nIdQuiz, nIdGroup, plugin );
175 }
176
177 /**
178 * Returns an instance of the article QuizQuestion whose identifier is
179 * specified in parameter
180 *
181 * @param plugin the plugin
182 * @return An instance of the QuizQuestion which corresponds to the key
183 */
184 public static QuizQuestion findLastQuestion( Plugin plugin )
185 {
186 return _dao.loadLastQuestion( plugin );
187 }
188
189 /**
190 * Gets a list of questions that has at least one answer
191 * @param nIdQuiz the Quiz Id
192 * @param plugin The plugin
193 * @return a list of questions
194 */
195 public static Collection<QuizQuestion> findQuestionsWithAnswer( int nIdQuiz, Plugin plugin )
196 {
197 return _dao.selectQuestionsListWithAnswer( nIdQuiz, plugin );
198 }
199
200 /**
201 * Gets a list of questions that has at least one answer and re associated
202 * with a given group
203 * @param nIdQuiz the Quiz Id
204 * @param nIdGroup The id of the group
205 * @param plugin The plugin
206 * @return a list of questions
207 */
208 public static Collection<QuizQuestion> findQuestionsWithAnswerByIdGroup( int nIdQuiz, int nIdGroup, Plugin plugin )
209 {
210 return _dao.selectQuestionsListWithAnswerByIdGroup( nIdQuiz, nIdGroup, plugin );
211 }
212 }