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.newsletter.business.portlet;
35
36 import fr.paris.lutece.plugins.newsletter.service.NewsletterPlugin;
37 import fr.paris.lutece.portal.business.portlet.Portlet;
38 import fr.paris.lutece.portal.service.plugin.PluginService;
39 import fr.paris.lutece.util.sql.DAOUtil;
40
41 import java.util.HashSet;
42 import java.util.Set;
43
44
45
46
47 public final class NewsLetterSubscriptionPortletDAO implements INewsLetterSubscriptionPortletDAO
48 {
49
50 private static final String SQL_QUERY_SELECT = "SELECT id_portlet FROM core_portlet WHERE id_portlet = ?";
51 private static final String SQL_QUERY_SELECT_SUBSCRIPTION_BY_PORTLET = "SELECT id_newsletter FROM newsletter_portlet_subscribe WHERE id_portlet = ?";
52 private static final String SQL_QUERY_INSERT_NEWSLETTER = "INSERT INTO newsletter_portlet_subscribe( id_portlet, id_newsletter ) VALUES ( ?, ? )";
53 private static final String SQL_QUERY_DELETE_NEWSLETTER = "DELETE FROM newsletter_portlet_subscribe WHERE id_portlet = ? AND id_newsletter = ?";
54 private static final String SQL_QUERY_DELETE = "DELETE FROM newsletter_portlet_subscribe WHERE id_portlet=? ";
55
56
57
58
59
60
61
62
63
64
65 public void insert( Portlet portlet )
66 {
67
68 }
69
70
71
72
73
74
75
76
77 public void delete( int nPortletId )
78 {
79 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, PluginService.getPlugin( NewsletterPlugin.PLUGIN_NAME ) );
80 daoUtil.setInt( 1, nPortletId );
81 daoUtil.executeUpdate( );
82 daoUtil.free( );
83 }
84
85
86
87
88
89
90
91
92 public Portlet load( int nPortletId )
93 {
94 NewsLetterSubscriptionPortlet/portlet/NewsLetterSubscriptionPortlet.html#NewsLetterSubscriptionPortlet">NewsLetterSubscriptionPortlet portlet = new NewsLetterSubscriptionPortlet( );
95
96 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
97
98 daoUtil.setInt( 1, nPortletId );
99
100 daoUtil.executeQuery( );
101
102 if ( daoUtil.next( ) )
103 {
104 portlet.setId( nPortletId );
105 }
106
107 daoUtil.free( );
108
109 return portlet;
110 }
111
112
113
114
115
116
117
118 public void store( Portlet portlet )
119 {
120
121 }
122
123
124
125
126
127
128
129
130
131 public void insertSubscription( int nPortletId, int nNewsletterId )
132 {
133 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT_NEWSLETTER, PluginService.getPlugin( NewsletterPlugin.PLUGIN_NAME ) );
134 daoUtil.setInt( 1, nPortletId );
135 daoUtil.setInt( 2, nNewsletterId );
136
137 daoUtil.executeUpdate( );
138 daoUtil.free( );
139 }
140
141
142
143
144
145
146
147
148
149 public void removeSubscription( int nPortletId, int nNewsletterId )
150 {
151 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_NEWSLETTER, PluginService.getPlugin( NewsletterPlugin.PLUGIN_NAME ) );
152 daoUtil.setInt( 1, nPortletId );
153 daoUtil.setInt( 2, nNewsletterId );
154
155 daoUtil.executeUpdate( );
156 daoUtil.free( );
157 }
158
159
160
161
162
163
164
165
166 public Set<Integer> findSelectedNewsletters( int nPortletId )
167 {
168 HashSet<Integer> results = new HashSet<Integer>( );
169
170 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_SUBSCRIPTION_BY_PORTLET, PluginService.getPlugin( NewsletterPlugin.PLUGIN_NAME ) );
171 daoUtil.setInt( 1, nPortletId );
172 daoUtil.executeQuery( );
173
174 while ( daoUtil.next( ) )
175 {
176 results.add( Integer.valueOf( daoUtil.getInt( 1 ) ) );
177 }
178
179 daoUtil.free( );
180
181 return results;
182 }
183 }