1 /*
2 * Copyright (c) 2002-2020, City of 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.participatorybudget.business.vote;
35
36 import java.util.List;
37
38 import fr.paris.lutece.plugins.participatorybudget.util.ParticipatoryBudgetConstants;
39 import fr.paris.lutece.portal.service.plugin.Plugin;
40 import fr.paris.lutece.portal.service.plugin.PluginService;
41 import fr.paris.lutece.portal.service.spring.SpringContextService;
42
43 /**
44 * This class provides instances management methods (create, find, ...) for Vote objects
45 */
46 public final class VoteHistoryHome
47 {
48 // Static variable pointed at the DAO instance
49 private static IVoteHistoryDAO./../../../../fr/paris/lutece/plugins/participatorybudget/business/vote/IVoteHistoryDAO.html#IVoteHistoryDAO">IVoteHistoryDAO _dao = (IVoteHistoryDAO) SpringContextService.getBean( "participatorybudget.voteHistoryDAO" );
50 private static Plugin _plugin = PluginService.getPlugin( ParticipatoryBudgetConstants.PLUGIN_NAME );
51
52 /**
53 * Private constructor - this class need not be instantiated
54 */
55 private VoteHistoryHome( )
56 {
57 }
58
59 /**
60 * Create an instance of the vote class
61 *
62 * @param vote
63 * The instance of the Vote which contains the informations to store
64 * @return The instance of vote which has been created with its primary key.
65 */
66 public static Voteef="../../../../../../../fr/paris/lutece/plugins/participatorybudget/business/vote/Vote.html#Vote">Vote create( Vote vote )
67 {
68 _dao.insert( vote, _plugin );
69
70 return vote;
71 }
72
73 /**
74 * Remove the vote whose identifier is specified in parameter
75 *
76 * @param nVoteId
77 * The vote Id
78 * @param plugin
79 * the Plugin
80 */
81 public static void remove( String strUserId, int nProjetId )
82 {
83 _dao.delete( strUserId, nProjetId, _plugin );
84 }
85
86 /**
87 * Load the data of all the vote objects and returns them in form of a list
88 *
89 * @return the list which contains the data of all the vote objects
90 */
91 public static List<Vote> getVotesList( )
92 {
93 return _dao.selectVotesList( _plugin );
94 }
95
96 /**
97 *
98 * @param nUserId
99 * @param nProjetId
100 */
101 public static void removeAll( String strUserId )
102 {
103 _dao.deleteAll( strUserId, _plugin );
104 }
105
106 /**
107 *
108 * @param nUserId
109 * @return
110 */
111 public static List<Vote> getVoteUser( String strUserId )
112 {
113 return _dao.selectVotesUser( strUserId, _plugin );
114 }
115
116 /**
117 *
118 * @param nUserId
119 * @param nLocation
120 * @return
121 */
122 public static int getVoteUserArrondissement( String strUserId, int nLocation )
123 {
124 return _dao.countNbVotesUserArrondissement( strUserId, nLocation, _plugin );
125 }
126
127 /**
128 *
129 * @param nUserId
130 * @param nLocation
131 * @return
132 */
133 public static int getVoteUserNotLocation( String strUserId, int nLocation )
134 {
135 return _dao.countNbVotesUser( strUserId, nLocation, _plugin );
136 }
137
138 /**
139 *
140 * @param strUserId
141 * @param nIdProject
142 * @return
143 */
144 public static Vote getVoteUser( String strUserId, int nIdProject )
145 {
146 return _dao.selectVoteUser( strUserId, nIdProject, _plugin );
147 }
148
149 /**
150 *
151 * @param nStatus
152 * @return
153 */
154 public static List<Vote> selectVotesListByExportStatus( int nStatus )
155 {
156 return _dao.selectVotesListByExportStatus( _plugin, nStatus );
157 }
158
159 /**
160 *
161 * @param nIdVote
162 * @param nTag
163 */
164 public static void updateVoteHistoryTag( Vote vote, int nTag )
165 {
166 _dao.updateTagStats( vote, nTag, _plugin );
167 }
168
169 }