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 import fr.paris.lutece.util.ReferenceList;
39
40 import java.util.List;
41
42
43 /**
44 * This class provides instances management methods (create, find, ...) for
45 * QuestionGroup objects
46 */
47 public final class QuestionGroupHome
48 {
49 // Static variable pointed at the DAO instance
50 private static IQuestionGroupDAO _dao = SpringContextService.getBean( "quiz.questionGroupDAO" );
51
52 /**
53 * Private constructor - this class need not be instantiated
54 */
55 private QuestionGroupHome( )
56 {
57 }
58
59 /**
60 * Create an instance of the group class
61 * @param nIdQuiz The quiz ID
62 * @param group The instance of the QuestionGroup which contains the
63 * informations to store
64 * @param plugin the Plugin
65 * @return The instance of group which has been created with its primary
66 * key.
67 */
68 public static QuestionGroup create( int nIdQuiz, QuestionGroup group, Plugin plugin )
69 {
70 _dao.insert( nIdQuiz, group, plugin );
71
72 return group;
73 }
74
75 /**
76 * Update of the group which is specified in parameter
77 * @param group The instance of the QuestionGroup which contains the data to
78 * store
79 * @param plugin the Plugin
80 * @return The instance of the group which has been updated
81 */
82 public static QuestionGroup update( QuestionGroup group, Plugin plugin )
83 {
84 _dao.store( group, plugin );
85
86 return group;
87 }
88
89 /**
90 * Remove the group whose identifier is specified in parameter
91 * @param nIdQuiz The quiz ID
92 * @param nGroupId The group Id
93 * @param plugin the Plugin
94 */
95 public static void remove( int nIdQuiz, int nGroupId, Plugin plugin )
96 {
97 _dao.delete( nIdQuiz, nGroupId, plugin );
98 }
99
100 ///////////////////////////////////////////////////////////////////////////
101 // Finders
102
103 /**
104 * Returns an instance of a group whose identifier is specified in parameter
105 * @param nKey The group primary key
106 * @param plugin the Plugin
107 * @return an instance of QuestionGroup
108 */
109 public static QuestionGroup findByPrimaryKey( int nKey, Plugin plugin )
110 {
111 return _dao.load( nKey, plugin );
112 }
113
114 /**
115 * Load the data of every group objects attached to a given quiz and returns
116 * them in a list
117 * @param nIdQuiz The quiz ID
118 * @param plugin the Plugin
119 * @return the list which contains the data of all the group objects
120 */
121 public static List<QuestionGroup> getGroupsList( int nIdQuiz, Plugin plugin )
122 {
123 return _dao.selectQuestionGroupsList( nIdQuiz, plugin );
124 }
125
126 /**
127 * Find a group by its quiz and position
128 * @param nIdQuiz The quiz ID
129 * @param nPosition The position of the required group
130 * @param plugin the Plugin
131 * @return The requested group, or null if no group has the given position
132 */
133 public static QuestionGroup getGroupByPosition( int nIdQuiz, int nPosition, Plugin plugin )
134 {
135 return _dao.selectQuestionGroupByPosition( nIdQuiz, nPosition, plugin );
136 }
137
138 /**
139 * Select the list of Groups
140 * @param nIdQuiz The quiz ID
141 * @return Groups list
142 * @param plugin plugin Quiz
143 */
144 public static ReferenceList getGroupsReferenceList( int nIdQuiz, Plugin plugin )
145 {
146 return _dao.selectQuestionGroupsReferenceList( nIdQuiz, plugin );
147 }
148
149 /**
150 * Remove a group for a given quiz
151 * @param nIdQuiz The quiz id
152 * @param plugin The plugin
153 */
154 public static void removeByQuiz( int nIdQuiz, Plugin plugin )
155 {
156 _dao.deleteByQuiz( nIdQuiz, plugin );
157 }
158
159 /**
160 * Move up a group
161 * @param nIdQuiz The quiz id
162 * @param group The group
163 * @param plugin The plugin
164 */
165 public static void moveUpGroup( int nIdQuiz, QuestionGroup group, Plugin plugin )
166 {
167 _dao.changePositionUp( nIdQuiz, group, plugin );
168 }
169
170 /**
171 * Move down a group
172 * @param nIdQuiz The quiz id
173 * @param group The group
174 * @param plugin The plugin
175 */
176 public static void moveDownGroup( int nIdQuiz, QuestionGroup group, Plugin plugin )
177 {
178 _dao.changePositionDown( nIdQuiz, group, plugin );
179 }
180
181 /**
182 * Find the id of last group in quiz
183 * @param nIdQuiz the quiz id
184 * @param plugin the plugin
185 * @return the id of corresponding group
186 */
187 public static int findLastByQuiz( int nIdQuiz, Plugin plugin )
188 {
189 return _dao.findLastByQuiz( nIdQuiz, plugin );
190 }
191
192 /**
193 * Check if a quiz has a free HTML group that will display the result of the
194 * quiz
195 * @param nIdQuiz The id of the quiz
196 * @param plugin The plugin
197 * @return True if the quiz has a free HTML group that will display the
198 * result of the quiz, false otherwise
199 */
200 public static boolean hasGroupDisplayScore( int nIdQuiz, Plugin plugin )
201 {
202 return _dao.hasGroupDisplayScore( nIdQuiz, plugin );
203 }
204 }